mirror of
				https://github.com/Ysurac/openmptcprouter-feeds.git
				synced 2025-03-09 15:40:03 +00:00 
			
		
		
		
	Use ubus when possible
This commit is contained in:
		
							parent
							
								
									2c27a090f3
								
							
						
					
					
						commit
						3193f4ef70
					
				
					 2 changed files with 8 additions and 697 deletions
				
			
		|  | @ -263,7 +263,8 @@ function wizard_add() | |||
| 
 | ||||
| 	-- Enable/disable IPv6 | ||||
| 	local disable_ipv6 = luci.http.formvalue("enableipv6") or "1" | ||||
| 	set_ipv6_state(disable_ipv6) | ||||
| 	local ut = require "luci.util" | ||||
| 	local result = ut.ubus("openmptcprouter", "set_ipv6_state", { disable_ipv6 = disable_ipv6 }) | ||||
| 
 | ||||
| 	-- Get VPN set by default | ||||
| 	local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp" | ||||
|  | @ -591,7 +592,7 @@ function settings_add() | |||
| 	 | ||||
| 	-- Disable IPv6 | ||||
| 	local disable_ipv6 = luci.http.formvalue("enableipv6") or "1" | ||||
| 	set_ipv6_state(disable_ipv6) | ||||
| 	local dump = require("luci.util").ubus("openmptcprouter", "disableipv6", { disable_ipv6 = disable_ipv6}) | ||||
| 
 | ||||
| 	-- Enable/disable external check | ||||
| 	local externalcheck = luci.http.formvalue("externalcheck") or "1" | ||||
|  | @ -667,184 +668,19 @@ function update_vps() | |||
| 	-- Update VPS | ||||
| 	local update_vps = luci.http.formvalue("flash") or "" | ||||
| 	if update_vps ~= "" then | ||||
| 		ucic:foreach("openmptcprouter", "server", function(s) | ||||
| 			local serverip = ucic:get("openmptcprouter",s[".name"],"ip") | ||||
| 			local adminport = ucic:get("openmptcprouter",s[".name"],"port") or "65500" | ||||
| 			local token = ucic:get("openmptcprouter",s[".name"],"token") or "" | ||||
| 			if token ~= "" then | ||||
| 				sys.exec('curl -4 --max-time 20 -s -k -H "Authorization: Bearer ' .. token .. '" https://' .. serverip .. ":" .. adminport .. "/update") | ||||
| 				luci.sys.call("/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null") | ||||
| 				luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/status")) | ||||
| 				return | ||||
| 			end | ||||
| 		end) | ||||
| 		local ut = require "luci.util" | ||||
| 		local result = ut.ubus("openmptcprouter", "update_vps", {}) | ||||
| 	end | ||||
| end | ||||
| 
 | ||||
| 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 | ||||
| 	if ip == "" then | ||||
| 		local dump = require("luci.util").ubus("network.interface.%s_4" % interface, "status", {}) | ||||
| 		if dump and dump['ipv4-address'] then | ||||
| 			local _, ipv4address | ||||
| 			for _, ipv4address in ipairs(dump['ipv4-address']) do | ||||
| 				ip = dump['ipv4-address'][_].address | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	return ip | ||||
| end | ||||
| 
 | ||||
| function get_device(interface) | ||||
| 	local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {}) | ||||
| 	return dump['l3_device'] | ||||
| end | ||||
| 
 | ||||
| function get_gateway(interface) | ||||
| 	local gateway = "" | ||||
| 	local dump = nil | ||||
| 
 | ||||
| 	dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {}) | ||||
| 
 | ||||
| 	if dump and dump.route then | ||||
| 		local _, route | ||||
| 		for _, route in ipairs(dump.route) do | ||||
| 			if dump.route[_].target == "0.0.0.0" then | ||||
| 				gateway = dump.route[_].nexthop | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	if gateway == "" then | ||||
| 		if dump and dump.inactive and dump.inactive.route then | ||||
| 			local _, route | ||||
| 			for _, route in ipairs(dump.inactive.route) do | ||||
| 				if dump.inactive.route[_].target == "0.0.0.0" then | ||||
| 					gateway = dump.inactive.route[_].nexthop | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	 | ||||
| 	if gateway == "" then | ||||
| 		dump = require("luci.util").ubus("network.interface.%s_4" % interface, "status", {}) | ||||
| 
 | ||||
| 		if dump and dump.route then | ||||
| 			local _, route | ||||
| 			for _, route in ipairs(dump.route) do | ||||
| 				if dump.route[_].target == "0.0.0.0" then | ||||
| 					gateway = dump.route[_].nexthop | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| 		if gateway == "" then | ||||
| 			if dump and dump.inactive and dump.inactive.route then | ||||
| 				local _, route | ||||
| 				for _, route in ipairs(dump.inactive.route) do | ||||
| 					if dump.inactive.route[_].target == "0.0.0.0" then | ||||
| 						gateway = dump.inactive.route[_].nexthop | ||||
| 					end | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	return gateway | ||||
| end | ||||
| 
 | ||||
