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_request(); |
133 |
$input = read_request(); |
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 180-234
sub telnet_transport {
Link Here
|
180 |
my $account = undef; |
180 |
my $account = undef; |
181 |
my $input; |
181 |
my $input; |
182 |
my $config = $self->{config}; |
182 |
my $config = $self->{config}; |
183 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
183 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
184 |
syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout); |
184 |
syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout); |
185 |
|
185 |
|
186 |
eval { |
186 |
eval { |
187 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
187 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
188 |
local $| = 1; # Unbuffered output |
188 |
local $| = 1; # Unbuffered output |
189 |
$/ = "\015"; # Internet Record Separator (lax version) |
189 |
$/ = "\015"; # Internet Record Separator (lax version) |
190 |
# Until the terminal has logged in, we don't trust it |
190 |
# Until the terminal has logged in, we don't trust it |
191 |
# so use a timeout to protect ourselves from hanging. |
191 |
# so use a timeout to protect ourselves from hanging. |
192 |
|
192 |
|
193 |
while ($strikes--) { |
193 |
while ($strikes--) { |
194 |
print "login: "; |
194 |
print "login: "; |
195 |
alarm $timeout; |
195 |
alarm $timeout; |
196 |
# $uid = &get_clean_input; |
196 |
# $uid = &get_clean_input; |
197 |
$uid = <STDIN>; |
197 |
$uid = <STDIN>; |
198 |
print "password: "; |
198 |
print "password: "; |
199 |
# $pwd = &get_clean_input || ''; |
199 |
# $pwd = &get_clean_input || ''; |
200 |
$pwd = <STDIN>; |
200 |
$pwd = <STDIN>; |
201 |
alarm 0; |
201 |
alarm 0; |
202 |
|
202 |
|
203 |
syslog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
203 |
syslog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
204 |
$uid = get_clean_string ($uid); |
204 |
$uid = get_clean_string ($uid); |
205 |
$pwd = get_clean_string ($pwd); |
205 |
$pwd = get_clean_string ($pwd); |
206 |
syslog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
206 |
syslog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
207 |
|
207 |
|
208 |
if (exists ($config->{accounts}->{$uid}) |
208 |
if( exists ($config->{accounts}->{$uid}) && ($pwd eq $config->{accounts}->{$uid}->{password})) { |
209 |
&& ($pwd eq $config->{accounts}->{$uid}->{password})) { |
209 |
$account = $config->{accounts}->{$uid}; |
210 |
$account = $config->{accounts}->{$uid}; |
210 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
211 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
211 |
last; |
212 |
last; |
212 |
} |
213 |
} |
213 |
} |
214 |
} |
214 |
syslog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
215 |
syslog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
215 |
print("Invalid login$CRLF"); |
216 |
print("Invalid login$CRLF"); |
216 |
} |
217 |
} |
|
|
218 |
}; # End of eval |
217 |
}; # End of eval |
219 |
|
218 |
|
220 |
if ($@) { |
219 |
if ($@) { |
221 |
syslog("LOG_ERR", "telnet_transport: Login timed out"); |
220 |
syslog("LOG_ERR", "telnet_transport: Login timed out"); |
222 |
die "Telnet Login Timed out"; |
221 |
die "Telnet Login Timed out"; |
223 |
} elsif (!defined($account)) { |
222 |
} elsif (!defined($account)) { |
224 |
syslog("LOG_ERR", "telnet_transport: Login Failed"); |
223 |
syslog("LOG_ERR", "telnet_transport: Login Failed"); |
225 |
die "Login Failure"; |
224 |
die "Login Failure"; |
226 |
} else { |
225 |
} else { |
227 |
print "Login OK. Initiating SIP$CRLF"; |
226 |
print "Login OK. Initiating SIP$CRLF"; |
228 |
} |
227 |
} |
229 |
|
228 |
|
230 |
$self->{account} = $account; |
229 |
$self->{account} = $account; |
231 |
syslog("LOG_DEBUG", "telnet_transport: uname/inst: '%s/%s'", $account->{id}, $account->{institution}); |
230 |
syslog("LOG_DEBUG", "telnet_transport: uname/inst: '%s/%s'", |
|
|
231 |
$account->{id}, $account->{institution}); |
232 |
$self->sip_protocol_loop(); |
232 |
$self->sip_protocol_loop(); |
233 |
syslog("LOG_INFO", "telnet_transport: shutting down"); |
233 |
syslog("LOG_INFO", "telnet_transport: shutting down"); |
234 |
return; |
234 |
return; |
Lines 240-253
sub telnet_transport {
Link Here
|
240 |
# telnet transport. From that point on, both the raw and the telnet |
240 |
# telnet transport. From that point on, both the raw and the telnet |
241 |
# processes are the same: |
241 |
# processes are the same: |
242 |
sub sip_protocol_loop { |
242 |
sub sip_protocol_loop { |
243 |
my $self = shift; |
243 |
my $self = shift; |
244 |
my $service = $self->{service}; |
244 |
my $service = $self->{service}; |
245 |
my $config = $self->{config}; |
245 |
my $config = $self->{config}; |
246 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
246 |
my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; |
247 |
|
247 |
|
248 |
# The spec says the first message will be: |
248 |
# The spec says the first message will be: |
249 |
# SIP v1: SC_STATUS |
249 |
# SIP v1: SC_STATUS |
250 |
# SIP v2: LOGIN (or SC_STATUS via telnet?) |
250 |
# SIP v2: LOGIN (or SC_STATUS via telnet?) |
251 |
# But it might be SC_REQUEST_RESEND. As long as we get |
251 |
# But it might be SC_REQUEST_RESEND. As long as we get |
252 |
# SC_REQUEST_RESEND, we keep waiting. |
252 |
# SC_REQUEST_RESEND, we keep waiting. |
253 |
|
253 |
|
Lines 255-263
sub sip_protocol_loop {
Link Here
|
255 |
# constraint, so we'll relax about it too. |
255 |
# constraint, so we'll relax about it too. |
256 |
# Using the SIP "raw" login process, rather than telnet, |
256 |
# Using the SIP "raw" login process, rather than telnet, |
257 |
# requires the LOGIN message and forces SIP 2.00. In that |
257 |
# requires the LOGIN message and forces SIP 2.00. In that |
258 |
# case, the LOGIN message has already been processed (above). |
258 |
# case, the LOGIN message has already been processed (above). |
259 |
# |
259 |
# |
260 |
# In short, we'll take any valid message here. |
260 |
# In short, we'll take any valid message here. |
261 |
eval { |
261 |
eval { |
262 |
local $SIG{ALRM} = sub { |
262 |
local $SIG{ALRM} = sub { |
263 |
syslog( 'LOG_DEBUG', 'Inactive: timed out' ); |
263 |
syslog( 'LOG_DEBUG', 'Inactive: timed out' ); |
264 |
- |
|
|