1
0
mirror of https://github.com/DigitalDevices/octonet.git synced 2023-10-10 13:36:52 +02:00
octonet/octoserve/var/www/systemsettings.lua

157 lines
3.6 KiB
Lua
Raw Normal View History

2015-08-05 22:22:06 +02:00
#!/usr/bin/lua
function SaveOctoserveConf(Section,Values)
local ConfStart
local ConfEnd
local f = io.open("/config/octoserve.conf","r")
if f then
local CurConf = f:read("*a")
f:close()
ConfStart,ConfEnd = string.match(CurConf,"(.-)%["..Section.."%].+\n(%[.+)")
os.remove("/config/octoserve.bak")
os.rename("/config/octoserve.conf","/config/octoserve.bak")
end
f = io.open("/config/octoserve.conf","w")
if ConfStart then
f:write(ConfStart)
end
f:write("["..Section.."]\n")
f:write(Values)
if ConfEnd then
f:write(ConfEnd)
end
f:close()
end
function ReadSetting(name)
local enabled = false
local tmp = io.open("/config/"..name..".enabled","r")
if tmp then
enabled = true
end
return(enabled)
end
function WriteSetting(name,enabled)
local wasenabled = false
if os.remove("/config/"..name..".enabled") then wasenabled = true end
if( enabled ) then
local f = io.open("/config/"..name..".enabled","w")
if f then
f:write("1")
f:close()
end
end
return enabled ~= wasenabled
end
local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING")
function http_print(s)
if s then
io.stdout:write(tostring(s).."\r\n")
else
io.stdout:write("\r\n")
end
end
function SendError(err,desc)
http_print(proto.." "..err)
http_print("Content-Type: text/html")
http_print()
local file = io.open("e404.html")
if file then
local tmp = file:read("*a")
tmp = string.gsub(tmp,"404 Not Found",err .. " " .. desc)
http_print(tmp)
file:close()
end
end
2015-08-05 22:22:06 +02:00
if arg[1] then
query = arg[1]
proto = "HTTP/1.0"
host = "local"
end
if query ~= "" then
os.execute("echo \""..query.."\" >/tmp/query")
local params = {}
for w in string.gmatch(query,"(%a%w+%=%d+%,?%d*%,?%d*)") do
table.insert(params,w)
end
-- TODO: More validation
local nextloc = "index.html"
local restart = 0;
for _,v in ipairs(params) do
name,value = string.match(v,"(%w+)%=(%d+)")
if( WriteSetting(name,value == "1") ) then
if name == "telnet" then
os.execute("/etc/init.d/S91telnet restart")
end
if name == "vlan" then restart = 1 end
if name == "nodms" then restart = 1 end
2015-08-05 22:22:06 +02:00
if name == "nodvbt" then restart = 1 end
if name == "noswitch" then restart = 1 end
if name == "strict" then restart = 1 end
nextloc = "wait.html?10"
2015-08-05 22:22:06 +02:00
end
end
if restart == 1 then os.execute("/etc/init.d/S99octo restartoctonet > /dev/null 2>&1 &") end
2015-08-05 22:22:06 +02:00
print(proto.." 303")
print("Location: http://"..host.."/"..nextloc)
print("")
else
http_print(proto.." 200")
http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/x-javascript")
http_print()
2015-08-05 22:22:06 +02:00
if ReadSetting("telnet") then
http_print("telnetEnabled = true;")
2015-08-05 22:22:06 +02:00
else
http_print("telnetEnabled = false;")
2015-08-05 22:22:06 +02:00
end
if ReadSetting("vlan") then
http_print("vlanEnabled = true;")
2015-08-05 22:22:06 +02:00
else
http_print("vlanEnabled = false;")
2015-08-05 22:22:06 +02:00
end
if ReadSetting("nodms") then
http_print("nodmsEnabled = true;")
2015-08-05 22:22:06 +02:00
else
http_print("nodmsEnabled = false;")
2015-08-05 22:22:06 +02:00
end
if ReadSetting("nodvbt") then
http_print("nodvbtEnabled = true;")
2015-08-05 22:22:06 +02:00
else
http_print("nodvbtEnabled = false;")
2015-08-05 22:22:06 +02:00
end
if ReadSetting("noswitch") then
http_print("noswitchEnabled = true;")
2015-08-05 22:22:06 +02:00
else
http_print("noswitchEnabled = false;")
2015-08-05 22:22:06 +02:00
end
if ReadSetting("strict") then
http_print("strictEnabled = true;")
else
http_print("strictEnabled = false;")
end
2015-08-05 22:22:06 +02:00
end