| -- 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> | ||||
| -- Modified by Ycarus (Yannick Chabanois) <ycarus@zugaina.org> | ||||
| -- Under GPL3+ | ||||
| function interfaces_status() | ||||
| 	local ut = require "luci.util" | ||||
| 	local rv = ut.ubus("openmptcprouter", "status", {}) or {_=0} | ||||
| 
 | ||||
| 	luci.http.prepare_content("application/json") | ||||
| 	luci.http.write_json(rv) | ||||
| end | ||||
| 
 | ||||
| function old_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=::'")) | ||||
| 	mArray.openmptcprouter["version"] = uci:get("openmptcprouter", "settings", "version") or ut.trim(sys.exec("cat /etc/os-release | grep VERSION= | sed -e 's:VERSION=::' -e 's/^.//' -e 's/.$//'")) | ||||
| 
 | ||||
| 	mArray.openmptcprouter["latest_version_omr"] = uci:get("openmptcprouter", "latest_versions", "omr") or "" | ||||
| 	mArray.openmptcprouter["latest_version_vps"] = uci:get("openmptcprouter", "latest_versions", "vps") or "" | ||||
| 	 | ||||
| 	mArray.openmptcprouter["service_addr"] = uci:get("shadowsocks-libev", "sss0", "server") or "" | ||||
| 	mArray.openmptcprouter["local_addr"] = uci:get("network", "lan", "ipaddr") | ||||
| 	mArray.openmptcprouter["hostname"] = "OpenMPTCProuter" | ||||
| 	ucic:foreach("system", "system", function(s) | ||||
| 		mArray.openmptcprouter["hostname"] = uci:get("system",s[".name"],"hostname") or "OpenMPTCProuter" | ||||
| 	end) | ||||
| 
 | ||||
| 	mArray.openmptcprouter["server_mptcp"] = "" | ||||
| 	-- dns | ||||
| 	mArray.openmptcprouter["dns"] = false | ||||
| 	local dns_test = sys.exec("dig openmptcprouter.com | grep 'ANSWER: 0'") | ||||
| 	if dns_test == "" then | ||||
| 		mArray.openmptcprouter["dns"] = true | ||||
| 	end | ||||
| 
 | ||||
| 	mArray.openmptcprouter["ipv6"] = "disabled" | ||||
| 	if uci:get("openmptcprouter","settings","disable_ipv6") ~= "1" then | ||||
| 		mArray.openmptcprouter["ipv6"] = "enabled" | ||||
| 	end | ||||
| 
 | ||||
| 	mArray.openmptcprouter["ss_addr"] = "" | ||||
| 	--mArray.openmptcprouter["ss_addr6"] = "" | ||||
| 	mArray.openmptcprouter["wan_addr"] = "" | ||||
| 	mArray.openmptcprouter["wan_addr6"] = "" | ||||
| 	local tracker_ip = "" | ||||
| 	local check_ipv4_website = uci:get("openmptcprouter","settings","check_ipv4_website") or "http://ip.openmptcprouter.com" | ||||
| 	local check_ipv6_website = uci:get("openmptcprouter","settings","check_ipv6_website") or "http://ipv6.openmptcprouter.com" | ||||
| 	if mArray.openmptcprouter["dns"] == true then | ||||
| 		-- wanaddr | ||||
| 		--mArray.openmptcprouter["wan_addr"] = uci:get("openmptcprouter","omr","public_detected_ipv4") or "" | ||||
| 		 | ||||
| 		if uci:get("openmptcprouter","settings","external_check") ~= "0" then | ||||
| 			mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("wget -4 -qO- -T 2 " .. check_ipv4_website)) | ||||
| 			if mArray.openmptcprouter["wan_addr"] == "" then | ||||
| 				mArray.openmptcprouter["wan_addr"] = ut.trim(sys.exec("dig TXT +timeout=2 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{print $2}'")) | ||||
| 			end | ||||
| 			if mArray.openmptcprouter["ipv6"] == "enabled" then | ||||
| 				mArray.openmptcprouter["wan_addr6"] = uci:get("openmptcprouter","omr","public_detected_ipv6") or "" | ||||
| 				if mArray.openmptcprouter["wan_addr6"] == "" then | ||||
| 					mArray.openmptcprouter["wan_addr6"] = ut.trim(sys.exec("wget -6 -qO- -T 2 " .. check_ipv6_website)) | ||||
| 				end | ||||
| 			end | ||||
| 			mArray.openmptcprouter["external_check"] = true | ||||
| 		else | ||||
| 			mArray.openmptcprouter["external_check"] = false | ||||
| 		end | ||||
| 		-- shadowsocksaddr | ||||
| 		mArray.openmptcprouter["ss_addr"] = uci:get("openmptcprouter","omr","detected_ss_ipv4") or "" | ||||
| 		if mArray.openmptcprouter["ss_addr"] == "" then | ||||
| 			tracker_ip = uci:get("shadowsocks-libev","tracker","local_address") or "" | ||||
| 			if tracker_ip ~= "" then | ||||
| 				local tracker_port = uci:get("shadowsocks-libev","tracker","local_port") | ||||
| 				if uci:get("openmptcprouter","settings","external_check") ~= "0" then | ||||
| 					mArray.openmptcprouter["ss_addr"] = ut.trim(sys.exec("curl -s -4 --socks5 " .. tracker_ip .. ":" .. tracker_port .. " -m 2 " .. check_ipv4_website)) | ||||
| 					--mArray.openmptcprouter["ss_addr6"] = sys.exec("curl -s -6 --socks5 " .. tracker_ip .. ":" .. tracker_port .. " -m 3 http://ipv6.openmptcprouter.com") | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	local mArray = ut.ubus("openmptcprouter", "status", {}) or {_=0} | ||||
| 
 | ||||
