From c405b23abd6d04f1e7a9d85162ea655735ba6443 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 28 Jun 2018 09:39:34 +0200 Subject: [PATCH] luci-mod-admin-full: unify DHCP lease status code Merge the DHCP lease status code of the status overview and DHCP/DNS pages into a single shared partial template. Also remove some redundant markup on the index page and wireless assoc list templates. Signed-off-by: Jo-Philipp Wich --- .../view/admin_network/lease_status.htm | 90 ++++------ .../view/admin_network/wifi_assoclist.htm | 22 ++- .../luasrc/view/admin_status/index.htm | 162 ++---------------- 3 files changed, 53 insertions(+), 221 deletions(-) diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm index a1b2c8454..8fbbdc947 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm @@ -1,27 +1,11 @@ -
- <%:Active DHCP Leases%> +
+

<%:Active DHCP Leases%>

-
+
<%:Hostname%>
<%:IPv4-Address%>
<%:MAC-Address%>
<%:Leasetime remaining%>
-
-

<%:Collecting data...%>
+
+
<%:Collecting data...%>
-
+ - + diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm index f3e2313ee..b6f84c060 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm @@ -68,17 +68,15 @@ ); //]]> -
-
-
-
<%:Network%>
-
<%:MAC-Address%>
-
<%:Host%>
-
<%:Signal%> / <%:Noise%>
-
<%:RX Rate%> / <%:TX Rate%>
-
-
-
<%:Collecting data...%>
-
+
+
+
<%:Network%>
+
<%:MAC-Address%>
+
<%:Host%>
+
<%:Signal%> / <%:Noise%>
+
<%:RX Rate%> / <%:TX Rate%>
+
+
+
<%:Collecting data...%>
diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm index 6083a8a2c..9aee30b5f 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm @@ -53,8 +53,6 @@ swap = swapinfo, connmax = conn_max, conncount = conn_count, - leases = stat.dhcp_leases(), - leases6 = stat.dhcp6_leases(), wifinets = stat.wifi_networks() } @@ -110,11 +108,6 @@ luci.http.prepare_content("application/json") luci.http.write_json(rv) - return - elseif luci.http.formvalue("hosts") == "1" then - luci.http.prepare_content("application/json") - luci.http.write_json(luci.sys.net.host_hints()) - return end -%> @@ -140,27 +133,6 @@ ); } - function duid2mac(duid) { - // DUID-LLT / Ethernet - if (duid.length === 28 && duid.substr(0, 8) === '00010001') - return duid.substr(16).replace(/(..)(?=..)/g, '$1:').toUpperCase(); - - // DUID-LL / Ethernet - if (duid.length === 20 && duid.substr(0, 8) === '00030001') - return duid.substr(8).replace(/(..)(?=..)/g, '$1:').toUpperCase(); - - return null; - } - - var npoll = 1; - var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%>; - - function updateHosts() { - XHR.get('<%=REQUEST_URI%>', { hosts: 1 }, function(x, data) { - hosts = data; - }); - } - function labelList(items, offset) { var rv = [ ]; @@ -201,9 +173,6 @@ XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 }, function(x, info) { - if (!(npoll++ % 5)) - updateHosts(); - var us = document.getElementById('upstream_status_table'); while (us.lastElementChild) @@ -312,77 +281,6 @@ ); <% end %> - <% if has_dhcp then %> - var ls = document.getElementById('lease_status_table'); - if (ls) - { - var rows = []; - - for (var i = 0; i < info.leases.length; i++) - { - var timestr; - - if (info.leases[i].expires === false) - timestr = '<%:unlimited%>'; - else if (info.leases[i].expires <= 0) - timestr = '<%:expired%>'; - else - timestr = String.format('%t', info.leases[i].expires); - - rows.push([ - info.leases[i].hostname ? info.leases[i].hostname : '?', - info.leases[i].ipaddr, - info.leases[i].macaddr, - timestr - ]); - } - - cbi_update_table(ls, rows, '<%:There are no active leases.%>'); - } - - var ls6 = document.getElementById('lease6_status_table'); - if (ls6 && info.leases6) - { - ls6.parentNode.parentNode.style.display = 'block'; - - var rows = []; - - for (var i = 0; i < info.leases6.length; i++) - { - var timestr; - - if (info.leases6[i].expires === false) - timestr = '<%:unlimited%>'; - else if (info.leases6[i].expires <= 0) - timestr = '<%:expired%>'; - else - timestr = String.format('%t', info.leases6[i].expires); - - var host = hosts[duid2mac(info.leases6[i].duid)], - name = info.leases6[i].hostname, - hint = null; - - if (!name) { - if (host) - hint = host.name || host.ipv4 || host.ipv6; - } - else { - if (host && host.name && info.leases6[i].hostname != host.name) - hint = host.name; - } - - rows.push([ - hint ? '%h (%h)'.format(name || '?', hint) : (name || '?'), - info.leases6[i].ip6addr, - info.leases6[i].duid, - timestr - ]); - } - - cbi_update_table(ls6, rows, '<%:There are no active leases.%>'); - } - <% end %> - <% if has_wifi then %> var ws = document.getElementById('wifi_status_table'); if (ws) @@ -545,58 +443,24 @@
-<% if has_dhcp then %> -
-

<%:DHCP Leases%>

- -
-
-
-
<%:Hostname%>
-
<%:IPv4-Address%>
-
<%:MAC-Address%>
-
<%:Leasetime remaining%>
-
-
-

<%:Collecting data...%>
-
-
-
-
- - -<% end %> +<% + if has_dhcp then + include("admin_network/lease_status") + end +%> <% if has_dsl then %>

<%:DSL%>

-
-
-
-
<%:DSL Status%>
-
-
-
-

?
-
<%:Collecting data...%>
-
+
+
+
<%:DSL Status%>
+
+
+
+

?
+
<%:Collecting data...%>
-- 2.25.1