From 3fe0697748c19ceaa0d95a5202f206f2fe9c1aa2 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 8 Mar 2010 22:45:06 +0000 Subject: [PATCH] luci-0.9: minor fixes and sanity checks in network config pages --- .../luasrc/model/cbi/admin_network/ifaces.lua | 3 ++- .../model/cbi/admin_network/network.lua | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua index 8758f7300c..415dab6a93 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua @@ -27,7 +27,8 @@ local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")() m = Map("network", translate("interfaces"), translate("a_n_ifaces1")) s = m:section(NamedSection, arg[1], "interface") -s.addremove = true +s.addremove = false +s.title = arg[1]:upper() back = s:option(DummyValue, "_overview", translate("overview")) back.value = "" 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 0d0ce2c9a2..d645f0f0bb 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$ ]]-- +local utl = require "luci.util" local sys = require "luci.sys" local wa = require "luci.tools.webadmin" local fs = require "nixio.fs" @@ -68,7 +69,11 @@ end ifname = s:option(DummyValue, "ifname", translate("device")) function ifname.cfgvalue(self, section) - return netstate[section] and netstate[section].ifname + local ix = utl.trim(netstate[section] and netstate[section].ifname or "") + if #ix > 0 then + return ix + end + return "?" end ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan") @@ -85,16 +90,26 @@ end hwaddr = s:option(DummyValue, "_hwaddr") function hwaddr.cfgvalue(self, section) - local ix = self.map:get(section, "ifname") or "" - return fs.readfile("/sys/class/net/" .. ix .. "/address") - or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n") - or "n/a" + local ix = utl.trim(self.map:get(section, "ifname") or "") + if #ix > 0 then + local mac = fs.readfile("/sys/class/net/" .. ix .. "/address") + or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n") + + if mac and #mac > 0 then + return mac:upper() + end + end + return "?" end ipaddr = s:option(DummyValue, "ipaddr", translate("addresses")) function ipaddr.cfgvalue(self, section) - return table.concat(wa.network_get_addresses(section), ", ") + local addr = table.concat(wa.network_get_addresses(section), ", ") + if addr and #addr > 0 then + return addr + end + return "?" end txrx = s:option(DummyValue, "_txrx") -- 2.30.2