| 	mArray.openmptcprouter["remote_addr"] = luci.http.getenv("REMOTE_ADDR") or "" | ||||
| 	mArray.openmptcprouter["remote_from_lease"] = false | ||||
|  | @ -856,531 +692,6 @@ function old_interfaces_status() | |||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| 	if  mArray.openmptcprouter["service_addr"] ~= "" and mArray.openmptcprouter["service_addr"] ~= "127.0.0.1" then | ||||
| 		mArray.openmptcprouter["vps_status"] = "DOWN" | ||||
| 	else | ||||
| 		mArray.openmptcprouter["vps_status"] = "UP" | ||||
| 	end | ||||
| 
 | ||||
| 	mArray.openmptcprouter["vps_admin"] = false | ||||
| 	mArray.openmptcprouter["vps_admin_error"] = false | ||||
| 	mArray.openmptcprouter["vps_admin_error_msg"] = "Not found" | ||||
| 	mArray.openmptcprouter["vps_hostname"] = "OpenMPTCProuter Server" | ||||
| 	-- Get VPS info | ||||
| 	ucic:foreach("openmptcprouter", "server", function(s) | ||||
| 		local serverip = uci:get("openmptcprouter",s[".name"],"ip") or "" | ||||
| 		if serverip ~= "" then | ||||
| 			mArray.openmptcprouter["vps_omr_version"] = uci:get("openmptcprouter", s[".name"], "omr_version") or "" | ||||
| 			mArray.openmptcprouter["vps_kernel"] = uci:get("openmptcprouter",s[".name"],"kernel") or "" | ||||
| 			mArray.openmptcprouter["vps_machine"] = uci:get("openmptcprouter",s[".name"],"machine") or "" | ||||
| 			if uci:get("openmptcprouter",s[".name"],"admin_error") == "1" then | ||||
| 				mArray.openmptcprouter["vps_admin_error"] = true | ||||
| 			end | ||||
| 			local adminport = uci:get("openmptcprouter",s[".name"],"port") or "65500" | ||||
| 			local token = uci:get("openmptcprouter",s[".name"],"token") or "" | ||||
| 			if token ~= "" then | ||||
| 				local vpsinfo_json = sys.exec('curl -4 --max-time 2 -s -k -H "Authorization: Bearer ' .. token .. '" https://' .. serverip .. ':' .. adminport .. '/status') | ||||
| 				if vpsinfo_json ~= "" and vpsinfo_json ~= nil then | ||||
| 					local status, vpsinfo = pcall(function()  | ||||
| 						return json.decode(vpsinfo_json) | ||||
| 					end) | ||||
| 					if status and vpsinfo.vps ~= nil then | ||||
| 						mArray.openmptcprouter["vps_loadavg"] = vpsinfo.vps.loadavg or "" | ||||
| 						mArray.openmptcprouter["vps_uptime"] = vpsinfo.vps.uptime or "" | ||||
| 						mArray.openmptcprouter["vps_mptcp"] = vpsinfo.vps.mptcp or "" | ||||
| 						mArray.openmptcprouter["vps_hostname"] = vpsinfo.vps.hostname or "" | ||||
| 						mArray.openmptcprouter["vps_admin"] = true | ||||
| 						mArray.openmptcprouter["vps_status"] = "UP" | ||||
| 						mArray.openmptcprouter["vps_admin_error_msg"] = "" | ||||
| 					else | ||||
| 						uci:set("openmptcprouter",s[".name"],"admin_error","1") | ||||
| 						mArray.openmptcprouter["vps_admin_error"] = true | ||||
| 						uci:delete("openmptcprouter",s[".name"],"token") | ||||
| 						uci:save("openmptcprouter",s[".name"]) | ||||
| 						uci:commit("openmptcprouter",s[".name"]) | ||||
| 						mArray.openmptcprouter["vps_admin"] = false | ||||
| 						mArray.openmptcprouter["vps_admin_error_msg"] = "Answer error" | ||||
| 					end | ||||
| 				else | ||||
| 					mArray.openmptcprouter["vps_admin"] = false | ||||
| 					mArray.openmptcprouter["vps_admin_error_msg"] = "No answer" | ||||
| 				end | ||||
| 			else | ||||
| 				mArray.openmptcprouter["vps_admin"] = false | ||||
| 				mArray.openmptcprouter["vps_admin_error_msg"] = "No token" | ||||
| 			end | ||||
| 		end | ||||
| 	end) | ||||
| 	if mArray.openmptcprouter["vps_hostname"] == "" then | ||||
| 		mArray.openmptcprouter["vps_hostname"] = "Server" | ||||
| 	end | ||||
| 	-- Check openmptcprouter service are running | ||||
| 	mArray.openmptcprouter["tun_service"] = false | ||||
| 	mArray.openmptcprouter["tun_state"] = "" | ||||
| 	mArray.openmptcprouter["tun6_state"] = "" | ||||
| 	if string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?glorytun(-udp)?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?mlvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?openvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?dsvpn?$'"), "%d+") then | ||||
| 		mArray.openmptcprouter["tun_service"] = true | ||||
| 		mArray.openmptcprouter["tun_ip"] = get_ip("omrvpn") | ||||
| 		local tun_dev = uci:get("network","omrvpn","ifname") | ||||
| 		if tun_dev == "" then | ||||
| 			tun_dev = get_device("omrvpn") | ||||
| 		end | ||||
| 		if tun_dev ~= "" then | ||||
| 			local peer = get_gateway("omrvpn") | ||||
| 			if peer == "" then | ||||
| 				peer = ut.trim(sys.exec("ip -4 r list dev " .. tun_dev .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'")) | ||||
| 			end | ||||
| 			if peer ~= "" then | ||||
| 				local tunnel_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 -I " .. tun_dev .. " " .. peer .. " | grep '100% packet loss'")) | ||||
| 				if tunnel_ping_test == "" then | ||||
| 					mArray.openmptcprouter["tun_state"] = "UP" | ||||
| 				else | ||||
| 					mArray.openmptcprouter["tun_state"] = "DOWN" | ||||
| 				end | ||||
| 				if mArray.openmptcprouter["ipv6"] == "enabled" then | ||||
| 					local tunnel_ping6_test = ut.trim(sys.exec("ping6 -w 1 -c 1 fe80::a00:1%6in4-omr6in4 | grep '100% packet loss'")) | ||||
| 					if tunnel_ping6_test == "" then | ||||
| 						mArray.openmptcprouter["tun6_state"] = "UP" | ||||
| 					else | ||||
| 						mArray.openmptcprouter["tun6_state"] = "DOWN" | ||||
| 					end | ||||
| 				end | ||||
| 			else | ||||
| 				mArray.openmptcprouter["tun_state"] = "DOWN" | ||||
| 				mArray.openmptcprouter["tun6_state"] = "DOWN" | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	 | ||||
| 	-- check Shadowsocks is running | ||||
| 	mArray.openmptcprouter["socks_service"] = false | ||||
| 	if string.find(sys.exec("/usr/bin/pgrep ss-redir"), "%d+") then | ||||
| 		mArray.openmptcprouter["socks_service"] = true | ||||
| 	end | ||||
| 
 | ||||
| 	mArray.openmptcprouter["socks_service_enabled"] = true | ||||
| 	local ss_server = uci:get("shadowsocks-libev","sss0","disabled") or "0" | ||||
| 	if ss_server == "1" then | ||||
| 		mArray.openmptcprouter["socks_service_enabled"] = false | ||||
| 	end | ||||
| 	local ss_key = uci:get("shadowsocks-libev","sss0","key") or "" | ||||
| 	mArray.openmptcprouter["socks_service_method"] = uci:get("shadowsocks-libev","sss0","method") | ||||
| 	if ss_key == "" then | ||||
| 		mArray.openmptcprouter["socks_service_key"] = false | ||||
| 	else | ||||
| 		mArray.openmptcprouter["socks_service_key"] = 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 == "3" then | ||||
| 				mArray.openmptcprouter.dhcpd[itf].router = value | ||||
| 			end | ||||
| 			if option == "option:dns-server" or option == "6" 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%.]+") | ||||
| 
 | ||||
| 	mArray.openmptcprouter["fstype"] = sys.exec("cat /proc/mounts 2>/dev/null | awk '/\\/dev\\/root/ {print $3}' | tr -d '\n'") | ||||
| 	if mArray.openmptcprouter["fstype"] == "ext4" then | ||||
| 		if sys.exec("cat /proc/mounts 2>/dev/null | awk '/\\/dev\\/root/ {print $4}' | grep ro") == "" then | ||||
| 			mArray.openmptcprouter["fsro"] = false | ||||
| 		else | ||||
| 			mArray.openmptcprouter["fsro"] = true | ||||
| 		end | ||||
| 	elseif mArray.openmptcprouter["fstype"] == "squashfs" then | ||||
| 		if sys.exec("cat /proc/mounts 2>/dev/null | awk '/overlayfs/ {print $4}' | grep overlay") == "" then | ||||
| 			mArray.openmptcprouter["fsro"] = true | ||||
| 		else | ||||
| 			mArray.openmptcprouter["fsro"] = false | ||||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| 	-- overview status | ||||
| 	mArray.wans = {} | ||||
| 	mArray.tunnels = {} | ||||
| 	allintf = {} | ||||
| 
 | ||||
| 	uci:foreach("network", "interface", function (section) | ||||
| 	    local interface = section[".name"] | ||||
| 	    local net = ntm:get_network(interface) | ||||
| 	    local ipaddr = net:ipaddr() or "" | ||||
| 	    local gateway = section["gateway"] or "" | ||||
| 	    local multipath = section["multipath"] | ||||
| 	    local enabled = section["auto"] | ||||
| 
 | ||||
| 	    --if not ipaddr or not gateway then return end | ||||
| 	    -- Don't show if0 in the overview | ||||
| 	    --if interface == "lo" then return end | ||||
| 
 | ||||
| 	    local ifname = get_device(interface) | ||||
| 	    if ifname == "" or ifname == nil then | ||||
| 		ifname = section["ifname"] or "" | ||||
| 	    end | ||||
| 	    duplicateif = false | ||||
| 	    if ifname ~= "" and ifname ~= nil then | ||||
| 		if allintf[ifname] then | ||||
| 		    connectivity = "ERROR" | ||||
| 		    duplicateif = true | ||||
| 		else | ||||
| 		    allintf[ifname] = true | ||||
| 		end | ||||
| 	    end | ||||
| 
 | ||||
| 	    --if multipath == "off" and not ifname:match("^tun.*") then return end | ||||
| 	    if multipath == "off" then return end | ||||
| 	     | ||||
| 	    if enabled == "0" then return end | ||||
| 
 | ||||
| 	    local connectivity | ||||
| 	    local multipath_state = "" | ||||
| 	    local current_multipath_state = "" | ||||
| 	    if ifname ~= "" and ifname ~= nil then | ||||
| 		    if fs.access("/sys/class/net/" .. ifname) then | ||||
| 			    multipath_state = ut.trim(sys.exec("multipath " .. ifname .. " | grep deactivated")) | ||||
| 			    if multipath_state == "" then | ||||
| 				connectivity = "OK" | ||||
| 			    else | ||||
| 				connectivity = "ERROR" | ||||
| 			    end | ||||
| 		    else | ||||
| 			    connectivity = "ERROR" | ||||
| 		    end | ||||
| 	    else | ||||
| 		    connectivity = "ERROR" | ||||
| 	    end | ||||
| 	    if ifname ~= "" and ifname ~= nil then | ||||
| 		    local test_current_multipath_state = ut.trim(sys.exec("multipath " .. ifname)) | ||||
| 		    if string.find(test_current_multipath_state,"deactivated") then | ||||
| 			    current_multipath_state = "off" | ||||
| 		    elseif string.find(test_current_multipath_state,"default") then | ||||
| 			    current_multipath_state = "on" | ||||
| 		    elseif string.find(test_current_multipath_state,"backup") then | ||||
| 			    current_multipath_state = "backup" | ||||
| 		    elseif string.find(test_current_multipath_state,"handover") then | ||||
| 			    current_multipath_state = "handover" | ||||
| 		    else | ||||
| 			    current_multipath_state = "" | ||||
| 		    end | ||||
| 	    end | ||||
| 
 | ||||
| 	    if ipaddr == "" and ifname ~= nil and ifname ~= "" then | ||||
| 		    ipaddr = ut.trim(sys.exec("ip -4 -br addr ls dev " .. ifname .. " | awk -F'[ /]+' '{print $3}' | tr -d '\n'")) | ||||
| 	    end | ||||
| 	    if ipaddr == "" and ifname ~= nil and ifname ~= "" then | ||||
| 		    ipaddr = ut.trim(sys.exec("ip -4 addr show dev " .. ifname .. " | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1 | tr -d '\n'")) | ||||
| 	    end | ||||
| 	    if ipaddr == "" then | ||||
| 		    connectivity = "ERROR" | ||||
| 	    end | ||||
| 
 | ||||
| 	    -- Detect WAN gateway status | ||||
| 	    local gw_ping = "UP" | ||||
| 	    if gateway == "" then | ||||
| 		    gateway = get_gateway(interface) | ||||
| 	    end | ||||
| 	    if gateway == "" and ifname ~= nil and ifname ~= "" then | ||||
| 		    if fs.access("/sys/class/net/" .. ifname) then | ||||
| 			    gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d '\n'")) | ||||
| 			    if gateway == "" then | ||||
| 				gateway = ut.trim(sys.exec("ip -4 r list dev " .. ifname .. " | grep default | awk '{print $3}' | tr -d '\n'")) | ||||
| 			    end | ||||
| 		    end | ||||
| 	    end | ||||
| 	    if gateway ~= "" then | ||||
| 		    local gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway .. " | grep '100% packet loss'")) | ||||
| 		    if gw_ping_test ~= "" then | ||||
| 			    gw_ping = "DOWN" | ||||
| 			    if connectivity == "OK" then | ||||
| 				    connectivity = "WARNING" | ||||
| 			    end | ||||
| 		    end | ||||
| 	    elseif gateway == "" then | ||||
| 		    gw_ping = "DOWN" | ||||
| 		    connectivity = "ERROR" | ||||
| 	    end | ||||
| 	     | ||||
| 	    local latency = "" | ||||
| 	    local server_ping = "" | ||||
| 	    if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" then | ||||
| 		    local serverip = mArray.openmptcprouter["service_addr"] | ||||
| 		    if serverip == "127.0.0.1" then | ||||
| 			    serverip = mArray.openmptcprouter["wan_addr"] | ||||
| 		    end | ||||
| 		    if serverip ~= "" then | ||||
| 			    local server_ping_test = sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. serverip) | ||||
| 			    local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'")) | ||||
| 			    if server_ping_result ~= "" then | ||||
| 				    server_ping = "DOWN" | ||||
| 				    if connectivity == "OK" then | ||||
| 					    connectivity = "WARNING" | ||||
| 				    end | ||||
| 			    else | ||||
| 				    mArray.openmptcprouter["vps_status"] = "UP" | ||||
| 				    server_ping = "UP" | ||||
| 				    latency = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | cut -d '/' -s -f5 | cut -d '.' -f1")) | ||||
| 			    end | ||||
| 		    end | ||||
| 	    end | ||||
| 
 | ||||
