diff options
Diffstat (limited to 'modules/luci-base')
-rw-r--r-- | modules/luci-base/luasrc/controller/admin/index.lua | 54 | ||||
-rw-r--r-- | modules/luci-base/luasrc/tools/status.lua | 250 | ||||
-rw-r--r-- | modules/luci-base/luasrc/view/lease_status.htm | 102 | ||||
-rw-r--r-- | modules/luci-base/luasrc/view/wifi_assoclist.htm | 120 |
4 files changed, 0 insertions, 526 deletions
diff --git a/modules/luci-base/luasrc/controller/admin/index.lua b/modules/luci-base/luasrc/controller/admin/index.lua index 928faa14b4..0cebfa4f57 100644 --- a/modules/luci-base/luasrc/controller/admin/index.lua +++ b/modules/luci-base/luasrc/controller/admin/index.lua @@ -71,27 +71,6 @@ function index() page.index = true toplevel_page(page, false, false) - if nixio.fs.access("/etc/config/dhcp") then - page = entry({"admin", "dhcplease_status"}, call("lease_status"), nil) - page.leaf = true - end - - local has_wifi = false - - uci:foreach("wireless", "wifi-device", - function(s) - has_wifi = true - return false - end) - - if has_wifi then - page = entry({"admin", "wireless_assoclist"}, call("wifi_assoclist"), nil) - page.leaf = true - - page = entry({"admin", "wireless_deauth"}, post("wifi_deauth"), nil) - page.leaf = true - end - page = entry({"admin", "translations"}, call("action_translations"), nil) page.leaf = true @@ -282,36 +261,3 @@ function action_ubus() luci.http.prepare_content("application/json") luci.http.write_json(response) end - -function lease_status() - local s = require "luci.tools.status" - - luci.http.prepare_content("application/json") - luci.http.write('[') - luci.http.write_json(s.dhcp_leases()) - luci.http.write(',') - luci.http.write_json(s.dhcp6_leases()) - luci.http.write(']') -end - -function wifi_assoclist() - local s = require "luci.tools.status" - - luci.http.prepare_content("application/json") - luci.http.write_json(s.wifi_assoclist()) -end - -function wifi_deauth() - local iface = luci.http.formvalue("iface") - local bssid = luci.http.formvalue("bssid") - - if iface and bssid then - luci.util.ubus("hostapd.%s" % iface, "del_client", { - addr = bssid, - deauth = true, - reason = 5, - ban_time = 60000 - }) - end - luci.http.status(200, "OK") -end diff --git a/modules/luci-base/luasrc/tools/status.lua b/modules/luci-base/luasrc/tools/status.lua deleted file mode 100644 index dc30c064c0..0000000000 --- a/modules/luci-base/luasrc/tools/status.lua +++ /dev/null @@ -1,250 +0,0 @@ --- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org> --- Licensed to the public under the Apache License 2.0. - -module("luci.tools.status", package.seeall) - -local uci = require "luci.model.uci".cursor() -local ipc = require "luci.ip" - -local function dhcp_leases_common(family) - local rv = { } - local nfs = require "nixio.fs" - local sys = require "luci.sys" - local leasefile = "/tmp/dhcp.leases" - - uci:foreach("dhcp", "dnsmasq", - function(s) - if s.leasefile and nfs.access(s.leasefile) then - leasefile = s.leasefile - return false - end - end) - - local fd = io.open(leasefile, "r") - if fd then - while true do - local ln = fd:read("*l") - if not ln then - break - else - local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)") - local expire = tonumber(ts) or 0 - if ts and mac and ip and name and duid then - if family == 4 and not ip:match(":") then - rv[#rv+1] = { - expires = (expire ~= 0) and os.difftime(expire, os.time()), - macaddr = ipc.checkmac(mac) or "00:00:00:00:00:00", - ipaddr = ip, - hostname = (name ~= "*") and name - } - elseif family == 6 and ip:match(":") then - rv[#rv+1] = { - expires = (expire ~= 0) and os.difftime(expire, os.time()), - ip6addr = ip, - duid = (duid ~= "*") and duid, - hostname = (name ~= "*") and name - } - end - end - end - end - fd:close() - end - - local lease6file = "/tmp/hosts/odhcpd" - uci:foreach("dhcp", "odhcpd", - function(t) - if t.leasefile and nfs.access(t.leasefile) then - lease6file = t.leasefile - return false - end - end) - local fd = io.open(lease6file, "r") - if fd then - while true do - local ln = fd:read("*l") - if not ln then - break - else - local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (-?%d+) (%S+) (%S+) (.*)") - local expire = tonumber(ts) or 0 - if ip and iaid ~= "ipv4" and family == 6 then - rv[#rv+1] = { - expires = (expire >= 0) and os.difftime(expire, os.time()), - duid = duid, - ip6addr = ip, - hostname = (name ~= "-") and name - } - elseif ip and iaid == "ipv4" and family == 4 then - rv[#rv+1] = { - expires = (expire >= 0) and os.difftime(expire, os.time()), - macaddr = sys.net.duid_to_mac(duid) or "00:00:00:00:00:00", - ipaddr = ip, - hostname = (name ~= "-") and name - } - end - end - end - fd:close() - end - - if family == 6 then - local _, lease - local hosts = sys.net.host_hints() - for _, lease in ipairs(rv) do - local mac = sys.net.duid_to_mac(lease.duid) - local host = mac and hosts[mac] - if host then - if not lease.name then - lease.host_hint = host.name or host.ipv4 or host.ipv6 - elseif host.name and lease.hostname ~= host.name then - lease.host_hint = host.name - end - end - end - end - - return rv -end - -function dhcp_leases() - return dhcp_leases_common(4) -end - -function dhcp6_leases() - return dhcp_leases_common(6) -end - -function wifi_networks() - local rv = { } - local ntm = require "luci.model.network".init() - - local dev - for _, dev in ipairs(ntm:get_wifidevs()) do - local rd = { - up = dev:is_up(), - device = dev:name(), - name = dev:get_i18n(), - networks = { } - } - - local net - for _, net in ipairs(dev:get_wifinets()) do - local a, an = nil, 0 - for _, a in pairs(net:assoclist() or {}) do - an = an + 1 - end - - rd.networks[#rd.networks+1] = { - name = net:shortname(), - link = net:adminlink(), - up = net:is_up(), - mode = net:active_mode(), - ssid = net:active_ssid(), - bssid = net:active_bssid(), - encryption = net:active_encryption(), - frequency = net:frequency(), - channel = net:channel(), - signal = net:signal(), - quality = net:signal_percent(), - noise = net:noise(), - bitrate = net:bitrate(), - ifname = net:ifname(), - country = net:country(), - txpower = net:txpower(), - txpoweroff = net:txpower_offset(), - num_assoc = an, - disabled = (dev:get("disabled") == "1" or - net:get("disabled") == "1") - } - end - - rv[#rv+1] = rd - end - - return rv -end - -function wifi_network(id) - local ntm = require "luci.model.network".init() - local net = ntm:get_wifinet(id) - if net then - local dev = net:get_device() - if dev then - return { - id = id, - name = net:shortname(), - link = net:adminlink(), - up = net:is_up(), - mode = net:active_mode(), - ssid = net:active_ssid(), - bssid = net:active_bssid(), - encryption = net:active_encryption(), - frequency = net:frequency(), - channel = net:channel(), - signal = net:signal(), - quality = net:signal_percent(), - noise = net:noise(), - bitrate = net:bitrate(), - ifname = net:ifname(), - country = net:country(), - txpower = net:txpower(), - txpoweroff = net:txpower_offset(), - disabled = (dev:get("disabled") == "1" or - net:get("disabled") == "1"), - device = { - up = dev:is_up(), - device = dev:name(), - name = dev:get_i18n() - } - } - end - end - return { } -end - -function wifi_assoclist() - local sys = require "luci.sys" - local ntm = require "luci.model.network".init() - local hosts = sys.net.host_hints() - - local assoc = {} - local _, dev, net, bss - - for _, dev in ipairs(ntm:get_wifidevs()) do - local radioname = dev:get_i18n() - - for _, net in ipairs(dev:get_wifinets()) do - local netname = net:shortname() - local netlink = net:adminlink() - local ifname = net:ifname() - - for _, bss in pairs(net:assoclist() or {}) do - local host = hosts[_] - - bss.bssid = _ - bss.ifname = ifname - bss.radio = radioname - bss.name = netname - bss.link = netlink - - bss.host_name = (host) and (host.name or host.ipv4 or host.ipv6) - bss.host_hint = (host and host.name and (host.ipv4 or host.ipv6)) and (host.ipv4 or host.ipv6) - - assoc[#assoc+1] = bss - end - end - end - - table.sort(assoc, function(a, b) - if a.radio ~= b.radio then - return a.radio < b.radio - elseif a.ifname ~= b.ifname then - return a.ifname < b.ifname - else - return a.bssid < b.bssid - end - end) - - return assoc -end diff --git a/modules/luci-base/luasrc/view/lease_status.htm b/modules/luci-base/luasrc/view/lease_status.htm deleted file mode 100644 index bbaf5986ba..0000000000 --- a/modules/luci-base/luasrc/view/lease_status.htm +++ /dev/null @@ -1,102 +0,0 @@ -<script type="text/javascript">//<![CDATA[ - XHR.poll(-1, '<%=url('admin/dhcplease_status')%>', null, - function(x, st) - { - var tb = document.getElementById('lease_status_table'); - if (st && st[0] && tb) - { - var rows = []; - - for (var i = 0; i < st[0].length; i++) - { - var timestr; - - if (st[0][i].expires === false) - timestr = '<em><%:unlimited%></em>'; - else if (st[0][i].expires <= 0) - timestr = '<em><%:expired%></em>'; - else - timestr = String.format('%t', st[0][i].expires); - - rows.push([ - st[0][i].hostname || '?', - st[0][i].ipaddr, - st[0][i].macaddr, - timestr - ]); - } - - cbi_update_table(tb, rows, '<em><%:There are no active leases.%></em>'); - } - - var tb6 = document.getElementById('lease6_status_table'); - if (st && st[1] && tb6) - { - tb6.parentNode.style.display = 'block'; - - var rows = []; - - for (var i = 0; i < st[1].length; i++) - { - var timestr; - - if (st[1][i].expires === false) - timestr = '<em><%:unlimited%></em>'; - else if (st[1][i].expires <= 0) - timestr = '<em><%:expired%></em>'; - else - timestr = String.format('%t', st[1][i].expires); - - var name = st[1][i].hostname, - hint = st[1][i].host_hint; - - rows.push([ - hint ? '%h (%h)'.format(name || '?', hint) : (name || '?'), - st[1][i].ip6addr, - st[1][i].duid, - timestr - ]); - } - - cbi_update_table(tb6, rows, '<em><%:There are no active leases.%></em>'); - } - } - ); -//]]></script> - -<div class="cbi-section"> - <h3><%:Active DHCP Leases%></h3> - <div class="table" id="lease_status_table"> - <div class="tr table-titles"> - <div class="th"><%:Hostname%></div> - <div class="th"><%:IPv4-Address%></div> - <div class="th"><%:MAC-Address%></div> - <div class="th"><%:Leasetime remaining%></div> - </div> - <div class="tr placeholder"> - <div class="td"><em><%:Collecting data...%></em></div> - </div> - </div> -</div> - -<% - local fs = require "nixio.fs" - local has_ipv6 = fs.access("/proc/net/ipv6_route") - - if has_ipv6 then --%> - <div class="cbi-section" style="display:none"> - <h3><%:Active DHCPv6 Leases%></h3> - <div class="table" id="lease6_status_table"> - <div class="tr table-titles"> - <div class="th"><%:Host%></div> - <div class="th"><%:IPv6-Address%></div> - <div class="th"><%:DUID%></div> - <div class="th"><%:Leasetime remaining%></div> - </div> - <div class="tr placeholder"> - <div class="td"><em><%:Collecting data...%></em></div> - </div> - </div> - </div> -<% end -%> diff --git a/modules/luci-base/luasrc/view/wifi_assoclist.htm b/modules/luci-base/luasrc/view/wifi_assoclist.htm deleted file mode 100644 index f6f66fbbc6..0000000000 --- a/modules/luci-base/luasrc/view/wifi_assoclist.htm +++ /dev/null @@ -1,120 +0,0 @@ -<% - local supports_deauth = {} - - local _, v - for _, v in ipairs(luci.util.ubus()) do - local iface = v:match("^hostapd%.(.+)$") - if iface then - local funcs = luci.util.ubus(v) - if type(funcs) == "table" and funcs.del_client then - supports_deauth[iface] = true - end - end - end -%> - -<script type="text/javascript">//<![CDATA[ - var supports_deauth = <%= luci.http.write_json(supports_deauth) %>; - - function wifirate(bss, rx) { - var p = rx ? 'rx_' : 'tx_', - s = '%.1f <%:Mbit/s%>, %d<%:MHz%>' - .format(bss[p+'rate'] / 1000, bss[p+'mhz']), - ht = bss[p+'ht'], vht = bss[p+'vht'], - mhz = bss[p+'mhz'], nss = bss[p+'nss'], - mcs = bss[p+'mcs'], sgi = bss[p+'short_gi']; - - if (ht || vht) { - if (vht) s += ', VHT-MCS %d'.format(mcs); - if (nss) s += ', VHT-NSS %d'.format(nss); - if (ht) s += ', MCS %s'.format(mcs); - if (sgi) s += ', <%:Short GI%>'; - } - - return s; - } - - function handleDeauth(ev) { - (new XHR()).post('<%=url('admin/wireless_deauth')%>', { - token: '<%=token%>', - iface: ev.target.getAttribute('data-iface'), - bssid: ev.target.getAttribute('data-bssid') - }, function() { - ev.target.disabled = true; - }); - } - - XHR.poll(-1, '<%=url('admin/wireless_assoclist')%>', null, - function(x, st) - { - var tb = document.getElementById('wifi_assoclist_table'); - if (st && tb) - { - var rows = []; - - st.forEach(function(bss) { - var icon; - var q = (-1 * (bss.noise - bss.signal)) / 5; - if (q < 1) - icon = "<%=resource%>/icons/signal-0.png"; - else if (q < 2) - icon = "<%=resource%>/icons/signal-0-25.png"; - else if (q < 3) - icon = "<%=resource%>/icons/signal-25-50.png"; - else if (q < 4) - icon = "<%=resource%>/icons/signal-50-75.png"; - else - icon = "<%=resource%>/icons/signal-75-100.png"; - - rows.push([ - '<span class="ifacebadge" title="%q"><img src="<%=resource%>/icons/wifi.png" /> <a href="%s">%h</a><small> (%h)</small></span>'.format( - bss.radio, - bss.link, - bss.name, - bss.ifname), - bss.bssid, - bss.host_hint ? '%h (%h)'.format(bss.host_name || '?', bss.host_hint) : (bss.host_name || '?'), - '<span class="ifacebadge" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src="%s" /> %d / %d <%:dBm%></span>'.format( - bss.signal, - bss.noise, - bss.signal - bss.noise, - icon, - bss.signal, - bss.noise), - E('span', {}, [ - E('span', wifirate(bss, true)), - E('br'), - E('span', wifirate(bss, false)) - ]), - supports_deauth[bss.ifname] ? E('input', { - type: 'button', - class: 'cbi-button cbi-button-remove', - value: '<%:Disconnect%>', - 'data-bssid': bss.bssid, - 'data-iface': bss.ifname, - click: handleDeauth - }) : '-' - ]); - }); - - cbi_update_table(tb, rows, '<em><%:No information available%></em>'); - } - } - ); -//]]></script> - -<div class="table" id="wifi_assoclist_table"> - <div class="tr table-titles"> - <div class="th nowrap"><%:Network%></div> - <div class="th hide-xs"><%:MAC-Address%></div> - <div class="th nowrap"><%:Host%></div> - <div class="th nowrap"><%:Signal%> / <%:Noise%></div> - <div class="th nowrap"><%:RX Rate%> / <%:TX Rate%></div> - <% if next(supports_deauth) then %> - <div class="th right"><%:Disconnect%></div> - <% end %> - </div> - <div class="tr placeholder"> - <div class="td"><em><%:Collecting data...%></em></div> - </div> -</div> |