diff options
author | Steven Barth <steven@midlink.org> | 2009-11-14 13:41:37 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-11-14 13:41:37 +0000 |
commit | 730a9b6f69ecd1ce26b0e1c9bcd51ccf42f56f31 (patch) | |
tree | b442df9dfbe1c7af86aeac148508ef7135b89421 /modules | |
parent | b882bdeb04adc817a477009c689ec3b79151bf71 (diff) |
NIU:
Redesign dashboard Level 1
Network / System status on dashboard
Rework "LAN IP has changed" warning
Fix Routing table not hiding when requested
Diffstat (limited to 'modules')
-rw-r--r-- | modules/niu/htdocs/luci-static/resources/icons32/folder.png | bin | 0 -> 645 bytes | |||
-rw-r--r-- | modules/niu/htdocs/luci-static/resources/icons32/network-workgroup.png | bin | 0 -> 2226 bytes | |||
-rw-r--r-- | modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png | bin | 0 -> 2171 bytes | |||
-rw-r--r-- | modules/niu/htdocs/luci-static/resources/niu.css | 26 | ||||
-rw-r--r-- | modules/niu/luasrc/controller/niu/dashboard.lua | 3 | ||||
-rw-r--r-- | modules/niu/luasrc/controller/niu/network.lua | 15 | ||||
-rw-r--r-- | modules/niu/luasrc/controller/niu/system.lua | 13 | ||||
-rw-r--r-- | modules/niu/luasrc/view/niu/dashboard.htm | 35 | ||||
-rw-r--r-- | modules/niu/luasrc/view/niu/network.htm | 101 | ||||
-rw-r--r-- | modules/niu/luasrc/view/niu/network/rtable.htm | 1 | ||||
-rw-r--r-- | modules/niu/luasrc/view/niu/network/warn_ip_change.htm | 13 | ||||
-rw-r--r-- | modules/niu/luasrc/view/niu/system.htm | 87 |
12 files changed, 226 insertions, 68 deletions
diff --git a/modules/niu/htdocs/luci-static/resources/icons32/folder.png b/modules/niu/htdocs/luci-static/resources/icons32/folder.png Binary files differnew file mode 100644 index 000000000..6919f984f --- /dev/null +++ b/modules/niu/htdocs/luci-static/resources/icons32/folder.png diff --git a/modules/niu/htdocs/luci-static/resources/icons32/network-workgroup.png b/modules/niu/htdocs/luci-static/resources/icons32/network-workgroup.png Binary files differnew file mode 100644 index 000000000..860ffb95e --- /dev/null +++ b/modules/niu/htdocs/luci-static/resources/icons32/network-workgroup.png diff --git a/modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png b/modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png Binary files differnew file mode 100644 index 000000000..2afbd23cc --- /dev/null +++ b/modules/niu/htdocs/luci-static/resources/icons32/preferences-system.png 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 %> - <fieldset style="float: left; margin: 1em; padding: 0.5em"> - <legend><%=v.title%></legend> - <% - tpl.render(v.dbtemplate) - %> + <fieldset class="dbbox"> + <h2<% if v.niu_dbicon then %> style="background-image: url(<%=resource%>/<%=v.niu_dbicon%>)"<% end %>><%=v.title%></h2> + <% if v.niu_dbtemplate then tpl.render(v.niu_dbtemplate) end %> + <% if v.niu_dbtasks then %> + <h4>Tasks:</h4> + <ul> + <% + 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 + %> + <li><a href="<%=dsp.build_url("niu", k, k2)%>"><%=v2.title%></a></li> + <% + end + %> + </ul> + <% end %> </fieldset> <% 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 -%> -<div>Status:</div> -<table> -<% -for _, v in ipairs(nws) do if v[".name"] ~= "loopback" then -%> -<tr><td><%=v[".name"]%></td><td><%=v.ipaddr%></td></tr> -<% end end %> -</table> -<br /> -<ul> -<% -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 -%> -<li><a href="<%=dsp.build_url("niu", "network", k)%>"><%=v.title%></a></li> -<% + +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 %> -</ul>
\ No newline at end of file + +<table class="dbstattbl"> +<% if wanon and wanon ~= "none" then %> +<tr> +<% if wanup then %> +<th>Uplink Address</th> +<td><span style="color: darkgreen"><%=wanip%></span> +</td> +<% else %> +<th>Uplink</th> +<td><span style="color: darkred"><em>offline</em></span> +</td> +<% end %> + +</tr> +<% end %> + +<% if wanul and wandl then %> +<tr> +<th>Uplink Traffic</th><td> +<%=("%.2f"):format(wandl)%> GB⇓ <%=("%.2f"):format(wanul)%> GB⇑ +</td> +</tr> +<% end %> + +<tr> +<th>Local Address</th><td> +<%=uci.inst_state:get("network", "lan", "ipaddr")%> +</td> +</tr> + +<% if arps then %> +<tr> +<th>Active IP-Devices</th><td><%=arps%><% if leasefn then %> +(<%=leasefn%> assigned) +<% end %></td> +</tr> +<% end %> + +</table> +<br />
\ 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 @@ -<strong>Warning!<br /> -Device IP has changed.</strong>
\ 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") +%> + +<div style="color: red">Warning! The device IP-address has been changed.<br /> +The router will be available in a few seconds at <a href="<%=url%>"><%=url%></a></div> +<br />
\ 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 %> -<div>Status:</div> -<table> +<table class="dbstattbl"> +<tr> +<th>Load:</th> +<td><%=load1%>% / <%=load15%>%</td> +</tr> <tr> -<th>System Load</th> -<td><%=load1%> %</td> +<th>Memory:</th> +<td><%=memused%> MiB / <%=totalram%> MiB</td> </tr> + + +<% if totalswap > 0 then %> <tr> -<th>Uptime</th> -<td><%=days%>d, <%=hour%>:<%=mins%></td> +<th>Swap:</th> +<td><%=usedswap%> MiB / <%=totalswap%> MiB</td> +</tr> +<% end %> + +<tr> +<th>Uptime:</th> +<td><%=date_format(sinfo.uptime)%></td> </tr> </table> -<br /> -<ul> -<% -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 -%> -<li><a href="<%=dsp.build_url("niu", "system", k)%>"><%=v.title%></a></li> -<% -end -%> -</ul>
\ No newline at end of file +<br />
\ No newline at end of file |