|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use IO::Socket::INET; |
| 4 |
use Getopt::Long; |
| 5 |
|
| 6 |
my $host; |
| 7 |
my $port = '6001'; |
| 8 |
|
| 9 |
my $login_user_id; |
| 10 |
my $login_password; |
| 11 |
my $location_code; |
| 12 |
|
| 13 |
my $patron_identifier; |
| 14 |
my $patron_password; |
| 15 |
|
| 16 |
GetOptions( |
| 17 |
"h|host=s" => \$host, # sip server ip |
| 18 |
"p|port" => \$port, # sip server port |
| 19 |
"su|sip_user" => \$login_user_id, # sip user |
| 20 |
"sp|sip_pass" => \$login_password, # sip password |
| 21 |
"l|location|location_code" => \$location_code, # sip location code |
| 22 |
|
| 23 |
"patron" => \$patron_identifier, # patron cardnumber or login |
| 24 |
"password" => \$patron_password, # patron's password |
| 25 |
); |
| 26 |
|
| 27 |
my ( $sec, $min, $hour, $day, $month, $year ) = localtime(time); |
| 28 |
$year += 1900; |
| 29 |
my $transaction_date = "$year$month$day $hour$min$sec"; |
| 30 |
|
| 31 |
my $institution_id = $location_code; |
| 32 |
my $terminal_password = $login_password; |
| 33 |
|
| 34 |
$socket = IO::Socket::INET->new("$host:$port") |
| 35 |
or die "ERROR in Socket Creation : $!\n"; |
| 36 |
|
| 37 |
my $login_command = "9300CN$login_user_id|CO$login_password|CP$location_code"; |
| 38 |
|
| 39 |
print $socket $login_command . "\n"; |
| 40 |
|
| 41 |
$data = <$socket>; |
| 42 |
|
| 43 |
print "RECEVIED DATA: '$data'"; |
| 44 |
|
| 45 |
if ( $data =~ '^941' ) { |
| 46 |
print "\nLOGGED IN\n"; |
| 47 |
|
| 48 |
my $patron_status_request = "23001" |
| 49 |
. $transaction_date . "AO" |
| 50 |
. $institution_id . "|AA" |
| 51 |
. $patron_identifier . "|AC" |
| 52 |
. $terminal_password . "|AD" |
| 53 |
. $patron_password; |
| 54 |
print $socket $patron_status_request . "\n"; |
| 55 |
|
| 56 |
$data = <$socket>; |
| 57 |
|
| 58 |
print "\nRECIEVED '$data'\n"; |
| 59 |
|
| 60 |
} |
| 61 |
else { |
| 62 |
print "\nLogin Failed!\n"; |
| 63 |
} |
| 64 |
|