| 	    local multipath_available | ||||
| 	    if connectivity ~= "ERROR" and mArray.openmptcprouter["dns"] == true and ifname ~= nil and ifname ~= "" and gateway ~= "" and gw_ping == "UP" then | ||||
| 		    -- Test if multipath can work on the connection | ||||
| 		    local multipath_available_state = uci:get("openmptcprouter",interface,"mptcp_status") or "" | ||||
| 		    if multipath_available_state == "" then | ||||
| 			    --if mArray.openmptcprouter["service_addr"] ~= "" then | ||||
| 			    --    multipath_available_state = ut.trim(sys.exec("omr-tracebox-mptcp " .. mArray.openmptcprouter["service_addr"] .. " " .. ifname .. " | grep 'MPTCP disabled'")) | ||||
| 			    --else | ||||
| 				    multipath_available_state = ut.trim(sys.exec("omr-mptcp-intf " .. ifname .. " | grep 'Nay, Nay, Nay'")) | ||||
| 			    --end | ||||
| 		    else | ||||
| 			    multipath_available_state = ut.trim(sys.exec("echo '" .. multipath_available_state .. "' | grep 'MPTCP disabled'")) | ||||
| 		    end | ||||
| 		    if multipath_available_state == "" then | ||||
| 			    multipath_available = "OK" | ||||
| 		    else | ||||
| 			    multipath_available_state_wan = ut.trim(sys.exec("omr-mptcp-intf " .. ifname .. " | grep 'Nay, Nay, Nay'")) | ||||
| 			    if multipath_available_state_wan == "" then | ||||
| 				    multipath_available = "OK" | ||||
| 				    if mArray.openmptcprouter["service_addr"] ~= "" and mArray.openmptcprouter["service_addr"] ~= "127.0.0.1" then | ||||
| 					    mArray.openmptcprouter["server_mptcp"] = "disabled" | ||||
| 				    end | ||||
| 			    else | ||||
| 				    multipath_available = "ERROR" | ||||
| 				    connectivity = "WARNING" | ||||
| 			    end | ||||
| 		    end | ||||
| 	    else | ||||
| 		    multipath_available = "NO CHECK" | ||||
| 	    end | ||||
| 
 | ||||
