From 17ee61c6014329d44f5864f45986dbe626868289 Mon Sep 17 00:00:00 2001 From: Jonathan Pagel Date: Tue, 9 Feb 2021 22:32:28 +0100 Subject: luci-app-babeld: rewrite javascript without CDN includes Rewrite luci app in javascript without external sources CC-Signed-off-by: Nick Hainke Signed-off-by: Jonathan Pagel --- .../root/www/luci-static/resources/babeld.js | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 applications/luci-app-babeld/root/www/luci-static/resources/babeld.js (limited to 'applications/luci-app-babeld/root/www/luci-static/resources/babeld.js') diff --git a/applications/luci-app-babeld/root/www/luci-static/resources/babeld.js b/applications/luci-app-babeld/root/www/luci-static/resources/babeld.js new file mode 100644 index 0000000000..864010ef6c --- /dev/null +++ b/applications/luci-app-babeld/root/www/luci-static/resources/babeld.js @@ -0,0 +1,189 @@ +function ubus_call(command, argument, params) { + var request_data = {}; + request_data.jsonrpc = "2.0"; + request_data.method = "call"; + request_data.params = [data.ubus_rpc_session, command, argument, params] + var request_json = JSON.stringify(request_data); + var request = new XMLHttpRequest(); + request.open("POST", ubus_url, false); + request.setRequestHeader("Content-type", "application/json"); + request.send(request_json); + if (request.status === 200) { + var response = JSON.parse(request.responseText) + if (!("error" in response) && "result" in response) { + if (response.result.length === 2) { + return response.result[1]; + } + } else { + console.err("Failed query ubus!"); + } + } +} + +function renderTableXRoutes(data, target_id) { + for (var protocol in data) { + var target = document.getElementById(target_id); + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('X-Routes ' + protocol)); + target.appendChild(title); + + var table = document.createElement('div'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_xroutes_' + protocol); + + var headerRow = document.createElement('div'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '
' + protocol + ' Prefix
\ +
Metric
\ +
Source-Prefix
'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + + for (var prefix in data[protocol]) { + var prefixRow = document.createElement('div'); + prefixRow.setAttribute('class', 'tr'); + var prefixContent = '
' + prefix + '
\ +
' + data[protocol][prefix]["metric"] + '
\ +
' + data[protocol][prefix]["src-prefix"] + '
'; + + prefixRow.innerHTML = prefixContent; + table.appendChild(prefixRow); + } + target.appendChild(table); + } +} + +function renderTableRoutes(data, target_id) { + for (var protocol in data) { + var target = document.getElementById(target_id); + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Routes ' + protocol)); + target.appendChild(title); + + var table = document.createElement('div'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_routes_' + protocol); + + var headerRow = document.createElement('div'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '
' + protocol + ' Prefix
\ +
Source-Prefix
\ +
Route-Metric
\ +
Route Smoothed Metric
\ +
Refmetric
\ +
ID
\ +
Seq. No.
\ +
Channes
\ +
Age
\ +
Via
\ +
Nexthop
\ +
Installed
\ +
Feasible
'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + for (var prefix in data[protocol]) { + var prefixRow = document.createElement('div'); + prefixRow.setAttribute('class', 'tr'); + var prefixContent = '
' + prefix + '
\ +
' + data[protocol][prefix]["src-prefix"] + '
\ +
' + data[protocol][prefix]["route_metric"] + '
\ +
' + data[protocol][prefix]["route_smoothed_metric"] + '
\ +
' + data[protocol][prefix]["refmetric"] + '
\ +
' + data[protocol][prefix]["id"] + '
\ +
' + data[protocol][prefix]["seqno"] + '
\ +
' + data[protocol][prefix]["channels"] + '
\ +
' + data[protocol][prefix]["age"] + '
\ +
' + data[protocol][prefix]["via"] + '
\ +
' + data[protocol][prefix]["nexthop"] + '
\ +
' + data[protocol][prefix]["installed"] + '
\ +
' + data[protocol][prefix]["feasible"] + '
'; + + prefixRow.innerHTML = prefixContent; + table.appendChild(prefixRow); + } + target.appendChild(table); + } +} + +function renderTableNeighbours(data, target_id) { + for (var protocol in data) { + var target = document.getElementById(target_id); + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Neighbours ' + protocol)); + target.appendChild(title); + + var table = document.createElement('div'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_neighbours_' + protocol); + + var headerRow = document.createElement('div'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '
' + protocol + ' Neighbour
\ +
Device
\ +
Hello-Reach
\ +
RX cost
\ +
TX cost
\ +
RTT
\ +
Channel
\ +
Interface up
'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + for (var neighbour in data[protocol]) { + var neighbourRow = document.createElement('div'); + neighbourRow.setAttribute('class', 'tr'); + var neighbourContent = '
' + neighbour + '
\ +
' + data[protocol][neighbour]["dev"] + '
\ +
' + data[protocol][neighbour]["hello-reach"] + '
\ +
' + data[protocol][neighbour]["rxcost"] + '
\ +
' + data[protocol][neighbour]["txcost"] + '
\ +
' + data[protocol][neighbour]["rtt"] + '
\ +
' + data[protocol][neighbour]["channel"] + '
\ +
' + data[protocol][neighbour]["if_up"] + '
'; + + neighbourRow.innerHTML = neighbourContent; + table.appendChild(neighbourRow); + } + target.appendChild(table); + } +} + +function renderTableInfo(data, target_id) { + var target = document.getElementById(target_id); + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Info')); + target.appendChild(title); + + var table = document.createElement('div'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_info'); + + + var headerRow = document.createElement('div'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '
Babeld Version
\ +
My-ID
\ +
Host
'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + var neighbourRow = document.createElement('div'); + neighbourRow.setAttribute('class', 'tr'); + var neighbourContent = '
' + data["babeld-version"] + '
\ +
' + data["my-id"] + '
\ +
' + data["host"] + '
'; + + neighbourRow.innerHTML = neighbourContent; + table.appendChild(neighbourRow); + target.appendChild(table); +} -- cgit v1.2.3