libs/core: fix nil access, implement luci.model.network.network.uptime()
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 1 Dec 2010 21:15:59 +0000 (21:15 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 1 Dec 2010 21:15:59 +0000 (21:15 +0000)
libs/core/luasrc/model/network.lua

index cc4200cb48378c55383d5f63ccbe2d81e1775007..30e75b9e4c4d69dc48e007dd7bad7cf3a9bf4b89 100644 (file)
@@ -481,6 +481,7 @@ function network.ifname(self)
        elseif self:is_virtual() then
                return p .. "-" .. self.sid
        else
+               local num = { }
                local dev = self:_get("ifname") or
                        uci_r:get("network", self.sid, "ifname")
 
@@ -525,6 +526,15 @@ function network.name(self)
        return self.sid
 end
 
+function network.uptime(self)
+       local cnt = tonumber(uci_s:get("network", self.sid, "connect_time"))
+       if cnt ~= nil then
+               return nxo.sysinfo().uptime - cnt
+       else
+               return 0
+       end
+end
+
 function network.is_bridge(self)
        return (self:type() == "bridge")
 end