X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=misc%2Fsip_cli_emulator.pl;h=b6d7880b77158c706bc13b934b00699e3b5e8b15;hb=8f223865275968312c786b577f9bf833cf5dfe82;hp=a379da2affb293903d9008cda06e7feea064e089;hpb=b2e8dfe816ad2f0b130a0b5fab07514c1464cee7;p=koha_fer diff --git a/misc/sip_cli_emulator.pl b/misc/sip_cli_emulator.pl index a379da2aff..b6d7880b77 100755 --- a/misc/sip_cli_emulator.pl +++ b/misc/sip_cli_emulator.pl @@ -1,5 +1,25 @@ #!/usr/bin/perl +# This file is part of Koha. +# +# Copyright (C) 2012-2013 ByWater Solutions +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Socket qw(:crlf); use IO::Socket::INET; use Getopt::Long; @@ -15,6 +35,8 @@ my $location_code; my $patron_identifier; my $patron_password; +my $terminator = q{}; + GetOptions( "a|address|host|hostaddress=s" => \$host, # sip server ip "p|port=s" => \$port, # sip server port @@ -25,6 +47,8 @@ GetOptions( "patron=s" => \$patron_identifier, # patron cardnumber or login "password=s" => \$patron_password, # patron's password + "t|terminator=s" => \$terminator, + 'h|help|?' => \$help ); @@ -36,10 +60,15 @@ if ( $help || !$patron_identifier || !$patron_password ) { - print help(); + print &help(); exit(); } +$terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF; + +# Set perl to expect the same record terminator it is sending +$/ = $terminator; + my ( $sec, $min, $hour, $day, $month, $year ) = localtime(time); $year += 1900; my $transaction_date = "$year$month$day $hour$min$sec"; @@ -47,15 +76,15 @@ my $transaction_date = "$year$month$day $hour$min$sec"; my $institution_id = $location_code; my $terminal_password = $login_password; -$socket = IO::Socket::INET->new("$host:$port") +my $socket = IO::Socket::INET->new("$host:$port") or die "ERROR in Socket Creation host=$host port=$port : $!\n"; my $login_command = "9300CN$login_user_id|CO$login_password|CP$location_code|"; print "\nOUTBOUND: $login_command\n"; -print $socket $login_command . "\r"; +print $socket $login_command . $terminator; -$data = <$socket>; +my $data = <$socket>; print "\nINBOUND: $data\n"; @@ -71,7 +100,7 @@ if ( $data =~ '^941' ) { ## we are logged in . "|AD" . $patron_password; print "\nOUTBOUND: $patron_status_request\n"; - print $socket $patron_status_request . "\r"; + print $socket $patron_status_request . $terminator; $data = <$socket>; @@ -80,7 +109,7 @@ if ( $data =~ '^941' ) { ## we are logged in ## Patron Information print "\nTrying 'Patron Information'\n"; my $summary = " "; - my $patron_status_request = "63001" + $patron_status_request = "63001" . $transaction_date . $summary . "AO" . $institution_id @@ -89,7 +118,7 @@ if ( $data =~ '^941' ) { ## we are logged in . "|AD" . $patron_password; print "\nOUTBOUND: $patron_status_request\n"; - print $socket $patron_status_request . "\r"; + print $socket $patron_status_request . $terminator; $data = <$socket>; @@ -100,29 +129,32 @@ else { print "\nLogin Failed!\n"; } -sub help() { +sub help { print -q/ -sip_cli_emulator.pl - SIP command line emulator +q/sip_cli_emulator.pl - SIP command line emulator - Usage: - sip_cli_emulator.pl --address localhost -port 6001 --sip_user myuser --sip_pass mypass --location MYLOCATION --patron 70000003 --password Patr0nP@ssword +Test a SIP2 service by sending patron status and patron +information requests. - Options: - --help brief help message +Usage: + sip_cli_emulator.pl [OPTIONS] - -a --address SIP server ip address or host name - -p --port SIP server port +Options: + --help display help message - -su --sip_user SIP server login username - -sp --sip_pass SIP server login password + -a --address SIP server ip address or host name + -p --port SIP server port - -l --location SIP location code + -su --sip_user SIP server login username + -sp --sip_pass SIP server login password - --patron ILS patron cardnumber or username - --password ILS patron password + -l --location SIP location code + + --patron ILS patron cardnumber or username + --password ILS patron password -sip_cli_emulator.pl will make requests for information about the given user from the given server via SIP2. + -t --terminator SIP2 message terminator, either CR, or CRLF + (defaults to CRLF) /