diff --git a/applications/luci-app-babeld/Makefile b/applications/luci-app-babeld/Makefile index c5f3d27c96..2c3675c3ee 100644 --- a/applications/luci-app-babeld/Makefile +++ b/applications/luci-app-babeld/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI support for babeld -LUCI_DEPENDS:=+luci-base +babeld +luci-compat +LUCI_DEPENDS:=+luci-base +babeld include ../../luci.mk diff --git a/applications/luci-app-babeld/htdocs/luci-static/resources/babeld.js b/applications/luci-app-babeld/htdocs/luci-static/resources/babeld.js new file mode 100644 index 0000000000..6bcbdf0e29 --- /dev/null +++ b/applications/luci-app-babeld/htdocs/luci-static/resources/babeld.js @@ -0,0 +1,171 @@ +function renderTableXRoutes(ubus_data, target_div) { + var data = ubus_data; + for (var protocol in data) { + var target = target_div; + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('X-Routes ' + protocol)); + target.appendChild(title); + + var table = document.createElement('table'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_xroutes_' + protocol); + + var headerRow = document.createElement('tr'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '' + '%h'.format(protocol) + ' Prefix\ + Metric\ + Source-Prefix'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + + for (var prefix in data[protocol]) { + var prefixRow = document.createElement('tr'); + prefixRow.setAttribute('class', 'tr'); + var prefixContent = '' + '%h'.format(prefix) + '\ + ' + '%h'.format(data[protocol][prefix]["metric"]) + '\ + ' + '%h'.format(data[protocol][prefix]["src-prefix"]) + ''; + + prefixRow.innerHTML = prefixContent; + table.appendChild(prefixRow); + } + target.appendChild(table); + } +} + +function renderTableRoutes(ubus_data, target_div) { + var data = ubus_data; + for (var protocol in data) { + var target = target_div; + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Routes ' + protocol)); + target.appendChild(title); + + var table = document.createElement('table'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_routes_' + protocol); + + var headerRow = document.createElement('tr'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '' + '%h'.format(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('tr'); + prefixRow.setAttribute('class', 'tr'); + var prefixContent = '' + '%h'.format(prefix) + '\ + ' + '%h'.format(data[protocol][prefix]["src-prefix"]) + '\ + ' + '%h'.format(data[protocol][prefix]["route_metric"]) + '\ + ' + '%h'.format(data[protocol][prefix]["route_smoothed_metric"]) + '\ + ' + '%h'.format(data[protocol][prefix]["refmetric"]) + '\ + ' + '%h'.format(data[protocol][prefix]["id"]) + '\ + ' + '%h'.format(data[protocol][prefix]["seqno"]) + '\ + ' + '%h'.format(data[protocol][prefix]["channels"]) + '\ + ' + '%h'.format(data[protocol][prefix]["age"]) + '\ + ' + '%h'.format(data[protocol][prefix]["via"]) + '\ + ' + '%h'.format(data[protocol][prefix]["nexthop"]) + '\ + ' + '%h'.format(data[protocol][prefix]["installed"]) + '\ + ' + '%h'.format(data[protocol][prefix]["feasible"]) + ''; + + prefixRow.innerHTML = prefixContent; + table.appendChild(prefixRow); + } + target.appendChild(table); + } +} + +function renderTableNeighbours(ubus_data, target_div) { + var data = ubus_data; + for (var protocol in data) { + var target = target_div; + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Neighbours ' + protocol)); + target.appendChild(title); + + var table = document.createElement('table'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_neighbours_' + protocol); + + var headerRow = document.createElement('tr'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = '' + '%h'.format(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('tr'); + neighbourRow.setAttribute('class', 'tr'); + var neighbourContent = '' + '%h'.format(neighbour) + '\ + ' + '%h'.format(data[protocol][neighbour]["dev"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["hello-reach"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["rxcost"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["txcost"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["rtt"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["channel"]) + '\ + ' + '%h'.format(data[protocol][neighbour]["if_up"]) + ''; + + neighbourRow.innerHTML = neighbourContent; + table.appendChild(neighbourRow); + } + target.appendChild(table); + } +} + +function renderTableInfo(ubus_data, target_div) { + var data = ubus_data; + var target = target_div; + + var title = document.createElement('h3'); + title.appendChild(document.createTextNode('Info')); + target.appendChild(title); + + var table = document.createElement('table'); + table.setAttribute('class', 'table'); + table.setAttribute('id', 'babel_overview_info'); + + + var headerRow = document.createElement('tr'); + headerRow.setAttribute('class', 'tr table-titles'); + var headerContent = 'Babeld Version\ + My-ID\ + Host'; + + headerRow.innerHTML = headerContent; + table.appendChild(headerRow); + + var neighbourRow = document.createElement('tr'); + neighbourRow.setAttribute('class', 'tr'); + var neighbourContent = '' + '%h'.format(data["babeld-version"]) + '\ + ' + '%h'.format(data["my-id"]) + '\ + ' + '%h'.format(data["host"]) + ''; + + neighbourRow.innerHTML = neighbourContent; + table.appendChild(neighbourRow); + target.appendChild(table); +} diff --git a/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js b/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js new file mode 100644 index 0000000000..1714866d0f --- /dev/null +++ b/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js @@ -0,0 +1,95 @@ +'use strict'; +'require uci'; +'require view'; +'require poll'; +'require ui'; +'require rpc'; + +return view.extend({ + callGetInfo: rpc.declare({ + object: 'babeld', + method: 'get_info' + }), + callGetXroutes: rpc.declare({ + object: 'babeld', + method: 'get_xroutes' + }), + callGetRoutes: rpc.declare({ + object: 'babeld', + method: 'get_routes' + }), + callGetNeighbours: rpc.declare({ + object: 'babeld', + method: 'get_neighbours' + }), + + fetch_babeld: function () { + var data; + var self = this; + return new Promise(function (resolve, reject) { + Promise.all([self.callGetInfo(), self.callGetXroutes(), self.callGetRoutes(), self.callGetNeighbours()]) + .then(function (res) { + data = res; + resolve([data]); + }) + .catch(function (err) { + console.error(err); + reject([null]); + }); + }); + }, + + action_babeld: function () { + var self = this; + return new Promise(function (resolve, reject) { + self + .fetch_babeld() + .then(function ([data]) { + var info = data[0]; + var xroutes = data[1]; + var routes = data[2]; + var neighbours = data[3]; + var result = { info, xroutes, routes, neighbours }; + resolve(result); + }) + .catch(function (err) { + reject(err); + }); + }); + }, + + load: function () { + var self = this; + return new Promise(function (resolve, reject) { + var script = E('script', { 'type': 'text/javascript' }); + script.onload = resolve; + script.onerror = reject; + script.src = L.resource('babeld.js'); + document.querySelector('head').appendChild(script); + }); + }, + render: function () { + var self = this; + return this.action_babeld() + .then(function (result) { + + var mainDiv = E('div', { + 'id': 'babeld' + }, []); + + renderTableInfo(result.info, mainDiv); + renderTableXRoutes(result.xroutes, mainDiv); + renderTableRoutes(result.routes, mainDiv); + renderTableNeighbours(result.neighbours, mainDiv); + + var result = E([], {}, mainDiv); + return result; + }) + .catch(function (error) { + console.error(error); + }); + }, + handleSaveApply: null, + handleSave: null, + handleReset: null, +}); diff --git a/applications/luci-app-babeld/luasrc/view/babeld.htm b/applications/luci-app-babeld/luasrc/view/babeld.htm deleted file mode 100644 index d3436f0e69..0000000000 --- a/applications/luci-app-babeld/luasrc/view/babeld.htm +++ /dev/null @@ -1,22 +0,0 @@ -<%+header%> - - -
- - -<%+footer%> diff --git a/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json b/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json index a5f7e9259e..4dd7df61ca 100644 --- a/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json +++ b/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json @@ -1,12 +1,12 @@ { + "admin/status/babeld": { "title": "Babeld", + "order": 5, "action": { - "type": "template", - "path": "babeld" - }, - "depends": { - "acl": [ "luci-app-babeld" ] + "type": "view", + "path": "babeld/babeld-view" } } + } diff --git a/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json b/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json index 71755b30d4..f2ed6fa64a 100644 --- a/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json +++ b/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json @@ -1,17 +1,25 @@ { "luci-app-babeld": { - "description": "Grant UCI access for babeld", + "description": "Grant UCI access for luci-app-babeld", "read": { - "uci": [ "babeld" ], + "uci": [ + "babeld" + ], "ubus": { - "babeld": [ "*" ] - } + "babeld": [ + "*" + ] + } }, "write": { - "uci": [ "babeld" ], + "uci": [ + "babeld" + ], "ubus": { - "babeld": [ "*" ] + "babeld": [ + "*" + ] } } } -} +} \ No newline at end of file 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 deleted file mode 100644 index b2468dfbea..0000000000 --- a/applications/luci-app-babeld/root/www/luci-static/resources/babeld.js +++ /dev/null @@ -1,189 +0,0 @@ -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('table'); - table.setAttribute('class', 'table'); - table.setAttribute('id', 'babel_overview_xroutes_' + protocol); - - var headerRow = document.createElement('tr'); - 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('tr'); - 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('table'); - table.setAttribute('class', 'table'); - table.setAttribute('id', 'babel_overview_routes_' + protocol); - - var headerRow = document.createElement('tr'); - 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('tr'); - 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('table'); - table.setAttribute('class', 'table'); - table.setAttribute('id', 'babel_overview_neighbours_' + protocol); - - var headerRow = document.createElement('tr'); - 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('tr'); - 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('table'); - table.setAttribute('class', 'table'); - table.setAttribute('id', 'babel_overview_info'); - - - var headerRow = document.createElement('tr'); - headerRow.setAttribute('class', 'tr table-titles'); - var headerContent = 'Babeld Version\ - My-ID\ - Host'; - - headerRow.innerHTML = headerContent; - table.appendChild(headerRow); - - var neighbourRow = document.createElement('tr'); - neighbourRow.setAttribute('class', 'tr'); - var neighbourContent = '' + data["babeld-version"] + '\ - ' + data["my-id"] + '\ - ' + data["host"] + ''; - - neighbourRow.innerHTML = neighbourContent; - table.appendChild(neighbourRow); - target.appendChild(table); -}