From 730a9b6f69ecd1ce26b0e1c9bcd51ccf42f56f31 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sat, 14 Nov 2009 13:41:37 +0000 Subject: [PATCH] NIU: Redesign dashboard Level 1 Network / System status on dashboard Rework "LAN IP has changed" warning Fix Routing table not hiding when requested --- .../luci-static/resources/icons32/folder.png | Bin 0 -> 645 bytes .../resources/icons32/network-workgroup.png | Bin 0 -> 2226 bytes .../resources/icons32/preferences-system.png | Bin 0 -> 2171 bytes modules/niu/htdocs/luci-static/resources/niu.css | 26 ++++++ modules/niu/luasrc/controller/niu/dashboard.lua | 3 +- modules/niu/luasrc/controller/niu/network.lua | 15 ++- modules/niu/luasrc/controller/niu/system.lua | 13 ++- modules/niu/luasrc/view/niu/dashboard.htm | 35 +++++-- modules/niu/luasrc/view/niu/network.htm | 101 ++++++++++++++++----- modules/niu/luasrc/view/niu/network/rtable.htm | 1 + .../niu/luasrc/view/niu/network/warn_ip_change.htm | 13 ++- modules/niu/luasrc/view/niu/system.htm | 87 +++++++++++++----- 12 files changed, 226 insertions(+), 68 deletions(-) create mode 100644 modules/niu/htdocs/luci-static/resources/icons32/folder.png create mode 100644 modules/niu/htdocs/luci-static/resources/icons32/network-workgroup.png create mode 100644 modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png create mode 100644 modules/niu/htdocs/luci-static/resources/niu.css diff --git a/modules/niu/htdocs/luci-static/resources/icons32/folder.png b/modules/niu/htdocs/luci-static/resources/icons32/folder.png new file mode 100644 index 0000000000000000000000000000000000000000..6919f984f0273935c51d8d9cd15af3f2e67a83e4 GIT binary patch literal 645 zcmV;00($+4P)u=l~CH&)_VEqZZ${D%6eRJeZ%6pX<-B-JGo8KjW&!S(FCcUp1T;-+r8|o_Yhp z*6$fj|h6P=pi`Q4m6cl(ax9L4iLsVn@oqB9JOUqpE-?X>95=X%ml^c+E`4 zo_%?5<}I8)$x>6{#0mZE>*qJV?|$cg=X~cr3!dlUUg8r+ei=z6lE?YjXj5aTOVw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+&4}<2Ab*l9ppiln$+Z>= z;-5Fl=-nE_mmllHR}S{$@V>2xH-}*JA(!)2!+;bDLk@<}y~V)tnn^$){dIzqQ7Pul z^x}^%-q8obA?ep5d9JVpc}1PPm#O@nY$Y4Ows;ttBKe|=H)#0O?lye(!7ivef$}qt z8T;A{EUgtGOCCJe0o#fuCL*28y>V9~dgHZk{6LqSd6h}(OkAaxCo^ovTP2KcjbfnH zAjJYjC34X1=z0-d#uGzvJWkg{qr;XQtu_69Z>4d&R7t8 zsDT|6SPR>ahmn6mR+v0#I!IS+-|tNiG$#*wKIauDXV2dlx8q9-KPvxUZ^d6c{;S@L zlj*+%2YPmToiTiJe-}o!MFA!(P#>b>kRA(D%OxbHmXN(Xlf!EE=}WJldX39_AH{3A zAKgRWIudG#d`*otjWuqIYrT9aNzh!%Y`NNM-nMS7CW@)-xtqI2Ui8jC?O-!O0QWrj zL)bNTXy8AS32$O@#@o05krzFF29A4OOU8YK$L|N+wAtPofv)QiVOan+Tg&^W;MlQa z`*={D6huXI1=$!H8hTuk6D?tJSZbJ9o~xZvaP+9zDZE?S7dU z47jfAoj7sg(UFmnt+q{Pt9zhVg7f^r!xJ+2gK_%w>GOp`!CHTo1HHYy`7>wEJhLeP zrfC+K(BQ!OuxTvUu3ba9T>c;x5O7=gl#Gpyu}ww)If7eXBi+){65rH6CX0)UX#mFh zeXUjlcZB8TWe~u+fc%9Sx7{0tfp|Pl`@MZ>Ns=rA*c=6;qoY9p>iRu*A#omthlh`- zs`@kBA!4yuZen6$Fq_Sq_&^Yxb@}q;Dn1nd1;ph&+L7}WkpKVy07*qoM6N<$g8M}x Av;Y7A literal 0 HcmV?d00001 diff --git a/modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png b/modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png new file mode 100644 index 0000000000000000000000000000000000000000..2afbd23ccc523e9ff83d22d5dfa13b46db40b604 GIT binary patch literal 2171 zcmV->2!!{EP)hXMG%fYvC20^tL~c)}RIH(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Pj$0;zA^E+96ZTuS&^*@hBN0m0D zS${xv0>j+{?1lRV_D4>l_mG;J+H|_P)YH@R*}8S>A}PHZU0n8qx)&lMB0%kzmsp_; ze_Z-WOi~!bR{Q^%Rn-uQ%G;EhF{98~IUCYUMbxD-WO=g^UReoD-p$R;jv~H^zAq=t zUb}X!Gnt(GoacKf?R`f0;C&|KzKME;-xgL<6-y){-k`Hw3C$@AkX&Nzea(uEr9Tbd z#>K_8X=rH7w zC*6-#(B5LMyI)8}C=~hx2M4$K`}?<%&&8^$s(;}ol2N%Vqn)O<26M93V@K%wCw+UP xe#rvDbb=9K6JaS~vP{ZlCn3jO$uY1${1>on!Ni=?(fj}a002ovPDHLkV1h5bE#?3K literal 0 HcmV?d00001 diff --git a/modules/niu/htdocs/luci-static/resources/niu.css b/modules/niu/htdocs/luci-static/resources/niu.css new file mode 100644 index 000000000..6f895c957 --- /dev/null +++ b/modules/niu/htdocs/luci-static/resources/niu.css @@ -0,0 +1,26 @@ +fieldset.dbbox { + float: left; + margin: 1em; + padding: 0.5em; + background: #eeeeee; + border: 1px solid #cccccc; + border-radius: 5px; + -khtml-border-radius: 5px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + -o-border-radius: 5px; +} + +fieldset.dbbox h2 { + background: url(icons32/folder.png) no-repeat right; + min-height: 24px; +} + +table.dbstattbl { + text-align: left; + width: 100%; +} + +table.dbstattbl th { + margin-right: 0.5em; +} \ No newline at end of file diff --git a/modules/niu/luasrc/controller/niu/dashboard.lua b/modules/niu/luasrc/controller/niu/dashboard.lua index f6c893980..bd4875cb9 100644 --- a/modules/niu/luasrc/controller/niu/dashboard.lua +++ b/modules/niu/luasrc/controller/niu/dashboard.lua @@ -26,7 +26,8 @@ function index() end entry({"niu"}, alias("niu", "dashboard"), "NIU", 10) - entry({"niu", "dashboard"}, call("dashboard"), "Dashboard", 1) + entry({"niu", "dashboard"}, call("dashboard"), "Dashboard", 1).css = + "niu.css" end local require = req diff --git a/modules/niu/luasrc/controller/niu/network.lua b/modules/niu/luasrc/controller/niu/network.lua index c90662b6e..9301e2502 100644 --- a/modules/niu/luasrc/controller/niu/network.lua +++ b/modules/niu/luasrc/controller/niu/network.lua @@ -16,23 +16,28 @@ local require = require module "luci.controller.niu.network" function index() - entry({"niu", "network"}, nil, "Network", 10).dbtemplate = "niu/network" + local toniu = {on_success_to={"niu"}} + + local e = entry({"niu", "network"}, alias("niu"), "Network", 10) + e.niu_dbtemplate = "niu/network" + e.niu_dbtasks = true + e.niu_dbicon = "icons32/network-workgroup.png" entry({"niu", "network", "wan"}, - cbi("niu/network/wan", {on_success_to={"niu"}}), "Configure Internet Connection", 10) + cbi("niu/network/wan", toniu), "Configure Internet Connection", 1) entry({"niu", "network", "lan"}, - cbi("niu/network/lan", {on_success_to={"niu"}}), "Configure Local Network", 20) + cbi("niu/network/lan", toniu), "Configure Local Network", 2) uci.inst_state:foreach("dhcp", "dhcp", function(s) if s.interface == "lan" and s.ignore ~= "1" then entry({"niu", "network", "assign"}, cbi("niu/network/assign", - {on_success_to={"niu"}}), "Display and Customize Address Assignment", 30) + toniu), "Display and Customize Address Assignment", 30) end end) entry({"niu", "network", "routes"}, cbi("niu/network/routes", - {on_success_to={"niu"}}), "Display and Customize Routing", 40) + toniu), "Display and Customize Routing", 40) entry({"niu", "network", "conntrack"}, call("cnntrck"), "Display Local Network Activity", 50) diff --git a/modules/niu/luasrc/controller/niu/system.lua b/modules/niu/luasrc/controller/niu/system.lua index 5ffed306b..2adf1d762 100644 --- a/modules/niu/luasrc/controller/niu/system.lua +++ b/modules/niu/luasrc/controller/niu/system.lua @@ -16,13 +16,18 @@ local require, pairs, unpack, tonumber = require, pairs, unpack, tonumber module "luci.controller.niu.system" function index() - entry({"niu", "system"}, nil, "System", 20).dbtemplate = "niu/system" + local toniu = {on_success_to={"niu"}} + + local e = entry({"niu", "system"}, alias("niu"), "System", 20) + e.niu_dbtemplate = "niu/system" + e.niu_dbtasks = true + e.niu_dbicon = "icons32/preferences-system.png" entry({"niu", "system", "general"}, - cbi("niu/system/general", {on_success_to={"niu"}}), "Configure Device", 10) + cbi("niu/system/general", toniu), "Configure Device", 1) - entry({"niu", "system", "backup"}, call("backup"), "Backup or Restore Settings", 20) - entry({"niu", "system", "upgrade"}, call("upgrade"), "Upgrade Firmware", 40) + entry({"niu", "system", "backup"}, call("backup"), "Backup or Restore Settings", 2) + entry({"niu", "system", "upgrade"}, call("upgrade"), "Upgrade Firmware", 30) end function backup() diff --git a/modules/niu/luasrc/view/niu/dashboard.htm b/modules/niu/luasrc/view/niu/dashboard.htm index cdd65663f..7c387edd2 100644 --- a/modules/niu/luasrc/view/niu/dashboard.htm +++ b/modules/niu/luasrc/view/niu/dashboard.htm @@ -1,17 +1,34 @@ -<%+header%> +<% +local dsp = require "luci.dispatcher" +local utl = require "luci.util" -<% +include("header") + local function cmp(a, b) - return (a.order or 100) < (b.order or 100) + return (nodes[a].order or 100) < (nodes[b].order or 100) end for k, v in utl.spairs(nodes, cmp) do - if v.dbtemplate then + if v.niu_dbtemplate or v.niu_dbtasks then %> -
- <%=v.title%> - <% - tpl.render(v.dbtemplate) - %> +
+ style="background-image: url(<%=resource%>/<%=v.niu_dbicon%>)"<% end %>><%=v.title%> + <% if v.niu_dbtemplate then tpl.render(v.niu_dbtemplate) end %> + <% if v.niu_dbtasks then %> +

Tasks:

+
    + <% + local nodes = dsp.node("niu", k).nodes + local function cmp(a, b) + return (nodes[a].order or 100) < (nodes[b].order or 100) + end + for k2, v2 in utl.spairs(nodes, cmp) do + %> +
  • "><%=v2.title%>
  • + <% + end + %> +
+ <% end %>
<% end diff --git a/modules/niu/luasrc/view/niu/network.htm b/modules/niu/luasrc/view/niu/network.htm index 864471231..0e057f199 100644 --- a/modules/niu/luasrc/view/niu/network.htm +++ b/modules/niu/luasrc/view/niu/network.htm @@ -1,7 +1,6 @@ <% -local dsp = require "luci.dispatcher" -local utl = require "luci.util" local uci = require "luci.model.uci" +local fs = require "nixio.fs" local nws = {} uci.inst_state:foreach("network", "interface", function(s) @@ -12,27 +11,85 @@ if uci.inst_state:get("network", "lan", "_ipchanged") and uci.inst_state:revert("network", "lan", "_ipchanged") then include("niu/network/warn_ip_change") end -%> -
Status:
- -<% -for _, v in ipairs(nws) do if v[".name"] ~= "loopback" then -%> - -<% end end %> -
<%=v[".name"]%><%=v.ipaddr%>
-
-
    -<% -local nodes = dsp.node("niu", "network").nodes -local function cmp(a, b) - return (nodes[a].order or 100) < (nodes[b].order or 100) +local wanon = uci.inst_state:get("network", "wan", "proto") +local wanup = uci.inst_state:get("network", "wan", "up") +local wanip = uci.inst_state:get("network", "wan", "ipaddr") +local wanif = uci.inst_state:get("network", "wan", "ifname") +local wanul, wandl + +if wanif then + local devstats = fs.readfile("/proc/net/dev") + local rx, tx = devstats:match("%s*"..wanif.. + ":%s*([0-9]+)%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+".. + "[0-9]+%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+([0-9]+)") + wanul = tx and (tonumber(tx) / 1000000000) + wandl = rx and (tonumber(rx) / 1000000000) end -for k, v in utl.spairs(nodes, cmp) do -%> -
  • "><%=v.title%>
  • -<% + +local leasefn +uci.inst:foreach("dhcp", "dnsmasq", + function(section) + leasefn = section.leasefile + end +) + +if leasefn then + local ln = io.lines(leasefn) + leasefn = 0 + while ln and ln() do + leasefn = leasefn + 1 + end +end + +local arps +if fs.access("/proc/net/arp", "r") then + local ln = io.lines("/proc/net/arp") + arps = -1 + while ln and ln() do + arps = arps + 1 + end + arps = arps >= 0 and arps end %> -
\ No newline at end of file + + +<% if wanon and wanon ~= "none" then %> + +<% if wanup then %> + + +<% else %> + + +<% end %> + + +<% end %> + +<% if wanul and wandl then %> + + + +<% end %> + + + + + +<% if arps then %> + + + +<% end %> + +
Uplink Address<%=wanip%> +Uplinkoffline +
Uplink Traffic +<%=("%.2f"):format(wandl)%> GB⇓ <%=("%.2f"):format(wanul)%> GB⇑ +
Local Address +<%=uci.inst_state:get("network", "lan", "ipaddr")%> +
Active IP-Devices<%=arps%><% if leasefn then %> +(<%=leasefn%> assigned) +<% end %>
+
\ No newline at end of file diff --git a/modules/niu/luasrc/view/niu/network/rtable.htm b/modules/niu/luasrc/view/niu/network/rtable.htm index 4452a87db..412baa166 100644 --- a/modules/niu/luasrc/view/niu/network/rtable.htm +++ b/modules/niu/luasrc/view/niu/network/rtable.htm @@ -42,6 +42,7 @@ $Id$ cursor:set("network", "lan", "_showrtable", rt == "1" and "0" or "1") cursor:save("network") cursor:unload("network") + inst:unload("network") end -%> diff --git a/modules/niu/luasrc/view/niu/network/warn_ip_change.htm b/modules/niu/luasrc/view/niu/network/warn_ip_change.htm index b5ebdd73c..9b41372bf 100644 --- a/modules/niu/luasrc/view/niu/network/warn_ip_change.htm +++ b/modules/niu/luasrc/view/niu/network/warn_ip_change.htm @@ -1,2 +1,11 @@ -Warning!
-Device IP has changed.
\ No newline at end of file +<% +local http = require "luci.http" +local dsp = require "luci.dispatcher" +local ip = require "luci.model.uci".inst:get("network", "lan", "ipaddr") +local url = (http.getenv("HTTPS") and "https" or "http") .. "://" .. ip .. +dsp.build_url("niu") +%> + +
Warning! The device IP-address has been changed.
+The router will be available in a few seconds at <%=url%>
+
\ No newline at end of file diff --git a/modules/niu/luasrc/view/niu/system.htm b/modules/niu/luasrc/view/niu/system.htm index 0f955d7bb..c702214e1 100644 --- a/modules/niu/luasrc/view/niu/system.htm +++ b/modules/niu/luasrc/view/niu/system.htm @@ -1,35 +1,72 @@ <% -local dsp = require "luci.dispatcher" -local utl = require "luci.util" local nxo = require "nixio" +local fs = require "nixio.fs" local sinfo = nxo.sysinfo() local load1 = nxo.bit.div(sinfo.loads[1] * 100, 1) -local days = nxo.bit.div(sinfo.uptime, 86400) -local hour = nxo.bit.div(sinfo.uptime, 3600) % 24 -local mins = nxo.bit.div(sinfo.uptime, 60) % 60 +local load15 = nxo.bit.div(sinfo.loads[3] * 100, 1) + +local meminfo = fs.readfile("/proc/meminfo") +local totalram = nxo.bit.div(sinfo.totalram, 1024) +local freeram = nxo.bit.div(sinfo.freeram, 1024) +local buffers = nxo.bit.div(sinfo.bufferram, 1024) +local cached = tonumber(meminfo:match("Cached:%s+([0-9]+)%s+")) +local memused = nxo.bit.div(totalram - freeram - cached - buffers, 1024) +totalram = nxo.bit.div(totalram, 1024) + +local totalswap = nxo.bit.div(sinfo.totalswap, 1048576) +local usedswap = totalswap - nxo.bit.div(sinfo.freeswap, 1048576) + + +local function date_format(secs) + local suff = {"min", "h", "d"} + local mins = 0 + local hour = 0 + local days = 0 + + secs = nxo.bit.div(secs, 1) + if secs > 60 then + mins = nxo.bit.div(secs, 60) + secs = secs % 60 + end + + if mins > 60 then + hour = nxo.bit.div(mins, 60) + mins = mins % 60 + end + + if hour > 24 then + days = nxo.bit.div(hour, 24) + hour = hour % 24 + end + + if days > 0 then + return string.format("%.0fd %02.0fh %02.0fmin", days, hour, mins) + else + return string.format("%02.0fh %02.0fmin", hour, mins) + end +end %> -
Status:
- +
+ + + + - - + + + + +<% if totalswap > 0 then %> - - + + + +<% end %> + + + +
Load:<%=load1%>% / <%=load15%>%
System Load<%=load1%> %Memory:<%=memused%> MiB / <%=totalram%> MiB
Uptime<%=days%>d, <%=hour%>:<%=mins%>Swap:<%=usedswap%> MiB / <%=totalswap%> MiB
Uptime:<%=date_format(sinfo.uptime)%>
-
-
    -<% -local nodes = dsp.node("niu", "system").nodes -local function cmp(a, b) - return (nodes[a].order or 100) < (nodes[b].order or 100) -end -for k, v in utl.spairs(nodes, cmp) do -%> -
  • "><%=v.title%>
  • -<% -end -%> -
\ No newline at end of file +
\ No newline at end of file -- 2.11.0