From 5f2e55f0a56d3ea9dd7f360445e17c2c523933d0 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 26 Aug 2014 15:28:05 +0200 Subject: [PATCH] checkin/checkout now toggle AFI security --- examples/selfcheck.html | 17 +------------ examples/selfcheck.js | 47 ++++++++++++++---------------------- scripts/RFID-JSONP-server.pl | 16 +++++++++--- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/examples/selfcheck.html b/examples/selfcheck.html index df0cd70..c295dd2 100644 --- a/examples/selfcheck.html +++ b/examples/selfcheck.html @@ -16,20 +16,13 @@ background: #cfc; } -label[for=pull-reader] { - position: absolute; - top: 1em; - right: 1em; - background: #eee; -} - ,page { font-size: 300%; border: 10px solid #ccc; } -#debug { +#tags { position: fixed; width: 20em; top: 0; @@ -48,18 +41,10 @@ input[type=button] { -
- - -
RFID reader not found or driver program not started.
-

Knjižnica Filozofskog fakulteta

diff --git a/examples/selfcheck.js b/examples/selfcheck.js index 1f1c6c1..ac9ea19 100644 --- a/examples/selfcheck.js +++ b/examples/selfcheck.js @@ -2,6 +2,7 @@ // configure timeouts var end_timeout = 3000; // ms from end page to start page var error_timeout = 5000; // ms from error page to start page +var tag_rescan = 200; // ms rescan tags every 0.2s // mock console if(!window.console) { @@ -22,10 +23,13 @@ function change_page(new_state) { new_state = 'circulation'; // page has different name $('.checkout').hide(); $('.checkin').show(); + circulation_type = 'checkin'; + borrower_cardnumber = 0; // fake } else if ( new_state == 'checkout' ) { new_state = 'circulation'; // page has different name $('.checkout').show(); $('.checkin').hide(); + circulation_type = 'checkout'; } state = new_state; @@ -40,8 +44,12 @@ function change_page(new_state) { console.info('change_page', state); if ( state == 'start' ) { - start_scan(); + circulation_type = 'checkout'; + book_barcodes = {}; + $('ul#books').html(''); // clear book list + scan_tags(); } + if ( state == 'end' ) { window.setTimeout(function(){ change_page('start'); @@ -90,7 +98,7 @@ function got_visible_tags(data,textStatus) { } console.debug( 'calling', state, content ); - window[state]( content ); // call function with barcode + window[state]( content, tag.sid ); // call function with barcode } }); @@ -108,34 +116,19 @@ function got_visible_tags(data,textStatus) { $('#tags').html( html ); scan_timeout = window.setTimeout(function(){ scan_tags(); - },200); // re-scan every 200ms + },tag_rescan); // re-scan every 200ms }; function scan_tags() { - if ( $('input#pull-reader').attr('checked') ) { - console.info('scan_tags'); - $.getJSON("/scan?callback=?", got_visible_tags); - } -} - -function start_scan() { - $('input#pull-reader').attr('checked', true); - scan_tags(); -} - -function stop_scan() { - $('input#pull-reader').attr('checked', ''); + console.info('scan_tags'); + $.getJSON("/scan?callback=?", got_visible_tags); } $(document).ready(function() { - $('input#pull-reader').click( function() { + $('div#tags').click( function() { scan_tags(); }); - $('div#tags').click( function() { - $('input#pull-reader').attr('checked', false); - } ); - change_page('start'); }); @@ -160,16 +153,12 @@ function start( cardnumber ) { } borrower_cardnumber = cardnumber; - circulation_type = 'checkout'; - book_barcodes = {}; change_page('borrower_check'); } function borrower_check() { - stop_scan(); - fill_in( 'borrower_number', borrower_cardnumber ); $.getJSON('/sip2/patron_info/'+borrower_cardnumber) @@ -189,15 +178,15 @@ function borrower_info() { // nop } -function circulation( barcode ) { +function circulation( barcode, sid ) { if ( barcode && barcode.length == 10 && barcode.substr(0,3) == 130 - && typeof book_barcodes[barcode] !== undefined + && book_barcodes[barcode] != 1 ) { // book, not seen yet - $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode , function( data ) { + $.getJSON('/sip2/'+circulation_type+'/'+borrower_cardnumber+'/'+barcode+'/'+sid , function( data ) { console.info( circulation_type, data ); - $('ul#books').append('
  • ' + data['AJ'] + ' ' + data['AF'] + '
  • '); + $('ul#books').append('
  • ' + ( data['AJ'] || barcode ) + ' ' + data['AF'] + '
  • '); book_barcodes[ barcode ] = 1; console.debug( book_barcodes ); }).fail( function() { diff --git a/scripts/RFID-JSONP-server.pl b/scripts/RFID-JSONP-server.pl index 298ff17..f29c638 100755 --- a/scripts/RFID-JSONP-server.pl +++ b/scripts/RFID-JSONP-server.pl @@ -37,6 +37,10 @@ my $sip2 = { password => 'viva2koha', loc => 'FFZG', }; +my $afi = { + secure => 0xDA, + unsecure => 0xD7, +}; use Getopt::Long; @@ -220,7 +224,7 @@ sub http_server { warn "PROGRAM $tag $content\n"; $rfid->write_blocks( $tag => $content ); - $rfid->write_afi( $tag => chr( $param->{$p} =~ /^130/ ? 0xDA : 0xD7 ) ); + $rfid->write_afi( $tag => chr( $param->{$p} =~ /^130/ ? $afi->{secure} : $afi->{unsecure} ) ); } print $client "HTTP/1.0 $status $method\r\nLocation: $server_url\r\n\r\n"; @@ -263,12 +267,18 @@ sub http_server { $hash = sip2_message("63000${ts} AO$loc|AA$patron|AC$password|"); } elsif ( $method eq 'checkout' ) { - my ($patron,$barcode) = split(/\//, $args, 2); + my ($patron,$barcode,$sid) = split(/\//, $args, 3); $hash = sip2_message("11YN${ts} AO$loc|AA$patron|AB$barcode|AC$password|BON|BIN|"); + if ( substr( $hash->{fixed}, 2, 1 ) == 1 ) { + $rfid->write_afi( $sid => chr( $afi->{unsecure} ) ); + } } elsif ( $method eq 'checkin' ) { - my $barcode = $args; + my ($patron,$barcode,$sid) = split(/\//, $args, 3); $hash = sip2_message("09N${ts}${ts}AP|AO${loc}|AB$barcode|AC|BIN|"); + if ( substr( $hash->{fixed}, 2, 1 ) == 1 ) { + $rfid->write_afi( $sid => chr( $afi->{secure} ) ); + } } else { print $client "HTTP/1.0 500 $method not implemented\r\n\r\n"; } -- 2.20.1