This is an old revision of the document!
Table of Contents
Brmdoor Scripts
This is a super-scary collection of hackish pasky's scripts controlling the brmdoor monster. If you change/rewrite them, please keep this page up-to-date.
All scripts are being run from within a screen running on brmlab@sargon.
USB-Network Interface on Asus
Lives in /jffs/brmdoor/
. Do not forget to manually insmod the correct usbserial, ftdi modules first.
Some of the shell I/O is coded awkwardly - this is carefully tuned to reach combination of serial device opens/closes for things to actually work.
brmdoor.rc:
PORT=/dev/usb/tts/0 DELAY=10 AUTHSERVER=192.168.1.28 AUTHPORT=2081 # stty -F $PORT 38400 parodd -cstopb # not needed
dooropener.sh - unlock door (for given number of seconds) from within the LAN:
#!/bin/sh . ./brmdoor.rc while true; do x="$(nc -l -p 2080)"; echo "$x" >$PORT; echo closed given $x; done
dooropen.sh - utility script for opening the door from other Asus scripts:
#!/bin/sh . ./brmdoor.rc #!/bin/sh . ./brmdoor.rc sleep 1 # give time for the arduino to potentially reset echo opening for $DELAY # echo "$DELAY" | nc localhost 2080 echo $DELAY >$PORT
doorrfid.sh - listen for rfid serial numbers coming from Arduino, ask auth server whether they are legit, give command to unlock the door if they are:
#!/bin/sh . ./brmdoor.rc while true; do echo wait... read rfid reply=$(echo $rfid | nc $AUTHSERVER $AUTHPORT) echo $rfid $reply if [ "$reply" = 1 ]; then # By the time we send over serial, we MUST be reading # it again already too. Uhh, stupid 2.4 kernel ftdi?! ./dooropen.sh & fi done <$PORT
Auth Server
Simple script running on sargon, checking rfid serials against a user database: brmdoor.pl
#!/usr/bin/perl use IO::Socket; $|=1; our %ids; open my $f, "brmdoor.users" or die "brmdoor.users: $!"; while(<$f>) { chomp; split/\t/; # print "ID '$_[1]' is of $_[0]\n"; $ids{$_[1]} = $_[0]; } close $f; # $/="\r\n"; my $sock = new IO::Socket::INET(Listen=>1,LocalPort=>2081,Reuse=>1) or die "$!"; while (1) { my $s = $sock->accept(); while (<$s>) { chomp; my $u = $ids{$_}; if ($u) { print $s "1\n"; print "$u\n"; } else { print $s "0\n"; print "INVALID: '$_'\n"; } } }
I'm sorry for the mess, it was quick 10-minute hack. Feel free to rewrite it.
brmdoor.users:
username<tab>serial pasky<tab>0123456789
Unlock Door over IRC
If nick brmlab_
(sic) receives an open command over privmsg, it unlocks the door for few seconds (and reports the action on #brmlab). You can find the command in members-only section of the wiki.
.irssi/scripts/brmdoor.pl takes care of it:
use strict; use warnings; use Irssi; use Irssi::Irc; use vars qw($VERSION %IRSSI); $VERSION = '0.1'; %IRSSI = ( authors => "Petr Baudis", contact => "brmlab\@brmlab.cz", name => "brmdoor", description => "brmdoor IRC interface", ); our ($lastt) = 0; sub on_private { my ($server, $message, $nick, $hostmask) = @_; my $cp = "!"; return unless $message =~ /^${cp}seememberssectionforthecommand/; my $delay = 20; system("echo $delay | nc 192.168.1.1 2080"); $server->send_message("#brmlab", "$nick asked for brmdoor open - unlocked for ${delay}s mark NOW", 0); } Irssi::signal_add('message private', 'on_private');