Skip to content

Instantly share code, notes, and snippets.

@awstanley
Last active November 13, 2019 05:40
Show Gist options
  • Save awstanley/e998e2bcdf476b8f389a8f89d0efe583 to your computer and use it in GitHub Desktop.
Save awstanley/e998e2bcdf476b8f389a8f89d0efe583 to your computer and use it in GitHub Desktop.
DJA0230TLS Dump Status
# Goes in the same directory as the output;
# create `rendered` (folder) and put index.html in it
from json import JSONEncoder, JSONDecoder
JE = JSONEncoder()
JD = JSONDecoder()
store = []
bits = []
count = 0
for i in range(512):
tmp = []
for j in range(16):
tmp.append(0)
bits.append(tmp)
from os import listdir
from os.path import isfile, join
for f in listdir("."):
if isfile(f):
date = f.split(".json")[0]
if date + ".json" == f:
with open(f) as src:
data = src.read()
data = data.replace(""", '"')
data = JD.decode(data)
loading = data["DSL Bit Loading"]
for i in range(512):
bits[i][loading[i]] += 1
count = count + 1
with open("rendered/bits.json", "w") as output:
output.write(JE.encode(bits))
--pretranslated: do not change this file
-- Enable localization
gettext.textdomain('webui-core')
local proxy = require("datamodel")
local ui_helper = require("web.ui_helper")
local post_helper = require("web.post_helper")
local content_helper = require("web.content_helper")
local table = table
local format = string.format
local floor = math.floor
local tonumber = tonumber
local untaint_mt = require("web.taint").untaint_mt
local setmetatable = setmetatable
local extra_content = {
dsl_status = "[email protected]",
dsl_type = "[email protected]",
dsl_linerate_up = "[email protected]",
dsl_linerate_down = "[email protected]",
dsl_linerate_up_max = "[email protected]",
dsl_linerate_down_max = "[email protected]",
dsl_uptime = "[email protected]",
dsl_power_up = "[email protected]",
dsl_power_down = "[email protected]",
dsl_attenuation_up = "[email protected]",
dsl_attenuation_down = "[email protected]",
dsl_margin_up = "[email protected]",
dsl_margin_down = "[email protected]",
dsl_transfered_up = "[email protected]",
dsl_transfered_down = "[email protected]",
dsl_downstream_delay = "[email protected]",
}
-- Get the content
content_helper.getExactContent(extra_content)
local DSLMode
local ddd = tonumber(extra_content["dsl_downstream_delay"])
if not ddd then
DSLMode = ""
elseif ddd>2 then
DSLMode = "Interleaved"
else
DSLMode = "Fast"
end
local xdsl_rpc_path = "sys.class.xdsl.@line0."
local xdsl_BitLoading = xdsl_rpc_path.."BitLoading"
--Constract the new version for the time show style
local function ChangeToStandardTime(time)
local timeM
if ((time >= 0) and (time < 10) ) then
timeM = 0 .. time
return timeM
else
return time
end
end
--Constract the new style of the standard changement from seconds to time
local function SecondsToTime(SecondsTime,mode)
local days = floor(SecondsTime / 86400)
local hours = floor(SecondsTime / 3600) % 24
local hoursM = ChangeToStandardTime(hours)
local minutes = floor(SecondsTime / 60) % 60
local minutesM = ChangeToStandardTime(minutes)
local seconds = SecondsTime % 60
local secondsM = ChangeToStandardTime(seconds)
if mode == "InstantTime" then
return format("%s:%s:%s", hoursM, minutesM, secondsM)
elseif mode == "HistoryTime" then
return format(T"%ddays, %s:%s:%s", days, hoursM, minutesM, secondsM)
else
return ""
end
end
--Constract the name mapping for the ModulationType
local modemapping = setmetatable({
["ADSL_G.dmt"] = "G.DMT",
["ADSL_ANSI_T1.413"] = "T1.413",
["ADSL_G.lite"] = "G.lite",
["ADSL_G.dmt.bis"] = "ADSL2",
["ADSL_2plus"] = "ADSL2+",
["ADSL_re-adsl"] = "RE-ADSL",
["VDSL2"] = "VDSL2",
["G.fast"] = "G.fast",
},untaint_mt)
local content = {
dsl_modemtimeuptime = "rpc.system.uptime",
dsl_currentdaystart = xdsl_rpc_path.."CurrentDayStart",
dsl_standard = xdsl_rpc_path.."ModulationType",
dsl_showtime = xdsl_rpc_path.."ShowtimeStart",
dsl_max_bandwidth_down = xdsl_rpc_path.."DownstreamMaxRate",
dsl_max_bandwidth_up = xdsl_rpc_path.."UpstreamMaxRate",
}
content_helper.getExactContent(content)
content["system_time"] = os.date("%a %b %d %Y %T %p",os.time())
local result = proxy.get(xdsl_BitLoading) or {}
local xdsl_BitLoading = result[1].value
local function GetLinkValueSYSclassXDSL(contentE,name)
contentE[1] = xdsl_rpc_path.."LinkRetrain" .. name
contentE[2] = xdsl_rpc_path.."UpstreamLOS" .. name
contentE[3] = xdsl_rpc_path.."DownstreamLOS" .. name
contentE[4] = xdsl_rpc_path.."UpstreamLOF" .. name
contentE[5] = xdsl_rpc_path.."DownstreamLOF" .. name
contentE[6] = xdsl_rpc_path.."UpstreamLOM" .. name
contentE[7] = xdsl_rpc_path.."DownstreamLOM" ..name
contentE[8] = xdsl_rpc_path.."UpstreamFEC" .. name
contentE[9] = xdsl_rpc_path.."DownstreamFEC" .. name
contentE[10] = xdsl_rpc_path.."UpstreamCRC" .. name
contentE[11] = xdsl_rpc_path.."DownstreamCRC" .. name
contentE[12] = xdsl_rpc_path.."UpstreamES" .. name
contentE[13] = xdsl_rpc_path.."DownstreamES" .. name
contentE[14] = xdsl_rpc_path.."UpstreamSES" .. name
contentE[15] = xdsl_rpc_path.."DownstreamSES" .. name
contentE[16] = xdsl_rpc_path.."UpstreamUAS" .. name
contentE[17] = xdsl_rpc_path.."DownstreamUAS" .. name
contentE[18] = xdsl_rpc_path.."UpstreamCurrRate"
contentE[19] = xdsl_rpc_path.."DownstreamCurrRate"
return contentE
end
local function GetTableFormatValue(InputTableNeed,value,m,n)
InputTableNeed[1][m] = format("%s",value[1])
local dslCurrRateUp = floor(value[18]/10)/100
local dslCurrRateDown = floor(value[19]/10)/100
if n==1 then
InputTableNeed[2][m] = format("[%s, %s]",dslCurrRateDown,dslCurrRateUp)
else
InputTableNeed[2][m] = format('""')
end
InputTableNeed[3][m] = format("[%s, %s]",value[2],value[3])
InputTableNeed[4][m] = format("[%s, %s]",value[4],value[5])
InputTableNeed[5][m] = format("[%s, %s]",value[6],value[7])
InputTableNeed[6][m] = format("[%s, %s]",value[8],value[9])
InputTableNeed[7][m] = format("[%s, %s]",value[10],value[11])
InputTableNeed[8][m] = format("[%s, %s]",value[12],value[13])
InputTableNeed[9][m] = format("[%s, %s]",value[14],value[15])
InputTableNeed[10][m] = format("[%s, %s]",value[16],value[17])
return InputTableNeed
end
local contentM_Last_15_min ={}
GetLinkValueSYSclassXDSL(contentM_Last_15_min,"PreviousQuarter")
content_helper.getExactContent(contentM_Last_15_min)
local contentM_Currentday ={}
GetLinkValueSYSclassXDSL(contentM_Currentday,"CurrentDay")
content_helper.getExactContent(contentM_Currentday)
local contentM_Priorday ={}
GetLinkValueSYSclassXDSL(contentM_Priorday,"PreviousDay")
content_helper.getExactContent(contentM_Priorday)
local contentM_Showtime ={}
GetLinkValueSYSclassXDSL(contentM_Showtime,"SinceSync")
content_helper.getExactContent(contentM_Showtime)
local columnsM ={}
for i=1, 10 do
columnsM[i]={}
end
columnsM[1][1] = T"Link Retrain Count"
columnsM[2][1] = T"Sync Bandwidth (Down/Up)"
columnsM[3][1] = T"Loss of Sync,LOS (Local/Remote)"
columnsM[4][1] = T"Loss of Framing,LOF (Local/Remote)"
columnsM[5][1] = T"Loss of Margin,LOM (Local/Remote)"
columnsM[6][1] = T"Forward Error Correction, FEC"
columnsM[7][1] = T"Cyclic Redundancy Correction, CRC"
columnsM[8][1] = T"Errored Seconds, ES"
columnsM[9][1] = T"Severely Errored Seconds, SES"
columnsM[10][1] = T"Unavailable Seconds, UAS"
GetTableFormatValue(columnsM,contentM_Last_15_min,2,2)
GetTableFormatValue(columnsM,contentM_Currentday,3,2)
GetTableFormatValue(columnsM,contentM_Priorday,4,2)
GetTableFormatValue(columnsM,contentM_Showtime,5,1)
local datarowsM ={}
for i=1, 5 do
datarowsM[i]={}
end
datarowsM[1]["header"] = T"Parameters"
datarowsM[2]["header"] = T"Last 15 min"
datarowsM[3]["header"] = T"Current Day"
datarowsM[4]["header"] = T"Prior Day"
datarowsM[5]["header"] = T"Showtime"
local uri = ngx.var.uri
-- dummy form so that refresh button knows which page to reload, keep it
--ngx.print('<form class="form-horizontal" method="post" action="modals/diagnostics-xdsl-modal.lp"></form>');
ngx.print('{"Modem Time": "'..SecondsToTime(content["dsl_modemtimeuptime"],"HistoryTime")..'",');
local dslCurrentDayStart = SecondsToTime(content["dsl_currentdaystart"],"InstantTime")
ngx.print('"Current Day Start": "'..SecondsToTime(content["dsl_currentdaystart"],"InstantTime")..'",');
local dslSystemTime = content["system_time"]
ngx.print('"Showtime": "'..format("%s, %s ago",dslSystemTime,dslCurrentDayStart)..'",');
local dslStandard = modemapping[content["dsl_standard"]] or content["dsl_standard"]
ngx.print('"DSL Standard": "'..dslStandard..'",');
local dslLineRateMaxDown = floor(content["dsl_max_bandwidth_down"]/10)/100
ngx.print('"Max Bandwidth Down": "'..format("%sMbps",dslLineRateMaxDown)..'",');
local dslLineRateMaxUp = floor(content["dsl_max_bandwidth_up"]/10)/100
ngx.print('"Max Bandwidth Up": "'..format("%sMbps",dslLineRateMaxUp)..'",');
ngx.print('"DSL Bit Loading": ['..xdsl_BitLoading..'],')
-- Re-flow the table manually.
-- ngx.print(ui_helper.createTable(datarowsM, columnsM, options))
-- columnsM = data (param, etc.)
-- datarowsM = names
ngx.print('"runtime": {')
ngx.print('"margin up": "'.. extra_content["dsl_margin_up"] ..' dB",')
ngx.print('"margin down": "'.. extra_content["dsl_margin_down"] ..' dB",')
ngx.print('"attenuation up": "'.. extra_content["dsl_attenuation_up"] ..' dB",')
ngx.print('"attenuation down": "'.. extra_content["dsl_attenuation_down"] ..' dB",')
ngx.print('"uptime": '.. post_helper.secondsToTime(extra_content["dsl_uptime"]) ..',')
local dslLineRateMaxUp = floor(extra_content["dsl_linerate_up_max"] / 10) / 100
local dslLineRateMaxDown = floor(extra_content["dsl_linerate_down_max"] / 10) / 100
ngx.print('"max_up": "'.. dslLineRateMaxUp ..'",')
ngx.print('"max_down": "'.. dslLineRateMaxDown ..'",')
local dslLineRateUp = floor(extra_content["dsl_linerate_up"] / 10) / 100
local dslLineRateDown = floor(extra_content["dsl_linerate_down"] / 10) / 100
ngx.print('"cur_up": "'.. dslLineRateUp ..'",')
ngx.print('"cur_down": "'.. dslLineRateDown ..'",')
local dslTransferedUp, dslTransferedDown
if tonumber(extra_content["dsl_transfered_up"]) ~= nil and tonumber(extra_content["dsl_transfered_down"]) ~= nil then
dslTransferedUp = floor(extra_content["dsl_transfered_up"] / 1048576 * 100) / 100
dslTransferedDown = floor(extra_content["dsl_transfered_down"] / 1048576 * 100) / 100
else
dslTransferedUp = 0
dslTransferedDown = 0
end
ngx.print('"uploaded": "'.. dslTransferedUp ..'",')
ngx.print('"downloaded": "'.. dslTransferedDown ..'"')
ngx.print('},')
ngx.print('"data": {')
for i=2,5 do
ngx.print('"'..datarowsM[i]["header"]..'": {')
local tmp={}
for _, cv in pairs(columnsM) do
table.insert(tmp, '"'..cv[1]..'": '..cv[i])
end
for j=1,#tmp do
ngx.print(tmp[j])
if j ~= #tmp then
ngx.print(",")
end
end
if i == 5 then
ngx.print('}')
else
ngx.print('},')
end
end
-- EOF
ngx.print('}}')
# Host the index.html file locally
python -m http.server 2357
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bit Loading</title>
</head>
<body>
<script>
const tile_size = 8;
document.addEventListener("DOMContentLoaded", function(){
let httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
let root_canvas = document.createElement('canvas');
let context = root_canvas.getContext('2d');
root_canvas.height = 16 * tile_size;
root_canvas.width = 512 * tile_size;
document.body.appendChild(root_canvas);
context.clearRect(0, 0, root_canvas.width, root_canvas.height);
let canvas = document.createElement('canvas');
canvas.height = 1000;
canvas.width = tile_size;
let ctx = canvas.getContext('2d');
let gradient = ctx.createLinearGradient(0, 0, 0, 1000);
/*
gradient.addColorStop(1, 'rgb(46, 127, 24)');
gradient.addColorStop(4/5, 'rgb(69, 115, 30)');
gradient.addColorStop(3/5, 'rgb(103, 94, 36)');
gradient.addColorStop(2/5, 'rgb(141, 71, 43)');
gradient.addColorStop(1/5, 'rgb(177, 52, 51)');
gradient.addColorStop(0, 'rgb(200, 37, 56)');
*/
gradient.addColorStop(0, 'rgba(0,0,0,255)');
gradient.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, tile_size, 1000);
// Load data.
let data = JSON.parse(httpRequest.responseText);
// Calculate total for percentage work.
let total = 0;
for(let i = 0; i < 15; i++) {
total += data[0][i];
}
for(let i = 0; i < 512; i++) {
let bit_data = data[i];
for(let j = 0; j < 16; j++) {
let bit = bit_data[j];
if (bit > 0) {
let percentage = bit / total;
context.drawImage(
canvas,
0, canvas.height - (percentage * canvas.height) - tile_size,
tile_size, tile_size,
tile_size * i, tile_size * (16-j),
tile_size, tile_size
);
}
}
}
}
}
};
httpRequest.open('GET', 'bits.json');
httpRequest.send();
});
</script>
</body>
</html>
# Run the contents.
# Put the other file '/www/docroot/dump.lp'
uci add_list web.ruleset_main.rules=dumpinfo
uci set web.dumpinfo=rule
uci set web.dumpinfo.target='/dump.lp'
uci add_list web.dumpinfo.roles='admin'
uci commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment