2018-03-28 08:57:02 +00:00
|
|
|
local tools = require "luci.tools.status"
|
|
|
|
local sys = require "luci.sys"
|
|
|
|
local json = require("luci.json")
|
2018-05-09 14:08:52 +00:00
|
|
|
local ucic = luci.model.uci.cursor()
|
2018-03-23 19:23:27 +00:00
|
|
|
module("luci.controller.openmptcprouter", package.seeall)
|
|
|
|
|
|
|
|
function index()
|
|
|
|
-- entry({"admin", "openmptcprouter"}, firstchild(), _("OpenMPTCProuter"), 19).index = true
|
|
|
|
-- entry({"admin", "openmptcprouter", "wizard"}, template("openmptcprouter/wizard"), _("Wizard"), 1).leaf = true
|
|
|
|
-- entry({"admin", "openmptcprouter", "wizard_add"}, post("wizard_add")).leaf = true
|
2018-03-28 08:59:15 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter"}, alias("admin", "system", "openmptcprouter", "wizard"), _("OpenMPTCProuter"), 1)
|
2018-03-28 08:57:02 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "wizard"}, template("openmptcprouter/wizard"), _("Settings Wizard"), 1)
|
2018-03-23 19:23:27 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "wizard_add"}, post("wizard_add"))
|
2018-03-28 08:57:02 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "status"}, template("openmptcprouter/wanstatus"), _("Status"), 2).leaf = true
|
|
|
|
entry({"admin", "system", "openmptcprouter", "interfaces_status"}, call("interfaces_status")).leaf = true
|
2018-04-12 13:18:56 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "settings"}, template("openmptcprouter/settings"), _("Advanced Settings"), 3).leaf = true
|
|
|
|
entry({"admin", "system", "openmptcprouter", "settings_add"}, post("settings_add")).leaf = true
|
2018-03-23 19:23:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function wizard_add()
|
2018-04-20 12:56:19 +00:00
|
|
|
local add_interface = luci.http.formvalue("add_interface") or ""
|
|
|
|
local gostatus = true
|
|
|
|
if add_interface ~= "" then
|
|
|
|
local i = 1
|
|
|
|
ucic:foreach("network", "interface", function(s)
|
|
|
|
local sectionname = s[".name"]
|
|
|
|
if sectionname:match("^wan(%d+)$") then
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
local defif = ucic:get("network","wan1","ifname") or "eth0"
|
|
|
|
ucic:set("network","wan" .. i,"interface")
|
|
|
|
ucic:set("network","wan" .. i,"ifname",defif)
|
|
|
|
ucic:set("network","wan" .. i,"proto","static")
|
|
|
|
ucic:set("network","wan" .. i,"type","macvlan")
|
|
|
|
ucic:set("network","wan" .. i,"ip4table","wan")
|
|
|
|
ucic:set("network","wan" .. i,"multipath","on")
|
|
|
|
ucic:set("network","wan" .. i,"defaultroute","0")
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
|
|
|
-- Dirty way to add new interface to firewall...
|
|
|
|
luci.sys.call("uci -q add_list firewall.@zone[1].network=wan" .. i)
|
|
|
|
|
|
|
|
luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null")
|
|
|
|
gostatus = false
|
|
|
|
end
|
|
|
|
|
|
|
|
local delete_intf = luci.http.formvaluetable("delete")
|
|
|
|
if delete_intf ~= "" then
|
|
|
|
for intf, _ in pairs(delete_intf) do
|
|
|
|
ucic:delete("network",intf)
|
|
|
|
ucic:delete("network",intf .. "_dev")
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
|
|
|
end
|
|
|
|
gostatus = false
|
|
|
|
end
|
|
|
|
|
2018-03-23 19:23:27 +00:00
|
|
|
local server_ip = luci.http.formvalue("server_ip")
|
2018-04-12 13:18:56 +00:00
|
|
|
|
|
|
|
-- Set ShadowSocks settings
|
2018-03-23 19:23:27 +00:00
|
|
|
local shadowsocks_key = luci.http.formvalue("shadowsocks_key")
|
|
|
|
if shadowsocks_key ~= "" then
|
|
|
|
ucic:set("shadowsocks-libev","sss0","server",server_ip)
|
|
|
|
ucic:set("shadowsocks-libev","sss0","key",shadowsocks_key)
|
|
|
|
ucic:set("shadowsocks-libev","sss0","method","aes-256-cfb")
|
|
|
|
ucic:set("shadowsocks-libev","sss0","server_port","65101")
|
|
|
|
ucic:set("shadowsocks-libev","sss0","disabled",0)
|
|
|
|
ucic:save("shadowsocks-libev")
|
|
|
|
ucic:commit("shadowsocks-libev")
|
|
|
|
end
|
2018-04-12 13:18:56 +00:00
|
|
|
|
|
|
|
-- Set Glorytun TCP settings
|
|
|
|
local glorytun_key = luci.http.formvalue("glorytun_key")
|
2018-03-23 19:23:27 +00:00
|
|
|
if glorytun_key ~= "" then
|
|
|
|
ucic:set("glorytun","vpn","host",server_ip)
|
|
|
|
ucic:set("glorytun","vpn","port","65001")
|
|
|
|
ucic:set("glorytun","vpn","key",glorytun_key)
|
|
|
|
ucic:set("glorytun","vpn","enable",1)
|
|
|
|
ucic:set("glorytun","vpn","mptcp",1)
|
|
|
|
ucic:set("glorytun","vpn","chacha20",1)
|
|
|
|
ucic:set("glorytun","vpn","proto","tcp")
|
|
|
|
ucic:save("glorytun")
|
|
|
|
ucic:commit("glorytun")
|
|
|
|
end
|
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
-- Set interfaces settings
|
2018-03-23 19:23:27 +00:00
|
|
|
local interfaces = luci.http.formvaluetable("intf")
|
|
|
|
for intf, _ in pairs(interfaces) do
|
|
|
|
local ipaddr = luci.http.formvalue("cbid.network.%s.ipaddr" % intf)
|
|
|
|
local netmask = luci.http.formvalue("cbid.network.%s.netmask" % intf)
|
|
|
|
local gateway = luci.http.formvalue("cbid.network.%s.gateway" % intf)
|
|
|
|
ucic:set("network",intf,"ipaddr",ipaddr)
|
|
|
|
ucic:set("network",intf,"netmask",netmask)
|
|
|
|
ucic:set("network",intf,"gateway",gateway)
|
|
|
|
end
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
|
|
|
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
|
|
|
|
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
|
2018-04-20 12:56:19 +00:00
|
|
|
if gostatus then
|
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/status"))
|
|
|
|
else
|
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/wizard"))
|
|
|
|
end
|
2018-03-26 13:06:16 +00:00
|
|
|
return
|
2018-03-28 08:57:02 +00:00
|
|
|
end
|
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
function settings_add()
|
|
|
|
-- Set tcp_keepalive_time
|
|
|
|
local tcp_keepalive_time = luci.http.formvalue("tcp_keepalive_time")
|
|
|
|
luci.sys.exec("sysctl -w net.ipv4.tcp_keepalive_time=%s" % tcp_keepalive_time)
|
|
|
|
luci.sys.exec("sed -i 's:^net.ipv4.tcp_keepalive_time = [0-9]*:net.ipv4.tcp_keepalive_time=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % tcp_keepalive_time)
|
|
|
|
|
|
|
|
-- Disable IPv6
|
|
|
|
local disable_ipv6 = luci.http.formvalue("disable_ipv6") or 0
|
|
|
|
luci.sys.exec("sysctl -w net.ipv6.conf.all.disable_ipv6=%s" % disable_ipv6)
|
|
|
|
luci.sys.exec("sed -i 's:^net.ipv6.conf.all.disable_ipv6 = [0-9]*:net.ipv6.conf.all.disable_ipv6=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % disable_ipv6)
|
|
|
|
ucic:set("firewall",ucic:get_first("firewall","defaults"),"disable_ipv6",disable_ipv6)
|
|
|
|
ucic:save("firewall")
|
|
|
|
ucic:commit("firewall")
|
2018-04-25 10:27:07 +00:00
|
|
|
if disable_ipv6 == 1 then
|
|
|
|
ucic:set("shadowsocks-libev","hi","local_address","0.0.0.0")
|
|
|
|
else
|
|
|
|
ucic:set("shadowsocks-libev","hi","local_address","::")
|
|
|
|
end
|
|
|
|
ucic:save("shadowsocks-libev")
|
|
|
|
ucic:commit("shadowsocks-libev")
|
2018-04-12 13:18:56 +00:00
|
|
|
|
2018-04-17 07:27:15 +00:00
|
|
|
-- Set CPU scaling minimum frequency
|
|
|
|
local scaling_min_freq = luci.http.formvalue("scaling_min_freq") or ""
|
|
|
|
if scaling_min_freq ~= "" then
|
|
|
|
ucic:set("openmptcprouter","settings","scaling_min_freq",scaling_min_freq)
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set CPU scaling maximum frequency
|
|
|
|
local scaling_max_freq = luci.http.formvalue("scaling_max_freq") or ""
|
|
|
|
if scaling_max_freq ~= "" then
|
|
|
|
ucic:set("openmptcprouter","settings","scaling_max_freq",scaling_max_freq)
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set CPU governor
|
|
|
|
local scaling_governor = luci.http.formvalue("scaling_governor") or ""
|
|
|
|
if scaling_governor ~= "" then
|
|
|
|
ucic:set("openmptcprouter","settings","scaling_governor",scaling_governor)
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
end
|
2018-04-17 12:48:55 +00:00
|
|
|
|
|
|
|
luci.sys.call("/etc/init.d/openmptcprouter restart >/dev/null 2>/dev/null")
|
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
-- Done, redirect
|
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/settings"))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-03 13:06:58 +00:00
|
|
|
function get_ip(interface)
|
|
|
|
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
|
|
|
|
local ip
|
|
|
|
if dump and dump['ipv4-address'] then
|
|
|
|
local _, ipv4address
|
|
|
|
for _, ipv4address in ipairs(dump['ipv4-address']) do
|
|
|
|
ip = dump['ipv4-address'][_].address
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ip
|
|
|
|
end
|
|
|
|
|
2018-05-18 07:40:50 +00:00
|
|
|
-- This function come from OverTheBox by OVH with some changes
|
|
|
|
-- Copyright 2015 OVH <OverTheBox@ovh.net>
|
|
|
|
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
|
|
|
|
-- Sebastien Duponcheel <sebastien.duponcheel@ovh.net>
|
|
|
|
-- Under GPL3+
|
2018-03-28 08:57:02 +00:00
|
|
|
function interfaces_status()
|
|
|
|
local ut = require "luci.util"
|
|
|
|
local ntm = require "luci.model.network".init()
|
|
|
|
local uci = require "luci.model.uci".cursor()
|
|
|
|
|
|
|
|
local mArray = {}
|
|
|
|
|
|
|
|
-- OpenMPTCProuter info
|
|
|
|
mArray.openmptcprouter = {}
|
|
|
|
mArray.openmptcprouter["version"] = ut.trim(sys.exec("cat /etc/os-release | grep VERSION= | sed -e 's:VERSION=::'"))
|
|
|
|
-- Check that requester is in same network
|
|
|
|
mArray.openmptcprouter["service_addr"] = uci:get("shadowsocks", "proxy", "server") or "0.0.0.0"
|
|
|
|
mArray.openmptcprouter["local_addr"] = uci:get("network", "lan", "ipaddr")
|
|
|
|
|
2018-05-09 09:15:43 +00:00
|
|
|
-- shadowsocksaddr
|
2018-05-14 19:10:01 +00:00
|
|
|
mArray.openmptcprouter["ss_addr"] = sys.exec("curl -s -4 --socks5 127.0.0.1:1111 -m 5 http://ip.openmptcprouter.com")
|
2018-03-28 08:57:02 +00:00
|
|
|
-- wanaddr
|
|
|
|
mArray.openmptcprouter["wan_addr"] = sys.exec("wget -4 -qO- -T 1 http://ip.openmptcprouter.com")
|
2018-05-13 19:24:00 +00:00
|
|
|
|
|
|
|
-- dns
|
|
|
|
mArray.openmptcprouter["dns"] = false
|
2018-05-18 07:40:50 +00:00
|
|
|
local dns_test = sys.exec("dig openmptcprouter.com | grep 'ANSWER: 0'")
|
2018-05-13 19:24:00 +00:00
|
|
|
if dns_test == "" then
|
|
|
|
mArray.openmptcprouter["dns"] = true
|
|
|
|
end
|
2018-03-28 08:57:02 +00:00
|
|
|
|
2018-04-04 16:08:10 +00:00
|
|
|
mArray.openmptcprouter["remote_addr"] = luci.http.getenv("REMOTE_ADDR") or ""
|
|
|
|
mArray.openmptcprouter["remote_from_lease"] = false
|
2018-03-28 08:57:02 +00:00
|
|
|
local leases=tools.dhcp_leases()
|
|
|
|
for _, value in pairs(leases) do
|
|
|
|
if value["ipaddr"] == mArray.openmptcprouter["remote_addr"] then
|
|
|
|
mArray.openmptcprouter["remote_from_lease"] = true
|
|
|
|
mArray.openmptcprouter["remote_hostname"] = value["hostname"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check openmptcprouter service are running
|
|
|
|
mArray.openmptcprouter["tun_service"] = false
|
|
|
|
if string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?glorytun(-udp)?$'"), "%d+") then
|
|
|
|
mArray.openmptcprouter["tun_service"] = true
|
2018-05-03 13:06:58 +00:00
|
|
|
mArray.openmptcprouter["tun_ip"] = get_ip("glorytun")
|
|
|
|
local tunnel_ping_test = ut.trim(sys.exec("ping -W 1 -c 1 10.0.0.1 | grep '100% packet loss'"))
|
|
|
|
if tunnel_ping_test == "" then
|
|
|
|
mArray.openmptcprouter["tun_state"] = 'UP'
|
|
|
|
else
|
|
|
|
mArray.openmptcprouter["tun_state"] = 'DOWN'
|
|
|
|
end
|
|
|
|
|
2018-03-28 08:57:02 +00:00
|
|
|
end
|
2018-05-03 13:06:58 +00:00
|
|
|
|
2018-03-28 08:57:02 +00:00
|
|
|
mArray.openmptcprouter["socks_service"] = false
|
|
|
|
if string.find(sys.exec("/usr/bin/pgrep ss-redir"), "%d+") then
|
|
|
|
mArray.openmptcprouter["socks_service"] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Add DHCP infos by parsing dnsmasq config file
|
|
|
|
mArray.openmptcprouter.dhcpd = {}
|
|
|
|
dnsmasq = ut.trim(sys.exec("cat /var/etc/dnsmasq.conf*"))
|
|
|
|
for itf, range_start, range_end, mask, leasetime in dnsmasq:gmatch("range=[%w,!:-]*set:(%w+),(%d+\.%d+\.%d+\.%d+),(%d+\.%d+\.%d+\.%d+),(%d+\.%d+\.%d+\.%d+),(%w+)") do
|
|
|
|
mArray.openmptcprouter.dhcpd[itf] = {}
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].interface = itf
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].range_start = range_start
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].range_end = range_end
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].netmask = mask
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].leasetime = leasetime
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].router = mArray.openmptcprouter["local_addr"]
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].dns = mArray.openmptcprouter["local_addr"]
|
|
|
|
end
|
|
|
|
for itf, option, value in dnsmasq:gmatch("option=(%w+),([%w:-]+),(%d+\.%d+\.%d+\.%d+)") do
|
|
|
|
if mArray.openmptcprouter.dhcpd[itf] then
|
|
|
|
if option == "option:router" or option == "6" then
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].router = value
|
|
|
|
end
|
|
|
|
if option == "option:dns-server" or option == "" then
|
|
|
|
mArray.openmptcprouter.dhcpd[itf].dns = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Parse mptcp kernel info
|
|
|
|
local mptcp = {}
|
|
|
|
local fullmesh = ut.trim(sys.exec("cat /proc/net/mptcp_fullmesh"))
|
|
|
|
for ind, addressId, backup, ipaddr in fullmesh:gmatch("(%d+), (%d+), (%d+), (%d+\.%d+\.%d+\.%d+)") do
|
|
|
|
mptcp[ipaddr] = {}
|
|
|
|
mptcp[ipaddr].index = ind
|
|
|
|
mptcp[ipaddr].id = addressId
|
|
|
|
mptcp[ipaddr].backup= backup
|
|
|
|
mptcp[ipaddr].ipaddr= ipaddr
|
|
|
|
end
|
|
|
|
|
|
|
|
-- retrieve core temperature
|
|
|
|
--mArray.openmptcprouter["core_temp"] = sys.exec("cat /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp2_input 2>/dev/null"):match("%d+")
|
|
|
|
mArray.openmptcprouter["loadavg"] = sys.exec("cat /proc/loadavg 2>/dev/null"):match("[%d%.]+ [%d%.]+ [%d%.]+")
|
|
|
|
mArray.openmptcprouter["uptime"] = sys.exec("cat /proc/uptime 2>/dev/null"):match("[%d%.]+")
|
|
|
|
|
|
|
|
-- overview status
|
|
|
|
mArray.wans = {}
|
|
|
|
mArray.tunnels = {}
|
|
|
|
|
|
|
|
uci:foreach("network", "interface", function (section)
|
|
|
|
local interface = section[".name"]
|
|
|
|
local net = ntm:get_network(interface)
|
|
|
|
local ipaddr = net:ipaddr()
|
2018-05-03 08:51:04 +00:00
|
|
|
local gateway = section['gateway'] or ""
|
2018-03-28 08:57:02 +00:00
|
|
|
local multipath = section['multipath']
|
|
|
|
|
|
|
|
--if not ipaddr or not gateway then return end
|
|
|
|
-- Don't show if0 in the overview
|
|
|
|
--if interface == "lo" then return end
|
|
|
|
|
2018-04-23 08:20:33 +00:00
|
|
|
local ifname = section['ifname'] or ""
|
2018-05-03 13:06:58 +00:00
|
|
|
--if multipath == "off" and not ifname:match("^tun.*") then return end
|
|
|
|
if multipath == "off" then return end
|
2018-03-28 08:57:02 +00:00
|
|
|
|
|
|
|
local asn
|
|
|
|
|
|
|
|
local connectivity
|
|
|
|
local multipath_state = ut.trim(sys.exec("multipath " .. ifname .. " | grep deactivated"))
|
2018-04-23 08:20:33 +00:00
|
|
|
if multipath_state == "" and ifname ~= "" then
|
2018-05-18 07:40:50 +00:00
|
|
|
connectivity = 'OK'
|
2018-03-28 08:57:02 +00:00
|
|
|
else
|
2018-05-18 07:40:50 +00:00
|
|
|
connectivity = 'ERROR'
|
|
|
|
end
|
|
|
|
|
|
|
|
if ipaddr == "" then
|
2018-03-28 08:57:02 +00:00
|
|
|
connectivity = 'ERROR'
|
|
|
|
end
|
|
|
|
|
2018-05-18 07:40:50 +00:00
|
|
|
-- Detect WAN gateway status
|
|
|
|
local gw_ping = 'UP'
|
2018-05-03 08:51:04 +00:00
|
|
|
if gateway ~= "" then
|
|
|
|
local gw_ping_test = ut.trim(sys.exec("ping -W 1 -c 1 " .. gateway .. " | grep '100% packet loss'"))
|
2018-05-18 07:40:50 +00:00
|
|
|
if gw_ping_test ~= "" then
|
2018-05-03 08:51:04 +00:00
|
|
|
gw_ping = 'DOWN'
|
2018-05-11 12:14:18 +00:00
|
|
|
if connectivity == "OK" then
|
2018-05-18 07:40:50 +00:00
|
|
|
connectivity = 'WARNING'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Detect if WAN get an IPv6
|
|
|
|
local ipv6_discover = 'NONE'
|
|
|
|
if tonumber((sys.exec("sysctl net.ipv6.conf.all.disable_ipv6")):match(" %d+")) == 0 then
|
|
|
|
local ipv6_result = _ipv6_discover(ifname)
|
|
|
|
if type(ipv6_result) == "table" and #ipv6_result > 0 then
|
|
|
|
local ipv6_addr_test
|
|
|
|
for k,v in ipairs(ipv6_result) do
|
|
|
|
if v.RecursiveDnsServer then
|
|
|
|
ipv6_addr_test = sys.exec('ip -6 addr | grep ' .. v.RecursiveDnsServer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if ipv6_addr_test == "" then
|
|
|
|
ipv6_discover = 'DETECTED'
|
|
|
|
if connectivity == "OK" then
|
|
|
|
connectivity = 'WARNING'
|
|
|
|
end
|
2018-05-11 12:14:18 +00:00
|
|
|
end
|
2018-05-03 08:51:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-28 08:57:02 +00:00
|
|
|
local publicIP = "-"
|
|
|
|
|
|
|
|
local latency = "-"
|
|
|
|
|
|
|
|
local data = {
|
|
|
|
label = section['label'] or interface,
|
2018-05-18 07:40:50 +00:00
|
|
|
name = interface,
|
|
|
|
link = net:adminlink(),
|
|
|
|
ifname = ifname,
|
|
|
|
ipaddr = ipaddr,
|
|
|
|
gateway = gateway,
|
|
|
|
multipath = section['multipath'],
|
|
|
|
status = connectivity,
|
|
|
|
wanip = publicIP,
|
|
|
|
latency = latency,
|
|
|
|
whois = asn and asn.as_description or "unknown",
|
|
|
|
qos = section['trafficcontrol'],
|
|
|
|
download = section['download'],
|
|
|
|
upload = section['upload'],
|
|
|
|
gw_ping = gw_ping,
|
|
|
|
ipv6_discover = ipv6_discover,
|
2018-03-28 08:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ifname:match("^tun.*") then
|
|
|
|
table.insert(mArray.tunnels, data);
|
|
|
|
else
|
|
|
|
table.insert(mArray.wans, data);
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
|
|
|
luci.http.write_json(mArray)
|
2018-05-18 07:40:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- This come from OverTheBox by OVH
|
|
|
|
-- Copyright 2015 OVH <OverTheBox@ovh.net>
|
|
|
|
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
|
|
|
|
-- Sebastien Duponcheel <sebastien.duponcheel@ovh.net>
|
|
|
|
-- Under GPL3+
|
|
|
|
function _ipv6_discover(interface)
|
|
|
|
local result = {}
|
|
|
|
|
|
|
|
--local ra6_list = (sys.exec("rdisc6 -nm " .. interface))
|
2018-05-21 05:58:37 +00:00
|
|
|
local ra6_list = (sys.exec("rdisc6 -n1 -r1 " .. interface))
|
2018-05-18 07:40:50 +00:00
|
|
|
-- dissect results
|
|
|
|
local lines = {}
|
|
|
|
local index = {}
|
|
|
|
ra6_list:gsub('[^\r\n]+', function(c)
|
|
|
|
table.insert(lines, c)
|
|
|
|
if c:match("Hop limit") then
|
|
|
|
table.insert(index, #lines)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
local ra6_result = {}
|
|
|
|
for k,v in ipairs(index) do
|
|
|
|
local istart = v
|
|
|
|
local iend = index[k+1] or #lines
|
|
|
|
|
|
|
|
local entry = {}
|
|
|
|
for i=istart,iend - 1 do
|
|
|
|
local level = lines[i]:find('%w')
|
|
|
|
local line = lines[i]:sub(level)
|
|
|
|
|
|
|
|
local param, value
|
|
|
|
if line:match('^from') then
|
|
|
|
param, value = line:match('(from)%s+(.*)$')
|
|
|
|
else
|
|
|
|
param, value = line:match('([^:]+):(.*)$')
|
|
|
|
-- Capitalize param name and remove spaces
|
|
|
|
param = param:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end):gsub("[%s-]",'')
|
|
|
|
param = param:gsub("%.$", '')
|
|
|
|
-- Remove text between brackets, seconds and spaces
|
|
|
|
value = value:lower()
|
|
|
|
value = value:gsub("%(.*%)", '')
|
|
|
|
value = value:gsub("%s-seconds%s-", '')
|
|
|
|
value = value:gsub("^%s+", '')
|
|
|
|
value = value:gsub("%s+$", '')
|
|
|
|
end
|
|
|
|
|
|
|
|
if entry[param] == nil then
|
|
|
|
entry[param] = value
|
|
|
|
elseif type(entry[param]) == "table" then
|
|
|
|
table.insert(entry[param], value)
|
|
|
|
else
|
|
|
|
old = entry[param]
|
|
|
|
entry[param] = {}
|
|
|
|
table.insert(entry[param], old)
|
|
|
|
table.insert(entry[param], value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(ra6_result, entry)
|
|
|
|
end
|
|
|
|
return ra6_result
|
|
|
|
end
|