F1rst commit

This commit is contained in:
root 2011-06-22 17:01:16 -06:00
commit e077c8f1f2
2 changed files with 144 additions and 0 deletions

75
cgi-bin/access.rb Executable file
View File

@ -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 <num> <usermask> <tagnumber>
#(a)ll user dump,(r)emove_user <num>,(o)open door <num>
#(u)nlock all doors,(l)lock all doors
#(1)disarm_alarm, (2)arm_alarm,(3)train_alarm (9)show_status
#(e)nable <password> - 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 ' <a href="/~access">Return.</a>'
else
puts "Invalid username or password."
end

69
index.html Executable file
View File

@ -0,0 +1,69 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
body { background-color: #2C2C29; color: #2C2C29; font-family: Tahoma; font-size: 11px; margin: 0; padding: 0; }
#wrapper { width: 811px; margin: 0 auto; }
#top { background:url('http://www.heatsynclabs.org/wp-content/themes/lightword/images/header-image.png') no-repeat; height:116px; margin: 0 0 0 5px; }
#top span { display: none; }
#content { background-color: #fff; padding: 1em; font-size: 1.2em; }
.caption {
background-color: #F3F3F3;
border: 1px solid #DDD;
padding: 4px;
margin: 0 30px;
display: inline-block;
}
.footer {
clear: both;
}
label {
display: block;
font-weight: bold;
}
h2 {
font-family: Helvetica, Georgia;
font-size: 24px;
letter-spacing: -1px;
margin: 10px 0px 3px;
border-bottom: 1px solid #DCDCDB;
}
</style>
</head>
<body>
<div id="wrapper">
<a href="http://www.heatsynclabs.org"><h1 id="top"><span>HeatSync Labs</span></h1></a>
<div id="content">
<h2>HeatSync Labs Access Control</h2>
<p>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.</p>
<div class="caption">
<form method="post" action="cgi-bin/access.rb">
<label for="user">Username <input type="text" id="user" name="user" /></label>
<label for="pass">Password <input type="password" id="pass" name="pass" /></label>
<label for="cmd">Command
<select id="cmd" name="cmd">
<option value="open-rear">Open Rear Door</option>
<option value="open-front">Open Front Door</option>
<option value="lock">Lock all doors</option>
<option value="unlock">Unlock all doors</option>
<option value="arm">Arm alarm</option>
<option value="disarm">Disarm alarm</option>
</select>
</label>
<input type="submit" id="submit" name="submit" value="Go!" />
</form>
</div>
<p class="footer">To report problems or ask for help/access, contact <a href="http://twitter.com/willbradley">@willbradley</a></p>
</div>
</div>
</body>
</html>