From 87225647c31d4306a80d041531217967c8302f4e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 22 Apr 2020 13:36:52 -0400 Subject: [PATCH] Bug 15253: Fix QA script issues --- C4/SIP/ILS/Transaction/Checkout.pm | 2 +- C4/SIP/Logger.pm | 10 +++ C4/SIP/SIPServer.pm | 112 ++++++++++++++--------------- C4/SIP/Sip.pm | 4 +- C4/SIP/Trapper.pm | 6 ++ 5 files changed, 75 insertions(+), 59 deletions(-) diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index 6b1f867298..a7dc21bab1 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -47,7 +47,7 @@ sub new { sub do_checkout { my $self = shift; - siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout..."); + siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout..."); my $shelf = $self->{item}->hold_shelf; my $barcode = $self->{item}->id; my $patron_barcode = $self->{patron}->id; diff --git a/C4/SIP/Logger.pm b/C4/SIP/Logger.pm index 8eff6826e2..d12e47157d 100644 --- a/C4/SIP/Logger.pm +++ b/C4/SIP/Logger.pm @@ -6,6 +6,10 @@ use Modern::Perl; our $activeSIPServer; our $activeLogger; +=head1 NAME + +C4::SIP::Logger - Module for handling SIP server logging + =head2 get_SIPServer my $sipServer = C4::SIP::SIPServer::get_SIPServer() @@ -36,6 +40,12 @@ sub get_logger { return $activeLogger; } +=head2 set_logger + + my $logger = C4::SIP::SIPServer::set_logger($logger) + +=cut + sub set_logger { my ($logger) = @_; $activeLogger = $logger; diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 8a208dde88..d28ebd2b2f 100755 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -30,7 +30,7 @@ use base qw(Net::Server::PreFork); use constant LOG_SIP => "local6"; # Local alias for the logging facility # -# Main # not really, since package SIPServer +# Main # not really, since package SIPServer # # FIXME: Is this a module or a script? # A script with no MAIN namespace? @@ -75,7 +75,7 @@ foreach my $svc (keys %{$config->{listeners}}) { # if (defined($config->{'server-params'})) { while (my ($key, $val) = each %{$config->{'server-params'}}) { - push @parms, $key . '=' . $val; + push @parms, $key . '=' . $val; } } @@ -125,17 +125,17 @@ sub process_request { $self->{service} = $config->find_service($sockaddr, $port, $proto); if (!defined($self->{service})) { - siplog("LOG_ERR", "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto); - die "process_request: Bad server connection"; + siplog("LOG_ERR", "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto); + die "process_request: Bad server connection"; } $transport = $transports{$self->{service}->{transport}}; if (!defined($transport)) { - siplog("LOG_WARNING", "Unknown transport '%s', dropping", $service->{transport}); - return; + siplog("LOG_WARNING", "Unknown transport '%s', dropping", $service->{transport}); + return; } else { - &$transport($self); + &$transport($self); } return; } @@ -201,27 +201,27 @@ sub raw_transport { } sub get_clean_string { - my $string = shift; - if (defined $string) { - siplog("LOG_DEBUG", "get_clean_string pre-clean(length %s): %s", length($string), $string); - chomp($string); - $string =~ s/^[^A-z0-9]+//; - $string =~ s/[^A-z0-9]+$//; - siplog("LOG_DEBUG", "get_clean_string post-clean(length %s): %s", length($string), $string); - } else { - siplog("LOG_INFO", "get_clean_string called on undefined"); - } - return $string; + my $string = shift; + if (defined $string) { + siplog("LOG_DEBUG", "get_clean_string pre-clean(length %s): %s", length($string), $string); + chomp($string); + $string =~ s/^[^A-z0-9]+//; + $string =~ s/[^A-z0-9]+$//; + siplog("LOG_DEBUG", "get_clean_string post-clean(length %s): %s", length($string), $string); + } else { + siplog("LOG_INFO", "get_clean_string called on undefined"); + } + return $string; } sub get_clean_input { - local $/ = "\012"; - my $in = ; - $in = get_clean_string($in); - while (my $extra = ){ - siplog("LOG_ERR", "get_clean_input got extra lines: %s", $extra); - } - return $in; + local $/ = "\012"; + my $in = ; + $in = get_clean_string($in); + while (my $extra = ){ + siplog("LOG_ERR", "get_clean_input got extra lines: %s", $extra); + } + return $in; } sub telnet_transport { @@ -235,47 +235,47 @@ sub telnet_transport { siplog("LOG_DEBUG", "telnet_transport: timeout is $timeout"); eval { - local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; - local $| = 1; # Unbuffered output - $/ = "\015"; # Internet Record Separator (lax version) + local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; + local $| = 1; # Unbuffered output + $/ = "\015"; # Internet Record Separator (lax version) # Until the terminal has logged in, we don't trust it # so use a timeout to protect ourselves from hanging. - while ($strikes--) { - print "login: "; - alarm $timeout; - # $uid = &get_clean_input; - $uid = ; - print "password: "; - # $pwd = &get_clean_input || ''; - $pwd = ; - alarm 0; - - siplog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); - $uid = get_clean_string ($uid); - $pwd = get_clean_string ($pwd); - siplog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); - - if (exists ($config->{accounts}->{$uid}) - && ($pwd eq $config->{accounts}->{$uid}->{password})) { - $account = $config->{accounts}->{$uid}; - if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { + while ($strikes--) { + print "login: "; + alarm $timeout; + # $uid = &get_clean_input; + $uid = ; + print "password: "; + # $pwd = &get_clean_input || ''; + $pwd = ; + alarm 0; + + siplog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); + $uid = get_clean_string ($uid); + $pwd = get_clean_string ($pwd); + siplog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); + + if (exists ($config->{accounts}->{$uid}) + && ($pwd eq $config->{accounts}->{$uid}->{password})) { + $account = $config->{accounts}->{$uid}; + if ( C4::SIP::Sip::MsgType::login_core($self,$uid,$pwd) ) { last; } - } - siplog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); - print("Invalid login$CRLF"); - } + } + siplog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); + print("Invalid login$CRLF"); + } }; # End of eval if ($@) { - siplog("LOG_ERR", "telnet_transport: Login timed out"); - die "Telnet Login Timed out"; + siplog("LOG_ERR", "telnet_transport: Login timed out"); + die "Telnet Login Timed out"; } elsif (!defined($account)) { - siplog("LOG_ERR", "telnet_transport: Login Failed"); - die "Login Failure"; + siplog("LOG_ERR", "telnet_transport: Login Failed"); + die "Login Failure"; } else { - print "Login OK. Initiating SIP$CRLF"; + print "Login OK. Initiating SIP$CRLF"; } $self->{account} = $account; diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index 1d9d9bf1cd..76f8598fe1 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -68,7 +68,7 @@ sub add_field { my ($i, $ent); if (!defined($value)) { - siplog("LOG_DEBUG", "add_field: Undefined value being added to '%s'", + siplog("LOG_DEBUG", "add_field: Undefined value being added to '%s'", $field_id); $value = ''; } @@ -127,7 +127,7 @@ sub add_count { $count = sprintf("%04d", $count); if (length($count) != 4) { - siplog("LOG_WARNING", "handle_patron_info: %s wrong size: '%s'", + siplog("LOG_WARNING", "handle_patron_info: %s wrong size: '%s'", $label, $count); $count = ' ' x 4; } diff --git a/C4/SIP/Trapper.pm b/C4/SIP/Trapper.pm index e134f246e4..76c8cfceaf 100644 --- a/C4/SIP/Trapper.pm +++ b/C4/SIP/Trapper.pm @@ -4,6 +4,12 @@ use Modern::Perl; use Koha::Logger; +=head1 NAME + +C4::SIP::Trapper - Trapper module to capture warnings to send to Koha::Logger + +=cut + sub TIEHANDLE { my $class = shift; bless [], $class; -- 2.24.2 (Apple Git-127)