From 57e51eba60cd95b82b11c5857651861decf8dcbe Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 11 Sep 2012 14:18:28 +0000 Subject: [PATCH] modules/admin-full, modules/admin-core, themes/base: add port status indicators to switch config page --- modules/admin-core/luasrc/tools/status.lua | 34 +++++++++++++++- .../admin-full/luasrc/controller/admin/network.lua | 12 +++++- .../luasrc/model/cbi/admin_network/vlan.lua | 7 +++- .../luasrc/view/admin_network/switch_status.htm | 44 +++++++++++++++++++++ .../luci-static/resources/icons/port_down.png | Bin 0 -> 982 bytes .../htdocs/luci-static/resources/icons/port_up.png | Bin 0 -> 1405 bytes 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 modules/admin-full/luasrc/view/admin_network/switch_status.htm create mode 100644 themes/base/htdocs/luci-static/resources/icons/port_down.png create mode 100644 themes/base/htdocs/luci-static/resources/icons/port_up.png diff --git a/modules/admin-core/luasrc/tools/status.lua b/modules/admin-core/luasrc/tools/status.lua index cd543f71e..e5c517f23 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 diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua index 00e1fe2ff..85dc68fff 100644 --- a/modules/admin-full/luasrc/controller/admin/network.lua +++ b/modules/admin-full/luasrc/controller/admin/network.lua @@ -10,7 +10,6 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id$ ]]-- module("luci.controller.admin.network", package.seeall) @@ -39,6 +38,9 @@ function index() page.target = cbi("admin_network/vlan") page.title = _("Switch") page.order = 20 + + page = entry({"admin", "network", "switch_status"}, call("switch_status"), nil) + page.leaf = true end @@ -417,6 +419,14 @@ function lease_status() luci.http.write(']') 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) local path = luci.dispatcher.context.requestpath local addr = path[#path] diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua b/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua index 25fd0a899..9dc3f2f63 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua @@ -10,7 +10,6 @@ You may obtain a copy of the License at 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 VLANs in which computers can communicate directly with each other. VLANs 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 end + + + -- Switch status template + s = m:section(SimpleSection) + s.template = "admin_network/switch_status" + s.switch = switch_name end ) diff --git a/modules/admin-full/luasrc/view/admin_network/switch_status.htm b/modules/admin-full/luasrc/view/admin_network/switch_status.htm new file mode 100644 index 000000000..31da264dc --- /dev/null +++ b/modules/admin-full/luasrc/view/admin_network/switch_status.htm @@ -0,0 +1,44 @@ + diff --git a/themes/base/htdocs/luci-static/resources/icons/port_down.png b/themes/base/htdocs/luci-static/resources/icons/port_down.png new file mode 100644 index 0000000000000000000000000000000000000000..25ea172324c04e222c575cd01089e36a5c416c3e GIT binary patch literal 982 zcmV;{11bE8P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq@ z4g)HQF(jJ+00UM@L_t(Y$HkUmZyQArhM$?;bL?0mkdlZmq)1d1p;bxM3L$~`2IM~= zBz|B1L5nIxnj#`Ziz^6xC{m#kO(Mr>9H+ML&bxfr^ZA@RC#jIY(rUf8bMxLi^Umzb z#>R%{fB0E|&%gL=#7Ojtw& zV-zm{TCtzanQfB9=LRGI&j3|57}em}dme1vr}emn_htK9ZI1QzbynWKOcd4d-jj~f zg6;G>;q$#O4Pz|U7(@gC;w0h8A5SVl0pfVbpHH6#ry>|t=As%Z5<*{aUtoNiX$bA0 z-{;QVJ3N2>H))yz&^vj_y>GYh-XS8W2+PY$e0Y0}*5ejCzwOXy)LFZ6lMmKz5=Ave z!+wc$iE&`02*RVEAM)(kU!-YD94G9z57^%R2@x>HV2q+h>2x~$vhzEG!H^_L=ys3U z+}fml&_+ZN(cr#-U72IalpDth0NX!4Vs~#pXJ}MI3bLUJySsbr?d@Z&<;L|@78e)k zc8^(lb14&_pJHvtiz#Ry96IN6wHj4KB?p(OLH>*^p8&=P!Z^piqMS;M2`^;8MipZw zET@3Az+A}x16Z|_TJtmOxVS4IF!C-Fn_`R!A5;wSDdsurab0Kcc;`#xY}Mz45-NmR zi+LqyS`PX6S?1iB5V?Z?ama0PF+mRTcB2VnHOgC;`ZVT7c!HonFe2GnXuoI@r%@hi zqoEIYHzUWTjwRFL8Y}tQl@807`V8ZU`drFzXlc|(4C07JE#*P$9omOAvfhfZq3bzZ z30TLBiz7&DA}%$dp+pw0UOvQ)l&dQpoHJZm>EN95?#cl#`%xA#pQ$>^8K3UhcCwt# zgNQKSYy$B9>U#hT`H0P(VDsI0{&h01UYm|w6xqC-W}Hsb8%Yw=sL%7s$Dh*a9B_Ep zDW5VP;<)-0vet6z)@@#2cq302oK?r!G#C!3*M}^;w!l|kem&!?%&VrL$nvk-JDSb7 z>gMp`=#b`olUl7lDX~ngDv~3s=%ndn`_4I%B<8qxL|izV&pwX}&7^nIgOlEQ7oH1V zg{sP_A{77jUUi;@EsEt;oL$&z#>K$`e1HFk|NMIU5B8^)T!cwsE&u=k07*qoM6N<$ Ef)7g4YybcN literal 0 HcmV?d00001 diff --git a/themes/base/htdocs/luci-static/resources/icons/port_up.png b/themes/base/htdocs/luci-static/resources/icons/port_up.png new file mode 100644 index 0000000000000000000000000000000000000000..9182478870c70ed771e05ece5b640aba22045757 GIT binary patch literal 1405 zcmV-@1%mpCP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq@ z4g(ZOP&qIF00jL>L_t(Y$HkV*Z&Xzr$3N$Br!##(U(2-`PAcUql-a<>FmBVkpQ!%kD zE-sKS6eznT%H=Y?9{`YuC)oMSZeD+NjG4RBEG*3N)7i6Z8W^CvD~S-2a1HCaIW{I> zX=!O)6hdp!TA>4tQVOLsslH8Y-?jrsJIv0_FgbM_*L4BN=L;mela=DLkFnOPn_B2X zKF76*YZzmy@6y9*Qhh0uia?uUafSxdbar$BFuyR%VlqjXqQX{0Gt#><#wF7;bKIE95^qW%YGkx0*+*wbXGMe})e8w5 z6xV7_gg^*^6beUcq*8o$?iOcfy4dz~4;?LvwpPXE@tc%&K&*KK@uozzaJsva^dx(# zp;pSNGG43L`q9>+9gXr8QYefSeDTdC&W+D9kla9eC`oH;Gv_Yeq@(^ zXh+l0-brt73JYAlngPIZbhVutOsD8T3W?)56juVi{OUI*rXP?_wUZv|K}f~v^Vcbt zJ(3*>j=bE<_H+ucl*?uM`!^$i>o;#OK0eNY0|#l}*ioZcPwHa}*@q#=zs`_-Xh^5p z868QHUvWAA`ycp$VdroM$KTyeTeDLU3PCK^gaGn|0z04D#dCZ1(cj-6saG-AnDHv^ zQm)Lg6IWPqEu#ZnY#r%i_Fj%lnJGeR8GC-1&yT!-qaUBi0w_K#($n2TBGH1@8qaen z6mxhrv$^g(Udp)~J2B3RYuPf`$+nSAOwB#uQf3ls;qYr)dH;N_fU67IRo}i)*4=C)CTiGRID2@O;=h(9P&bDgqs!!~#e5r#bXeifrKlCNP9y zSXDbAEK*6@H@2fxO+T-hcy&X4^hAch2!{LH**en4^nA7o`rg4bhhE(LsJ~;fp~JfO z7+e2#qrbhP@B