2015-01-16 22:38:38 +00:00
|
|
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
2015-10-20 20:17:23 +00:00
|
|
|
-- Copyright 2011-2015 Jo-Philipp Wich <jow@openwrt.org>
|
2015-01-16 22:38:38 +00:00
|
|
|
-- Licensed to the public under the Apache License 2.0.
|
2010-10-30 00:46:41 +00:00
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
module("luci.controller.admin.network", package.seeall)
|
2008-05-22 14:04:03 +00:00
|
|
|
|
|
|
|
function index()
|
2008-08-26 23:00:44 +00:00
|
|
|
local uci = require("luci.model.uci").cursor()
|
2010-10-25 22:26:08 +00:00
|
|
|
local page
|
|
|
|
|
|
|
|
page = node("admin", "network")
|
2011-10-26 00:48:33 +00:00
|
|
|
page.target = firstchild()
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Network")
|
2008-05-22 14:04:03 +00:00
|
|
|
page.order = 50
|
2008-10-09 20:28:07 +00:00
|
|
|
page.index = true
|
2008-09-06 18:21:58 +00:00
|
|
|
|
2011-11-07 10:44:20 +00:00
|
|
|
-- if page.inreq then
|
2011-11-07 10:38:41 +00:00
|
|
|
local has_switch = false
|
2009-05-13 23:46:56 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
uci:foreach("network", "switch",
|
|
|
|
function(s)
|
|
|
|
has_switch = true
|
|
|
|
return false
|
|
|
|
end)
|
|
|
|
|
|
|
|
if has_switch then
|
|
|
|
page = node("admin", "network", "vlan")
|
|
|
|
page.target = cbi("admin_network/vlan")
|
|
|
|
page.title = _("Switch")
|
|
|
|
page.order = 20
|
2012-09-11 14:18:28 +00:00
|
|
|
|
|
|
|
page = entry({"admin", "network", "switch_status"}, call("switch_status"), nil)
|
|
|
|
page.leaf = true
|
2011-11-07 10:38:41 +00:00
|
|
|
end
|
2009-05-13 23:46:56 +00:00
|
|
|
|
2010-10-19 04:08:15 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
local has_wifi = false
|
2012-06-26 21:49:27 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
uci:foreach("wireless", "wifi-device",
|
|
|
|
function(s)
|
|
|
|
has_wifi = true
|
|
|
|
return false
|
|
|
|
end)
|
2012-06-26 21:49:27 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
if has_wifi then
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "wireless_join"}, post("wifi_join"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "wireless_add"}, post("wifi_add"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "wireless_delete"}, post("wifi_delete"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
|
|
|
page = entry({"admin", "network", "wireless_status"}, call("wifi_status"), nil)
|
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "wireless_reconnect"}, post("wifi_reconnect"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "wireless_shutdown"}, post("wifi_shutdown"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2016-06-09 08:55:20 +00:00
|
|
|
page = entry({"admin", "network", "wireless"}, arcombine(template("admin_network/wifi_overview"), cbi("admin_network/wifi")), _("Wireless"), 15)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
|
|
|
page.subindex = true
|
|
|
|
|
|
|
|
if page.inreq then
|
|
|
|
local wdev
|
|
|
|
local net = require "luci.model.network".init(uci)
|
|
|
|
for _, wdev in ipairs(net:get_wifidevs()) do
|
|
|
|
local wnet
|
|
|
|
for _, wnet in ipairs(wdev:get_wifinets()) do
|
|
|
|
entry(
|
|
|
|
{"admin", "network", "wireless", wnet:id()},
|
|
|
|
alias("admin", "network", "wireless"),
|
|
|
|
wdev:name() .. ": " .. wnet:shortname()
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-04-06 10:10:16 +00:00
|
|
|
page = entry({"admin", "network", "iface_add"}, form("admin_network/iface_add"), nil)
|
2009-12-21 02:50:30 +00:00
|
|
|
page.leaf = true
|
2009-09-26 11:10:01 +00:00
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "iface_delete"}, post("iface_delete"), nil)
|
2009-12-25 00:41:55 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = entry({"admin", "network", "iface_status"}, call("iface_status"), nil)
|
2011-09-25 23:29:21 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "iface_reconnect"}, post("iface_reconnect"), nil)
|
2011-09-25 23:29:21 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "iface_shutdown"}, post("iface_shutdown"), nil)
|
2009-12-21 02:50:30 +00:00
|
|
|
page.leaf = true
|
2011-01-20 23:25:40 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), _("Interfaces"), 10)
|
|
|
|
page.leaf = true
|
|
|
|
page.subindex = true
|
2009-10-29 02:23:58 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
if page.inreq then
|
|
|
|
uci:foreach("network", "interface",
|
|
|
|
function (section)
|
|
|
|
local ifc = section[".name"]
|
|
|
|
if ifc ~= "loopback" then
|
|
|
|
entry({"admin", "network", "network", ifc},
|
|
|
|
true, ifc:upper())
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
2009-05-13 23:46:56 +00:00
|
|
|
|
2010-11-15 22:04:56 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
if nixio.fs.access("/etc/config/dhcp") then
|
|
|
|
page = node("admin", "network", "dhcp")
|
|
|
|
page.target = cbi("admin_network/dhcp")
|
|
|
|
page.title = _("DHCP and DNS")
|
|
|
|
page.order = 30
|
2010-10-25 22:26:08 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = entry({"admin", "network", "dhcplease_status"}, call("lease_status"), nil)
|
|
|
|
page.leaf = true
|
2009-10-10 15:59:46 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = node("admin", "network", "hosts")
|
|
|
|
page.target = cbi("admin_network/hosts")
|
|
|
|
page.title = _("Hostnames")
|
|
|
|
page.order = 40
|
|
|
|
end
|
2010-11-15 22:04:56 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = node("admin", "network", "routes")
|
|
|
|
page.target = cbi("admin_network/routes")
|
|
|
|
page.title = _("Static Routes")
|
|
|
|
page.order = 50
|
2010-11-15 22:04:56 +00:00
|
|
|
|
2011-11-07 10:38:41 +00:00
|
|
|
page = node("admin", "network", "diagnostics")
|
|
|
|
page.target = template("admin_network/diagnostics")
|
|
|
|
page.title = _("Diagnostics")
|
|
|
|
page.order = 60
|
2008-09-06 18:21:58 +00:00
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "diag_ping"}, post("diag_ping"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
2010-11-07 23:31:19 +00:00
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "diag_nslookup"}, post("diag_nslookup"), nil)
|
2010-11-07 23:31:19 +00:00
|
|
|
page.leaf = true
|
2008-09-06 18:21:58 +00:00
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "diag_traceroute"}, post("diag_traceroute"), nil)
|
2011-11-07 10:38:41 +00:00
|
|
|
page.leaf = true
|
2012-11-11 12:20:56 +00:00
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "diag_ping6"}, post("diag_ping6"), nil)
|
2012-11-11 12:20:56 +00:00
|
|
|
page.leaf = true
|
|
|
|
|
2015-10-20 20:17:23 +00:00
|
|
|
page = entry({"admin", "network", "diag_traceroute6"}, post("diag_traceroute6"), nil)
|
2012-11-11 12:20:56 +00:00
|
|
|
page.leaf = true
|
2011-11-07 10:44:20 +00:00
|
|
|
-- end
|
2009-05-13 23:46:56 +00:00
|
|
|
end
|
2009-09-26 11:10:01 +00:00
|
|
|
|
|
|
|
function wifi_join()
|
2015-10-20 20:17:23 +00:00
|
|
|
local tpl = require "luci.template"
|
|
|
|
local http = require "luci.http"
|
|
|
|
local dev = http.formvalue("device")
|
|
|
|
local ssid = http.formvalue("join")
|
2009-09-26 11:10:01 +00:00
|
|
|
|
|
|
|
if dev and ssid then
|
2015-10-20 20:17:23 +00:00
|
|
|
local cancel = (http.formvalue("cancel") or http.formvalue("cbi.cancel"))
|
|
|
|
if not cancel then
|
2009-11-08 02:38:22 +00:00
|
|
|
local cbi = require "luci.cbi"
|
|
|
|
local map = luci.cbi.load("admin_network/wifi_add")[1]
|
|
|
|
|
|
|
|
if map:parse() ~= cbi.FORM_DONE then
|
|
|
|
tpl.render("header")
|
|
|
|
map:render()
|
|
|
|
tpl.render("footer")
|
|
|
|
end
|
2015-10-20 20:17:23 +00:00
|
|
|
|
|
|
|
return
|
2009-09-26 11:10:01 +00:00
|
|
|
end
|
|
|
|
end
|
2015-10-20 20:17:23 +00:00
|
|
|
|
|
|
|
tpl.render("admin_network/wifi_join")
|
2009-09-26 11:10:01 +00:00
|
|
|
end
|
2009-10-29 02:23:58 +00:00
|
|
|
|
2009-12-25 00:41:55 +00:00
|
|
|
function wifi_add()
|
2010-10-19 04:08:15 +00:00
|
|
|
local dev = luci.http.formvalue("device")
|
2010-10-30 00:46:41 +00:00
|
|
|
local ntm = require "luci.model.network".init()
|
2009-12-25 00:41:55 +00:00
|
|
|
|
2010-10-30 00:46:41 +00:00
|
|
|
dev = dev and ntm:get_wifidev(dev)
|
2009-12-25 00:41:55 +00:00
|
|
|
|
2010-10-30 00:46:41 +00:00
|
|
|
if dev then
|
|
|
|
local net = dev:add_wifinet({
|
2009-12-25 00:41:55 +00:00
|
|
|
mode = "ap",
|
|
|
|
ssid = "OpenWrt",
|
|
|
|
encryption = "none"
|
|
|
|
})
|
|
|
|
|
2010-10-30 00:46:41 +00:00
|
|
|
ntm:save("wireless")
|
|
|
|
luci.http.redirect(net:adminlink())
|
2009-12-25 00:41:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-29 02:23:58 +00:00
|
|
|
function wifi_delete(network)
|
2010-10-30 00:46:41 +00:00
|
|
|
local ntm = require "luci.model.network".init()
|
2011-10-26 22:52:18 +00:00
|
|
|
local wnet = ntm:get_wifinet(network)
|
|
|
|
if wnet then
|
|
|
|
local dev = wnet:get_device()
|
2012-06-26 21:49:27 +00:00
|
|
|
local nets = wnet:get_networks()
|
2011-10-26 22:29:57 +00:00
|
|
|
if dev then
|
|
|
|
ntm:del_wifinet(network)
|
|
|
|
ntm:commit("wireless")
|
2012-06-26 21:49:27 +00:00
|
|
|
local _, net
|
|
|
|
for _, net in ipairs(nets) do
|
|
|
|
if net:is_empty() then
|
|
|
|
ntm:del_network(net:name())
|
|
|
|
ntm:commit("network")
|
|
|
|
end
|
2011-10-26 22:52:18 +00:00
|
|
|
end
|
2013-12-08 16:46:55 +00:00
|
|
|
luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>/dev/null")
|
2011-10-26 22:29:57 +00:00
|
|
|
end
|
|
|
|
end
|
2009-10-29 02:23:58 +00:00
|
|
|
|
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
|
|
|
|
end
|
2010-10-19 04:08:15 +00:00
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function iface_status(ifaces)
|
2010-12-01 21:16:49 +00:00
|
|
|
local netm = require "luci.model.network".init()
|
2010-10-30 00:46:41 +00:00
|
|
|
local rv = { }
|
|
|
|
|
|
|
|
local iface
|
2012-11-21 19:29:47 +00:00
|
|
|
for iface in ifaces:gmatch("[%w%.%-_]+") do
|
2010-12-01 21:16:49 +00:00
|
|
|
local net = netm:get_network(iface)
|
2011-09-24 00:58:58 +00:00
|
|
|
local device = net and net:get_interface()
|
|
|
|
if device then
|
2011-11-02 18:59:18 +00:00
|
|
|
local data = {
|
2011-09-24 00:58:58 +00:00
|
|
|
id = iface,
|
|
|
|
proto = net:proto(),
|
|
|
|
uptime = net:uptime(),
|
|
|
|
gwaddr = net:gwaddr(),
|
2015-11-17 16:36:00 +00:00
|
|
|
ipaddrs = net:ipaddrs(),
|
|
|
|
ip6addrs = net:ip6addrs(),
|
2011-09-24 00:58:58 +00:00
|
|
|
dnsaddrs = net:dnsaddrs(),
|
mod-admin-full: Add IPv6 Prefix Delegation information to Status Pages
The Overview page and Network>Interfaces page currently do not give much information about IPv6, particularly with Prefix Delegated setups. In these setups, ISP will delegate a prefix to the router. Currently LuCI doesn't display this Prefix Delegation from the ISP anywhere. A number of changes was added to this commit:
1) self:_ubus("ipv6-prefix") was extracted and put into protocol.ip6prefix.
2) Network>Interfaces page, if a .ip6prefix is present, show it under Status. (IPv6-PD).
3) On the Overview page, "Type" and "Prefix Delegated" has been added to the IPv6 Network Overview Status:
- Type will display the .proto, similar to the IPv4 case. If a .ip6prefix is present, it'll display a "-pd" at the end of the Type: i.e. dhcpv6-pd vs. dhcpv6.
- If no .ip6prefix is present, it'll do what it does currently, and just show Address, or :: if no address is present.
- If .ip6prefix is present, it'll show the "Prefix Delegated", it'll also hide "Address" if no address is present, else it'll show ifc6.ip6addr as well.
Signed-off-by: Cody R. Brown <dev@codybrown.ca>
2017-01-28 09:38:06 +00:00
|
|
|
ip6prefix = net:ip6prefix(),
|
2011-09-24 00:58:58 +00:00
|
|
|
name = device:shortname(),
|
|
|
|
type = device:type(),
|
|
|
|
ifname = device:name(),
|
|
|
|
macaddr = device:mac(),
|
|
|
|
is_up = device:is_up(),
|
|
|
|
rx_bytes = device:rx_bytes(),
|
|
|
|
tx_bytes = device:tx_bytes(),
|
|
|
|
rx_packets = device:rx_packets(),
|
|
|
|
tx_packets = device:tx_packets(),
|
|
|
|
|
|
|
|
subdevices = { }
|
2011-03-13 14:00:45 +00:00
|
|
|
}
|
2011-09-24 00:58:58 +00:00
|
|
|
|
2011-09-25 22:58:17 +00:00
|
|
|
for _, device in ipairs(net:get_interfaces() or {}) do
|
2011-09-24 00:58:58 +00:00
|
|
|
data.subdevices[#data.subdevices+1] = {
|
|
|
|
name = device:shortname(),
|
|
|
|
type = device:type(),
|
|
|
|
ifname = device:name(),
|
|
|
|
macaddr = device:mac(),
|
|
|
|
is_up = device:is_up(),
|
|
|
|
rx_bytes = device:rx_bytes(),
|
|
|
|
tx_bytes = device:tx_bytes(),
|
|
|
|
rx_packets = device:rx_packets(),
|
|
|
|
tx_packets = device:tx_packets(),
|
|
|
|
}
|
2010-12-01 21:16:49 +00:00
|
|
|
end
|
2011-09-24 00:58:58 +00:00
|
|
|
|
|
|
|
rv[#rv+1] = data
|
2011-10-18 13:20:43 +00:00
|
|
|
else
|
|
|
|
rv[#rv+1] = {
|
|
|
|
id = iface,
|
|
|
|
name = iface,
|
|
|
|
type = "ethernet"
|
|
|
|
}
|
2010-10-30 00:46:41 +00:00
|
|
|
end
|
2010-10-25 22:26:08 +00:00
|
|
|
end
|
|
|
|
|
2010-10-30 00:46:41 +00:00
|
|
|
if #rv > 0 then
|
2010-10-25 22:26:08 +00:00
|
|
|
luci.http.prepare_content("application/json")
|
2010-11-07 19:28:07 +00:00
|
|
|
luci.http.write_json(rv)
|
2010-10-25 22:26:08 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such device")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function iface_reconnect(iface)
|
2010-11-15 22:04:56 +00:00
|
|
|
local netmd = require "luci.model.network".init()
|
|
|
|
local net = netmd:get_network(iface)
|
|
|
|
if net then
|
2018-04-05 07:32:22 +00:00
|
|
|
luci.sys.call("env -i /sbin/ifup %s >/dev/null 2>/dev/null"
|
|
|
|
% luci.util.shellquote(iface))
|
2010-11-15 22:04:56 +00:00
|
|
|
luci.http.status(200, "Reconnected")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such interface")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function iface_shutdown(iface)
|
2010-11-15 22:04:56 +00:00
|
|
|
local netmd = require "luci.model.network".init()
|
|
|
|
local net = netmd:get_network(iface)
|
|
|
|
if net then
|
2018-04-05 07:32:22 +00:00
|
|
|
luci.sys.call("env -i /sbin/ifdown %s >/dev/null 2>/dev/null"
|
|
|
|
% luci.util.shellquote(iface))
|
2010-11-15 22:04:56 +00:00
|
|
|
luci.http.status(200, "Shutdown")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such interface")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function iface_delete(iface)
|
2010-11-15 22:04:56 +00:00
|
|
|
local netmd = require "luci.model.network".init()
|
|
|
|
local net = netmd:del_network(iface)
|
|
|
|
if net then
|
2018-04-05 07:32:22 +00:00
|
|
|
luci.sys.call("env -i /sbin/ifdown %s >/dev/null 2>/dev/null"
|
|
|
|
% luci.util.shellquote(iface))
|
2010-11-15 22:04:56 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/network/network"))
|
|
|
|
netmd:commit("network")
|
|
|
|
netmd:commit("wireless")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such interface")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function wifi_status(devs)
|
2011-03-13 17:25:54 +00:00
|
|
|
local s = require "luci.tools.status"
|
2010-10-30 00:46:41 +00:00
|
|
|
local rv = { }
|
|
|
|
|
|
|
|
local dev
|
2012-11-21 19:29:47 +00:00
|
|
|
for dev in devs:gmatch("[%w%.%-]+") do
|
2011-03-13 17:25:54 +00:00
|
|
|
rv[#rv+1] = s.wifi_network(dev)
|
2010-10-30 00:46:41 +00:00
|
|
|
end
|
2010-10-19 04:08:15 +00:00
|
|
|
|
2010-10-30 00:46:41 +00:00
|
|
|
if #rv > 0 then
|
2010-10-19 04:08:15 +00:00
|
|
|
luci.http.prepare_content("application/json")
|
2010-11-07 19:28:07 +00:00
|
|
|
luci.http.write_json(rv)
|
2010-10-19 04:08:15 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such device")
|
|
|
|
end
|
2010-11-07 23:31:19 +00:00
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
local function wifi_reconnect_shutdown(shutdown, wnet)
|
2011-09-22 02:43:38 +00:00
|
|
|
local netmd = require "luci.model.network".init()
|
|
|
|
local net = netmd:get_wifinet(wnet)
|
2011-09-22 02:49:03 +00:00
|
|
|
local dev = net:get_device()
|
|
|
|
if dev and net then
|
|
|
|
dev:set("disabled", nil)
|
2012-11-21 19:29:47 +00:00
|
|
|
net:set("disabled", shutdown and 1 or nil)
|
2011-09-22 02:43:38 +00:00
|
|
|
netmd:commit("wireless")
|
|
|
|
|
2013-12-08 16:46:55 +00:00
|
|
|
luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>/dev/null")
|
2012-11-21 19:29:47 +00:00
|
|
|
luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
|
2011-09-22 02:43:38 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(404, "No such radio")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function wifi_reconnect(wnet)
|
|
|
|
wifi_reconnect_shutdown(false, wnet)
|
|
|
|
end
|
|
|
|
|
|
|
|
function wifi_shutdown(wnet)
|
|
|
|
wifi_reconnect_shutdown(true, wnet)
|
|
|
|
end
|
|
|
|
|
2010-11-07 23:31:19 +00:00
|
|
|
function lease_status()
|
2011-03-13 14:00:45 +00:00
|
|
|
local s = require "luci.tools.status"
|
2010-11-07 23:31:19 +00:00
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
2012-08-17 15:06:46 +00:00
|
|
|
luci.http.write('[')
|
2011-03-13 14:00:45 +00:00
|
|
|
luci.http.write_json(s.dhcp_leases())
|
2012-08-17 15:06:46 +00:00
|
|
|
luci.http.write(',')
|
|
|
|
luci.http.write_json(s.dhcp6_leases())
|
|
|
|
luci.http.write(']')
|
2010-11-07 23:31:19 +00:00
|
|
|
end
|
2010-11-24 20:09:37 +00:00
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function switch_status(switches)
|
2012-09-11 14:18:28 +00:00
|
|
|
local s = require "luci.tools.status"
|
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
2012-11-21 19:29:47 +00:00
|
|
|
luci.http.write_json(s.switch_status(switches))
|
2012-09-11 14:18:28 +00:00
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_command(cmd, addr)
|
2010-11-24 20:09:37 +00:00
|
|
|
if addr and addr:match("^[a-zA-Z0-9%-%.:_]+$") then
|
|
|
|
luci.http.prepare_content("text/plain")
|
|
|
|
|
2018-04-05 07:32:22 +00:00
|
|
|
local util = io.popen(cmd % luci.util.shellquote(addr))
|
2010-11-24 20:09:37 +00:00
|
|
|
if util then
|
|
|
|
while true do
|
|
|
|
local ln = util:read("*l")
|
|
|
|
if not ln then break end
|
|
|
|
luci.http.write(ln)
|
|
|
|
luci.http.write("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
util:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.status(500, "Bad address")
|
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_ping(addr)
|
2018-04-05 07:32:22 +00:00
|
|
|
diag_command("ping -c 5 -W 1 %s 2>&1", addr)
|
2010-11-24 20:09:37 +00:00
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_traceroute(addr)
|
2018-04-05 07:32:22 +00:00
|
|
|
diag_command("traceroute -q 1 -w 1 -n %s 2>&1", addr)
|
2010-11-24 20:09:37 +00:00
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_nslookup(addr)
|
2018-04-05 07:32:22 +00:00
|
|
|
diag_command("nslookup %s 2>&1", addr)
|
2010-11-24 20:09:37 +00:00
|
|
|
end
|
2012-11-11 12:20:56 +00:00
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_ping6(addr)
|
2018-04-05 07:32:22 +00:00
|
|
|
diag_command("ping6 -c 5 %s 2>&1", addr)
|
2012-11-11 12:20:56 +00:00
|
|
|
end
|
|
|
|
|
2012-11-21 19:29:47 +00:00
|
|
|
function diag_traceroute6(addr)
|
2018-04-05 07:32:22 +00:00
|
|
|
diag_command("traceroute6 -q 1 -w 2 -n %s 2>&1", addr)
|
2012-11-11 12:20:56 +00:00
|
|
|
end
|