summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-core/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-09-11 14:18:28 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-09-11 14:18:28 +0000
commit57e51eba60cd95b82b11c5857651861decf8dcbe (patch)
treeeca82dc0108f5675f09e76f4a3743c9b8a0f1509 /modules/admin-core/luasrc
parent1aa81b4ae095cea55119e8bc4142fbfb61cf40ff (diff)
modules/admin-full, modules/admin-core, themes/base: add port status indicators to switch config page
Diffstat (limited to 'modules/admin-core/luasrc')
-rw-r--r--modules/admin-core/luasrc/tools/status.lua34
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/admin-core/luasrc/tools/status.lua b/modules/admin-core/luasrc/tools/status.lua
index cd543f71e8..e5c517f238 100644
--- a/modules/admin-core/luasrc/tools/status.lua
+++ b/modules/admin-core/luasrc/tools/status.lua
@@ -9,7 +9,6 @@ You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
-$Id$
]]--
module("luci.tools.status", package.seeall)
@@ -153,3 +152,36 @@ function wifi_network(id)
end
return { }
end
+
+function switch_status(dev)
+ local ports = { }
+ local swc = io.popen("swconfig dev %q show" % dev, "r")
+ if swc then
+ local l
+ repeat
+ l = swc:read("*l")
+ if l then
+ local port, up = l:match("port:(%d+) link:(%w+)")
+ if port then
+ local speed = l:match(" speed:(%d+)")
+ local duplex = l:match(" (%w+)-duplex")
+ local txflow = l:match(" (txflow)")
+ local rxflow = l:match(" (rxflow)")
+ local auto = l:match(" (auto)")
+
+ ports[#ports+1] = {
+ port = tonumber(port) or 0,
+ speed = tonumber(speed) or 0,
+ link = (up == "up"),
+ duplex = (duplex == "full"),
+ rxflow = (not not rxflow),
+ txflow = (not not txflow),
+ auto = (not not auto)
+ }
+ end
+ end
+ until not l
+ swc:close()
+ end
+ return ports
+end