Set up Open Access API
This commit is contained in:
@@ -29,7 +29,6 @@ puts "Content-type: text/html \r\n\r\n"
|
||||
|
||||
if users[cgi['user']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['pass']).to_s then
|
||||
|
||||
2.times do #do the serial stuff twice as sometimes the serial port is occupied
|
||||
|
||||
serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
|
||||
serial.print "e 1234\r"
|
||||
@@ -47,6 +46,22 @@ if users[cgi['user']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['pass
|
||||
when "lock"
|
||||
puts "Doors locked."
|
||||
serial.print "l\r"
|
||||
when "status"
|
||||
serial.print "9\r"
|
||||
sleep 1
|
||||
continue = 1
|
||||
while continue == 1 do
|
||||
serial.read_timeout = -1
|
||||
lines = serial.readlines
|
||||
if lines.length > 0
|
||||
for l in lines
|
||||
puts l
|
||||
puts "\n"
|
||||
end
|
||||
else
|
||||
continue = 0
|
||||
end
|
||||
end
|
||||
when "arm"
|
||||
if(users[cgi['user']]['admin'] == true) then
|
||||
puts "Armed."
|
||||
@@ -68,7 +83,6 @@ if users[cgi['user']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['pass
|
||||
serial.close
|
||||
puts ' <a href="/~access">Return.</a>'
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
puts "Invalid username or password."
|
||||
|
||||
15
cgi-bin/spaceapi.conf
Normal file
15
cgi-bin/spaceapi.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"api" : "0.11",
|
||||
"space" : "HeatSync Labs",
|
||||
"logo" : "http://farm5.static.flickr.com/4053/4411484429_029466651b_o.gif",
|
||||
"url" : "http://heatsynclabs.org",
|
||||
"address" : "140 w. Main Street, Mesa, AZ 85281",
|
||||
"contact" : {
|
||||
"phone" : "",
|
||||
"irc" : "irc://irc.freenode.net/#heatsynclabs",
|
||||
"twitter" : "@heatsynclabs",
|
||||
"ml" : "http://groups.google.com/group/heatsynclabs"
|
||||
},
|
||||
|
||||
"cam" : "http://live.heatsynclabs.org"
|
||||
}
|
||||
68
cgi-bin/spaceapi.rb
Executable file
68
cgi-bin/spaceapi.rb
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env ruby
|
||||
###############################################################################
|
||||
#
|
||||
# 23b interface to SpaceAPI (https://hackerspaces.nl/spaceapi/)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Copyright 2011 Ryan Rix <ry@n.rix.si>
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
#config = []
|
||||
#config['space_name'] = "HeatSync Labs"
|
||||
|
||||
require 'rubygems'
|
||||
require 'cgi'
|
||||
require 'serialport'
|
||||
require 'json'
|
||||
|
||||
#cgi = CGI.new
|
||||
json = JSON.parse(File.read("spaceapi.conf"))
|
||||
|
||||
puts "Content-type: text/json \r\n\r\n"
|
||||
|
||||
# Basically, this is nicked from access.rb
|
||||
|
||||
# start by getting the current status of the lock system
|
||||
serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
|
||||
serial.print "e 1234\r"
|
||||
|
||||
# query for status
|
||||
serial.print "9\r"
|
||||
sleep 1
|
||||
serial.read_timeout = 1000
|
||||
lines = serial.readlines
|
||||
|
||||
# ugly as shit
|
||||
caps = []
|
||||
for line in lines
|
||||
if m = /\(\d=(\w*)\)/.match(line) then
|
||||
caps << m.captures
|
||||
end
|
||||
end
|
||||
|
||||
# more ugly. Space is open when the doors are open or unlocked
|
||||
hs_open = false # because when is anyone open these days?
|
||||
|
||||
if caps[2] == "open" then hs_open = true end
|
||||
if caps[3] == "open" then hs_open = true end
|
||||
if caps[4] == "unlocked" then hs_open = true end
|
||||
if caps[5] == "unlocked" then hs_open = true end
|
||||
|
||||
#take all those nice unformatted garbages from 23b and put'm in a json
|
||||
|
||||
json["open"] = hs_open
|
||||
|
||||
puts JSON.generate json
|
||||
89
cgi-bin/usermanagement.rb
Normal file
89
cgi-bin/usermanagement.rb
Normal file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Copyright 2011 Will Bradley <bradley.will@gmail.com>
|
||||
#
|
||||
# Released under the Chicken Dance License, as detailed
|
||||
# http://supertunaman.com/cdl/cdl_v0-1.txt
|
||||
#
|
||||
# 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'
|
||||
require 'digest/sha2'
|
||||
|
||||
cgi = CGI.new
|
||||
userfile = File.read('../../users.json')
|
||||
users = JSON.parse(userfile)
|
||||
|
||||
puts "Content-type: text/html \r\n\r\n"
|
||||
|
||||
if users[cgi['adminuser']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['adminpass']).to_s then
|
||||
|
||||
serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
|
||||
serial.print "e 1234\r"
|
||||
|
||||
if params['submit'] == "Add User" then
|
||||
newuser = cgi['newuser']
|
||||
newpass = cgi['newpass']
|
||||
|
||||
else if params['submit'] == "Delete User" then
|
||||
|
||||
end
|
||||
|
||||
/*
|
||||
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/management.html">Return.</a>'
|
||||
|
||||
else
|
||||
puts "Invalid administrator username or password."
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user