2015-08-05 22:22:06 +02:00
|
|
|
#!/usr/bin/lua
|
|
|
|
|
2016-06-16 13:26:38 +02:00
|
|
|
local url = require("socket.url")
|
|
|
|
|
2015-08-05 22:22:06 +02:00
|
|
|
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)
|
2016-06-16 13:26:38 +02:00
|
|
|
local enabled = "false"
|
2015-08-05 22:22:06 +02:00
|
|
|
local tmp = io.open("/config/"..name..".enabled","r")
|
|
|
|
if tmp then
|
2016-06-16 13:26:38 +02:00
|
|
|
enabled = "true"
|
|
|
|
tmp:close()
|
2015-08-05 22:22:06 +02:00
|
|
|
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
|
|
|
|
|
2016-06-16 13:26:38 +02:00
|
|
|
function WriteConfigFile(name,value)
|
|
|
|
local f = io.open("/config/"..name,"w")
|
|
|
|
if f then
|
|
|
|
f:write(value)
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CheckMaxS8()
|
|
|
|
local isMaxS8 = "false"
|
|
|
|
local tmp = io.open("/sys/class/ddbridge/ddbridge0/devid1")
|
|
|
|
if tmp then
|
|
|
|
devid = tmp:read("*l")
|
|
|
|
tmp:close()
|
|
|
|
if devid == "0007dd01" then
|
|
|
|
isMaxS8 = "true"
|
|
|
|
end
|
2018-09-26 13:03:15 +02:00
|
|
|
if devid == "0009dd01" then
|
|
|
|
isMaxS8 = "true"
|
|
|
|
end
|
2016-06-16 13:26:38 +02:00
|
|
|
end
|
|
|
|
return isMaxS8
|
|
|
|
end
|
|
|
|
|
|
|
|
function GetBoxName()
|
|
|
|
local boxname = ""
|
|
|
|
local tmp = io.open("/config/boxname")
|
|
|
|
if tmp then
|
2017-03-14 21:49:57 +01:00
|
|
|
local pat = "OctopusNet:";
|
2016-06-16 13:26:38 +02:00
|
|
|
boxname = tmp:read("*l")
|
2017-03-14 21:49:57 +01:00
|
|
|
boxname = boxname:gsub(pat:gsub(".","%."),"",1);
|
2016-06-16 13:26:38 +02:00
|
|
|
tmp:close()
|
|
|
|
end
|
|
|
|
return boxname
|
|
|
|
end
|
|
|
|
|
|
|
|
function GetMSMode()
|
|
|
|
local msmode = "quad"
|
|
|
|
local tmp = io.open("/config/msmode")
|
|
|
|
if tmp then
|
2016-11-09 12:10:59 +01:00
|
|
|
local t = tmp:read("*l")
|
2016-06-16 13:26:38 +02:00
|
|
|
tmp:close()
|
2016-11-09 12:10:59 +01:00
|
|
|
if t then
|
|
|
|
msmode = t
|
|
|
|
end
|
2016-07-12 18:47:26 +02:00
|
|
|
elseif ReadSetting('noswitch') == "true" then
|
2016-06-16 13:26:38 +02:00
|
|
|
msmode = "none"
|
|
|
|
end
|
|
|
|
return msmode
|
|
|
|
end
|
|
|
|
|
2015-08-05 22:22:06 +02:00
|
|
|
|
|
|
|
local host = os.getenv("HTTP_HOST")
|
|
|
|
local proto = os.getenv("SERVER_PROTOCOL")
|
|
|
|
local query = os.getenv("QUERY_STRING")
|
|
|
|
|
2015-09-24 19:09:08 +02:00
|
|
|
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
|
2016-06-16 13:26:38 +02:00
|
|
|
query = url.unescape(query)
|
2015-08-05 22:22:06 +02:00
|
|
|
os.execute("echo \""..query.."\" >/tmp/query")
|
|
|
|
local params = {}
|
2016-06-16 13:26:38 +02:00
|
|
|
for w in string.gmatch(query,"(%a%w*%=[%w %(%)%-@/]*)") do
|
2015-08-05 22:22:06 +02:00
|
|
|
table.insert(params,w)
|
2016-06-16 13:26:38 +02:00
|
|
|
os.execute("echo \""..w.."\" >>/tmp/query")
|
2015-08-05 22:22:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO: More validation
|
|
|
|
local nextloc = "index.html"
|
|
|
|
local restart = 0;
|
2016-06-16 13:26:38 +02:00
|
|
|
local restartdms = 0;
|
2015-08-05 22:22:06 +02:00
|
|
|
for _,v in ipairs(params) do
|
2016-06-16 13:26:38 +02:00
|
|
|
name,value = string.match(v,"(%w+)%=(.+)")
|
|
|
|
if name == "msmode" then
|
|
|
|
os.remove("/config/noswitch.enabled")
|
|
|
|
WriteConfigFile("msmode",value);
|
|
|
|
restart = 1;
|
|
|
|
elseif name == "boxname" then
|
|
|
|
if value ~= "" then
|
|
|
|
WriteConfigFile("boxname","OctopusNet:"..value);
|
|
|
|
else
|
|
|
|
os.remove("/config/boxname")
|
|
|
|
end
|
|
|
|
restart = 1;
|
|
|
|
restartdms = 1;
|
|
|
|
elseif( WriteSetting(name,value == "1") ) then
|
2015-08-05 22:22:06 +02:00
|
|
|
if name == "telnet" then
|
|
|
|
os.execute("/etc/init.d/S91telnet restart")
|
|
|
|
end
|
|
|
|
if name == "vlan" then restart = 1 end
|
2015-09-03 14:32:02 +02:00
|
|
|
if name == "nodms" then restart = 1 end
|
2015-08-05 22:22:06 +02:00
|
|
|
if name == "nodvbt" then restart = 1 end
|
2015-09-11 14:53:05 +02:00
|
|
|
if name == "strict" then restart = 1 end
|
2015-08-05 22:22:06 +02:00
|
|
|
end
|
|
|
|
end
|
2016-11-09 14:34:32 +01:00
|
|
|
os.execute("/bin/sync >/dev/null 2>&1");
|
2016-06-16 13:26:38 +02:00
|
|
|
if restart == 1 then
|
|
|
|
os.execute("/etc/init.d/S99octo restartoctonet > /dev/null 2>&1 &")
|
|
|
|
nextloc = "wait.html?10"
|
|
|
|
end
|
|
|
|
if restartdms == 1 then
|
|
|
|
os.execute("/etc/init.d/S92dms restart > /dev/null 2>&1 &")
|
|
|
|
nextloc = "wait.html?10"
|
|
|
|
end
|
2015-08-05 22:22:06 +02:00
|
|
|
print(proto.." 303")
|
|
|
|
print("Location: http://"..host.."/"..nextloc)
|
|
|
|
print("")
|
|
|
|
else
|
|
|
|
|
2015-09-24 19:09:08 +02:00
|
|
|
http_print(proto.." 200")
|
|
|
|
http_print("Pragma: no-cache")
|
|
|
|
http_print("Cache-Control: no-cache")
|
2016-06-16 13:26:38 +02:00
|
|
|
http_print("Content-Type: application/json; charset=utf-8")
|
2015-09-24 19:09:08 +02:00
|
|
|
http_print()
|
2015-08-05 22:22:06 +02:00
|
|
|
|
2016-06-16 13:26:38 +02:00
|
|
|
http_print('{')
|
|
|
|
|
|
|
|
http_print(' "BoxName":"' .. GetBoxName() .. '",')
|
|
|
|
http_print(' "isMaxS8":' .. CheckMaxS8() .. ',')
|
|
|
|
http_print(' "telnetEnabled":' .. ReadSetting('telnet') .. ',')
|
|
|
|
http_print(' "vlanEnabled":' .. ReadSetting('vlan') .. ',')
|
|
|
|
http_print(' "nodmsEnabled":' .. ReadSetting('nodms') .. ',')
|
|
|
|
http_print(' "nodvbtEnabled":' .. ReadSetting('nodvbt') .. ',')
|
|
|
|
http_print(' "MSMode":"' .. GetMSMode() .. '",')
|
|
|
|
http_print(' "strictEnabled":' .. ReadSetting('strict'))
|
|
|
|
|
|
|
|
http_print('}')
|
2015-09-11 14:53:05 +02:00
|
|
|
|
|
|
|
|
2015-08-05 22:22:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|