mirror of
https://github.com/DigitalDevices/octonet.git
synced 2023-10-10 11:36:52 +00:00
Channelscan
Added backup and restore previous list Added delete list to allow to revert to legacy mode Added ID created from key,onid,tsid,sid Userinterface improvment. (Note requires updated octoscan from, dddvb)
This commit is contained in:
@@ -102,6 +102,15 @@ function OnLoad()
|
||||
|
||||
}
|
||||
|
||||
function DisableButtons(disabled)
|
||||
{
|
||||
document.getElementById("ScanButton").disabled = disabled;
|
||||
document.getElementById("StatusButton").disabled = disabled;
|
||||
document.getElementById("DeleteButton").disabled = disabled;
|
||||
document.getElementById("RestoreButton").disabled = disabled;
|
||||
}
|
||||
|
||||
|
||||
var ScanReq = new XMLHttpRequest();
|
||||
|
||||
ScanReq.onreadystatechange=function()
|
||||
@@ -110,6 +119,12 @@ ScanReq.onreadystatechange=function()
|
||||
{
|
||||
if( ScanReq.status == 200 )
|
||||
ScanStatus(ScanReq.responseText);
|
||||
else
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = "\u00A0";
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Error " + ScanReq.status;
|
||||
DisableButtons(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,31 +137,56 @@ function GetStatus()
|
||||
function ScanStatus(response)
|
||||
{
|
||||
var s = JSON.parse(response);
|
||||
if( s.status == "active" )
|
||||
var done = false;
|
||||
if( s.status )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = s.count;
|
||||
document.getElementById("scantext").firstChild.nodeValue = s.msg;
|
||||
window.setTimeout(GetStatus,500);
|
||||
if( s.status == "active" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = s.count;
|
||||
document.getElementById("scantext").firstChild.nodeValue = s.msg;
|
||||
}
|
||||
else if( s.status == "busy" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = "\u00A0";
|
||||
document.getElementById("scantext").firstChild.nodeValue = "BUSY";
|
||||
done = true;
|
||||
}
|
||||
else if( s.status == "done" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = s.count;
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Channels found";
|
||||
done = true;
|
||||
}
|
||||
else if( s.status == "deleted" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = "\u00A0";
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Channel list deleted";
|
||||
done = true;
|
||||
}
|
||||
else if( s.status == "restored" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = "\u00A0";
|
||||
if( s.count == 0 )
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Nothing restored";
|
||||
else
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Previous channel list restored";
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
else if( s.status == "busy" )
|
||||
|
||||
if( done )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = "";
|
||||
document.getElementById("scantext").firstChild.nodeValue = "BUSY";
|
||||
}
|
||||
else if( s.status == "done" )
|
||||
{
|
||||
document.getElementById("scancount").firstChild.nodeValue = s.count;
|
||||
document.getElementById("scantext").firstChild.nodeValue = "Channels found";
|
||||
DisableButtons(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.setTimeout(GetStatus,500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function InitiateScan()
|
||||
{
|
||||
DisableButtons(true);
|
||||
|
||||
var param = "";
|
||||
for(var i = 1; i < document.Cable.Select.options.length; i += 1)
|
||||
{
|
||||
@@ -188,6 +228,26 @@ function InitiateScan()
|
||||
}
|
||||
}
|
||||
|
||||
function PollStatus()
|
||||
{
|
||||
DisableButtons(true);
|
||||
GetStatus();
|
||||
}
|
||||
|
||||
function DeleteScan()
|
||||
{
|
||||
DisableButtons(true);
|
||||
ScanReq.open("GET", "/channelscan.lua?select=delete", true);
|
||||
ScanReq.send();
|
||||
}
|
||||
|
||||
function RestoreScan()
|
||||
{
|
||||
DisableButtons(true);
|
||||
ScanReq.open("GET", "/channelscan.lua?select=restore", true);
|
||||
ScanReq.send();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
@@ -257,7 +317,8 @@ function InitiateScan()
|
||||
<td> </td>
|
||||
<td style="text-align:right">
|
||||
<form action="">
|
||||
<input type="Button" value="Start Scan" onclick="InitiateScan()" >
|
||||
<input id="ScanButton" type="Button" value="Start Scan" onclick="InitiateScan()" >
|
||||
<input id="StatusButton" type="Button" value="Get Status" onclick="PollStatus()" >
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -269,6 +330,15 @@ function InitiateScan()
|
||||
<div id="scantext" style="text-align:left"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td style="text-align:right">
|
||||
<form action="">
|
||||
<input id="DeleteButton" type="Button" value="Delete Scan" onclick="DeleteScan()" >
|
||||
<input id="RestoreButton" type="Button" value="Restore Previous Scan" onclick="RestoreScan()" >
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
|
@@ -56,22 +56,22 @@ local function LoadTransponderList()
|
||||
end
|
||||
|
||||
if method == "GET" then
|
||||
local filename = nil
|
||||
local contenttype = "application/json; charset=utf-8"
|
||||
local data = nil
|
||||
local filename = nil
|
||||
local contenttype = "application/json; charset=utf-8"
|
||||
local data = nil
|
||||
|
||||
local q,v
|
||||
local params = ""
|
||||
local cmd = ""
|
||||
for q,v in query:gmatch("(%a+)=([%w%.]+)") do
|
||||
local q,v
|
||||
local params = ""
|
||||
local cmd = ""
|
||||
for q,v in query:gmatch("(%a+)=([%w%.]+)") do
|
||||
if q == "select" then
|
||||
cmd = v
|
||||
else
|
||||
params = params.." "..q.."="..v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if cmd == "keys" then
|
||||
if cmd == "keys" then
|
||||
local tl = LoadTransponderList()
|
||||
if tl then
|
||||
local kl = { KeyList = { } }
|
||||
@@ -83,12 +83,17 @@ if method == "GET" then
|
||||
local encode = newencoder()
|
||||
data = encode(kl)
|
||||
end
|
||||
elseif cmd == "scan" then
|
||||
elseif cmd == "scan" then
|
||||
local rc = os.execute("mkdir /tmp/doscan.lock")
|
||||
if rc ~= 0 then
|
||||
data = '{"status":"busy"}'
|
||||
else
|
||||
data = '{"status":"retry"}'
|
||||
local f = io.open("/tmp/doscan.msg","w+")
|
||||
if f then
|
||||
f:write("Scanning")
|
||||
f:close()
|
||||
end
|
||||
os.execute("/var/channels/doscan.lua "..params.." >/tmp/doscan.log 2>&1 &")
|
||||
end
|
||||
elseif cmd == "status" then
|
||||
@@ -96,40 +101,75 @@ if method == "GET" then
|
||||
local f = io.open("/tmp/doscan.lock/doscan.msg")
|
||||
if f then
|
||||
js.status = "active"
|
||||
else
|
||||
f = io.open("/tmp/doscan.msg")
|
||||
if f then
|
||||
js.status = "done"
|
||||
else
|
||||
js.status = "retry"
|
||||
end
|
||||
end
|
||||
if f then
|
||||
local m = f:read("*l")
|
||||
local count,msg = m:match("(%d+):(.*)")
|
||||
js.count = count
|
||||
js.msg = msg
|
||||
f:close()
|
||||
else
|
||||
f = io.open("/tmp/doscan.msg")
|
||||
if f then
|
||||
local m = f:read("*l")
|
||||
local count,msg = m:match("(%d+):(.*)")
|
||||
if count and msg then
|
||||
js.count = count
|
||||
js.msg = msg
|
||||
js.status = "done"
|
||||
else
|
||||
if m == "Scanning" then
|
||||
js.status = "retry"
|
||||
else
|
||||
js.status = nil
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
else
|
||||
js.status = ""
|
||||
end
|
||||
end
|
||||
local encode = newencoder()
|
||||
data = encode(js)
|
||||
end
|
||||
elseif cmd == "delete" then
|
||||
local rc = os.execute("mkdir /tmp/doscan.lock")
|
||||
if rc ~= 0 then
|
||||
data = '{"status":"busy"}'
|
||||
else
|
||||
data = '{"status":"deleted"}'
|
||||
os.execute("rm /config/ChannelList.json");
|
||||
os.execute("rm /tmp/doscan.msg");
|
||||
os.execute("rm -rf /tmp/doscan.lock");
|
||||
end
|
||||
elseif cmd == "restore" then
|
||||
local rc = os.execute("mkdir /tmp/doscan.lock")
|
||||
if rc ~= 0 then
|
||||
data = '{"status":"busy"}'
|
||||
else
|
||||
local rc = os.execute("mv /config/ChannelList.bak /config/ChannelList.json");
|
||||
if rc == 0 then
|
||||
data = '{"status":"restored", "count":1}'
|
||||
else
|
||||
data = '{"status":"restored", "count":0}'
|
||||
end
|
||||
os.execute("rm /tmp/doscan.msg");
|
||||
os.execute("rm -rf /tmp/doscan.lock");
|
||||
end
|
||||
end
|
||||
|
||||
if data then
|
||||
http_print(proto.." 200" )
|
||||
http_print("Pragma: no-cache")
|
||||
http_print("Cache-Control: no-cache")
|
||||
http_print("Content-Type: "..contenttype)
|
||||
if filename then
|
||||
http_print('Content-Disposition: filename="'..filename..'"')
|
||||
end
|
||||
http_print(string.format("Content-Length: %d",#data))
|
||||
http_print()
|
||||
http_print(data)
|
||||
else
|
||||
SendError("404","not found")
|
||||
end
|
||||
if data then
|
||||
http_print(proto.." 200" )
|
||||
http_print("Pragma: no-cache")
|
||||
http_print("Cache-Control: no-cache")
|
||||
http_print("Content-Type: "..contenttype)
|
||||
if filename then
|
||||
http_print('Content-Disposition: filename="'..filename..'"')
|
||||
end
|
||||
http_print(string.format("Content-Length: %d",#data))
|
||||
http_print()
|
||||
http_print(data)
|
||||
else
|
||||
SendError("404","not found")
|
||||
end
|
||||
|
||||
else
|
||||
SendError("500","What")
|
||||
SendError("500","What")
|
||||
end
|
||||
|
Reference in New Issue
Block a user