From 928816fbe40657d8e5567501e4d797ba4dad966e Mon Sep 17 00:00:00 2001 From: mvoelkel Date: Thu, 24 Sep 2015 19:09:08 +0200 Subject: [PATCH] script cleanup unified output using http_print added Cache-Control header --- octoserve/var/www/btvchannels.lua | 77 ++++++++++++++++++---------- octoserve/var/www/delchannels.lua | 40 +++++++++------ octoserve/var/www/dlchannels.lua | 21 +++++--- octoserve/var/www/lnbsettings.lua | 72 ++++++++++++++++---------- octoserve/var/www/mcconfig.lua | 14 ++--- octoserve/var/www/mclist.lua | 1 + octoserve/var/www/monitor.lua | 2 + octoserve/var/www/multicast.lua | 1 + octoserve/var/www/reboot.lua | 2 + octoserve/var/www/scifdb.lua | 62 ++++++++++++++-------- octoserve/var/www/scifsettings.lua | 33 +++++++----- octoserve/var/www/systeminfo.lua | 22 +++++++- octoserve/var/www/systemsettings.lua | 54 +++++++++++++------ octoserve/var/www/update.lua | 7 +-- octoserve/var/www/uplchannels.lua | 40 +++++++++------ 15 files changed, 295 insertions(+), 153 deletions(-) diff --git a/octoserve/var/www/btvchannels.lua b/octoserve/var/www/btvchannels.lua index 0a17e48..d72cc58 100644 --- a/octoserve/var/www/btvchannels.lua +++ b/octoserve/var/www/btvchannels.lua @@ -6,24 +6,47 @@ local host = os.getenv("HTTP_HOST") local proto = os.getenv("SERVER_PROTOCOL") local query = os.getenv("QUERY_STRING") -print(proto.." 200") ---print("Pragma: no-cache") -print("Content-Type: application/x-javascript") -print("") +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 + + +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 = {} for _,f in ipairs(db.SourceList) do f.ChannelList = {} SourceList[f.refid] = f - print("// " .. f.refid .. " " .. f.title ) + http_print("// " .. f.refid .. " " .. f.title ) end for _,c in ipairs(db.ChannelList) do local f = SourceList[c.refid] if f then 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 @@ -32,41 +55,41 @@ local icable = 0 local iter = 0 local ichannel = 0 -print("var SourceListSat = new Array();") -print("var SourceListCable = new Array();") -print("var SourceListTer = new Array();") +http_print("var SourceListSat = new Array();") +http_print("var SourceListCable = new Array();") +http_print("var SourceListTer = new Array();") for _,f in pairs(SourceList) do if f.system == "dvbs" or f.system == "dvbs2" then - print("") - print(string.format("SourceListSat[%d] = new Object();",isat)) - print(string.format("SourceListSat[%d].name = '%s';",isat,f.title)) - print(string.format("SourceListSat[%d].ChannelList = new Array();",isat)) + http_print("") + http_print(string.format("SourceListSat[%d] = new Object();",isat)) + http_print(string.format("SourceListSat[%d].name = '%s';",isat,f.title)) + http_print(string.format("SourceListSat[%d].ChannelList = new Array();",isat)) ichannel = 0 for _,c in ipairs(f.ChannelList) do - print("") - 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,"'","\\'"))) - 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("") + http_print(string.format("SourceListSat[%d].ChannelList[%d] = new Object();",isat,ichannel)) + http_print(string.format("SourceListSat[%d].ChannelList[%d].name = '%s';",isat,ichannel,string.gsub(c.title,"'","\\'"))) + http_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].tracks = new Array(%s);",isat,ichannel,c.tracks)) ichannel = ichannel + 1 end isat = isat + 1 end if f.system == "dvbc" or f.system == "dvbc2" then - print("") - print(string.format("SourceListCable[%d] = new Object();",icable)) - print(string.format("SourceListCable[%d].name = '%s';",icable,f.title)) - print(string.format("SourceListCable[%d].ChannelList = new Array();",icable)) + http_print("") + http_print(string.format("SourceListCable[%d] = new Object();",icable)) + http_print(string.format("SourceListCable[%d].name = '%s';",icable,f.title)) + http_print(string.format("SourceListCable[%d].ChannelList = new Array();",icable)) ichannel = 0 for _,c in ipairs(f.ChannelList) do - print("") - 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,"'","\\'"))) - 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("") + http_print(string.format("SourceListCable[%d].ChannelList[%d] = new Object();",icable,ichannel)) + http_print(string.format("SourceListCable[%d].ChannelList[%d].name = '%s';",icable,ichannel,string.gsub(c.title,"'","\\'"))) + http_print(string.format("SourceListCable[%d].ChannelList[%d].request = '?%s';",icable,ichannel,c.request)) + http_print(string.format("SourceListCable[%d].ChannelList[%d].tracks = new Array(%s);",icable,ichannel,c.tracks)) ichannel = ichannel + 1 end icable = icable + 1 diff --git a/octoserve/var/www/delchannels.lua b/octoserve/var/www/delchannels.lua index 5481621..d86a085 100644 --- a/octoserve/var/www/delchannels.lua +++ b/octoserve/var/www/delchannels.lua @@ -4,6 +4,27 @@ 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 + if arg[1] then query = arg[1] if query == "get" then query = "" end @@ -11,22 +32,9 @@ if arg[1] then host = "local" 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") -io.stdout:write(proto.." 303".."\r\n") -io.stdout:write("Location: http://"..host.."/reboot.html".."\r\n") -io.stdout:write("\r\n") +http_print(proto.." 303") +http_print("Location: http://"..host.."/reboot.html") +http_print() diff --git a/octoserve/var/www/dlchannels.lua b/octoserve/var/www/dlchannels.lua index c669ef3..f2933b2 100644 --- a/octoserve/var/www/dlchannels.lua +++ b/octoserve/var/www/dlchannels.lua @@ -4,6 +4,14 @@ 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 + if arg[1] then query = arg[1] if query == "get" then query = "" end @@ -52,12 +60,13 @@ if p then end if gz then - io.stdout:write(proto.." 200" .."\r\n") - io.stdout:write("Pragma: no-cache".."\r\n") - io.stdout:write("Content-Type: application/gzip".."\r\n") - io.stdout:write('Content-Disposition: filename="channels.tar.gz"'.."\r\n") - io.stdout:write(string.format("Content-Length: %d",#gz).."\r\n") - io.stdout:write("\r\n") + http_print(proto.." 200") + http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") + http_print("Content-Type: application/gzip") + http_print('Content-Disposition: filename="channels.tar.gz"') + http_print(string.format("Content-Length: %d",#gz)) + http_print() io.stdout:write(gz) else SendError("500","internal error") diff --git a/octoserve/var/www/lnbsettings.lua b/octoserve/var/www/lnbsettings.lua index ea4b2b2..0525acf 100644 --- a/octoserve/var/www/lnbsettings.lua +++ b/octoserve/var/www/lnbsettings.lua @@ -85,6 +85,28 @@ 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 + + if arg[1] then query = arg[1] if query == "get" then query = "" end @@ -99,17 +121,12 @@ if query ~= "" then local auto = false local conf = "" - -- print(proto.." 200") - -- print("Pragma: no-cache") - -- print("Content-Type: text/plain") - -- print("") - - print(proto.." 303") - print("Location: http://"..host.."/"..nextloc) - print("") + http_print(proto.." 303") + http_print("Location: http://"..host.."/"..nextloc) + http_print("") for p,v in string.gmatch(params,"(%a+)=([0123456789%.]+)") do - print(p,v) + http_print(p,v) if p == "auto" and p == "1" then auto = true break @@ -133,12 +150,13 @@ if query ~= "" then os.execute("/etc/init.d/S99octo restartoctoserve&") else - print(proto.." 200") - print("Pragma: no-cache") - print("Content-Type: application/x-javascript") - print("") + http_print(proto.." 200") + http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") + http_print("Content-Type: application/x-javascript") + http_print("") - print("LNBList = new Array();") + http_print("LNBList = new Array();") local i,lnb local Conf = LoadOctoserveConf("LNB") @@ -158,26 +176,26 @@ else if n == "LOF1" then LOF1 = v end if n == "LOF2" then LOF2 = v end if n == "LOFS" then LOFS = v end - print("// " .. n .. " = " .. v); + http_print("// " .. n .. " = " .. v); end - print(string.format("LNBList[%d] = new Object();" ,i)) - print(string.format("LNBList[%d].Tuner = %d;" ,i,Tuner )) - print(string.format("LNBList[%d].Source = %d;" ,i,Source)) - print(string.format("LNBList[%d].LOF1 = %d;" ,i,LOF1 )) - print(string.format("LNBList[%d].LOF2 = %d;" ,i,LOF2 )) - print(string.format("LNBList[%d].LOFS = %d;" ,i,LOFS )) + http_print(string.format("LNBList[%d] = new Object();" ,i)) + http_print(string.format("LNBList[%d].Tuner = %d;" ,i,Tuner )) + http_print(string.format("LNBList[%d].Source = %d;" ,i,Source)) + http_print(string.format("LNBList[%d].LOF1 = %d;" ,i,LOF1 )) + http_print(string.format("LNBList[%d].LOF2 = %d;" ,i,LOF2 )) + http_print(string.format("LNBList[%d].LOFS = %d;" ,i,LOFS )) i = i + 1 end - -- print("LNBList[0] = new Object();") - -- print("LNBList[0].Tuner = 0;") - -- print("LNBList[0].Source = 0;") - -- print("LNBList[0].LOF1 = 9750;") - -- print("LNBList[0].LOF2 = 10600;") - -- print("LNBList[0].LOFS = 11700;") + -- http_print("LNBList[0] = new Object();") + -- http_print("LNBList[0].Tuner = 0;") + -- http_print("LNBList[0].Source = 0;") + -- http_print("LNBList[0].LOF1 = 9750;") + -- http_print("LNBList[0].LOF2 = 10600;") + -- http_print("LNBList[0].LOFS = 11700;") end diff --git a/octoserve/var/www/mcconfig.lua b/octoserve/var/www/mcconfig.lua index fb9f6e6..4edae0d 100644 --- a/octoserve/var/www/mcconfig.lua +++ b/octoserve/var/www/mcconfig.lua @@ -15,14 +15,9 @@ function http_print(s) end end -if #arg> 0 then - method="GET" - query="select=m3u" - proto = "HTTP/1.0" -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 @@ -33,6 +28,12 @@ function SendError(err,desc) end end +if #arg> 0 then + method="GET" + query="select=m3u" + proto = "HTTP/1.0" +end + function GetDevID() local devid = nil local tmp = io.open("/config/device.id") @@ -90,6 +91,7 @@ if method == "GET" then if data then http_print(proto.." 200" ) http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") http_print("Content-Type: text/"..subtype) http_print('Content-Disposition: filename="'..disposition..'"') http_print(string.format("Content-Length: %d",#data)) diff --git a/octoserve/var/www/mclist.lua b/octoserve/var/www/mclist.lua index 5e8c13f..bfcbb47 100644 --- a/octoserve/var/www/mclist.lua +++ b/octoserve/var/www/mclist.lua @@ -92,6 +92,7 @@ local mclist = ReadList() http_print("HTTP/1.1 200") http_print("Pragma: no-cache") +http_print("Cache-Control: no-cache") http_print("Content-Type: application/x-javascript") http_print() diff --git a/octoserve/var/www/monitor.lua b/octoserve/var/www/monitor.lua index c0af731..ffd805b 100644 --- a/octoserve/var/www/monitor.lua +++ b/octoserve/var/www/monitor.lua @@ -17,6 +17,7 @@ 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 @@ -91,6 +92,7 @@ if method == "GET" then http_print(proto.." "..status ) http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") http_print("Content-Type: application/json; charset=UTF-8") http_print(string.format("Content-Length: %d",#data)) http_print() diff --git a/octoserve/var/www/multicast.lua b/octoserve/var/www/multicast.lua index 8de0116..8b2b91a 100644 --- a/octoserve/var/www/multicast.lua +++ b/octoserve/var/www/multicast.lua @@ -159,6 +159,7 @@ if method == "GET" then if data then http_print(proto.." 200" ) http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") http_print("Content-Type: text/"..subtype) http_print('Content-Disposition: filename="'..disposition..'"') http_print(string.format("Content-Length: %d",#data)) diff --git a/octoserve/var/www/reboot.lua b/octoserve/var/www/reboot.lua index a87fe96..3f966bf 100644 --- a/octoserve/var/www/reboot.lua +++ b/octoserve/var/www/reboot.lua @@ -17,6 +17,7 @@ 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 @@ -56,6 +57,7 @@ JSONData = "{\"Rebooting\":"..Rebooting.."}" http_print(proto.." 200" ) http_print("Pragma: no-cache") +http_print("Cache-Control: no-cache") http_print("Content-Type: application/json; charset=UTF-8") http_print(string.format("Content-Length: %d",#JSONData)) http_print() diff --git a/octoserve/var/www/scifdb.lua b/octoserve/var/www/scifdb.lua index b3702d1..6f0c6dd 100644 --- a/octoserve/var/www/scifdb.lua +++ b/octoserve/var/www/scifdb.lua @@ -5,6 +5,27 @@ local SCIFDataBase = io.open('SCIFDataBase.xml'):read("*a") -- SLAXML:parse(SCIFDataBase,{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 unit @@ -19,7 +40,7 @@ local ManufacturerArray = {} local ManufacturerCount = 0 for i,child in ipairs(dom.kids) do - print (i,child.name) + http_print (i,child.name) if child.name == "SCIFDataBase" then for j,unit in ipairs(child.kids) do 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 Manufacturer then Manufacturer = "" end if not Type then Type = "LNB" end - -- print ( " ",Name,Manufacturer,Type) + -- http_print ( " ",Name,Manufacturer,Type) local CurManu = ManufacturerList[Manufacturer] if not CurManu then CurManu = { UnitList = {}, UnitCount = 0, Name = Manufacturer } @@ -47,7 +68,7 @@ for i,child in ipairs(dom.kids) do fcount = fcount + 1 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 @@ -55,32 +76,33 @@ for i,child in ipairs(dom.kids) do end end --- print(ManufacturerCount) +-- http_print(ManufacturerCount) -print("HTTP/1.1 200 ") -print("Pragma: no-cache") -print("Content-Type: application/x-javascript") -print("") +http_print("HTTP/1.1 200 ") +http_print("Pragma: no-cache") +http_print("Cache-Control: no-cache") +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 - print("") - print(string.format("ManufacturerList[%d] = new Object();",i-1)) - print(string.format("ManufacturerList[%d].Name = \"%s\";",i-1,CurManu.Name)) - print(string.format("ManufacturerList[%d].UnitList = new Array();",i-1)) + http_print() + http_print(string.format("ManufacturerList[%d] = new Object();",i-1)) + http_print(string.format("ManufacturerList[%d].Name = \"%s\";",i-1,CurManu.Name)) + http_print(string.format("ManufacturerList[%d].UnitList = new Array();",i-1)) for j,CurUnit in ipairs(CurManu.UnitList) do - print("") - 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)) - 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() + http_print(string.format("ManufacturerList[%d].UnitList[%d] = new Object();",i-1,j-1)) + http_print(string.format("ManufacturerList[%d].UnitList[%d].Name = \"%s\";",i-1,j-1,CurUnit.Name)) + http_print(string.format("ManufacturerList[%d].UnitList[%d].Protocol = \"%s\";",i-1,j-1,CurUnit.Protocol)) + http_print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies = new Array();",i-1,j-1)) 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 i = i + 1 end -print("") \ No newline at end of file +http_print() diff --git a/octoserve/var/www/scifsettings.lua b/octoserve/var/www/scifsettings.lua index aa9d05e..5dd37a3 100644 --- a/octoserve/var/www/scifsettings.lua +++ b/octoserve/var/www/scifsettings.lua @@ -64,6 +64,14 @@ function LoadOctoserveConf(Section) return(Values) 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 proto = os.getenv("SERVER_PROTOCOL") @@ -71,9 +79,9 @@ local query = os.getenv("QUERY_STRING") if query ~= "" then - print(proto.." 303") - print("Location: http://"..host.."/wait.html?5") - print("") + http_print(proto.." 303") + http_print("Location: http://"..host.."/wait.html?5") + http_print() -- print(string.format("Set Unicable %s", query )) @@ -112,10 +120,11 @@ if query ~= "" then SaveOctoserveConf("scif",Values) os.execute("/etc/init.d/S99octo restartoctoserve&") else - print(proto.." 200") - print("Pragma: no-cache") - print("Content-Type: application/x-javascript") - print("") + http_print(proto.." 200") + http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") + http_print("Content-Type: application/x-javascript") + http_print() Values = LoadOctoserveConf("scif") @@ -124,14 +133,14 @@ else name,i,v1,v2,v3 = string.match(v,"(%a+)(%d-)%=(%d+)%,?(%d*)%,?(%d*)") if name == "Tuner" then - 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] = new Object();",i-1)) + http_print(string.format("Tuner[%d].Slot = %d;",i-1,v1)) 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 - print(string.format("Tuner[%d].Pin = %d;",i-1,v3)) + http_print(string.format("Tuner[%d].Pin = %d;",i-1,v3)) else - print( name .. " = " .. v1 .. ";" ) + http_print( name .. " = " .. v1 .. ";" ) end end end diff --git a/octoserve/var/www/systeminfo.lua b/octoserve/var/www/systeminfo.lua index a6d0f5c..aedcb70 100644 --- a/octoserve/var/www/systeminfo.lua +++ b/octoserve/var/www/systeminfo.lua @@ -5,7 +5,24 @@ local proto = os.getenv("SERVER_PROTOCOL") local query = os.getenv("QUERY_STRING") 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 function readattr(attr) @@ -21,9 +38,10 @@ end http_print("HTTP/1.1 200") http_print("Pragma: no-cache") +http_print("Cache-Control: no-cache") http_print("Content-Type: application/x-javascript") --http_print("Content-Type: text/plain") -http_print("") +http_print() dev0 = tonumber(readattr("devid0"),16) hwid = tonumber(readattr("hwid"),16) diff --git a/octoserve/var/www/systemsettings.lua b/octoserve/var/www/systemsettings.lua index 6e5344b..f9b3d7a 100644 --- a/octoserve/var/www/systemsettings.lua +++ b/octoserve/var/www/systemsettings.lua @@ -51,6 +51,27 @@ 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 + if arg[1] then query = arg[1] proto = "HTTP/1.0" @@ -88,45 +109,46 @@ if query ~= "" then print("") else - print(proto.." 200") - print("Pragma: no-cache") - print("Content-Type: application/x-javascript") - print("") + http_print(proto.." 200") + http_print("Pragma: no-cache") + http_print("Cache-Control: no-cache") + http_print("Content-Type: application/x-javascript") + http_print() if ReadSetting("telnet") then - print("telnetEnabled = true;") + http_print("telnetEnabled = true;") else - print("telnetEnabled = false;") + http_print("telnetEnabled = false;") end if ReadSetting("vlan") then - print("vlanEnabled = true;") + http_print("vlanEnabled = true;") else - print("vlanEnabled = false;") + http_print("vlanEnabled = false;") end if ReadSetting("nodms") then - print("nodmsEnabled = true;") + http_print("nodmsEnabled = true;") else - print("nodmsEnabled = false;") + http_print("nodmsEnabled = false;") end if ReadSetting("nodvbt") then - print("nodvbtEnabled = true;") + http_print("nodvbtEnabled = true;") else - print("nodvbtEnabled = false;") + http_print("nodvbtEnabled = false;") end if ReadSetting("noswitch") then - print("noswitchEnabled = true;") + http_print("noswitchEnabled = true;") else - print("noswitchEnabled = false;") + http_print("noswitchEnabled = false;") end if ReadSetting("strict") then - print("strictEnabled = true;") + http_print("strictEnabled = true;") else - print("strictEnabled = false;") + http_print("strictEnabled = false;") end diff --git a/octoserve/var/www/update.lua b/octoserve/var/www/update.lua index 4354cb0..bb2b63d 100644 --- a/octoserve/var/www/update.lua +++ b/octoserve/var/www/update.lua @@ -17,6 +17,7 @@ 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 @@ -158,12 +159,8 @@ end http_print(proto.." 200" ) http_print("Pragma: no-cache") +http_print("Cache-Control: no-cache") http_print("Content-Type: application/json; charset=UTF-8") http_print(string.format("Content-Length: %d",#JSONData)) http_print() http_print(JSONData) - - - - - diff --git a/octoserve/var/www/uplchannels.lua b/octoserve/var/www/uplchannels.lua index ea40a29..ea05691 100644 --- a/octoserve/var/www/uplchannels.lua +++ b/octoserve/var/www/uplchannels.lua @@ -7,6 +7,27 @@ local method = os.getenv("REQUEST_METHOD") local clength = os.getenv("CONTENT_LENGTH") 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 query = arg[1] if query == "get" then query = "" end @@ -14,19 +35,6 @@ if arg[1] then host = "local" 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 tmp = "/var/tmp/xxxx" @@ -76,7 +84,7 @@ os.remove("/tmp/"..filename) -- TODO validate -io.stdout:write(proto.." 303".."\r\n") -io.stdout:write("Location: http://"..host.."/reboot.html") -io.stdout:write("\r\n") +http_print(proto.." 303") +http_print("Location: http://"..host.."/reboot.html") +http_print()