From e077c8f1f26758c317d499dbcc0db19aae35d5b9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 22 Jun 2011 17:01:16 -0600 Subject: [PATCH] F1rst commit --- cgi-bin/access.rb | 75 +++++++++++++++++++++++++++++++++++++++++++++++ index.html | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 cgi-bin/access.rb create mode 100755 index.html diff --git a/cgi-bin/access.rb b/cgi-bin/access.rb new file mode 100755 index 0000000..5baf08a --- /dev/null +++ b/cgi-bin/access.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +# +# Ruby interface to 23b's Open Access Control system +# By Will Bradley, twitter.com/willbradley of HeatSync Labs +# +# Valid access control commands: +#(d)ate, (s)show user, (m)odify user +#(a)ll user dump,(r)emove_user ,(o)open door +#(u)nlock all doors,(l)lock all doors +#(1)disarm_alarm, (2)arm_alarm,(3)train_alarm (9)show_status +#(e)nable - enable or disable priveleged mode + +require 'rubygems' +require 'cgi' +require 'serialport' +require 'json' + +cgi = CGI.new +userfile = File.read('../../users.json') +users = JSON.parse(userfile) + +puts "Content-type: text/html \r\n\r\n" + +if(users[cgi['user']]['pass'] == cgi['pass']) then + + serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE) + serial.print "e 1234\r" + + case cgi['cmd'] + when "open-front" + puts "Front door opened." + serial.print "o 1\r" + when "open-rear" + puts "Rear door opened." + serial.print "o 2\r" + when "unlock" + if(users[cgi['user']]['admin'] == true) then + puts "Doors unlocked, remember to re-lock them." + serial.print "u\r" + else + puts "Fail. Don't be a naughty user!" + end + when "lock" + if(users[cgi['user']]['admin'] == true) then + puts "Doors locked." + serial.print "l\r" + else + puts "Fail. Don't be a naughty user!" + end + when "arm" + if(users[cgi['user']]['admin'] == true) then + puts "Armed." + serial.print "2\r" + else + puts "Fail. Don't be a naughty user!" + end + when "disarm" + if(users[cgi['user']]['admin'] == true) then + puts "Disarmed." + serial.print "1\r" + else + puts "Fail. Don't be a naughty user!" + end + else + puts "Fail. Don't be a naughty user!" + end + + serial.close + puts ' Return.' + +else + puts "Invalid username or password." +end + diff --git a/index.html b/index.html new file mode 100755 index 0000000..33717d1 --- /dev/null +++ b/index.html @@ -0,0 +1,69 @@ + + + + + + + +
+

HeatSync Labs

+ +
+

HeatSync Labs Access Control

+

Beware all ye who enter here! Only authorized users are allowed to open and close the lab. If you don't have a username/password to this system, don't be a naughty user.

+
+
+ + + + +
+
+ +
+ +
+ +