| 	     | ||||
| 	    -- Detect if WAN get an IPv6 | ||||
| 	    local ipv6_discover = "NONE" | ||||
| 	    if ifname ~= "" and ifname ~= nil and mArray.openmptcprouter["ipv6"] == "enabled" 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 | ||||
| 					    if type(v.RecursiveDnsServer) ~= "table" then | ||||
| 						    ipv6_addr_test = sys.exec("ip -6 addr | grep " .. v.RecursiveDnsServer) | ||||
| 						    if ipv6_addr_test == "" then | ||||
| 							    ipv6_discover = "DETECTED" | ||||
| 							    if connectivity == "OK" then | ||||
| 								    connectivity = "WARNING" | ||||
| 							    end | ||||
| 						    end | ||||
| 					    end | ||||
| 				    end | ||||
| 			    end | ||||
| 		    end | ||||
| 	    end | ||||
| 
 | ||||
| 	    local publicIP = uci:get("openmptcprouter",interface,"publicip") or "" | ||||
| 	    if ifname ~= nil and publicIP == "" and uci:get("openmptcprouter","settings","external_check") ~= "0" then | ||||
| 		    publicIP = ut.trim(sys.exec("omr-ip-intf " .. ifname)) | ||||
| 	    end | ||||
| 	    local whois = "" | ||||
| 	    if publicIP ~= "" then | ||||
| 		    whois = uci:get("openmptcprouter",interface,"asn") or "" | ||||
| 		    if whois == "" and uci:get("openmptcprouter","settings","external_check") ~= "0" then | ||||
| 			    --whois = ut.trim(sys.exec("whois " .. publicIP .. " | grep -i 'netname' | awk '{print $2}'")) | ||||
| 			    whois = ut.trim(sys.exec("wget -4 -qO- -T 1 'http://api.iptoasn.com/v1/as/ip/" .. publicIP .. "' | jsonfilter -q -e '@.as_description'")) | ||||
| 		    end | ||||
| 	    end | ||||
| 	     | ||||
| 	    local mtu = "" | ||||
| 	    if ifname ~= "" and ifname ~= nil then | ||||
| 		    if fs.access("/sys/class/net/" .. ifname) then | ||||
| 			    mtu = ut.trim(sys.exec("cat /sys/class/net/" .. ifname .. "/mtu | tr -d '\n'")) | ||||
| 			    if mtu == "" and interface ~= nil then | ||||
| 					mtu = uci:get("openmptcprouter",interface,"mtu") or "" | ||||
| 			    end | ||||
| 		    end | ||||
| 	    end | ||||
| 
 | ||||
