From 659a8bdf014a617cd8f254e90d73bed07b4d1e15 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 22 Sep 2011 02:43:38 +0000 Subject: modules/admin-full: implement per-wifi-iface disable option --- .../admin-full/luasrc/controller/admin/network.lua | 20 +++++ .../luasrc/model/cbi/admin_network/wifi.lua | 31 ++++++-- .../luasrc/view/admin_network/wifi_overview.htm | 89 ++++++++++++++++++++-- 3 files changed, 126 insertions(+), 14 deletions(-) (limited to 'modules/admin-full/luasrc') diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua index 85456483a3..d2f17a4fa1 100644 --- a/modules/admin-full/luasrc/controller/admin/network.lua +++ b/modules/admin-full/luasrc/controller/admin/network.lua @@ -343,6 +343,26 @@ function wifi_status() luci.http.status(404, "No such device") end +function wifi_reconnect() + local path = luci.dispatcher.context.requestpath + local mode = path[#path-1] + local wnet = path[#path] + local netmd = require "luci.model.network".init() + + local net = netmd:get_wifinet(wnet) + if net then + net:set("disabled", (mode == "wireless_shutdown") and 1 or nil) + netmd:commit("wireless") + + luci.sys.call("(env -i /sbin/wifi down; env -i /sbin/wifi up) >/dev/null 2>/dev/null") + luci.http.status(200, (mode == "wireless_shutdown") and "Shutdown" or "Reconnected") + + return + end + + luci.http.status(404, "No such radio") +end + function lease_status() local s = require "luci.tools.status" diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua index cc534f5c93..d0ebba2155 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua @@ -47,6 +47,22 @@ if not wnet or not wdev then return end +-- wireless toggle was requested, commit and reload page +if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then + if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then + wnet:set("disabled", nil) + else + wnet:set("disabled", "1") + end + wdev:set("disabled", nil) + + nw:commit("wireless") + luci.sys.call("(env -i /sbin/wifi down; env -i /sbin/wifi up) >/dev/null 2>/dev/null") + + luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1])) + return +end + m.title = luci.util.pcdata(wnet:get_i18n()) @@ -75,13 +91,16 @@ st = s:taboption("general", DummyValue, "__status", translate("Status")) st.template = "admin_network/wifi_status" st.ifname = arg[1] -en = s:taboption("general", Flag, "disabled", translate("Enable device")) -en.enabled = "0" -en.disabled = "1" -en.rmempty = false +en = s:taboption("general", Button, "__toggle") -function en.cfgvalue(self, section) - return Flag.cfgvalue(self, section) or "0" +if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then + en.title = translate("Wireless network is disabled") + en.inputtitle = translate("Enable") + en.inputstyle = "apply" +else + en.title = translate("Wireless network is enabled") + en.inputtitle = translate("Disable") + en.inputstyle = "reset" end diff --git a/modules/admin-full/luasrc/view/admin_network/wifi_overview.htm b/modules/admin-full/luasrc/view/admin_network/wifi_overview.htm index 8e64d1422c..04e5df2329 100644 --- a/modules/admin-full/luasrc/view/admin_network/wifi_overview.htm +++ b/modules/admin-full/luasrc/view/admin_network/wifi_overview.htm @@ -123,6 +123,49 @@ $Id$ var wifidevs = <%=luci.http.write_json(netdevs)%>; var arptable = <%=luci.http.write_json(arpcache)%>; + var is_reconnecting = false; + + function wifi_shutdown(id, toggle) { + var reconnect = (toggle.getAttribute('active') == 'false'); + + if (!reconnect && !confirm(String.format('<%:Really shutdown network ?\nYou might loose access to this router if you are connected via this interface.%>'))) + return; + + is_reconnecting = true; + + var s = document.getElementById('iw-rc-status'); + if (s) + { + s.parentNode.style.display = 'block'; + s.innerHTML = '<%:Waiting for router...%>'; + } + + for (var net in wifidevs) + { + var st = document.getElementById(net + '-iw-status'); + if (st) + st.innerHTML = '<%:Wireless is restarting...%>'; + } + + var rcxhr = new XHR(); + rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null, + function(x) + { + if (s) + { + s.innerHTML = reconnect + ? '<%:Wireless restarted%>' + : '<%:Wireless shut down%>'; + + window.setTimeout(function() { + s.parentNode.style.display = 'none'; + is_reconnecting = false; + }, 1000); + } + } + ); + } + var update_status = function() { iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null, function(x, st) @@ -168,6 +211,26 @@ $Id$ '%d%%', icon, iw.signal, iw.noise, p ); + var toggle = document.getElementById(iw.id + '-iw-toggle'); + if (toggle) + { + if (is_assoc) + { + toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reset.gif)'; + toggle.value = '<%:Disable%>'; + toggle.title = '<%:Shutdown this network%>'; + } + else + { + toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reload.gif)'; + toggle.value = '<%:Enable%>'; + toggle.title = '<%:Activate this network%>'; + + } + + toggle.setAttribute('active', is_assoc); + } + var info = document.getElementById(iw.id + '-iw-status'); if (info) { @@ -184,8 +247,11 @@ $Id$ info.innerHTML = String.format( '<%:SSID%>: %h | ' + '<%:Mode%>: %s
' + - '<%:Wireless is disabled or not associated%>', - iw.ssid || '?', iw.mode + '%s', + iw.ssid || '?', iw.mode, + is_reconnecting + ? '<%:Wireless is restarting...%>' + : '<%:Wireless is disabled or not associated%>' ); } @@ -280,6 +346,12 @@ $Id$

<%:Wireless Overview%>

+ +
<% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %> @@ -293,9 +365,9 @@ $Id$ <%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)
- - ?device=<%=dev:name()%>"><%:Find and join network%> - ?device=<%=dev:name()%>"><%:Provide new network%> + + ?device=<%=dev:name()%>'" title="<%:Find and join network%>" value="<%:Scan%>" /> + ?device=<%=dev:name()%>'" title="<%:Provide new network%>" value="<%:Add%>" /> @@ -312,9 +384,10 @@ $Id$ <%:Collecting data...%> - - <%:Edit this network%> - " onclick="return confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might loose access to this router if you are connected via this network.%>')"><%:Delete this network%> + + + + '" title="<%:Delete this network%>" value="<%:Remove%>" /> <% end %> -- cgit v1.2.3