summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-13 14:09:33 +0000
committerSteven Barth <steven@midlink.org>2008-08-13 14:09:33 +0000
commit5a92c0fc089f8af4cdd5c35e94a563526c872ffd (patch)
tree50dedc13d40efbcad813f61d1b64eb9a87c9e7f6 /modules
parenta59044df9b87c7e4ce668649726aa2d355206965 (diff)
libs/cbi: Improved user interface draft #1
Diffstat (limited to 'modules')
-rw-r--r--modules/admin-core/luasrc/tools/webadmin.lua12
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/network.lua40
2 files changed, 40 insertions, 12 deletions
diff --git a/modules/admin-core/luasrc/tools/webadmin.lua b/modules/admin-core/luasrc/tools/webadmin.lua
index 45bd910ac..b9f18ac40 100644
--- a/modules/admin-core/luasrc/tools/webadmin.lua
+++ b/modules/admin-core/luasrc/tools/webadmin.lua
@@ -14,6 +14,18 @@ $Id$
]]--
module("luci.tools.webadmin", package.seeall)
+require("luci.model.uci")
+
+function byte_format(byte)
+ local suff = {"B", "KB", "MB", "GB", "TB"}
+ for i=1, 5 do
+ if byte > 1024 and i < 5 then
+ byte = byte / 1024
+ else
+ return string.format("%.2f %s", byte, suff[i])
+ end
+ end
+end
function cbi_add_networks(field)
luci.model.uci.foreach("network", "interface",
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
index 75c9f2818..00c001e50 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
@@ -13,6 +13,7 @@ You may obtain a copy of the License at
$Id$
]]--
require("luci.sys")
+require("luci.tools.webadmin")
m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
@@ -49,11 +50,14 @@ function up.write(self, section, value)
os.execute(call .. " " .. section)
end
-ipaddr = s:option(DummyValue, "ipaddr", translate("ipaddress"))
-ipaddr.stateful = true
+hwaddr = s:option(DummyValue, "_hwaddr")
+function hwaddr.cfgvalue(self, section)
+ local ix = self.map:stateget(section, "ifname") or ""
+ return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
+end
+
-ip6addr = s:option(DummyValue, "ip6addr", translate("ip6address"))
-ip6addr.stateful = true
+ipaddr = s:option(DummyValue, "ipaddr")
function ipaddr.cfgvalue(self, section)
local ip = self.map:stateget(section, "ipaddr")
@@ -63,20 +67,32 @@ function ipaddr.cfgvalue(self, section)
return parsed and parsed:string() or ""
end
-rx = s:option(DummyValue, "_rx")
+txrx = s:option(DummyValue, "_rx", "TX / RX")
-function rx.cfgvalue(self, section)
+function txrx.cfgvalue(self, section)
local ix = self.map:stateget(section, "ifname")
- local bt = netstat and netstat[ix] and netstat[ix][1]
- return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)
+
+ local rx = netstat and netstat[ix] and netstat[ix][1]
+ rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
+
+ local tx = netstat and netstat[ix] and netstat[ix][9]
+ tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
+
+ return string.format("%s / %s", tx, rx)
end
-tx = s:option(DummyValue, "_tx")
+errors = s:option(DummyValue, "_err", "Errors", "TX / RX")
-function tx.cfgvalue(self, section)
+function errors.cfgvalue(self, section)
local ix = self.map:stateget(section, "ifname")
- local bt = netstat and netstat[ix] and netstat[ix][9]
- return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)
+
+ local rx = netstat and netstat[ix] and netstat[ix][3]
+ local tx = netstat and netstat[ix] and netstat[ix][11]
+
+ rx = rx and tostring(rx) or "-"
+ tx = tx and tostring(tx) or "-"
+
+ return string.format("%s / %s", tx, rx)
end
return m \ No newline at end of file