modules/admin-full, modules/admin-core, themes/base: add port status indicators to switch config page
This commit is contained in:
parent
1aa81b4ae0
commit
57e51eba60
6 changed files with 94 additions and 3 deletions
|
@ -9,7 +9,6 @@ You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
$Id$
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module("luci.tools.status", package.seeall)
|
module("luci.tools.status", package.seeall)
|
||||||
|
@ -153,3 +152,36 @@ function wifi_network(id)
|
||||||
end
|
end
|
||||||
return { }
|
return { }
|
||||||
end
|
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
|
||||||
|
|
|
@ -10,7 +10,6 @@ You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
$Id$
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module("luci.controller.admin.network", package.seeall)
|
module("luci.controller.admin.network", package.seeall)
|
||||||
|
@ -39,6 +38,9 @@ function index()
|
||||||
page.target = cbi("admin_network/vlan")
|
page.target = cbi("admin_network/vlan")
|
||||||
page.title = _("Switch")
|
page.title = _("Switch")
|
||||||
page.order = 20
|
page.order = 20
|
||||||
|
|
||||||
|
page = entry({"admin", "network", "switch_status"}, call("switch_status"), nil)
|
||||||
|
page.leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -417,6 +419,14 @@ function lease_status()
|
||||||
luci.http.write(']')
|
luci.http.write(']')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function switch_status()
|
||||||
|
local path = luci.dispatcher.context.requestpath
|
||||||
|
local s = require "luci.tools.status"
|
||||||
|
|
||||||
|
luci.http.prepare_content("application/json")
|
||||||
|
luci.http.write_json(s.switch_status(path[#path]))
|
||||||
|
end
|
||||||
|
|
||||||
function diag_command(cmd)
|
function diag_command(cmd)
|
||||||
local path = luci.dispatcher.context.requestpath
|
local path = luci.dispatcher.context.requestpath
|
||||||
local addr = path[#path]
|
local addr = path[#path]
|
||||||
|
|
|
@ -10,7 +10,6 @@ You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
$Id$
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
m = Map("network", translate("Switch"), translate("The network ports on this device can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))
|
m = Map("network", translate("Switch"), translate("The network ports on this device can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))
|
||||||
|
@ -276,6 +275,12 @@ m.uci:foreach("network", "switch",
|
||||||
|
|
||||||
port_opts[#port_opts+1] = po
|
port_opts[#port_opts+1] = po
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Switch status template
|
||||||
|
s = m:section(SimpleSection)
|
||||||
|
s.template = "admin_network/switch_status"
|
||||||
|
s.switch = switch_name
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
var tb;
|
||||||
|
var ths = document.getElementsByTagName('th');
|
||||||
|
for (var i = 0; i < ths.length; i++)
|
||||||
|
if (ths[i].className = 'cbi-section-table-cell' && !ths[i].innerHTML)
|
||||||
|
{
|
||||||
|
ths[i].innerHTML = '<%:Port status:%>';
|
||||||
|
tb = ths[i].parentNode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tb)
|
||||||
|
{
|
||||||
|
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "switch_status", self.switch)%>', null,
|
||||||
|
function(x, st)
|
||||||
|
{
|
||||||
|
if (st && st.length)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < st.length; i++)
|
||||||
|
{
|
||||||
|
var th = tb.childNodes[i+1];
|
||||||
|
|
||||||
|
if (st[i].link)
|
||||||
|
{
|
||||||
|
th.innerHTML = String.format(
|
||||||
|
'<small><img src="<%=resource%>/icons/port_up.png" />' +
|
||||||
|
'<br />%d<%:baseT%> %s</small>',
|
||||||
|
st[i].speed, st[i].duplex
|
||||||
|
? '<%:full-duplex%>' : '<%:half-duplex%>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
th.innerHTML = String.format(
|
||||||
|
'<small><img src="<%=resource%>/icons/port_down.png" />' +
|
||||||
|
'<br /><%:no link%></small>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//]]></script>
|
BIN
themes/base/htdocs/luci-static/resources/icons/port_down.png
Normal file
BIN
themes/base/htdocs/luci-static/resources/icons/port_down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 982 B |
BIN
themes/base/htdocs/luci-static/resources/icons/port_up.png
Normal file
BIN
themes/base/htdocs/luci-static/resources/icons/port_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in a new issue