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

script cleanup

unified output using http_print
added Cache-Control header
This commit is contained in:
mvoelkel 2015-09-24 19:09:08 +02:00
parent fb0aab674e
commit 928816fbe4
15 changed files with 295 additions and 153 deletions

View File

@ -6,24 +6,47 @@ local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") local query = os.getenv("QUERY_STRING")
print(proto.." 200") function http_print(s)
--print("Pragma: no-cache") if s then
print("Content-Type: application/x-javascript") io.stdout:write(tostring(s).."\r\n")
print("") 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
http_print(proto.." 200")
--http_print("Pragma: no-cache")
--http_print("Cache-Control: no-cache")
http_print("Content-Type: application/x-javascript")
http_print("")
local SourceList = {} local SourceList = {}
for _,f in ipairs(db.SourceList) do for _,f in ipairs(db.SourceList) do
f.ChannelList = {} f.ChannelList = {}
SourceList[f.refid] = f SourceList[f.refid] = f
print("// " .. f.refid .. " " .. f.title ) http_print("// " .. f.refid .. " " .. f.title )
end end
for _,c in ipairs(db.ChannelList) do for _,c in ipairs(db.ChannelList) do
local f = SourceList[c.refid] local f = SourceList[c.refid]
if f then if f then
table.insert(f.ChannelList,c) table.insert(f.ChannelList,c)
-- print("// " .. c.refid .. " " .. c.title .. " " .. c.request .. " " .. c.tracks ) -- http_print("// " .. c.refid .. " " .. c.title .. " " .. c.request .. " " .. c.tracks )
end end
end end
@ -32,41 +55,41 @@ local icable = 0
local iter = 0 local iter = 0
local ichannel = 0 local ichannel = 0
print("var SourceListSat = new Array();") http_print("var SourceListSat = new Array();")
print("var SourceListCable = new Array();") http_print("var SourceListCable = new Array();")
print("var SourceListTer = new Array();") http_print("var SourceListTer = new Array();")
for _,f in pairs(SourceList) do for _,f in pairs(SourceList) do
if f.system == "dvbs" or f.system == "dvbs2" then if f.system == "dvbs" or f.system == "dvbs2" then
print("") http_print("")
print(string.format("SourceListSat[%d] = new Object();",isat)) http_print(string.format("SourceListSat[%d] = new Object();",isat))
print(string.format("SourceListSat[%d].name = '%s';",isat,f.title)) http_print(string.format("SourceListSat[%d].name = '%s';",isat,f.title))
print(string.format("SourceListSat[%d].ChannelList = new Array();",isat)) http_print(string.format("SourceListSat[%d].ChannelList = new Array();",isat))
ichannel = 0 ichannel = 0
for _,c in ipairs(f.ChannelList) do for _,c in ipairs(f.ChannelList) do
print("") http_print("")
print(string.format("SourceListSat[%d].ChannelList[%d] = new Object();",isat,ichannel)) http_print(string.format("SourceListSat[%d].ChannelList[%d] = new Object();",isat,ichannel))
print(string.format("SourceListSat[%d].ChannelList[%d].name = '%s';",isat,ichannel,string.gsub(c.title,"'","\\'"))) http_print(string.format("SourceListSat[%d].ChannelList[%d].name = '%s';",isat,ichannel,string.gsub(c.title,"'","\\'")))
print(string.format("SourceListSat[%d].ChannelList[%d].request = '?src=%s&%s';",isat,ichannel,f.src,c.request)) http_print(string.format("SourceListSat[%d].ChannelList[%d].request = '?src=%s&%s';",isat,ichannel,f.src,c.request))
print(string.format("SourceListSat[%d].ChannelList[%d].tracks = new Array(%s);",isat,ichannel,c.tracks)) http_print(string.format("SourceListSat[%d].ChannelList[%d].tracks = new Array(%s);",isat,ichannel,c.tracks))
ichannel = ichannel + 1 ichannel = ichannel + 1
end end
isat = isat + 1 isat = isat + 1
end end
if f.system == "dvbc" or f.system == "dvbc2" then if f.system == "dvbc" or f.system == "dvbc2" then
print("") http_print("")
print(string.format("SourceListCable[%d] = new Object();",icable)) http_print(string.format("SourceListCable[%d] = new Object();",icable))
print(string.format("SourceListCable[%d].name = '%s';",icable,f.title)) http_print(string.format("SourceListCable[%d].name = '%s';",icable,f.title))
print(string.format("SourceListCable[%d].ChannelList = new Array();",icable)) http_print(string.format("SourceListCable[%d].ChannelList = new Array();",icable))
ichannel = 0 ichannel = 0
for _,c in ipairs(f.ChannelList) do for _,c in ipairs(f.ChannelList) do
print("") http_print("")
print(string.format("SourceListCable[%d].ChannelList[%d] = new Object();",icable,ichannel)) http_print(string.format("SourceListCable[%d].ChannelList[%d] = new Object();",icable,ichannel))
print(string.format("SourceListCable[%d].ChannelList[%d].name = '%s';",icable,ichannel,string.gsub(c.title,"'","\\'"))) http_print(string.format("SourceListCable[%d].ChannelList[%d].name = '%s';",icable,ichannel,string.gsub(c.title,"'","\\'")))
print(string.format("SourceListCable[%d].ChannelList[%d].request = '?%s';",icable,ichannel,c.request)) http_print(string.format("SourceListCable[%d].ChannelList[%d].request = '?%s';",icable,ichannel,c.request))
print(string.format("SourceListCable[%d].ChannelList[%d].tracks = new Array(%s);",icable,ichannel,c.tracks)) http_print(string.format("SourceListCable[%d].ChannelList[%d].tracks = new Array(%s);",icable,ichannel,c.tracks))
ichannel = ichannel + 1 ichannel = ichannel + 1
end end
icable = icable + 1 icable = icable + 1

