RFID: improve interface, show reader checkbox and IP
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 2 Mar 2016 21:55:31 +0000 (22:55 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 25 Mar 2019 14:43:15 +0000 (15:43 +0100)
ffzg/rfid/IntranetUserJS.js [new file with mode: 0644]
ffzg/rfid/README
ffzg/rfid/apache-rfid.conf [new file with mode: 0644]
ffzg/rfid/koha-rfid.js
ffzg/rfid/register.pl

diff --git a/ffzg/rfid/IntranetUserJS.js b/ffzg/rfid/IntranetUserJS.js
new file mode 100644 (file)
index 0000000..58c9960
--- /dev/null
@@ -0,0 +1,8 @@
+$(document).ready(function(){
+
+koha_login = $('.loggedinusername').text();
+console.log('koha_login', koha_login);
+
+$.getScript('/rfid/register.pl?intranet-js=1&koha_login='+koha_login);
+
+});
index ff46a9a..1d06c1e 100644 (file)
@@ -1,22 +1,13 @@
-0. add new rfid registration vhost to apache config
 
-dpavlin@koha-dev:/srv/koha_ffzg/ffzg/rfid(koha_ffzg) $ sudo ln -sf /srv/koha_ffzg/ffzg/rfid/rfid.koha-dev.vbz.ffzg.hr.conf /etc/apache2/sites-available/
-dpavlin@koha-dev:/srv/koha_ffzg/ffzg/rfid(koha_ffzg) $ sudo a2ensite rfid.koha-dev.vbz.ffzg.hr
-Enabling site rfid.koha-dev.vbz.ffzg.hr.
-To activate the new configuration, you need to run:
-  service apache2 reload
-dpavlin@koha-dev:/srv/koha_ffzg/ffzg/rfid(koha_ffzg) $ sudo service apache2 reload
+1. Configure Apache apache-rfid.conf
 
 
+2. Koha system preference IntranetUserJS.js
 
-1. add following to IntranetUserJS system preferences in Koha:
 
-$.getScript('http://rfid.koha-dev.vbz.ffzg.hr/register.pl?intranet-js=1');
+3. start RFID reader and point it to your koha registration:
 
-
-2. start RFID reader and point it to your koha registration:
-
-pi@rfid0 ~/Biblio-RFID $ RFID_URL=http://rfid.koha-dev.vbz.ffzg.hr KOHA_URL=http://ffzg.koha-dev.rot13.org:8080 ./scripts/RFID-JSONP-server.pl
+pi@rfid0 ~/Biblio-RFID $ RFID_URL=http://rfid.koha-dev.vbz.ffzg.hr KOHA_URL=https://ffzg.koha-dev.rot13.org:8443 ./scripts/RFID-JSONP-server.pl
 http://ffzg.koha-dev.rot13.org:8080 at ./scripts/RFID-JSONP-server.pl line 31.
 { _last => "eth0", eth0 => "10.60.1.210", lo => "127.0.0.1" } at ./scripts/RFID-JSONP-server.pl line 368, <DATA> line 1.
 GET http://rfid.koha-dev.vbz.ffzg.hr/register.pl?local_ip=10.60.1.210 at ./scripts/RFID-JSONP-server.pl line 375, <DATA> line 1.
@@ -24,5 +15,10 @@ REGISTER: { local_ip => "10.60.1.210", remote_host => "10.60.1.210" } at ./scrip
 Server ./scripts/RFID-JSONP-server.pl ready at http://:9000
 
 
-3. check under /srv/koha_ffzg/ffzg/rfid/ip/ for your client IP address, which should have IP address
+4. check under /srv/koha_ffzg/ffzg/rfid/ip/ for your client IP address, which should have IP address
 of RFID reader inside it
+
+
+5. assign new reader to user
+
+cp ip/10.60.1.210 user/dpavlin@ffzg.hr
diff --git a/ffzg/rfid/apache-rfid.conf b/ffzg/rfid/apache-rfid.conf
new file mode 100644 (file)
index 0000000..985c2e2
--- /dev/null
@@ -0,0 +1,5 @@
+# include after ScriptAlias and before first existing RewriteCond
+# Include /srv/koha_ffzg/ffzg/rfid/apache-rfid.conf
+
+ScriptAlias /rfid/register.pl "/srv/koha_ffzg/ffzg/rfid/register.pl"
+RewriteRule ^/rfid/to/(.+) http://$1 [P,L]
index 5eae901..5aa98af 100644 (file)
@@ -32,7 +32,7 @@ function rfid_secure_json(t,val, success) {
        if ( t.security.toUpperCase() == val.toUpperCase() ) return;
        rfid_refresh = 0; // disable rfid pull until secure call returns
        console.log('rfid_secure_json', t, val);
-       $.getJSON( 'http://localhost:9000/secure.js?' + t.sid + '=' + val + ';callback=?', success );
+       $.getJSON( '///localhost:9000/secure.js?' + t.sid + '=' + val + ';callback=?', success );
 }
 
 function rfid_secure_check(t,val) {
@@ -48,15 +48,24 @@ var rfid_blank_sid   = false;
 
 function rfid_scan(data,textStatus) {
 
-       console.debug( 'rfid_scan', data, textStatus );
+       $.cookie('rfid', 'localhost'); // set cookie
+
+       console.debug( 'rfid_scan', data, textStatus, $.cookie('rfid') );
        rfid_current_sid = false;
        rfid_blank_sid = false;
 
        var span = $('span#rfid');
 
-       if ( span.size() == 0 ) // insert last in language bar on bottom
+       if ( span.size() == 0 ) {
+               // insert last in language bar on bottom
 //             span = $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
-               span = $('#breadcrumbs').append('<div id="rfid_popup" style="position: fixed; bottom: 0; right: 0; background: #fff; border: 3px solid #ff0; padding: 1em; opacity: 0.7; z-index: 10;"><span id="rfid">RFID reader</span></div>');
+
+               // alternative pop-up version
+               span = $('#breadcrumbs').append('<div id="rfid_popup" style="position: fixed; bottom: 3em; right: 1em; background: #fff; border: 3px solid #ff0; padding: 1em; opacity: 0.7; z-index: 10;"><label for="rfid_active"><input type=checkbox id="rfid_active"> local_ip <span id="rfid">RFID reader</span></label></div>');
+               $('input#rfid_active').attr('checked',true);
+               $('input#rfid_active').click(scan_tags);
+       }
+
 
        if ( span.size() == 0 ) // or before login on top
                span = $('div#login').prepend('<span id=rfid>RFID reader found</span>');
@@ -148,18 +157,29 @@ function rfid_scan(data,textStatus) {
                }
        }
 
-       if (rfid_refresh > 1) {
+       if (rfid_refresh > 1 && $('input#rfid_active').attr('checked') == 'checked' ) {
                window.setTimeout( function() {
-                       $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
+                       $('#rfid_popup').css('border','3px solid #fff');
+                       $.getJSON("///localhost:9000/scan?callback=?", rfid_scan);
                }, rfid_refresh );
        } else {
                console.debug('rfid_refresh disabled',rfid_refresh);
        }
+
+       $('#rfid_popup').css('border','3px solid #ff0');
+}
+
+function scan_tags() {
+       console.info('scan_tags');
+       $.getJSON("///localhost:9000/scan?callback=?", rfid_scan);
 }
 
 $(document).ready( function() {
-       $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
+       console.log('rfid_active', $('input#rfid_active').attr('checked') );
+
+       scan_tags();
 
+       // intranet catalogingdd
        shortcut.add('F4', function() {
                // extract barcode from window title
                var barcode = document.title.split(/\(barcode\s+#|\)/)[1];
@@ -169,7 +189,7 @@ $(document).ready( function() {
                        }
 
                        console.debug('program barcode', barcode, 'to', rfid_blank_sid);
-                       $.getJSON( 'http://localhost:9000/program?' + rfid_blank_sid + '=' + barcode + ';callback=?', function(data) {
+                       $.getJSON( '///localhost:9000/program?' + rfid_blank_sid + '=' + barcode + ';callback=?', function(data) {
                                console.info('programmed', rfid_blank_sid, barcode, data);
                        });
                } else {
index f56c465..9e0b86f 100755 (executable)
@@ -9,6 +9,9 @@ use FindBin;
 
 my $query = new CGI;
 
+use Data::Dump qw(dump);
+warn "# query ", dump( $query );
+
 my $hash = {
        remote_host => $query->remote_host,
 };
@@ -16,6 +19,7 @@ my $hash = {
 my $dir = $FindBin::Bin;
 my $path = "$dir/ip/" . $hash->{remote_host};
 
+
 if ( my $ip = $query->param('local_ip') ) {
 
        $hash->{local_ip} = $ip;
@@ -30,19 +34,41 @@ if ( my $ip = $query->param('local_ip') ) {
        chomp $ip;
        $hash->{local_ip} = $ip;
        close($fh);
+
+} elsif ( my $koha_login = $query->param('koha_login') ) {
+       my $path = "$dir/user/$koha_login";
+       if ( -e $path ) {
+               open(my $fh, '<', $path);
+               $hash->{local_ip} = <$fh>;
+               close $fh;
+       } else {
+               warn "# no $path";
+       }
+
 } else {
        warn $hash->{_error} = "ERROR: ", $hash->{remote_host}, " don't have RFID reader assigned";
 }
 
 if ( $query->param('intranet-js') ) {
        print "Content-type: application/javascript\r\n\r\n";
-       open(my $js, '<', 'koha-rfid.js');
-       while(<$js>) {
-               s/localhost/$hash->{local_ip}/g;
-               print;
+
+       if ( my $local_ip = $hash->{local_ip} ) {
+                       chomp $local_ip;
+                       my $url = "/rfid/to/$local_ip";
+                       open(my $js, '<', 'koha-rfid.js');
+                       while(<$js>) {
+                               s/local_ip/$local_ip/g;
+                               s/localhost/$url/g;
+                               s{///$url}{$url}g; # relative urls
+                               print;
+                       }
+                       close($js);
+       } else {
+                       print 'console.log("no RFID reader for client "'. $hash->{remote_host}, ");\n";
+
        }
-       close($js);
 } else {
        print "Content-type: application/json; charset=utf-8\r\n\r\n";
        print encode_json $hash;
+       warn "# hash = ",dump($hash);
 }