modules/admin-{mini,full}: prevent crash in iface overview page if ifconfig does...
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 27 Mar 2010 14:54:06 +0000 (14:54 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 27 Mar 2010 14:54:06 +0000 (14:54 +0000)
modules/admin-full/luasrc/model/cbi/admin_network/network.lua
modules/admin-mini/luasrc/model/cbi/mini/network.lua

index 8d34fa7cfff740be4c39e2392ee94e8c450e9213..2dc9e9b43aae91220eaddf26f1231a9b3a726090 100644 (file)
@@ -86,9 +86,18 @@ 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 mac = fs.readfile("/sys/class/net/" .. ix .. "/address")
+
+       if not mac then
+               mac = luci.util.exec("ifconfig " .. ix)
+               mac = mac and mac:match(" ([A-F0-9:]+)%s*\n")
+       end
+
+       if mac and #mac > 0 then
+               return mac:upper()
+       end
+
+       return "?"
 end
 
 
index 43ad212cc36277f9df53cf3af3354e5517448419..57edc47187861c11a429c9fee84dfcb9a3cb41bf 100644 (file)
@@ -41,9 +41,18 @@ hwaddr = s:option(DummyValue, "_hwaddr",
  translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"), translate("Hardware Address"))
 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 mac = fs.readfile("/sys/class/net/" .. ix .. "/address")
+
+       if not mac then
+               mac = luci.util.exec("ifconfig " .. ix)
+               mac = mac and mac:match(" ([A-F0-9:]+)%s*\n")
+       end
+
+       if mac and #mac > 0 then
+               return mac:upper()
+       end
+
+       return "?"
 end