|
Lines 128-148
sub raw_transport {
Link Here
|
| 128 |
my $service = $self->{service}; |
128 |
my $service = $self->{service}; |
| 129 |
|
129 |
|
| 130 |
while (!$self->{account}) { |
130 |
while (!$self->{account}) { |
| 131 |
local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; }; |
131 |
local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; }; |
| 132 |
syslog("LOG_DEBUG", "raw_transport: timeout is %d", $service->{timeout}); |
132 |
syslog("LOG_DEBUG", "raw_transport: timeout is %d", $service->{timeout}); |
| 133 |
$input = read_SIP_packet(*STDIN); |
133 |
$input = read_SIP_packet(*STDIN); |
| 134 |
if (!$input) { |
134 |
if (!$input) { |
| 135 |
# EOF on the socket |
135 |
# EOF on the socket |
| 136 |
syslog("LOG_INFO", "raw_transport: shutting down: EOF during login"); |
136 |
syslog("LOG_INFO", "raw_transport: shutting down: EOF during login"); |
| 137 |
return; |
137 |
return; |
| 138 |
} |
138 |
} |
| 139 |
$input =~ s/[\r\n]+$//sm; # Strip off trailing line terminator(s) |
139 |
$input =~ s/[\r\n]+$//sm; # Strip off trailing line terminator(s) |
| 140 |
last if C4::SIP::Sip::MsgType::handle($input, $self, LOGIN); |
140 |
last if C4::SIP::Sip::MsgType::handle($input, $self, LOGIN); |
| 141 |
} |
141 |
} |
| 142 |
|
142 |
|
| 143 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
143 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
| 144 |
$self->{account}->{id}, |
144 |
$self->{account}->{id}, |
| 145 |
$self->{account}->{institution}); |
145 |
$self->{account}->{institution}); |
| 146 |
|
146 |
|
| 147 |
$self->sip_protocol_loop(); |
147 |
$self->sip_protocol_loop(); |
| 148 |
syslog("LOG_INFO", "raw_transport: shutting down"); |
148 |
syslog("LOG_INFO", "raw_transport: shutting down"); |
|
Lines 179-233
sub telnet_transport {
Link Here
|
| 179 |
my $account = undef; |
179 |
my $account = undef; |
| 180 |
my $input; |
180 |
my $input; |
| 181 |
my $config = $self->{config}; |
181 |
my $config = $self->{config}; |
| 182 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
182 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
| 183 |
syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout); |
183 |
syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout); |
| 184 |
|
184 |
|
| 185 |
eval { |
185 |
eval { |
| 186 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
186 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
| 187 |
local $| = 1; # Unbuffered output |
187 |
local $| = 1; # Unbuffered output |
| 188 |
$/ = "\015"; # Internet Record Separator (lax version) |
188 |
$/ = "\015"; # Internet Record Separator (lax version) |
| 189 |
# Until the terminal has logged in, we don't trust it |
189 |
# Until the terminal has logged in, we don't trust it |
| 190 |
# so use a timeout to protect ourselves from hanging. |
190 |
# so use a timeout to protect ourselves from hanging. |
| 191 |
|
191 |
|
| 192 |
while ($strikes--) { |
192 |
while ($strikes--) { |
| 193 |
print "login: "; |
193 |
print "login: "; |
| 194 |
alarm $timeout; |
194 |
alarm $timeout; |
| 195 |
# $uid = &get_clean_input; |
195 |
# $uid = &get_clean_input; |
| 196 |
$uid = <STDIN>; |
196 |
$uid = <STDIN>; |
| 197 |
print "password: "; |
197 |
print "password: "; |
| 198 |
# $pwd = &get_clean_input || ''; |
198 |
# $pwd = &get_clean_input || ''; |
| 199 |
$pwd = <STDIN>; |
199 |
$pwd = <STDIN>; |
| 200 |
alarm 0; |
200 |
alarm 0; |
| 201 |
|
201 |
|
| 202 |
syslog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
202 |
syslog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
| 203 |
$uid = get_clean_string ($uid); |
203 |
$uid = get_clean_string ($uid); |
| 204 |
$pwd = get_clean_string ($pwd); |
204 |
$pwd = get_clean_string ($pwd); |
| 205 |
syslog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
205 |
syslog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
| 206 |
|
206 |
|
| 207 |
if (exists ($config->{accounts}->{$uid}) |
207 |
if( exists ($config->{accounts}->{$uid}) && ($pwd eq $config->{accounts}->{$uid}->{password})) { |
| 208 |
&& ($pwd eq $config->{accounts}->{$uid}->{password})) { |
208 |
$account = $config->{accounts}->{$uid}; |
| 209 |
$account = $config->{accounts}->{$uid}; |
209 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
| 210 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
210 |
last; |
| 211 |
last; |
211 |
} |
| 212 |
} |
212 |
} |
| 213 |
} |
213 |
syslog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
| 214 |
syslog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
214 |
print("Invalid login$CRLF"); |
| 215 |
print("Invalid login$CRLF"); |
215 |
} |
| 216 |
} |
|
|
| 217 |
}; # End of eval |
216 |
}; # End of eval |
| 218 |
|
217 |
|
| 219 |
if ($@) { |
218 |
if ($@) { |
| 220 |
syslog("LOG_ERR", "telnet_transport: Login timed out"); |
219 |
syslog("LOG_ERR", "telnet_transport: Login timed out"); |
| 221 |
die "Telnet Login Timed out"; |
220 |
die "Telnet Login Timed out"; |
| 222 |
} elsif (!defined($account)) { |
221 |
} elsif (!defined($account)) { |
| 223 |
syslog("LOG_ERR", "telnet_transport: Login Failed"); |
222 |
syslog("LOG_ERR", "telnet_transport: Login Failed"); |
| 224 |
die "Login Failure"; |
223 |
die "Login Failure"; |
| 225 |
} else { |
224 |
} else { |
| 226 |
print "Login OK. Initiating SIP$CRLF"; |
225 |
print "Login OK. Initiating SIP$CRLF"; |
| 227 |
} |
226 |
} |
| 228 |
|
227 |
|
| 229 |
$self->{account} = $account; |
228 |
$self->{account} = $account; |
| 230 |
syslog("LOG_DEBUG", "telnet_transport: uname/inst: '%s/%s'", $account->{id}, $account->{institution}); |
229 |
syslog("LOG_DEBUG", "telnet_transport: uname/inst: '%s/%s'", |
|
|
230 |
$account->{id}, $account->{institution}); |
| 231 |
$self->sip_protocol_loop(); |
231 |
$self->sip_protocol_loop(); |
| 232 |
syslog("LOG_INFO", "telnet_transport: shutting down"); |
232 |
syslog("LOG_INFO", "telnet_transport: shutting down"); |
| 233 |
} |
233 |
} |
|
Lines 238-252
sub telnet_transport {
Link Here
|
| 238 |
# telnet transport. From that point on, both the raw and the telnet |
238 |
# telnet transport. From that point on, both the raw and the telnet |
| 239 |
# processes are the same: |
239 |
# processes are the same: |
| 240 |
sub sip_protocol_loop { |
240 |
sub sip_protocol_loop { |
| 241 |
my $self = shift; |
241 |
my $self = shift; |
| 242 |
my $service = $self->{service}; |
242 |
my $service = $self->{service}; |
| 243 |
my $config = $self->{config}; |
243 |
my $config = $self->{config}; |
| 244 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
244 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
| 245 |
my $input; |
245 |
my $input; |
| 246 |
|
246 |
|
| 247 |
# The spec says the first message will be: |
247 |
# The spec says the first message will be: |
| 248 |
# SIP v1: SC_STATUS |
248 |
# SIP v1: SC_STATUS |
| 249 |
# SIP v2: LOGIN (or SC_STATUS via telnet?) |
249 |
# SIP v2: LOGIN (or SC_STATUS via telnet?) |
| 250 |
# But it might be SC_REQUEST_RESEND. As long as we get |
250 |
# But it might be SC_REQUEST_RESEND. As long as we get |
| 251 |
# SC_REQUEST_RESEND, we keep waiting. |
251 |
# SC_REQUEST_RESEND, we keep waiting. |
| 252 |
|
252 |
|
|
Lines 254-294
sub sip_protocol_loop {
Link Here
|
| 254 |
# constraint, so we'll relax about it too. |
254 |
# constraint, so we'll relax about it too. |
| 255 |
# Using the SIP "raw" login process, rather than telnet, |
255 |
# Using the SIP "raw" login process, rather than telnet, |
| 256 |
# requires the LOGIN message and forces SIP 2.00. In that |
256 |
# requires the LOGIN message and forces SIP 2.00. In that |
| 257 |
# case, the LOGIN message has already been processed (above). |
257 |
# case, the LOGIN message has already been processed (above). |
| 258 |
# |
258 |
# |
| 259 |
# In short, we'll take any valid message here. |
259 |
# In short, we'll take any valid message here. |
| 260 |
#my $expect = SC_STATUS; |
260 |
#my $expect = SC_STATUS; |
| 261 |
local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; }; |
261 |
local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; }; |
| 262 |
my $expect = ''; |
262 |
my $expect = ''; |
| 263 |
while (1) { |
263 |
while (1) { |
| 264 |
alarm $timeout; |
264 |
alarm $timeout; |
| 265 |
$input = read_SIP_packet(*STDIN); |
265 |
$input = read_SIP_packet(*STDIN); |
| 266 |
unless ($input) { |
266 |
unless ($input) { |
| 267 |
return; # EOF |
267 |
return; # EOF |
| 268 |
} |
268 |
} |
| 269 |
# begin input hacks ... a cheap stand in for better Telnet layer |
269 |
# begin input hacks ... a cheap stand in for better Telnet layer |
| 270 |
$input =~ s/^[^A-z0-9]+//s; # Kill leading bad characters... like Telnet handshakers |
270 |
$input =~ s/^[^A-z0-9]+//s; # Kill leading bad characters... like Telnet handshakers |
| 271 |
$input =~ s/[^A-z0-9]+$//s; # Same on the end, should get DOSsy ^M line-endings too. |
271 |
$input =~ s/[^A-z0-9]+$//s; # Same on the end, should get DOSsy ^M line-endings too. |
| 272 |
while (chomp($input)) {warn "Extra line ending on input";} |
272 |
while (chomp($input)) {warn "Extra line ending on input";} |
| 273 |
unless ($input) { |
273 |
unless ($input) { |
| 274 |
syslog("LOG_ERR", "sip_protocol_loop: empty input skipped"); |
274 |
syslog("LOG_ERR", "sip_protocol_loop: empty input skipped"); |
| 275 |
print("96$CR"); |
275 |
print("96$CR"); |
| 276 |
next; |
276 |
next; |
| 277 |
} |
277 |
} |
| 278 |
# end cheap input hacks |
278 |
# end cheap input hacks |
| 279 |
my $status = handle($input, $self, $expect); |
279 |
my $status = handle($input, $self, $expect); |
| 280 |
if (!$status) { |
280 |
if (!$status) { |
| 281 |
syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2)); |
281 |
syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2)); |
| 282 |
} |
282 |
} |
| 283 |
next if $status eq REQUEST_ACS_RESEND; |
283 |
next if $status eq REQUEST_ACS_RESEND; |
| 284 |
if ($expect && ($status ne $expect)) { |
284 |
if ($expect && ($status ne $expect)) { |
| 285 |
# We received a non-"RESEND" that wasn't what we were expecting. |
285 |
# We received a non-"RESEND" that wasn't what we were expecting. |
| 286 |
syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input); |
286 |
syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input); |
| 287 |
} |
287 |
} |
| 288 |
# We successfully received and processed what we were expecting |
288 |
# We successfully received and processed what we were expecting |
| 289 |
$expect = ''; |
289 |
$expect = ''; |
| 290 |
alarm 0; |
290 |
alarm 0; |
| 291 |
} |
291 |
} |
| 292 |
} |
292 |
} |
| 293 |
|
293 |
|
| 294 |
1; |
294 |
1; |
| 295 |
- |
|
|