checkin/checkout now toggle AFI security
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 26 Aug 2014 13:28:05 +0000 (15:28 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 27 Aug 2014 11:45:44 +0000 (13:45 +0200)
examples/selfcheck.html
examples/selfcheck.js
scripts/RFID-JSONP-server.pl

index df0cd70..c295dd2 100644 (file)
        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] {
 </head>
 <body>
 
-<div id="debug">
-
-<label for=pull-reader>
-<input id=pull-reader type=checkbox checked=1>
-active
-</label>
-
 <div id="tags">
 RFID reader not found or driver program not started.
 </div>
 
-</div>
 
 <h1>Knjižnica Filozofskog fakulteta</h1>
 
index 1f1c6c1..ac9ea19 100644 (file)
@@ -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('<li>' + data['AJ'] + ' <small>' + data['AF'] + '</small></li>');
+                       $('ul#books').append('<li>' + ( data['AJ'] || barcode ) + ' <small>' + data['AF'] + '</small></li>');
                        book_barcodes[ barcode ] = 1;
                        console.debug( book_barcodes );
                }).fail( function() {
index 298ff17..f29c638 100755 (executable)
@@ -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";
                                }