|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use IO::Socket::INET; |
| 4 |
use Getopt::Long; |
| 5 |
|
| 6 |
my $help = 0; |
| 7 |
|
| 8 |
my $host; |
| 9 |
my $port = '6001'; |
| 10 |
|
| 11 |
my $login_user_id; |
| 12 |
my $login_password; |
| 13 |
my $location_code; |
| 14 |
|
| 15 |
my $patron_identifier; |
| 16 |
my $patron_password; |
| 17 |
|
| 18 |
GetOptions( |
| 19 |
"a|address|host|hostaddress=s" => \$host, # sip server ip |
| 20 |
"p|port=s" => \$port, # sip server port |
| 21 |
"su|sip_user=s" => \$login_user_id, # sip user |
| 22 |
"sp|sip_pass=s" => \$login_password, # sip password |
| 23 |
"l|location|location_code=s" => \$location_code, # sip location code |
| 24 |
|
| 25 |
"patron=s" => \$patron_identifier, # patron cardnumber or login |
| 26 |
"password=s" => \$patron_password, # patron's password |
| 27 |
|
| 28 |
'h|help|?' => \$help |
| 29 |
); |
| 30 |
|
| 31 |
if ( $help |
| 32 |
|| !$host |
| 33 |
|| !$login_user_id |
| 34 |
|| !$login_password |
| 35 |
|| !$location_code |
| 36 |
|| !$patron_identifier |
| 37 |
|| !$patron_password ) |
| 38 |
{ |
| 39 |
print help(); |
| 40 |
exit(); |
| 41 |
} |
| 42 |
|
| 43 |
my ( $sec, $min, $hour, $day, $month, $year ) = localtime(time); |
| 44 |
$year += 1900; |
| 45 |
my $transaction_date = "$year$month$day $hour$min$sec"; |
| 46 |
|
| 47 |
my $institution_id = $location_code; |
| 48 |
my $terminal_password = $login_password; |
| 49 |
|
| 50 |
$socket = IO::Socket::INET->new("$host:$port") |
| 51 |
or die "ERROR in Socket Creation host=$host port=$port : $!\n"; |
| 52 |
|
| 53 |
my $login_command = "9300CN$login_user_id|CO$login_password|CP$location_code|"; |
| 54 |
|
| 55 |
print "\nOUTBOUND: $login_command\n"; |
| 56 |
print $socket $login_command . "\r"; |
| 57 |
|
| 58 |
$data = <$socket>; |
| 59 |
|
| 60 |
print "\nINBOUND: $data\n"; |
| 61 |
|
| 62 |
if ( $data =~ '^941' ) { ## we are logged in |
| 63 |
|
| 64 |
## Patron Status Request |
| 65 |
print "\nTrying 'Patron Status Request'\n"; |
| 66 |
my $patron_status_request = "23001" |
| 67 |
. $transaction_date |
| 68 |
. "AO" . $institution_id |
| 69 |
. "|AA" . $patron_identifier |
| 70 |
. "|AC" . $terminal_password |
| 71 |
. "|AD" . $patron_password; |
| 72 |
|
| 73 |
print "\nOUTBOUND: $patron_status_request\n"; |
| 74 |
print $socket $patron_status_request . "\r"; |
| 75 |
|
| 76 |
$data = <$socket>; |
| 77 |
|
| 78 |
print "\nINBOUND: $data\n"; |
| 79 |
|
| 80 |
## Patron Information |
| 81 |
print "\nTrying 'Patron Information'\n"; |
| 82 |
my $summary = " "; |
| 83 |
my $patron_status_request = "63001" |
| 84 |
. $transaction_date |
| 85 |
. $summary |
| 86 |
. "AO" . $institution_id |
| 87 |
. "|AA" . $patron_identifier |
| 88 |
. "|AC" . $terminal_password |
| 89 |
. "|AD" . $patron_password; |
| 90 |
|
| 91 |
print "\nOUTBOUND: $patron_status_request\n"; |
| 92 |
print $socket $patron_status_request . "\r"; |
| 93 |
|
| 94 |
$data = <$socket>; |
| 95 |
|
| 96 |
print "\nINBOUND: $data\n"; |
| 97 |
|
| 98 |
} |
| 99 |
else { |
| 100 |
print "\nLogin Failed!\n"; |
| 101 |
} |
| 102 |
|
| 103 |
sub help() { |
| 104 |
print |
| 105 |
q/ |
| 106 |
sip_cli_emulator.pl - SIP command line emulator |
| 107 |
|
| 108 |
Usage: |
| 109 |
sip_cli_emulator.pl --address localhost -port 6001 --sip_user myuser --sip_pass mypass --location MYLOCATION --patron 70000003 --password Patr0nP@ssword |
| 110 |
|
| 111 |
Options: |
| 112 |
--help brief help message |
| 113 |
|
| 114 |
-a --address SIP server ip address or host name |
| 115 |
-p --port SIP server port |
| 116 |
|
| 117 |
-su --sip_user SIP server login username |
| 118 |
-sp --sip_pass SIP server login password |
| 119 |
|
| 120 |
-l --location SIP location code |
| 121 |
|
| 122 |
--patron ILS patron cardnumber or username |
| 123 |
--password ILS patron password |
| 124 |
|
| 125 |
sip_cli_emulator.pl will make requests for information about the given user from the given server via SIP2. |
| 126 |
|
| 127 |
/ |
| 128 |
|
| 129 |
} |