diff --git a/octoserve/var/www/channellist.lua b/octoserve/var/www/channellist.lua index 6cd0bd7..6c2c38a 100644 --- a/octoserve/var/www/channellist.lua +++ b/octoserve/var/www/channellist.lua @@ -118,7 +118,7 @@ function Legacy2JSON() return data end -function CreateJSON(host) +function CreateJSON() local data = nil local file = io.open("/config/ChannelList.json") if file then @@ -130,9 +130,26 @@ function CreateJSON(host) return data end +function TransponderList(user) + local data = nil + local file + if user then + file = io.open("/config/TransponderList.json","r") + end + if not file then + file = io.open("/var/channels/TransponderList.json","r") + end + if file then + data = file:read("*a") + file:close() + end + return data +end + function LoadSourceList() local db = require("DataBase") local SourceList = {} + local f,c for _,f in ipairs(db.SourceList) do f.ChannelList = {} @@ -160,7 +177,15 @@ if method == "GET" then elseif string.match(query,"select=json") then filename = "ChannelList.json" contenttype = "application/json; charset=utf-8" - data = CreateJSON(host) + data = CreateJSON() + elseif string.match(query,"select=stl") then + filename = "TransponderList.json" + contenttype = "application/json; charset=utf-8" + data = TransponderList(false) + elseif string.match(query,"select=tl") then + filename = "TransponderList.json" + contenttype = "application/json; charset=utf-8" + data = TransponderList(true) end if data then diff --git a/octoserve/var/www/channellists.html b/octoserve/var/www/channellists.html index 5721303..c452624 100644 --- a/octoserve/var/www/channellists.html +++ b/octoserve/var/www/channellists.html @@ -1,4 +1,4 @@ - + @@ -107,7 +107,9 @@ function DisableButtons(disabled) document.getElementById("ScanButton").disabled = disabled; document.getElementById("StatusButton").disabled = disabled; document.getElementById("DeleteButton").disabled = disabled; + document.getElementById("DeleteAllButton").disabled = disabled; document.getElementById("RestoreButton").disabled = disabled; + document.getElementById("UploadButton").disabled = disabled; } @@ -169,6 +171,16 @@ function ScanStatus(response) else document.getElementById("scantext").firstChild.nodeValue = "Previous channel list restored"; } + else if( s.status == "error" ) + { + document.getElementById("scancount").firstChild.nodeValue = "Error"; + document.getElementById("scantext").firstChild.nodeValue = s.msg; + } + else if( s.status == "updated" ) + { + document.getElementById("scancount").firstChild.nodeValue = "\u00A0"; + document.getElementById("scantext").firstChild.nodeValue = s.msg + " updated"; + } else if( s.status == "retry" ) { done = false; @@ -236,11 +248,12 @@ function PollStatus() GetStatus(); } -function DeleteScan() +function DeleteScan(all) { DisableButtons(true); + ScanReq.open("POST", "/channelscan.lua", true); ScanReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); - ScanReq.send("select=delete"); + ScanReq.send("select=delete" + (all ? "&all=true" : "")); } function RestoreScan() @@ -251,15 +264,32 @@ function RestoreScan() ScanReq.send("select=restore"); } + +function Uploader(event) +{ + event.preventDefault(); + document.getElementById("scancount").firstChild.nodeValue = "\u00A0"; + document.getElementById("scantext").firstChild.nodeValue = "\u00A0"; + var fileSelect = document.getElementById("UploadList"); + if( fileSelect.files.length > 0 ) + { + var formData = new FormData(); + formData.append('filename', fileSelect.files[0], fileSelect.files[0].name) + DisableButtons(true); + ScanReq.open("POST", "/channelscan.lua", true); + ScanReq.send(formData); + } +} + - +
- - + +
DD @@ -270,7 +300,7 @@ function RestoreScan()
- +
+ + +
+
+ + +
+
+
+
+

Downloads

+ Channel List: +  JSON +  M3U +
+ Transponder List: +  Current +  Default +
+
+ +
+

- +

Old Format Lists

