Lines 30-36
use base qw(Net::Server::PreFork);
Link Here
|
30 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
30 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
31 |
|
31 |
|
32 |
# |
32 |
# |
33 |
# Main # not really, since package SIPServer |
33 |
# Main # not really, since package SIPServer |
34 |
# |
34 |
# |
35 |
# FIXME: Is this a module or a script? |
35 |
# FIXME: Is this a module or a script? |
36 |
# A script with no MAIN namespace? |
36 |
# A script with no MAIN namespace? |
Lines 75-81
foreach my $svc (keys %{$config->{listeners}}) {
Link Here
|
75 |
# |
75 |
# |
76 |
if (defined($config->{'server-params'})) { |
76 |
if (defined($config->{'server-params'})) { |
77 |
while (my ($key, $val) = each %{$config->{'server-params'}}) { |
77 |
while (my ($key, $val) = each %{$config->{'server-params'}}) { |
78 |
push @parms, $key . '=' . $val; |
78 |
push @parms, $key . '=' . $val; |
79 |
} |
79 |
} |
80 |
} |
80 |
} |
81 |
|
81 |
|
Lines 125-141
sub process_request {
Link Here
|
125 |
$self->{service} = $config->find_service($sockaddr, $port, $proto); |
125 |
$self->{service} = $config->find_service($sockaddr, $port, $proto); |
126 |
|
126 |
|
127 |
if (!defined($self->{service})) { |
127 |
if (!defined($self->{service})) { |
128 |
siplog("LOG_ERR", "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto); |
128 |
siplog("LOG_ERR", "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto); |
129 |
die "process_request: Bad server connection"; |
129 |
die "process_request: Bad server connection"; |
130 |
} |
130 |
} |
131 |
|
131 |
|
132 |
$transport = $transports{$self->{service}->{transport}}; |
132 |
$transport = $transports{$self->{service}->{transport}}; |
133 |
|
133 |
|
134 |
if (!defined($transport)) { |
134 |
if (!defined($transport)) { |
135 |
siplog("LOG_WARNING", "Unknown transport '%s', dropping", $service->{transport}); |
135 |
siplog("LOG_WARNING", "Unknown transport '%s', dropping", $service->{transport}); |
136 |
return; |
136 |
return; |
137 |
} else { |
137 |
} else { |
138 |
&$transport($self); |
138 |
&$transport($self); |
139 |
} |
139 |
} |
140 |
return; |
140 |
return; |
141 |
} |
141 |
} |
Lines 201-227
sub raw_transport {
Link Here
|
201 |
} |
201 |
} |
202 |
|
202 |
|
203 |
sub get_clean_string { |
203 |
sub get_clean_string { |
204 |
my $string = shift; |
204 |
my $string = shift; |
205 |
if (defined $string) { |
205 |
if (defined $string) { |
206 |
siplog("LOG_DEBUG", "get_clean_string pre-clean(length %s): %s", length($string), $string); |
206 |
siplog("LOG_DEBUG", "get_clean_string pre-clean(length %s): %s", length($string), $string); |
207 |
chomp($string); |
207 |
chomp($string); |
208 |
$string =~ s/^[^A-z0-9]+//; |
208 |
$string =~ s/^[^A-z0-9]+//; |
209 |
$string =~ s/[^A-z0-9]+$//; |
209 |
$string =~ s/[^A-z0-9]+$//; |
210 |
siplog("LOG_DEBUG", "get_clean_string post-clean(length %s): %s", length($string), $string); |
210 |
siplog("LOG_DEBUG", "get_clean_string post-clean(length %s): %s", length($string), $string); |
211 |
} else { |
211 |
} else { |
212 |
siplog("LOG_INFO", "get_clean_string called on undefined"); |
212 |
siplog("LOG_INFO", "get_clean_string called on undefined"); |
213 |
} |
213 |
} |
214 |
return $string; |
214 |
return $string; |
215 |
} |
215 |
} |
216 |
|
216 |
|
217 |
sub get_clean_input { |
217 |
sub get_clean_input { |
218 |
local $/ = "\012"; |
218 |
local $/ = "\012"; |
219 |
my $in = <STDIN>; |
219 |
my $in = <STDIN>; |
220 |
$in = get_clean_string($in); |
220 |
$in = get_clean_string($in); |
221 |
while (my $extra = <STDIN>){ |
221 |
while (my $extra = <STDIN>){ |
222 |
siplog("LOG_ERR", "get_clean_input got extra lines: %s", $extra); |
222 |
siplog("LOG_ERR", "get_clean_input got extra lines: %s", $extra); |
223 |
} |
223 |
} |
224 |
return $in; |
224 |
return $in; |
225 |
} |
225 |
} |
226 |
|
226 |
|
227 |
sub telnet_transport { |
227 |
sub telnet_transport { |
Lines 235-281
sub telnet_transport {
Link Here
|
235 |
siplog("LOG_DEBUG", "telnet_transport: timeout is $timeout"); |
235 |
siplog("LOG_DEBUG", "telnet_transport: timeout is $timeout"); |
236 |
|
236 |
|
237 |
eval { |
237 |
eval { |
238 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
238 |
local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; |
239 |
local $| = 1; # Unbuffered output |
239 |
local $| = 1; # Unbuffered output |
240 |
$/ = "\015"; # Internet Record Separator (lax version) |
240 |
$/ = "\015"; # Internet Record Separator (lax version) |
241 |
# Until the terminal has logged in, we don't trust it |
241 |
# Until the terminal has logged in, we don't trust it |
242 |
# so use a timeout to protect ourselves from hanging. |
242 |
# so use a timeout to protect ourselves from hanging. |
243 |
|
243 |
|
244 |
while ($strikes--) { |
244 |
while ($strikes--) { |
245 |
print "login: "; |
245 |
print "login: "; |
246 |
alarm $timeout; |
246 |
alarm $timeout; |
247 |
# $uid = &get_clean_input; |
247 |
# $uid = &get_clean_input; |
248 |
$uid = <STDIN>; |
248 |
$uid = <STDIN>; |
249 |
print "password: "; |
249 |
print "password: "; |
250 |
# $pwd = &get_clean_input || ''; |
250 |
# $pwd = &get_clean_input || ''; |
251 |
$pwd = <STDIN>; |
251 |
$pwd = <STDIN>; |
252 |
alarm 0; |
252 |
alarm 0; |
253 |
|
253 |
|
254 |
siplog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
254 |
siplog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); |
255 |
$uid = get_clean_string ($uid); |
255 |
$uid = get_clean_string ($uid); |
256 |
$pwd = get_clean_string ($pwd); |
256 |
$pwd = get_clean_string ($pwd); |
257 |
siplog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
257 |
siplog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); |
258 |
|
258 |
|
259 |
if (exists ($config->{accounts}->{$uid}) |
259 |
if (exists ($config->{accounts}->{$uid}) |
260 |
&& ($pwd eq $config->{accounts}->{$uid}->{password})) { |
260 |
&& ($pwd eq $config->{accounts}->{$uid}->{password})) { |
261 |
$account = $config->{accounts}->{$uid}; |
261 |
$account = $config->{accounts}->{$uid}; |
262 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
262 |
if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { |
263 |
last; |
263 |
last; |
264 |
} |
264 |
} |
265 |
} |
265 |
} |
266 |
siplog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
266 |
siplog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); |
267 |
print("Invalid login$CRLF"); |
267 |
print("Invalid login$CRLF"); |
268 |
} |
268 |
} |
269 |
}; # End of eval |
269 |
}; # End of eval |
270 |
|
270 |
|
271 |
if ($@) { |
271 |
if ($@) { |
272 |
siplog("LOG_ERR", "telnet_transport: Login timed out"); |
272 |
siplog("LOG_ERR", "telnet_transport: Login timed out"); |
273 |
die "Telnet Login Timed out"; |
273 |
die "Telnet Login Timed out"; |
274 |
} elsif (!defined($account)) { |
274 |
} elsif (!defined($account)) { |
275 |
siplog("LOG_ERR", "telnet_transport: Login Failed"); |
275 |
siplog("LOG_ERR", "telnet_transport: Login Failed"); |
276 |
die "Login Failure"; |
276 |
die "Login Failure"; |
277 |
} else { |
277 |
} else { |
278 |
print "Login OK. Initiating SIP$CRLF"; |
278 |
print "Login OK. Initiating SIP$CRLF"; |
279 |
} |
279 |
} |
280 |
|
280 |
|
281 |
$self->{account} = $account; |
281 |
$self->{account} = $account; |