Bug 3186 - invalid or uninstalled SMSSendDriver (or bad number format) causes process...
[koha.git] / misc / sip_cli_emulator.pl
blobb6d7880b77158c706bc13b934b00699e3b5e8b15
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright (C) 2012-2013 ByWater Solutions
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Socket qw(:crlf);
23 use IO::Socket::INET;
24 use Getopt::Long;
26 my $help = 0;
28 my $host;
29 my $port = '6001';
31 my $login_user_id;
32 my $login_password;
33 my $location_code;
35 my $patron_identifier;
36 my $patron_password;
38 my $terminator = q{};
40 GetOptions(
41 "a|address|host|hostaddress=s" => \$host, # sip server ip
42 "p|port=s" => \$port, # sip server port
43 "su|sip_user=s" => \$login_user_id, # sip user
44 "sp|sip_pass=s" => \$login_password, # sip password
45 "l|location|location_code=s" => \$location_code, # sip location code
47 "patron=s" => \$patron_identifier, # patron cardnumber or login
48 "password=s" => \$patron_password, # patron's password
50 "t|terminator=s" => \$terminator,
52 'h|help|?' => \$help
55 if ( $help
56 || !$host
57 || !$login_user_id
58 || !$login_password
59 || !$location_code
60 || !$patron_identifier
61 || !$patron_password )
63 print &help();
64 exit();
67 $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF;
69 # Set perl to expect the same record terminator it is sending
70 $/ = $terminator;
72 my ( $sec, $min, $hour, $day, $month, $year ) = localtime(time);
73 $year += 1900;
74 my $transaction_date = "$year$month$day $hour$min$sec";
76 my $institution_id = $location_code;
77 my $terminal_password = $login_password;
79 my $socket = IO::Socket::INET->new("$host:$port")
80 or die "ERROR in Socket Creation host=$host port=$port : $!\n";
82 my $login_command = "9300CN$login_user_id|CO$login_password|CP$location_code|";
84 print "\nOUTBOUND: $login_command\n";
85 print $socket $login_command . $terminator;
87 my $data = <$socket>;
89 print "\nINBOUND: $data\n";
91 if ( $data =~ '^941' ) { ## we are logged in
93 ## Patron Status Request
94 print "\nTrying 'Patron Status Request'\n";
95 my $patron_status_request = "23001"
96 . $transaction_date
97 . "AO" . $institution_id
98 . "|AA" . $patron_identifier
99 . "|AC" . $terminal_password
100 . "|AD" . $patron_password;
102 print "\nOUTBOUND: $patron_status_request\n";
103 print $socket $patron_status_request . $terminator;
105 $data = <$socket>;
107 print "\nINBOUND: $data\n";
109 ## Patron Information
110 print "\nTrying 'Patron Information'\n";
111 my $summary = " ";
112 $patron_status_request = "63001"
113 . $transaction_date
114 . $summary
115 . "AO" . $institution_id
116 . "|AA" . $patron_identifier
117 . "|AC" . $terminal_password
118 . "|AD" . $patron_password;
120 print "\nOUTBOUND: $patron_status_request\n";
121 print $socket $patron_status_request . $terminator;
123 $data = <$socket>;
125 print "\nINBOUND: $data\n";
128 else {
129 print "\nLogin Failed!\n";
132 sub help {
133 print
134 q/sip_cli_emulator.pl - SIP command line emulator
136 Test a SIP2 service by sending patron status and patron
137 information requests.
139 Usage:
140 sip_cli_emulator.pl [OPTIONS]
142 Options:
143 --help display help message
145 -a --address SIP server ip address or host name
146 -p --port SIP server port
148 -su --sip_user SIP server login username
149 -sp --sip_pass SIP server login password
151 -l --location SIP location code
153 --patron ILS patron cardnumber or username
154 --password ILS patron password
156 -t --terminator SIP2 message terminator, either CR, or CRLF
157 (defaults to CRLF)