+
System Channel Database diff --git a/octoserve/var/www/channelscan.lua b/octoserve/var/www/channelscan.lua index 9fb51dd..0be7985 100644 --- a/octoserve/var/www/channelscan.lua +++ b/octoserve/var/www/channelscan.lua @@ -34,6 +34,11 @@ function SendError(err,desc) end end +function perr(s) + io.stderr:write(tostring(s).."\n") +end + + -- local newdecoder = require("lunajson.decoder") local newencoder = require("lunajson.encoder") @@ -55,6 +60,75 @@ local function LoadTransponderList() return tl end +local function CheckTransponderList(tl) + local i,Source + for i,Source in ipairs(tl.SourceList) do + if not Source.Title then + error("SourceList["..i.."].Title missing",0) + end + if not Source.Key then + error("SourceList["..i.."].Key missing",0) + end + if not Source.DVBType then + error("SourceList["..i.."].DVBType missing",0) + end + if not Source.TransponderList then + error("SourceList["..i.."].TransponderList missing",0) + end + local j,Transponder + for j,Transponder in ipairs(Source.TransponderList) do + if not Transponder.Request then + error("SourceList["..i.."].TransponderList["..j.."].Request missing",0) + end + end + end + if tl.CIMapList then + local CIMap + for i,CIMap in ipairs(tl.CIMapList) do + if not CIMap.Slot then + error("CIMapList["..i.."].Slot missing",0) + end + end + end + if tl.ChannelOverwriteList then + local ChannelOverwrite + for i,ChannelOverwrite in ipairs(tl.ChannelOverwriteList) do + if not ChannelOverwrite.ID then + error("ChannelOverwriteList["..i.."].ID missing",0) + end + end + end + if tl.GroupList then + local Group + for i,Group in ipairs(tl.GroupList) do + if not Group.Title then + error("GroupList["..i.."].Title missing",0) + end + end + end + return "TransponderList.json" +end + +local function CheckChannelList(cl) + local i,Group + for i,Group in ipairs(cl.GroupList) do + if not Group.Title then + error("GroupList["..i.."].Title missing",0) + end + local j,Channel + for j,Channel in ipairs(Group.ChannelList) do + if not Channel.Title then + error("GroupList["..i.."].ChannelList["..j.."].Title missing",0) + end + if not Channel.Request then + error("GroupList["..i.."].ChannelList["..j.."].Request missing",0) + end + end + end + return "ChannelList.json" +end + + local function GetCMD(s) local q,v local params = "" @@ -139,7 +213,7 @@ local function Status() return data end -local function Delete() +local function Delete(params) local data = nil local rc = os.execute("mkdir /tmp/doscan.lock") if rc ~= 0 then @@ -147,6 +221,9 @@ local function Delete() else data = '{"status":"deleted"}' os.execute("rm /config/ChannelList.json"); + if params == " all=true" then + os.execute("rm /config/TransponderList.json"); + end os.execute("rm /tmp/doscan.msg"); os.execute("rm -rf /tmp/doscan.lock"); end @@ -171,6 +248,70 @@ local function Restore() return data end +local function Upload() + local data = nil + local rc = os.execute("mkdir /tmp/doscan.lock") + if rc ~= 0 then + data = '{"status":"busy"}' + else + local boundary = string.match(ctype,"boundary=(.*)") + if boundary then + while true do + local line = io.stdin:read() + line = string.gsub(line,"\r","") + if line == "" then break end + end + + local filedata = io.stdin:read("*a") + local i = filedata:find("--"..boundary,1,true) + if i then + filedata = filedata:sub(1,i-1) + else + filedata = "{}" + end + + local decode = newdecoder() + local rc,json = pcall(decode,filedata) + + if rc then + rc = false + local msg = "invalid list" + if json.SourceList then + rc,msg = pcall(CheckTransponderList,json) + data = '{"status":"updated", "msg":"Transponder list"}' + elseif json.GroupList then + rc,msg = pcall(CheckChannelList,json) + end + if rc then + local f = io.open("/config/"..msg,"w+") + if f then + f:write(filedata) + f:close() + data = '{"status":"updated", "msg":"'..msg..'"}' + else + data = '{"status":"error", "msg":"'..msg..' not saved"}' + end + else + data = '{"status":"error", "msg":"'..msg..'"}' + end + else + local msg = "unknown error" + if json then + msg = json:match(".-: (.*)") + end + data = '{"status":"error", "msg":"'..msg..'"}' + end + + else + data = '{"status":"error","msg":"malformed request"}' + end + os.execute("rm /tmp/doscan.msg"); + os.execute("rm -rf /tmp/doscan.lock"); + end + return data +end + + local filename = nil local contenttype = "application/json; charset=utf-8" local data = nil @@ -184,6 +325,8 @@ elseif method == "POST" and clength and ctype then local query = io.read(tonumber(clength)) query = string.gsub(query,"\r","") cmd,params = GetCMD(query) + elseif ctype:match("multipart/form%-data") then + cmd = "upload" end else SendError("500","What") @@ -197,9 +340,11 @@ elseif cmd == "scan" then elseif cmd == "status" then data = Status() elseif cmd == "delete" then - data = Delete() + data = Delete(params) elseif cmd == "restore" then data = Restore() +elseif cmd == "upload" then + data = Upload() end if data then diff --git a/octoserve/var/www/uplchannels.lua b/octoserve/var/www/uplchannels.lua index ea05691..8cf8622 100644 --- a/octoserve/var/www/uplchannels.lua +++ b/octoserve/var/www/uplchannels.lua @@ -48,7 +48,7 @@ if not string.match(ctype,"multipart/form%-data") then return end -local boundary = string.match(ctype,"boundary=(.*)") +local boundary = string.match(ctype,"boundary=(.*)") if not boundary then SendError("404","???") return @@ -66,25 +66,32 @@ while true do end data = io.stdin:read("*a") -data = string.sub(data,1,#data - #boundary - 4) - -local file = io.open("/tmp/"..filename,"w") -if file then - file:write(data) - file:close() +local i = data:find("--"..boundary,1,true) +if i then + data = data:sub(1,i-1) +else + data = nil end -if string.match(filename,"%.tar%.gz$") then - os.execute("rm -rf /config/channels;mkdir /config/channels;cd /config/channels;gunzip -c /tmp/"..filename.."|tar -xf -"); -elseif string.match(filename,"%.zip$") then - os.execute("rm -rf /config/channels;mkdir /config/channels;cd /config/channels;unzip -q /tmp/"..filename); -end +if data then + local file = io.open("/tmp/"..filename,"w") + if file then + file:write(data) + file:close() + end -os.remove("/tmp/"..filename) + if string.match(filename,"%.tar%.gz$") then + os.execute("rm -rf /config/channels;mkdir /config/channels;cd /config/channels;gunzip -c /tmp/"..filename.."|tar -xf -"); + elseif string.match(filename,"%.zip$") then + os.execute("rm -rf /config/channels;mkdir /config/channels;cd /config/channels;unzip -q /tmp/"..filename); + end + + os.remove("/tmp/"..filename) +end -- TODO validate http_print(proto.." 303") http_print("Location: http://"..host.."/reboot.html") http_print() - +