| 	    local data = { | ||||
| 		label = section["label"] or interface, | ||||
| 		name = interface, | ||||
| 		link = net:adminlink(), | ||||
| 		ifname = ifname, | ||||
| 		ipaddr = ipaddr, | ||||
| 		gateway = gateway, | ||||
| 		multipath = section["multipath"], | ||||
| 		status = connectivity, | ||||
| 		wanip = publicIP, | ||||
| 		latency = latency, | ||||
| 		mtu = mtu, | ||||
| 		whois = whois or "unknown", | ||||
| 		qos = section["trafficcontrol"], | ||||
| 		download = section["download"], | ||||
| 		upload = section["upload"], | ||||
| 		gw_ping = gw_ping, | ||||
| 		server_ping = server_ping, | ||||
| 		ipv6_discover = ipv6_discover, | ||||
| 		multipath_available = multipath_available, | ||||
| 		multipath_state = current_multipath_state, | ||||
| 		duplicateif = duplicateif, | ||||
| 	    } | ||||
| 
 | ||||
| 	    if ifname ~= nil and ifname:match("^tun.*") then | ||||
| 		    table.insert(mArray.tunnels, data); | ||||
| 	    elseif ifname ~= nil and ifname:match("^mlvpn.*") 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) | ||||
| 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)) | ||||
| 	local ra6_list = (sys.exec("rdisc6 -n1 -r1 " .. interface)) | ||||
| 	-- 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 | ||||
| 
 | ||||
