2012-08-25 06:28:00 +00:00
|
|
|
class DoorLog < ActiveRecord::Base
|
|
|
|
attr_accessible :data, :key
|
|
|
|
require 'open-uri'
|
|
|
|
|
|
|
|
def self.download_from_door
|
2012-09-16 03:41:17 +00:00
|
|
|
# load config values
|
|
|
|
door_access_url = APP_CONFIG['door_access_url']
|
|
|
|
door_access_password = APP_CONFIG['door_access_password']
|
|
|
|
|
|
|
|
# connect to door access system
|
|
|
|
source = open("#{door_access_url}?e=#{door_access_password}").read
|
2013-02-09 09:08:43 +00:00
|
|
|
results = source.scan(/ok/)
|
2012-08-25 06:28:00 +00:00
|
|
|
if(results.size > 0) then
|
|
|
|
@end_results = Array.new
|
|
|
|
|
|
|
|
#only continue if we've got an OK login
|
2012-09-16 03:41:17 +00:00
|
|
|
source = open("#{door_access_url}?z").read
|
2012-08-25 06:28:00 +00:00
|
|
|
results = source.scan(/(.*): (.*)\r\n/)
|
|
|
|
|
|
|
|
results.each do |r|
|
|
|
|
if(r[0] != "\000") then
|
|
|
|
DoorLog.create!({:key => r[0], :data => r[1]})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#clear log
|
2012-09-16 03:41:17 +00:00
|
|
|
open("#{door_access_url}?y")
|
2012-08-25 06:28:00 +00:00
|
|
|
#logout
|
2012-09-16 03:41:17 +00:00
|
|
|
open("#{door_access_url}?e=0000")
|
2012-08-25 06:28:00 +00:00
|
|
|
|
|
|
|
if(results.size > 0) then
|
|
|
|
#only return true if we got some kind of decent response
|
|
|
|
return results
|
|
|
|
else
|
|
|
|
# We didn't get a decent response.
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# We didn't get an OK login.
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|