luci-0.9: minor fixes and sanity checks in network config pages
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 8 Mar 2010 22:45:06 +0000 (22:45 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 8 Mar 2010 22:45:06 +0000 (22:45 +0000)
modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua
modules/admin-full/luasrc/model/cbi/admin_network/network.lua

index 8758f73..415dab6 100644 (file)
@@ -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 = ""
index 0d0ce2c..d645f0f 100644 (file)
@@ -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")