View File

@ -4,6 +4,27 @@ local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") 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
if arg[1] then if arg[1] then
query = arg[1] query = arg[1]
if query == "get" then query = "" end if query == "get" then query = "" end
@ -11,22 +32,9 @@ if arg[1] then
host = "local" host = "local"
end end
function SendError(err,desc)
io.stdout:write(proto.." "..err.."\r\n")
io.stdout:write("\r\n")
local file = io.open("e404.html")
if file then
local tmp = file:read("*a")
tmp = string.gsub(tmp,"404 Not Found",err .. " " .. desc)
io.stdout:write(tmp)
file:close()
end
end
os.execute("rm -rf /config/channels") os.execute("rm -rf /config/channels")
io.stdout:write(proto.." 303".."\r\n") http_print(proto.." 303")
io.stdout:write("Location: http://"..host.."/reboot.html".."\r\n") http_print("Location: http://"..host.."/reboot.html")
io.stdout:write("\r\n") http_print()

View File

@ -4,6 +4,14 @@ local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") 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
if arg[1] then if arg[1] then
query = arg[1] query = arg[1]
if query == "get" then query = "" end if query == "get" then query = "" end
@ -52,12 +60,13 @@ if p then
end end
if gz then if gz then
io.stdout:write(proto.." 200" .."\r\n") http_print(proto.." 200")
io.stdout:write("Pragma: no-cache".."\r\n") http_print("Pragma: no-cache")
io.stdout:write("Content-Type: application/gzip".."\r\n") http_print("Cache-Control: no-cache")
io.stdout:write('Content-Disposition: filename="channels.tar.gz"'.."\r\n") http_print("Content-Type: application/gzip")
io.stdout:write(string.format("Content-Length: %d",#gz).."\r\n") http_print('Content-Disposition: filename="channels.tar.gz"')
io.stdout:write("\r\n") http_print(string.format("Content-Length: %d",#gz))
http_print()
io.stdout:write(gz) io.stdout:write(gz)
else else
SendError("500","internal error") SendError("500","internal error")

View File

@ -85,6 +85,28 @@ local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") 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
if arg[1] then if arg[1] then
query = arg[1] query = arg[1]
if query == "get" then query = "" end if query == "get" then query = "" end
@ -99,17 +121,12 @@ if query ~= "" then
local auto = false local auto = false
local conf = "" local conf = ""
-- print(proto.." 200") http_print(proto.." 303")
-- print("Pragma: no-cache") http_print("Location: http://"..host.."/"..nextloc)
-- print("Content-Type: text/plain") http_print("")
-- print("")
print(proto.." 303")
print("Location: http://"..host.."/"..nextloc)
print("")
for p,v in string.gmatch(params,"(%a+)=([0123456789%.]+)") do for p,v in string.gmatch(params,"(%a+)=([0123456789%.]+)") do
print(p,v) http_print(p,v)
if p == "auto" and p == "1" then if p == "auto" and p == "1" then
auto = true auto = true
break break
@ -133,12 +150,13 @@ if query ~= "" then
os.execute("/etc/init.d/S99octo restartoctoserve&") os.execute("/etc/init.d/S99octo restartoctoserve&")
else else
print(proto.." 200") http_print(proto.." 200")
print("Pragma: no-cache") http_print("Pragma: no-cache")
print("Content-Type: application/x-javascript") http_print("Cache-Control: no-cache")
print("") http_print("Content-Type: application/x-javascript")
http_print("")
print("LNBList = new Array();") http_print("LNBList = new Array();")
local i,lnb local i,lnb
local Conf = LoadOctoserveConf("LNB") local Conf = LoadOctoserveConf("LNB")
@ -158,26 +176,26 @@ else
if n == "LOF1" then LOF1 = v end if n == "LOF1" then LOF1 = v end
if n == "LOF2" then LOF2 = v end if n == "LOF2" then LOF2 = v end
if n == "LOFS" then LOFS = v end if n == "LOFS" then LOFS = v end
print("// " .. n .. " = " .. v); http_print("// " .. n .. " = " .. v);
end end
print(string.format("LNBList[%d] = new Object();" ,i)) http_print(string.format("LNBList[%d] = new Object();" ,i))
print(string.format("LNBList[%d].Tuner = %d;" ,i,Tuner )) http_print(string.format("LNBList[%d].Tuner = %d;" ,i,Tuner ))
print(string.format("LNBList[%d].Source = %d;" ,i,Source)) http_print(string.format("LNBList[%d].Source = %d;" ,i,Source))
print(string.format("LNBList[%d].LOF1 = %d;" ,i,LOF1 )) http_print(string.format("LNBList[%d].LOF1 = %d;" ,i,LOF1 ))
print(string.format("LNBList[%d].LOF2 = %d;" ,i,LOF2 )) http_print(string.format("LNBList[%d].LOF2 = %d;" ,i,LOF2 ))
print(string.format("LNBList[%d].LOFS = %d;" ,i,LOFS )) http_print(string.format("LNBList[%d].LOFS = %d;" ,i,LOFS ))
i = i + 1 i = i + 1
end end
-- print("LNBList[0] = new Object();") -- http_print("LNBList[0] = new Object();")
-- print("LNBList[0].Tuner = 0;") -- http_print("LNBList[0].Tuner = 0;")
-- print("LNBList[0].Source = 0;") -- http_print("LNBList[0].Source = 0;")
-- print("LNBList[0].LOF1 = 9750;") -- http_print("LNBList[0].LOF1 = 9750;")
-- print("LNBList[0].LOF2 = 10600;") -- http_print("LNBList[0].LOF2 = 10600;")
-- print("LNBList[0].LOFS = 11700;") -- http_print("LNBList[0].LOFS = 11700;")
end end

View File

@ -15,14 +15,9 @@ function http_print(s)
end end
end end
if #arg> 0 then
method="GET"
query="select=m3u"
proto = "HTTP/1.0"
end
function SendError(err,desc) function SendError(err,desc)
http_print(proto.." "..err) http_print(proto.." "..err)
http_print("Content-Type: text/html")
http_print() http_print()
local file = io.open("e404.html") local file = io.open("e404.html")
if file then if file then
@ -33,6 +28,12 @@ function SendError(err,desc)
end end
end end
if #arg> 0 then
method="GET"
query="select=m3u"
proto = "HTTP/1.0"
end
function GetDevID() function GetDevID()
local devid = nil local devid = nil
local tmp = io.open("/config/device.id") local tmp = io.open("/config/device.id")
@ -90,6 +91,7 @@ if method == "GET" then
if data then if data then
http_print(proto.." 200" ) http_print(proto.." 200" )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: text/"..subtype) http_print("Content-Type: text/"..subtype)
http_print('Content-Disposition: filename="'..disposition..'"') http_print('Content-Disposition: filename="'..disposition..'"')
http_print(string.format("Content-Length: %d",#data)) http_print(string.format("Content-Length: %d",#data))

View File

@ -92,6 +92,7 @@ local mclist = ReadList()
http_print("HTTP/1.1 200") http_print("HTTP/1.1 200")
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/x-javascript") http_print("Content-Type: application/x-javascript")
http_print() http_print()

View File

@ -17,6 +17,7 @@ end
function SendError(err,desc) function SendError(err,desc)
http_print(proto.." "..err) http_print(proto.." "..err)
http_print("Content-Type: text/html")
http_print() http_print()
local file = io.open("e404.html") local file = io.open("e404.html")
if file then if file then
@ -91,6 +92,7 @@ if method == "GET" then
http_print(proto.." "..status ) http_print(proto.." "..status )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/json; charset=UTF-8") http_print("Content-Type: application/json; charset=UTF-8")
http_print(string.format("Content-Length: %d",#data)) http_print(string.format("Content-Length: %d",#data))
http_print() http_print()

View File

@ -159,6 +159,7 @@ if method == "GET" then
if data then if data then
http_print(proto.." 200" ) http_print(proto.." 200" )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: text/"..subtype) http_print("Content-Type: text/"..subtype)
http_print('Content-Disposition: filename="'..disposition..'"') http_print('Content-Disposition: filename="'..disposition..'"')
http_print(string.format("Content-Length: %d",#data)) http_print(string.format("Content-Length: %d",#data))

View File

@ -17,6 +17,7 @@ end
function SendError(err,desc) function SendError(err,desc)
http_print(proto.." "..err) http_print(proto.." "..err)
http_print("Content-Type: text/html")
http_print() http_print()
local file = io.open("e404.html") local file = io.open("e404.html")
if file then if file then
@ -56,6 +57,7 @@ JSONData = "{\"Rebooting\":"..Rebooting.."}"
http_print(proto.." 200" ) http_print(proto.." 200" )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/json; charset=UTF-8") http_print("Content-Type: application/json; charset=UTF-8")
http_print(string.format("Content-Length: %d",#JSONData)) http_print(string.format("Content-Length: %d",#JSONData))
http_print() http_print()

View File

@ -5,6 +5,27 @@ local SCIFDataBase = io.open('SCIFDataBase.xml'):read("*a")
-- SLAXML:parse(SCIFDataBase,{stripWhitespace=true}) -- SLAXML:parse(SCIFDataBase,{stripWhitespace=true})
local dom = SLAXML:dom(SCIFDataBase,{ simple=false,stripWhitespace=true }) local dom = SLAXML:dom(SCIFDataBase,{ simple=false,stripWhitespace=true })
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
local child local child
local unit local unit
@ -19,7 +40,7 @@ local ManufacturerArray = {}
local ManufacturerCount = 0 local ManufacturerCount = 0
for i,child in ipairs(dom.kids) do for i,child in ipairs(dom.kids) do
print (i,child.name) http_print (i,child.name)
if child.name == "SCIFDataBase" then if child.name == "SCIFDataBase" then
for j,unit in ipairs(child.kids) do for j,unit in ipairs(child.kids) do
if unit.name == "OutdoorUnit" then if unit.name == "OutdoorUnit" then
@ -30,7 +51,7 @@ for i,child in ipairs(dom.kids) do
if not Protocol then Protocol = "EN50494" end if not Protocol then Protocol = "EN50494" end
if not Manufacturer then Manufacturer = "" end if not Manufacturer then Manufacturer = "" end
if not Type then Type = "LNB" end if not Type then Type = "LNB" end
-- print ( " ",Name,Manufacturer,Type) -- http_print ( " ",Name,Manufacturer,Type)
local CurManu = ManufacturerList[Manufacturer] local CurManu = ManufacturerList[Manufacturer]
if not CurManu then if not CurManu then
CurManu = { UnitList = {}, UnitCount = 0, Name = Manufacturer } CurManu = { UnitList = {}, UnitCount = 0, Name = Manufacturer }
@ -47,7 +68,7 @@ for i,child in ipairs(dom.kids) do
fcount = fcount + 1 fcount = fcount + 1
CurUnit.Frequencies[fcount] = Frequency.attr["Frequency"] CurUnit.Frequencies[fcount] = Frequency.attr["Frequency"]
-- print(" -------------------------", Frequency.type, Frequency.name, Frequency.attr["Frequency"]) -- http_print(" -------------------------", Frequency.type, Frequency.name, Frequency.attr["Frequency"])
end end
end end
end end
@ -55,32 +76,33 @@ for i,child in ipairs(dom.kids) do
end end
end end
-- print(ManufacturerCount) -- http_print(ManufacturerCount)
print("HTTP/1.1 200 ") http_print("HTTP/1.1 200 ")
print("Pragma: no-cache") http_print("Pragma: no-cache")
print("Content-Type: application/x-javascript") http_print("Cache-Control: no-cache")
print("") http_print("Content-Type: application/x-javascript")
http_print()
print("ManufacturerList = new Array();") http_print("ManufacturerList = new Array();")
for i,CurManu in ipairs(ManufacturerArray) do for i,CurManu in ipairs(ManufacturerArray) do
print("") http_print()
print(string.format("ManufacturerList[%d] = new Object();",i-1)) http_print(string.format("ManufacturerList[%d] = new Object();",i-1))
print(string.format("ManufacturerList[%d].Name = \"%s\";",i-1,CurManu.Name)) http_print(string.format("ManufacturerList[%d].Name = \"%s\";",i-1,CurManu.Name))
print(string.format("ManufacturerList[%d].UnitList = new Array();",i-1)) http_print(string.format("ManufacturerList[%d].UnitList = new Array();",i-1))
for j,CurUnit in ipairs(CurManu.UnitList) do for j,CurUnit in ipairs(CurManu.UnitList) do
print("") http_print()
print(string.format("ManufacturerList[%d].UnitList[%d] = new Object();",i-1,j-1)) http_print(string.format("ManufacturerList[%d].UnitList[%d] = new Object();",i-1,j-1))
print(string.format("ManufacturerList[%d].UnitList[%d].Name = \"%s\";",i-1,j-1,CurUnit.Name)) http_print(string.format("ManufacturerList[%d].UnitList[%d].Name = \"%s\";",i-1,j-1,CurUnit.Name))
print(string.format("ManufacturerList[%d].UnitList[%d].Protocol = \"%s\";",i-1,j-1,CurUnit.Protocol)) http_print(string.format("ManufacturerList[%d].UnitList[%d].Protocol = \"%s\";",i-1,j-1,CurUnit.Protocol))
print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies = new Array();",i-1,j-1)) http_print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies = new Array();",i-1,j-1))
for k,Frequency in ipairs(CurUnit.Frequencies) do for k,Frequency in ipairs(CurUnit.Frequencies) do
print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies[%d] = %d;",i-1,j-1,k-1,Frequency)) http_print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies[%d] = %d;",i-1,j-1,k-1,Frequency))
end end
end end
i = i + 1 i = i + 1
end end
print("") http_print()

View File

@ -64,6 +64,14 @@ function LoadOctoserveConf(Section)
return(Values) return(Values)
end end
function http_print(s)
if s then
io.stdout:write(tostring(s).."\r\n")
else
io.stdout:write("\r\n")
end
end
local host = os.getenv("HTTP_HOST") local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
@ -71,9 +79,9 @@ local query = os.getenv("QUERY_STRING")
if query ~= "" then if query ~= "" then
print(proto.." 303") http_print(proto.." 303")
print("Location: http://"..host.."/wait.html?5") http_print("Location: http://"..host.."/wait.html?5")
print("") http_print()
-- print(string.format("Set Unicable %s", query )) -- print(string.format("Set Unicable %s", query ))
@ -112,10 +120,11 @@ if query ~= "" then
SaveOctoserveConf("scif",Values) SaveOctoserveConf("scif",Values)
os.execute("/etc/init.d/S99octo restartoctoserve&") os.execute("/etc/init.d/S99octo restartoctoserve&")
else else
print(proto.." 200") http_print(proto.." 200")
print("Pragma: no-cache") http_print("Pragma: no-cache")
print("Content-Type: application/x-javascript") http_print("Cache-Control: no-cache")
print("") http_print("Content-Type: application/x-javascript")
http_print()
Values = LoadOctoserveConf("scif") Values = LoadOctoserveConf("scif")
@ -124,14 +133,14 @@ else
name,i,v1,v2,v3 = string.match(v,"(%a+)(%d-)%=(%d+)%,?(%d*)%,?(%d*)") name,i,v1,v2,v3 = string.match(v,"(%a+)(%d-)%=(%d+)%,?(%d*)%,?(%d*)")
if name == "Tuner" then if name == "Tuner" then
print(string.format("Tuner[%d] = new Object();",i-1)) http_print(string.format("Tuner[%d] = new Object();",i-1))
print(string.format("Tuner[%d].Slot = %d;",i-1,v1)) http_print(string.format("Tuner[%d].Slot = %d;",i-1,v1))
if v2 == "" then v2 = 0 end if v2 == "" then v2 = 0 end
print(string.format("Tuner[%d].Freq = %d;",i-1,v2)) http_print(string.format("Tuner[%d].Freq = %d;",i-1,v2))
if v3 == "" then v3 = -1 end if v3 == "" then v3 = -1 end
print(string.format("Tuner[%d].Pin = %d;",i-1,v3)) http_print(string.format("Tuner[%d].Pin = %d;",i-1,v3))
else else
print( name .. " = " .. v1 .. ";" ) http_print( name .. " = " .. v1 .. ";" )
end end
end end
end end

View File

@ -5,7 +5,24 @@ local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") local query = os.getenv("QUERY_STRING")
function http_print(s) function http_print(s)
io.stdout:write(s.."\r\n") 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 end
function readattr(attr) function readattr(attr)
@ -21,9 +38,10 @@ end
http_print("HTTP/1.1 200") http_print("HTTP/1.1 200")
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/x-javascript") http_print("Content-Type: application/x-javascript")
--http_print("Content-Type: text/plain") --http_print("Content-Type: text/plain")
http_print("") http_print()
dev0 = tonumber(readattr("devid0"),16) dev0 = tonumber(readattr("devid0"),16)
hwid = tonumber(readattr("hwid"),16) hwid = tonumber(readattr("hwid"),16)

View File

@ -51,6 +51,27 @@ local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL") local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING") 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
if arg[1] then if arg[1] then
query = arg[1] query = arg[1]
proto = "HTTP/1.0" proto = "HTTP/1.0"
@ -88,45 +109,46 @@ if query ~= "" then
print("") print("")
else else
print(proto.." 200") http_print(proto.." 200")
print("Pragma: no-cache") http_print("Pragma: no-cache")
print("Content-Type: application/x-javascript") http_print("Cache-Control: no-cache")
print("") http_print("Content-Type: application/x-javascript")
http_print()
if ReadSetting("telnet") then if ReadSetting("telnet") then
print("telnetEnabled = true;") http_print("telnetEnabled = true;")
else else
print("telnetEnabled = false;") http_print("telnetEnabled = false;")
end end
if ReadSetting("vlan") then if ReadSetting("vlan") then
print("vlanEnabled = true;") http_print("vlanEnabled = true;")
else else
print("vlanEnabled = false;") http_print("vlanEnabled = false;")
end end
if ReadSetting("nodms") then if ReadSetting("nodms") then
print("nodmsEnabled = true;") http_print("nodmsEnabled = true;")
else else
print("nodmsEnabled = false;") http_print("nodmsEnabled = false;")
end end
if ReadSetting("nodvbt") then if ReadSetting("nodvbt") then
print("nodvbtEnabled = true;") http_print("nodvbtEnabled = true;")
else else
print("nodvbtEnabled = false;") http_print("nodvbtEnabled = false;")
end end
if ReadSetting("noswitch") then if ReadSetting("noswitch") then
print("noswitchEnabled = true;") http_print("noswitchEnabled = true;")
else else
print("noswitchEnabled = false;") http_print("noswitchEnabled = false;")
end end
if ReadSetting("strict") then if ReadSetting("strict") then
print("strictEnabled = true;") http_print("strictEnabled = true;")
else else
print("strictEnabled = false;") http_print("strictEnabled = false;")
end end

View File

@ -17,6 +17,7 @@ end
function SendError(err,desc) function SendError(err,desc)
http_print(proto.." "..err) http_print(proto.." "..err)
http_print("Content-Type: text/html")
http_print() http_print()
local file = io.open("e404.html") local file = io.open("e404.html")
if file then if file then
@ -158,12 +159,8 @@ end
http_print(proto.." 200" ) http_print(proto.." 200" )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Cache-Control: no-cache")
http_print("Content-Type: application/json; charset=UTF-8") http_print("Content-Type: application/json; charset=UTF-8")
http_print(string.format("Content-Length: %d",#JSONData)) http_print(string.format("Content-Length: %d",#JSONData))
http_print() http_print()
http_print(JSONData) http_print(JSONData)

View File

@ -7,6 +7,27 @@ local method = os.getenv("REQUEST_METHOD")
local clength = os.getenv("CONTENT_LENGTH") local clength = os.getenv("CONTENT_LENGTH")
local ctype = os.getenv("CONTENT_TYPE") local ctype = os.getenv("CONTENT_TYPE")
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
if arg[1] then if arg[1] then
query = arg[1] query = arg[1]
if query == "get" then query = "" end if query == "get" then query = "" end
@ -14,19 +35,6 @@ if arg[1] then
host = "local" host = "local"
end end
function SendError(err,desc)
io.stdout:write(proto.." "..err.."\r\n")
io.stdout:write("Content-Type: text/html".."\r\n")
io.stdout:write("\r\n")
local file = io.open("e404.html")
if file then
local tmp = file:read("*a")
tmp = string.gsub(tmp,"404 Not Found",err .. " " .. desc)
io.stdout:write(tmp)
file:close()
end
end
local path = nil local path = nil
local tmp = "/var/tmp/xxxx" local tmp = "/var/tmp/xxxx"
@ -76,7 +84,7 @@ os.remove("/tmp/"..filename)
-- TODO validate -- TODO validate
io.stdout:write(proto.." 303".."\r\n") http_print(proto.." 303")
io.stdout:write("Location: http://"..host.."/reboot.html") http_print("Location: http://"..host.."/reboot.html")
io.stdout:write("\r\n") http_print()