| function set_ipv6_state(disable_ipv6) | ||||
| 	-- Disable/Enable IPv6 support | ||||
| 	--luci.sys.exec("sysctl -qw 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) | ||||
| 	luci.sys.exec("sysctl -qw net.ipv6.conf.all.disable_ipv6=0") | ||||
| 	luci.sys.exec("sed -i 's:^net.ipv6.conf.all.disable_ipv6=[0-9]*:net.ipv6.conf.all.disable_ipv6=0:' /etc/sysctl.d/zzz_openmptcprouter.conf" % disable_ipv6) | ||||
| 
 | ||||
| 	-- Disable/Enable IPv6 for firewall | ||||
| 	ucic:set("firewall",ucic:get_first("firewall","defaults"),"disable_ipv6",disable_ipv6) | ||||
| 	ucic:save("firewall") | ||||
| 	ucic:commit("firewall") | ||||
| 
 | ||||
| 	-- Disable/Enable IPv6 in OpenMPTCProuter settings | ||||
| 	ucic:set("openmptcprouter","settings","disable_ipv6",disable_ipv6) | ||||
| 	ucic:commit("openmptcprouter") | ||||
| 
 | ||||
| 	-- Disable/Enable route announce of IPv6 | ||||
| 	if disable_ipv6 == "1" then | ||||
| 		ucic:set("dhcp","lan","ra_default","0") | ||||
| 		ucic:set("network","lan","ipv6","0") | ||||
| 		--luci.sys.call("uci -q del network.lan.ipifaceid") | ||||
| 	else | ||||
| 	--	ucic:set("dhcp","lan","ra_default","1") | ||||
| 		ucic:set("network","lan","ipv6","1") | ||||
| 		ucic:set("network","lan","delegate","0") | ||||
| 		--ucic:set("network","lan","ipifaceid","random") | ||||
| 	end | ||||
| 	ucic:save("network") | ||||
| 	ucic:commit("network") | ||||
| 
 | ||||
| 	-- Disable/Enable IPv6 DHCP and change Shadowsocks listen address | ||||
| 	if disable_ipv6 == "1" then | ||||
| 		luci.sys.call("uci -q del dhcp.lan.dhcpv6") | ||||
| 		luci.sys.call("uci -q del dhcp.lan.ra") | ||||
| 		luci.sys.call("uci -q del dhcp.lan.ra_default") | ||||
| 		luci.sys.call("uci -q del dhcp.lan.ra_management") | ||||
| 		luci.sys.call("uci -q del dhcp.lan.ra_preference") | ||||
| 		ucic:set("shadowsocks-libev","hi","local_address","0.0.0.0") | ||||
| 	else | ||||
| 		ucic:set("dhcp","lan","dhcpv6","server") | ||||
| 		ucic:set("dhcp","lan","ra","server") | ||||
| 		ucic:set("dhcp","lan","ra_default","1") | ||||
| 		ucic:set("dhcp","lan","ra_preference","high") | ||||
| 		ucic:set("dhcp","lan","ra_management","1") | ||||
| 		ucic:set("shadowsocks-libev","hi","local_address","::") | ||||
| 	end | ||||
| 	ucic:save("dhcp") | ||||
| 	ucic:commit("dhcp") | ||||
| 	--if disable_ipv6 == "1" then | ||||
| 	--	luci.sys.exec("/etc/init.d/odhcpd stop >/dev/null 2>&1") | ||||
| 	--	luci.sys.exec("/etc/init.d/odhcpd disable >/dev/null 2>&1") | ||||
| 	--else | ||||
| 	--	luci.sys.exec("/etc/init.d/odhcpd start >/dev/null 2>&1") | ||||
| 	--	luci.sys.exec("/etc/init.d/odhcpd enable >/dev/null 2>&1") | ||||
| 	--end | ||||
| end | ||||
|  | @ -75,7 +75,7 @@ | |||
| 						var statusMessage = _('Your IP was not leased by this router'); | ||||
| 					} | ||||
| 				} else { | ||||
| 					var title = String.format('<br /><strong>%s</strong>', _('You')) | ||||
| 					var title = String.format('<br /><strong>%s</strong>', _('Clients')) | ||||
| 					var statusMessageClass = ""; | ||||
| 					var statusIcon = "<%=resource%>/openmptcprouter/images/statusOK.png"; | ||||
| 					var statusMessage = ""; | ||||
|  | @ -544,7 +544,7 @@ | |||
| 		<h3>Settings</h3> | ||||
| 		<fieldset class="cbi-section"> | ||||
| 			<div class="cbi-value"> | ||||
| 				<label class="cbi-value-title">Anonymize public IPs (at next refresh)</label> | ||||
| 				<label class="cbi-value-title">Anonymize public IPs</label> | ||||
| 				<div class="cbi-value-field"> | ||||
| 					<input type="checkbox" name="anon" id="anon" class="cbi-input-checkbox" value="1" onclick="setAnonymize(this)" \> | ||||
| 				</div> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue