2013-10-10 12:11:16 +02:00
|
|
|
local log = require('util.logger')
|
|
|
|
local utils = require('util.utils')
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.hasControl(ip)
|
|
|
|
local controllerIP = M.getController()
|
|
|
|
return (controllerIP == "" or (controllerIP ~= "" and controllerIP == ip))
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.getController()
|
|
|
|
local file, error = io.open('/tmp/controller.txt','r')
|
|
|
|
if file == nil then
|
|
|
|
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
|
|
|
return ""
|
|
|
|
else
|
|
|
|
controllerIP = file:read('*a')
|
|
|
|
file:close()
|
2013-10-23 16:12:19 +02:00
|
|
|
--strip trailing newline (useful when manually editing controller.txt)
|
|
|
|
if controllerIP:find('\n') == controllerIP:len() then controllerIP = controllerIP:sub(0, -2) end
|
2013-10-10 12:11:16 +02:00
|
|
|
return controllerIP
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.setController(ip)
|
|
|
|
local file = io.open('/tmp/controller.txt','w')
|
|
|
|
file:write(ip)
|
|
|
|
file:flush()
|
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
|
2013-10-23 16:12:19 +02:00
|
|
|
return M
|