2019-04-04 07:40:08 +00:00
|
|
|
local math = require "math"
|
2018-03-28 08:57:02 +00:00
|
|
|
local sys = require "luci.sys"
|
|
|
|
local json = require("luci.json")
|
2018-06-12 17:22:55 +00:00
|
|
|
local fs = require("nixio.fs")
|
2018-09-01 19:59:02 +00:00
|
|
|
local net = require "luci.model.network".init()
|
2019-04-04 07:40:08 +00:00
|
|
|
local ucic = luci.model.uci.cursor()
|
2019-11-07 08:41:09 +00:00
|
|
|
local ipc = require "luci.ip"
|
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
|
2019-11-14 20:21:49 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "settings_add"}, post("settings_add"))
|
|
|
|
entry({"admin", "system", "openmptcprouter", "update_vps"}, post("update_vps"))
|
2019-10-09 16:40:05 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "backup"}, template("openmptcprouter/backup"), _("Backup on server"), 3).leaf = true
|
2019-11-14 20:21:49 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "backupgr"}, post("backupgr"))
|
2019-04-15 20:14:35 +00:00
|
|
|
entry({"admin", "system", "openmptcprouter", "debug"}, template("openmptcprouter/debug"), _("Show all settings"), 5).leaf = true
|
2018-03-23 19:23:27 +00:00
|
|
|
end
|
|
|
|
|
2018-09-01 19:59:02 +00:00
|
|
|
function interface_from_device(dev)
|
|
|
|
for _, iface in ipairs(net:get_networks()) do
|
|
|
|
local ifacen = iface:name()
|
|
|
|
local ifacename = ucic:get("network",ifacen,"ifname")
|
|
|
|
if ifacename == dev then
|
|
|
|
return ifacen
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2018-03-23 19:23:27 +00:00
|
|
|
function wizard_add()
|
2018-12-12 20:30:15 +00:00
|
|
|
local gostatus = true
|
|
|
|
-- Add new server
|
|
|
|
local add_server = luci.http.formvalue("add_server") or ""
|
|
|
|
local add_server_name = luci.http.formvalue("add_server_name") or ""
|
|
|
|
if add_server ~= "" and add_server_name ~= "" then
|
2018-12-13 12:54:06 +00:00
|
|
|
ucic:set("openmptcprouter",add_server_name:gsub("[^%w_]+","_"),"server")
|
2018-12-12 20:30:15 +00:00
|
|
|
gostatus = false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Remove existing server
|
2018-12-17 19:46:53 +00:00
|
|
|
local delete_server = luci.http.formvaluetable("deleteserver") or ""
|
2018-12-12 20:30:15 +00:00
|
|
|
if delete_server ~= "" then
|
2018-12-17 19:46:53 +00:00
|
|
|
for serverdel, _ in pairs(delete_server) do
|
2018-12-21 15:20:20 +00:00
|
|
|
ucic:foreach("network", "interface", function(s)
|
|
|
|
local sectionname = s[".name"]
|
|
|
|
ucic:delete("network","server_" .. serverdel .. "_" .. sectionname .. "_route")
|
|
|
|
end)
|
|
|
|
ucic:delete("network","server_" .. serverdel .. "_default_route")
|
|
|
|
ucic:delete("openmptcprouter",serverdel)
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/wizard"))
|
|
|
|
return
|
2018-12-12 20:30:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Add new interface
|
2018-04-20 12:56:19 +00:00
|
|
|
local add_interface = luci.http.formvalue("add_interface") or ""
|
2018-09-01 19:59:02 +00:00
|
|
|
local add_interface_ifname = luci.http.formvalue("add_interface_ifname") or ""
|
2018-04-20 12:56:19 +00:00
|
|
|
if add_interface ~= "" then
|
|
|
|
local i = 1
|
2018-06-22 08:00:46 +00:00
|
|
|
local multipath_master = false
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:foreach("network", "interface", function(s)
|
|
|
|
local sectionname = s[".name"]
|
|
|
|
if sectionname:match("^wan(%d+)$") then
|
|
|
|
i = i + 1
|
|
|
|
end
|
2018-07-01 08:22:02 +00:00
|
|
|
if ucic:get("network",sectionname,"multipath") == "master" then
|
2018-06-22 08:00:46 +00:00
|
|
|
multipath_master = true
|
|
|
|
end
|
2018-04-20 12:56:19 +00:00
|
|
|
end)
|
2018-09-01 19:59:02 +00:00
|
|
|
local defif = "eth0"
|
|
|
|
if add_interface_ifname == "" then
|
|
|
|
local defif1 = ucic:get("network","wan1_dev","ifname") or ""
|
|
|
|
if defif1 ~= "" then
|
|
|
|
defif = defif1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
defif = add_interface_ifname
|
|
|
|
end
|
|
|
|
|
|
|
|
local ointf = interface_from_device(defif) or ""
|
2019-02-19 18:46:08 +00:00
|
|
|
local wanif = defif
|
2018-09-01 19:59:02 +00:00
|
|
|
if ointf ~= "" then
|
|
|
|
if ucic:get("network",ointf,"type") == "" then
|
|
|
|
ucic:set("network",ointf,"type","macvlan")
|
|
|
|
end
|
2019-02-19 18:46:08 +00:00
|
|
|
wanif = "wan" .. i
|
2018-09-01 19:59:02 +00:00
|
|
|
end
|
|
|
|
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:set("network","wan" .. i,"interface")
|
|
|
|
ucic:set("network","wan" .. i,"ifname",defif)
|
|
|
|
ucic:set("network","wan" .. i,"proto","static")
|
2019-10-26 07:16:28 +00:00
|
|
|
ucic:set("openmptcprouter","wan" .. i,"interface")
|
2018-09-01 19:59:02 +00:00
|
|
|
if ointf ~= "" then
|
|
|
|
ucic:set("network","wan" .. i,"type","macvlan")
|
2019-10-20 19:12:40 +00:00
|
|
|
ucic:set("macvlan","wan" .. i,"macvlan")
|
2018-09-01 19:59:02 +00:00
|
|
|
end
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:set("network","wan" .. i,"ip4table","wan")
|
2018-06-22 08:00:46 +00:00
|
|
|
if multipath_master then
|
|
|
|
ucic:set("network","wan" .. i,"multipath","on")
|
2019-08-27 20:24:45 +00:00
|
|
|
ucic:set("openmptcprouter","wan" .. i,"multipath","on")
|
2018-06-22 08:00:46 +00:00
|
|
|
else
|
|
|
|
ucic:set("network","wan" .. i,"multipath","master")
|
2019-08-27 20:24:45 +00:00
|
|
|
ucic:set("openmptcprouter","wan" .. i,"multipath","master")
|
2018-06-22 08:00:46 +00:00
|
|
|
end
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:set("network","wan" .. i,"defaultroute","0")
|
2018-12-11 12:24:22 +00:00
|
|
|
ucic:reorder("network","wan" .. i, i + 2)
|
2019-10-20 19:12:40 +00:00
|
|
|
ucic:save("macvlan")
|
|
|
|
ucic:commit("macvlan")
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
2019-08-27 20:24:45 +00:00
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
2018-10-01 18:46:24 +00:00
|
|
|
|
|
|
|
ucic:set("qos","wan" .. i,"interface")
|
|
|
|
ucic:set("qos","wan" .. i,"classgroup","Default")
|
|
|
|
ucic:set("qos","wan" .. i,"enabled","0")
|
|
|
|
ucic:set("qos","wan" .. i,"upload","4000")
|
|
|
|
ucic:set("qos","wan" .. i,"download","100000")
|
|
|
|
ucic:save("qos")
|
|
|
|
ucic:commit("qos")
|
|
|
|
|
|
|
|
ucic:set("sqm","wan" .. i,"queue")
|
2019-04-03 21:14:25 +00:00
|
|
|
if ointf ~= "" then
|
|
|
|
ucic:set("sqm","wan" .. i,"interface","wan" .. i)
|
|
|
|
else
|
|
|
|
ucic:set("sqm","wan" .. i,"interface",defif)
|
|
|
|
end
|
2018-10-01 18:46:24 +00:00
|
|
|
ucic:set("sqm","wan" .. i,"qdisc","fq_codel")
|
|
|
|
ucic:set("sqm","wan" .. i,"script","simple.qos")
|
|
|
|
ucic:set("sqm","wan" .. i,"qdisc_advanced","0")
|
|
|
|
ucic:set("sqm","wan" .. i,"linklayer","none")
|
|
|
|
ucic:set("sqm","wan" .. i,"enabled","0")
|
|
|
|
ucic:set("sqm","wan" .. i,"debug_logging","0")
|
|
|
|
ucic:set("sqm","wan" .. i,"verbosity","5")
|
|
|
|
ucic:set("sqm","wan" .. i,"download","0")
|
|
|
|
ucic:set("sqm","wan" .. i,"upload","0")
|
|
|
|
ucic:save("sqm")
|
|
|
|
ucic:commit("sqm")
|
2018-10-22 17:18:16 +00:00
|
|
|
|
2019-02-19 18:46:08 +00:00
|
|
|
luci.sys.call("uci -q add_list vnstat.@vnstat[-1].interface=" .. wanif)
|
2018-12-04 15:56:02 +00:00
|
|
|
luci.sys.call("uci -q commit vnstat")
|
2018-10-01 18:46:24 +00:00
|
|
|
|
2018-04-20 12:56:19 +00:00
|
|
|
-- Dirty way to add new interface to firewall...
|
|
|
|
luci.sys.call("uci -q add_list firewall.@zone[1].network=wan" .. i)
|
2018-07-05 08:44:47 +00:00
|
|
|
luci.sys.call("uci -q commit firewall")
|
2018-04-20 12:56:19 +00:00
|
|
|
|
|
|
|
luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null")
|
|
|
|
gostatus = false
|
|
|
|
end
|
|
|
|
|
2018-12-12 20:30:15 +00:00
|
|
|
-- Remove existing interface
|
2018-06-15 06:29:35 +00:00
|
|
|
local delete_intf = luci.http.formvaluetable("delete") or ""
|
2018-04-20 12:56:19 +00:00
|
|
|
if delete_intf ~= "" then
|
|
|
|
for intf, _ in pairs(delete_intf) do
|
2019-05-04 05:02:04 +00:00
|
|
|
local defif = ucic:get("network",intf,"ifname")
|
2018-04-20 12:56:19 +00:00
|
|
|
ucic:delete("network",intf)
|
|
|
|
ucic:delete("network",intf .. "_dev")
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
2018-10-01 18:46:24 +00:00
|
|
|
ucic:delete("sqm",intf)
|
|
|
|
ucic:save("sqm")
|
|
|
|
ucic:commit("sqm")
|
|
|
|
ucic:delete("qos",intf)
|
|
|
|
ucic:save("qos")
|
|
|
|
ucic:commit("qos")
|
2019-07-23 15:45:44 +00:00
|
|
|
if defif ~= nil and defif ~= "" then
|
2019-05-04 05:02:04 +00:00
|
|
|
luci.sys.call("uci -q del_list vnstat.@vnstat[-1].interface=" .. defif)
|
|
|
|
end
|
2019-03-20 19:09:28 +00:00
|
|
|
luci.sys.call("uci -q commit vnstat")
|
2019-03-21 06:16:41 +00:00
|
|
|
luci.sys.call("uci -q del_list firewall.@zone[1].network=" .. intf)
|
2019-03-20 19:09:28 +00:00
|
|
|
luci.sys.call("uci -q commit firewall")
|
2018-11-27 14:21:47 +00:00
|
|
|
gostatus = false
|
2018-04-20 12:56:19 +00:00
|
|
|
end
|
|
|
|
end
|
2018-06-07 15:10:52 +00:00
|
|
|
|
|
|
|
-- Set interfaces settings
|
|
|
|
local interfaces = luci.http.formvaluetable("intf")
|
|
|
|
for intf, _ in pairs(interfaces) do
|
2018-11-27 14:21:47 +00:00
|
|
|
local proto = luci.http.formvalue("cbid.network.%s.proto" % intf) or "static"
|
2018-08-08 14:00:11 +00:00
|
|
|
local ipaddr = luci.http.formvalue("cbid.network.%s.ipaddr" % intf) or ""
|
|
|
|
local netmask = luci.http.formvalue("cbid.network.%s.netmask" % intf) or ""
|
|
|
|
local gateway = luci.http.formvalue("cbid.network.%s.gateway" % intf) or ""
|
2019-04-03 21:14:25 +00:00
|
|
|
local sqmenabled = luci.http.formvalue("cbid.sqm.%s.enabled" % intf) or "0"
|
2018-11-27 14:21:47 +00:00
|
|
|
if proto ~= "other" then
|
|
|
|
ucic:set("network",intf,"proto",proto)
|
|
|
|
end
|
2018-06-07 15:10:52 +00:00
|
|
|
ucic:set("network",intf,"ipaddr",ipaddr)
|
|
|
|
ucic:set("network",intf,"netmask",netmask)
|
|
|
|
ucic:set("network",intf,"gateway",gateway)
|
2018-08-02 07:39:43 +00:00
|
|
|
|
2019-05-21 19:35:25 +00:00
|
|
|
ucic:delete("openmptcprouter",intf,"lc")
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
|
2019-10-26 07:16:28 +00:00
|
|
|
local multipathvpn = luci.http.formvalue("multipathvpn.%s.enabled" % intf) or "0"
|
|
|
|
ucic:set("openmptcprouter",intf,"multipathvpn",multipathvpn)
|
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
|
2018-10-26 14:51:30 +00:00
|
|
|
local downloadspeed = luci.http.formvalue("cbid.sqm.%s.download" % intf) or "0"
|
|
|
|
local uploadspeed = luci.http.formvalue("cbid.sqm.%s.upload" % intf) or "0"
|
2019-01-13 10:10:05 +00:00
|
|
|
|
2019-02-06 19:28:14 +00:00
|
|
|
if not ucic:get("qos",intf) ~= "" then
|
2019-01-13 10:10:05 +00:00
|
|
|
ucic:set("qos",intf,"interface")
|
|
|
|
ucic:set("qos",intf,"classgroup","Default")
|
|
|
|
ucic:set("qos",intf,"enabled","0")
|
|
|
|
ucic:set("qos",intf,"upload","4000")
|
|
|
|
ucic:set("qos",intf,"download","100000")
|
|
|
|
end
|
|
|
|
|
2019-02-06 19:28:14 +00:00
|
|
|
if not ucic:get("sqm",intf) ~= "" then
|
2019-04-03 21:14:25 +00:00
|
|
|
local defif = get_device(intf)
|
2019-01-13 10:10:05 +00:00
|
|
|
if defif == "" then
|
|
|
|
defif = ucic:get("network",intf,"ifname") or ""
|
|
|
|
end
|
|
|
|
ucic:set("sqm",intf,"queue")
|
|
|
|
ucic:set("sqm",intf,"interface",defif)
|
|
|
|
ucic:set("sqm",intf,"qdisc","fq_codel")
|
|
|
|
ucic:set("sqm",intf,"script","simple.qos")
|
|
|
|
ucic:set("sqm",intf,"qdisc_advanced","0")
|
|
|
|
ucic:set("sqm",intf,"linklayer","none")
|
|
|
|
ucic:set("sqm",intf,"enabled","0")
|
|
|
|
ucic:set("sqm",intf,"debug_logging","0")
|
|
|
|
ucic:set("sqm",intf,"verbosity","5")
|
|
|
|
ucic:set("sqm",intf,"download","0")
|
|
|
|
ucic:set("sqm",intf,"upload","0")
|
|
|
|
end
|
|
|
|
|
2018-10-26 14:51:30 +00:00
|
|
|
if downloadspeed ~= "0" and uploadspeed ~= "0" then
|
2019-03-22 19:27:13 +00:00
|
|
|
ucic:set("network",intf,"downloadspeed",downloadspeed)
|
|
|
|
ucic:set("network",intf,"uploadspeed",uploadspeed)
|
2019-04-04 07:40:08 +00:00
|
|
|
ucic:set("sqm",intf,"download",math.ceil(downloadspeed*95/100))
|
|
|
|
ucic:set("sqm",intf,"upload",math.ceil(uploadspeed*95/100))
|
|
|
|
ucic:set("qos",intf,"download",math.ceil(downloadspeed*95/100))
|
|
|
|
ucic:set("qos",intf,"upload",math.ceil(uploadspeed*95/100))
|
2019-04-03 21:14:25 +00:00
|
|
|
else
|
|
|
|
ucic:set("sqm",intf,"download","0")
|
|
|
|
ucic:set("sqm",intf,"upload","0")
|
|
|
|
ucic:set("sqm",intf,"enabled","0")
|
|
|
|
ucic:set("qos",intf,"download","0")
|
|
|
|
ucic:set("qos",intf,"upload","0")
|
|
|
|
ucic:set("qos",intf,"enabled","0")
|
2018-08-02 07:39:43 +00:00
|
|
|
end
|
2019-08-15 17:11:18 +00:00
|
|
|
if sqmenabled == "1" then
|
|
|
|
ucic:set("sqm",intf,"enabled","1")
|
|
|
|
ucic:set("qos",intf,"enabled","1")
|
|
|
|
else
|
|
|
|
ucic:set("sqm",intf,"enabled","0")
|
|
|
|
ucic:set("qos",intf,"enabled","0")
|
|
|
|
end
|
2018-06-07 15:10:52 +00:00
|
|
|
end
|
2019-06-23 06:09:02 +00:00
|
|
|
-- Disable multipath on LAN, VPN and loopback
|
|
|
|
ucic:set("network","loopback","multipath","off")
|
|
|
|
ucic:set("network","lan","multipath","off")
|
|
|
|
ucic:set("network","omr6in4","multipath","off")
|
|
|
|
ucic:set("network","omrvpn","multipath","off")
|
|
|
|
|
2018-08-02 07:39:43 +00:00
|
|
|
ucic:save("sqm")
|
|
|
|
ucic:commit("sqm")
|
2018-08-20 12:02:56 +00:00
|
|
|
ucic:save("qos")
|
|
|
|
ucic:commit("qos")
|
2018-06-07 15:10:52 +00:00
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
2018-04-12 13:18:56 +00:00
|
|
|
|
2018-08-16 14:57:34 +00:00
|
|
|
-- Enable/disable IPv6
|
2019-10-09 16:40:05 +00:00
|
|
|
local disableipv6 = luci.http.formvalue("enableipv6") or "1"
|
|
|
|
ucic:set("openmptcprouter","settings","disable_ipv6",disable_ipv6)
|
|
|
|
--local ut = require "luci.util"
|
|
|
|
--local result = ut.ubus("openmptcprouter", "set_ipv6_state", { disable_ipv6 = disableipv6 })
|
2019-03-06 17:24:22 +00:00
|
|
|
|
2018-06-26 16:07:36 +00:00
|
|
|
-- Get VPN set by default
|
|
|
|
local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp"
|
2018-07-02 11:52:36 +00:00
|
|
|
local vpn_port = ""
|
|
|
|
local vpn_intf = ""
|
2018-06-26 16:07:36 +00:00
|
|
|
if default_vpn:match("^glorytun.*") then
|
|
|
|
vpn_port = 65001
|
2018-07-02 11:52:36 +00:00
|
|
|
vpn_intf = "tun0"
|
2019-07-05 16:20:39 +00:00
|
|
|
--ucic:set("network","omrvpn","proto","dhcp")
|
|
|
|
ucic:set("network","omrvpn","proto","none")
|
2018-06-26 16:07:36 +00:00
|
|
|
elseif default_vpn == "mlvpn" then
|
|
|
|
vpn_port = 65201
|
2018-07-02 11:52:36 +00:00
|
|
|
vpn_intf = "mlvpn0"
|
2019-01-03 16:40:19 +00:00
|
|
|
ucic:set("network","omrvpn","proto","dhcp")
|
2019-10-27 07:42:52 +00:00
|
|
|
elseif default_vpn == "ubond" then
|
|
|
|
vpn_port = 65201
|
|
|
|
vpn_intf = "ubond0"
|
|
|
|
ucic:set("network","omrvpn","proto","dhcp")
|
2019-08-02 20:37:45 +00:00
|
|
|
elseif default_vpn == "dsvpn" then
|
|
|
|
vpn_port = 65011
|
|
|
|
vpn_intf = "tun0"
|
|
|
|
ucic:set("network","omrvpn","proto","none")
|
2018-06-26 16:07:36 +00:00
|
|
|
elseif default_vpn == "openvpn" then
|
|
|
|
vpn_port = 65301
|
2018-07-02 11:52:36 +00:00
|
|
|
vpn_intf = "tun0"
|
2019-01-03 16:40:19 +00:00
|
|
|
ucic:set("network","omrvpn","proto","dhcp")
|
2018-07-02 11:52:36 +00:00
|
|
|
end
|
|
|
|
if vpn_intf ~= "" then
|
|
|
|
ucic:set("network","omrvpn","ifname",vpn_intf)
|
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
2018-06-26 16:07:36 +00:00
|
|
|
end
|
|
|
|
|
2018-12-12 20:30:15 +00:00
|
|
|
-- Retrieve all server settings
|
|
|
|
local serversnb = 0
|
|
|
|
local servers = luci.http.formvaluetable("server")
|
|
|
|
for server, _ in pairs(servers) do
|
|
|
|
local server_ip = luci.http.formvalue("%s.server_ip" % server) or ""
|
2019-01-14 17:13:04 +00:00
|
|
|
local master = luci.http.formvalue("master") or ""
|
2018-12-12 20:30:15 +00:00
|
|
|
|
|
|
|
-- OpenMPTCProuter VPS
|
|
|
|
local openmptcprouter_vps_key = luci.http.formvalue("%s.openmptcprouter_vps_key" % server) or ""
|
2019-11-03 18:22:51 +00:00
|
|
|
local openmptcprouter_vps_username = luci.http.formvalue("%s.openmptcprouter_vps_username" % server) or ""
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("openmptcprouter",server,"server")
|
2019-11-03 18:22:51 +00:00
|
|
|
ucic:set("openmptcprouter",server,"username",openmptcprouter_vps_username)
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("openmptcprouter",server,"password",openmptcprouter_vps_key)
|
2019-01-14 17:38:26 +00:00
|
|
|
if master == server or (master == "" and serversnb == 0) then
|
2018-12-14 12:19:58 +00:00
|
|
|
ucic:set("openmptcprouter",server,"get_config","1")
|
2019-01-14 17:13:04 +00:00
|
|
|
ucic:set("openmptcprouter",server,"master","1")
|
|
|
|
ucic:set("openmptcprouter",server,"backup","0")
|
2018-12-14 12:19:58 +00:00
|
|
|
else
|
|
|
|
ucic:set("openmptcprouter",server,"get_config","0")
|
2019-01-14 17:13:04 +00:00
|
|
|
ucic:set("openmptcprouter",server,"master","0")
|
|
|
|
ucic:set("openmptcprouter",server,"backup","1")
|
2018-12-14 12:19:58 +00:00
|
|
|
end
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("openmptcprouter",server,"ip",server_ip)
|
2018-12-13 15:46:40 +00:00
|
|
|
ucic:set("openmptcprouter",server,"port","65500")
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
if server_ip ~= "" then
|
|
|
|
serversnb = serversnb + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local ss_servers_nginx = {}
|
|
|
|
local ss_servers_ha = {}
|
|
|
|
local vpn_servers = {}
|
|
|
|
local k = 0
|
|
|
|
local ss_ip
|
|
|
|
|
|
|
|
for server, _ in pairs(servers) do
|
2019-01-14 17:13:04 +00:00
|
|
|
local master = luci.http.formvalue("master") or ""
|
2019-01-07 06:54:18 +00:00
|
|
|
local server_ip = luci.http.formvalue("%s.server_ip" % server) or ""
|
2018-12-12 20:30:15 +00:00
|
|
|
-- We have an IP, so set it everywhere
|
|
|
|
if server_ip ~= "" then
|
|
|
|
-- Check if we have more than one IP, in this case use Nginx HA
|
|
|
|
if serversnb > 1 then
|
2019-01-14 17:13:04 +00:00
|
|
|
if master == server then
|
2018-12-12 20:30:15 +00:00
|
|
|
ss_ip=server_ip
|
2018-12-14 12:19:58 +00:00
|
|
|
table.insert(ss_servers_nginx,server_ip .. ":65101 max_fails=2 fail_timeout=20s")
|
2018-12-12 20:59:08 +00:00
|
|
|
table.insert(ss_servers_ha,server_ip .. ":65101 check")
|
2018-07-02 11:52:36 +00:00
|
|
|
if vpn_port ~= "" then
|
2018-12-14 12:19:58 +00:00
|
|
|
table.insert(vpn_servers,server_ip .. ":" .. vpn_port .. " max_fails=2 fail_timeout=20s")
|
2018-07-02 11:52:36 +00:00
|
|
|
end
|
2018-06-26 16:07:36 +00:00
|
|
|
else
|
2018-12-12 20:30:15 +00:00
|
|
|
table.insert(ss_servers_nginx,server_ip .. ":65101 backup")
|
2018-12-12 20:59:08 +00:00
|
|
|
table.insert(ss_servers_ha,server_ip .. ":65101 backup")
|
2018-07-02 11:52:36 +00:00
|
|
|
if vpn_port ~= "" then
|
2018-12-12 20:30:15 +00:00
|
|
|
table.insert(vpn_servers,server_ip .. ":" .. vpn_port .. " backup")
|
2018-07-02 11:52:36 +00:00
|
|
|
end
|
2018-06-26 16:07:36 +00:00
|
|
|
end
|
|
|
|
k = k + 1
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("nginx-ha","ShadowSocks","enable","1")
|
|
|
|
ucic:set("nginx-ha","VPN","enable","1")
|
|
|
|
ucic:set("nginx-ha","ShadowSocks","upstreams",ss_servers_nginx)
|
|
|
|
ucic:set("nginx-ha","VPN","upstreams",vpn_servers)
|
|
|
|
ucic:set("haproxy-tcp","general","enable","0")
|
|
|
|
ucic:set("haproxy-tcp","general","upstreams",ss_servers_ha)
|
2019-09-17 17:52:48 +00:00
|
|
|
ucic:set("openmptcprouter","settings","ha","1")
|
2018-12-12 20:30:15 +00:00
|
|
|
server_ip = "127.0.0.1"
|
|
|
|
--ucic:set("shadowsocks-libev","sss0","server",ss_ip)
|
|
|
|
else
|
2019-09-17 17:52:48 +00:00
|
|
|
ucic:set("openmptcprouter","settings","ha","0")
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("nginx-ha","ShadowSocks","enable","0")
|
|
|
|
ucic:set("nginx-ha","VPN","enable","0")
|
|
|
|
--ucic:set("shadowsocks-libev","sss0","server",server_ip)
|
|
|
|
--ucic:set("openmptcprouter","vps","ip",server_ip)
|
|
|
|
--ucic:save("openmptcprouter")
|
2018-06-26 16:07:36 +00:00
|
|
|
end
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("shadowsocks-libev","sss0","server",server_ip)
|
|
|
|
ucic:set("glorytun","vpn","host",server_ip)
|
2019-08-02 20:37:45 +00:00
|
|
|
ucic:set("dsvpn","vpn","host",server_ip)
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:set("mlvpn","general","host",server_ip)
|
2019-10-27 07:42:52 +00:00
|
|
|
ucic:set("ubond","general","host",server_ip)
|
2018-12-12 20:30:15 +00:00
|
|
|
luci.sys.call("uci -q del openvpn.omr.remote")
|
|
|
|
luci.sys.call("uci -q add_list openvpn.omr.remote=" .. server_ip)
|
2018-06-26 16:07:36 +00:00
|
|
|
ucic:set("qos","serverin","srchost",server_ip)
|
|
|
|
ucic:set("qos","serverout","dsthost",server_ip)
|
|
|
|
end
|
2018-06-07 14:51:37 +00:00
|
|
|
end
|
|
|
|
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:save("qos")
|
|
|
|
ucic:commit("qos")
|
|
|
|
ucic:save("nginx-ha")
|
|
|
|
ucic:commit("nginx-ha")
|
|
|
|
ucic:save("openvpn")
|
2019-09-22 06:33:54 +00:00
|
|
|
--ucic:commit("openvpn")
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:save("mlvpn")
|
2019-10-27 07:42:52 +00:00
|
|
|
ucic:save("ubond")
|
2019-09-22 06:33:54 +00:00
|
|
|
--ucic:commit("mlvpn")
|
2019-08-02 20:37:45 +00:00
|
|
|
ucic:save("dsvpn")
|
2019-09-22 06:33:54 +00:00
|
|
|
--ucic:commit("dsvpn")
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:save("glorytun")
|
2019-09-22 06:33:54 +00:00
|
|
|
--ucic:commit("glorytun")
|
2018-12-12 20:30:15 +00:00
|
|
|
ucic:save("shadowsocks-libev")
|
2019-09-22 06:33:54 +00:00
|
|
|
--ucic:commit("shadowsocks-libev")
|
2018-12-12 20:30:15 +00:00
|
|
|
|
|
|
|
|
2019-09-22 06:33:54 +00:00
|
|
|
local encryption = luci.http.formvalue("encryption")
|
|
|
|
if encryption == "none" then
|
|
|
|
ucic:set("shadowsocks-libev","sss0","method","none")
|
|
|
|
elseif encryption == "aes-256-gcm" then
|
|
|
|
ucic:set("shadowsocks-libev","sss0","method","aes-256-gcm")
|
|
|
|
ucic:set("glorytun","vpn","chacha20","0")
|
2019-11-01 08:15:51 +00:00
|
|
|
elseif encryption == "chacha20-ietf-poly1305" then
|
|
|
|
ucic:set("shadowsocks-libev","sss0","method","chacha20-ietf-poly1305")
|
2019-09-22 06:33:54 +00:00
|
|
|
ucic:set("glorytun","vpn","chacha20","1")
|
|
|
|
end
|
|
|
|
|
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")
|
2018-11-27 14:21:47 +00:00
|
|
|
local shadowsocks_disable = luci.http.formvalue("disableshadowsocks") or "0"
|
2018-03-23 19:23:27 +00:00
|
|
|
if shadowsocks_key ~= "" then
|
|
|
|
ucic:set("shadowsocks-libev","sss0","key",shadowsocks_key)
|
2019-11-01 08:15:51 +00:00
|
|
|
--ucic:set("shadowsocks-libev","sss0","method","chacha20-ietf-poly1305")
|
2019-01-14 16:26:36 +00:00
|
|
|
--ucic:set("shadowsocks-libev","sss0","server_port","65101")
|
2018-11-27 14:21:47 +00:00
|
|
|
ucic:set("shadowsocks-libev","sss0","disabled",shadowsocks_disable)
|
2018-03-23 19:23:27 +00:00
|
|
|
ucic:save("shadowsocks-libev")
|
|
|
|
ucic:commit("shadowsocks-libev")
|
2019-08-12 14:42:30 +00:00
|
|
|
if shadowsocks_disable == "1" then
|
|
|
|
luci.sys.call("/etc/init.d/shadowsocks rules_down >/dev/null 2>/dev/null")
|
|
|
|
end
|
2018-06-08 12:53:35 +00:00
|
|
|
else
|
|
|
|
ucic:set("shadowsocks-libev","sss0","key","")
|
2018-11-27 14:21:47 +00:00
|
|
|
ucic:set("shadowsocks-libev","sss0","disabled",shadowsocks_disable)
|
2018-06-08 12:53:35 +00:00
|
|
|
ucic:save("shadowsocks-libev")
|
|
|
|
ucic:commit("shadowsocks-libev")
|
2018-09-19 13:28:32 +00:00
|
|
|
luci.sys.call("/etc/init.d/shadowsocks rules_down >/dev/null 2>/dev/null")
|
2018-03-23 19:23:27 +00:00
|
|
|
end
|
2018-04-12 13:18:56 +00:00
|
|
|
|
2018-06-12 17:26:32 +00:00
|
|
|
-- Set Glorytun settings
|
|
|
|
if default_vpn:match("^glorytun.*") then
|
|
|
|
ucic:set("glorytun","vpn","enable",1)
|
|
|
|
else
|
|
|
|
ucic:set("glorytun","vpn","enable",0)
|
|
|
|
end
|
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
local glorytun_key = luci.http.formvalue("glorytun_key")
|
2018-03-23 19:23:27 +00:00
|
|
|
if glorytun_key ~= "" then
|
|
|
|
ucic:set("glorytun","vpn","port","65001")
|
|
|
|
ucic:set("glorytun","vpn","key",glorytun_key)
|
|
|
|
ucic:set("glorytun","vpn","mptcp",1)
|
2018-06-11 08:21:48 +00:00
|
|
|
if default_vpn == "glorytun_udp" then
|
|
|
|
ucic:set("glorytun","vpn","proto","udp")
|
2019-07-29 15:31:34 +00:00
|
|
|
ucic:set("glorytun","vpn","localip","10.255.254.2")
|
|
|
|
ucic:set("glorytun","vpn","remoteip","10.255.254.1")
|
|
|
|
ucic:set("network","omr6in4","ipaddr","10.255.254.2")
|
|
|
|
ucic:set("network","omr6in4","peeraddr","10.255.254.1")
|
2018-06-11 08:21:48 +00:00
|
|
|
else
|
|
|
|
ucic:set("glorytun","vpn","proto","tcp")
|
2019-07-29 15:31:34 +00:00
|
|
|
ucic:set("glorytun","vpn","localip","10.255.255.2")
|
|
|
|
ucic:set("glorytun","vpn","remoteip","10.255.255.1")
|
|
|
|
ucic:set("network","omr6in4","ipaddr","10.255.255.2")
|
|
|
|
ucic:set("network","omr6in4","peeraddr","10.255.255.1")
|
2018-06-11 08:21:48 +00:00
|
|
|
end
|
2019-07-29 15:31:34 +00:00
|
|
|
ucic:set("network","omrvpn","proto","none")
|
2018-06-08 12:53:35 +00:00
|
|
|
else
|
|
|
|
ucic:set("glorytun","vpn","key","")
|
2019-08-05 14:58:17 +00:00
|
|
|
--ucic:set("glorytun","vpn","enable",0)
|
2018-06-08 12:53:35 +00:00
|
|
|
ucic:set("glorytun","vpn","proto","tcp")
|
2018-03-23 19:23:27 +00:00
|
|
|
end
|
2018-12-04 15:56:02 +00:00
|
|
|
ucic:save("glorytun")
|
|
|
|
ucic:commit("glorytun")
|
2018-03-23 19:23:27 +00:00
|
|
|
|
2019-08-02 20:37:45 +00:00
|
|
|
-- Set A Dead Simple VPN settings
|
|
|
|
if default_vpn == "dsvpn" then
|
|
|
|
ucic:set("dsvpn","vpn","enable",1)
|
|
|
|
else
|
|
|
|
ucic:set("dsvpn","vpn","enable",0)
|
|
|
|
end
|
|
|
|
|
|
|
|
local dsvpn_key = luci.http.formvalue("dsvpn_key")
|
|
|
|
if dsvpn_key ~= "" then
|
|
|
|
ucic:set("dsvpn","vpn","port","65011")
|
|
|
|
ucic:set("dsvpn","vpn","key",dsvpn_key)
|
2019-08-07 21:09:02 +00:00
|
|
|
ucic:set("dsvpn","vpn","localip","10.255.251.2")
|
|
|
|
ucic:set("dsvpn","vpn","remoteip","10.255.251.1")
|
2019-08-02 20:37:45 +00:00
|
|
|
ucic:set("network","omr6in4","ipaddr","10.255.251.2")
|
|
|
|
ucic:set("network","omr6in4","peeraddr","10.255.251.1")
|
|
|
|
ucic:set("network","omrvpn","proto","none")
|
|
|
|
else
|
|
|
|
ucic:set("dsvpn","vpn","key","")
|
2019-08-05 14:58:17 +00:00
|
|
|
--ucic:set("dsvpn","vpn","enable",0)
|
2019-08-02 20:37:45 +00:00
|
|
|
end
|
|
|
|
ucic:save("dsvpn")
|
|
|
|
ucic:commit("dsvpn")
|
|
|
|
|
2018-06-07 14:51:37 +00:00
|
|
|
-- Set MLVPN settings
|
2018-06-12 17:26:32 +00:00
|
|
|
if default_vpn == "mlvpn" then
|
|
|
|
ucic:set("mlvpn","general","enable",1)
|
2019-07-29 15:31:34 +00:00
|
|
|
ucic:set("network","omrvpn","proto","dhcp")
|
2018-06-12 17:26:32 +00:00
|
|
|
else
|
|
|
|
ucic:set("mlvpn","general","enable",0)
|
|
|
|
end
|
|
|
|
|
2018-06-07 14:51:37 +00:00
|
|
|
local mlvpn_password = luci.http.formvalue("mlvpn_password")
|
|
|
|
if mlvpn_password ~= "" then
|
|
|
|
ucic:set("mlvpn","general","password",mlvpn_password)
|
|
|
|
ucic:set("mlvpn","general","firstport","65201")
|
|
|
|
ucic:set("mlvpn","general","interface_name","mlvpn0")
|
2018-06-08 12:53:35 +00:00
|
|
|
else
|
2018-11-27 14:21:47 +00:00
|
|
|
--ucic:set("mlvpn","general","enable",0)
|
2018-06-08 12:53:35 +00:00
|
|
|
ucic:set("mlvpn","general","password","")
|
2018-06-07 14:51:37 +00:00
|
|
|
end
|
2018-12-04 15:56:02 +00:00
|
|
|
ucic:save("mlvpn")
|
|
|
|
ucic:commit("mlvpn")
|
2018-06-07 14:51:37 +00:00
|
|
|
|
2019-10-27 07:42:52 +00:00
|
|
|
-- Set UBOND settings
|
|
|
|
if default_vpn == "ubond" then
|
|
|
|
ucic:set("ubond","general","enable",1)
|
|
|
|
ucic:set("network","omrvpn","proto","dhcp")
|
|
|
|
else
|
|
|
|
ucic:set("ubond","general","enable",0)
|
|
|
|
end
|
|
|
|
|
|
|
|
local ubond_password = luci.http.formvalue("ubond_password")
|
|
|
|
if ubond_password ~= "" then
|
|
|
|
ucic:set("ubond","general","password",ubond_password)
|
|
|
|
ucic:set("ubond","general","firstport","65201")
|
|
|
|
ucic:set("ubond","general","interface_name","ubond0")
|
|
|
|
else
|
|
|
|
--ucic:set("ubond","general","enable",0)
|
|
|
|
ucic:set("ubond","general","password","")
|
|
|
|
end
|
|
|
|
ucic:save("ubond")
|
|
|
|
ucic:commit("ubond")
|
|
|
|
|
2018-06-12 17:22:55 +00:00
|
|
|
if default_vpn == "openvpn" then
|
|
|
|
ucic:set("openvpn","omr","enabled",1)
|
2019-11-06 17:10:30 +00:00
|
|
|
ucic:set("network","omrvpn","proto","none")
|
2018-06-12 17:26:32 +00:00
|
|
|
else
|
|
|
|
ucic:set("openvpn","omr","enabled",0)
|
2018-06-12 17:22:55 +00:00
|
|
|
end
|
2018-12-04 15:56:02 +00:00
|
|
|
ucic:save("openvpn")
|
|
|
|
ucic:commit("openvpn")
|
2019-07-29 15:31:34 +00:00
|
|
|
ucic:save("network")
|
|
|
|
ucic:commit("network")
|
2018-06-12 17:22:55 +00:00
|
|
|
|
2018-11-27 14:21:47 +00:00
|
|
|
-- OpenMPTCProuter VPS
|
2018-12-12 20:30:15 +00:00
|
|
|
--local openmptcprouter_vps_key = luci.http.formvalue("openmptcprouter_vps_key") or ""
|
|
|
|
--ucic:set("openmptcprouter","vps","username","openmptcprouter")
|
|
|
|
--ucic:set("openmptcprouter","vps","password",openmptcprouter_vps_key)
|
|
|
|
--ucic:set("openmptcprouter","vps","get_config","1")
|
2018-11-27 14:21:47 +00:00
|
|
|
local shadowsocks_disable = luci.http.formvalue("disableshadowsocks") or "0"
|
|
|
|
ucic:set("openmptcprouter","settings","shadowsocks_disable",shadowsocks_disable)
|
|
|
|
ucic:set("openmptcprouter","settings","vpn",default_vpn)
|
2018-12-13 12:54:06 +00:00
|
|
|
ucic:delete("openmptcprouter","settings","master_lcintf")
|
2018-11-27 14:21:47 +00:00
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
|
2018-11-02 19:20:53 +00:00
|
|
|
-- Restart all
|
2018-03-23 19:23:27 +00:00
|
|
|
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
|
2018-12-11 12:24:22 +00:00
|
|
|
luci.sys.call("/etc/init.d/mptcp restart >/dev/null 2>/dev/null")
|
2018-11-27 14:21:47 +00:00
|
|
|
if openmptcprouter_vps_key ~= "" then
|
|
|
|
luci.sys.call("/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null")
|
|
|
|
os.execute("sleep 2")
|
|
|
|
end
|
2019-07-23 16:40:58 +00:00
|
|
|
luci.sys.call("/etc/init.d/shadowsocks-libev restart >/dev/null 2>/dev/null")
|
2018-06-14 21:09:43 +00:00
|
|
|
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
|
|
|
|
luci.sys.call("/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null")
|
2019-09-02 16:01:06 +00:00
|
|
|
luci.sys.call("/etc/init.d/mlvpn restart >/dev/null 2>/dev/null")
|
2019-10-27 07:42:52 +00:00
|
|
|
luci.sys.call("/etc/init.d/ubond restart >/dev/null 2>/dev/null")
|
2018-06-14 21:09:43 +00:00
|
|
|
luci.sys.call("/etc/init.d/openvpn restart >/dev/null 2>/dev/null")
|
2019-09-02 16:01:06 +00:00
|
|
|
luci.sys.call("/etc/init.d/dsvpn restart >/dev/null 2>/dev/null")
|
2018-12-28 12:18:20 +00:00
|
|
|
luci.sys.call("/etc/init.d/omr-tracker restart >/dev/null 2>/dev/null")
|
2019-02-13 06:42:27 +00:00
|
|
|
luci.sys.call("/etc/init.d/omr-6in4 restart >/dev/null 2>/dev/null")
|
2018-06-07 14:51:37 +00:00
|
|
|
if gostatus == true then
|
2018-04-20 12:56:19 +00:00
|
|
|
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()
|
2018-11-27 14:21:47 +00:00
|
|
|
-- Redirects all ports from VPS to OpenMPTCProuter
|
2019-01-07 06:54:18 +00:00
|
|
|
local servers = luci.http.formvaluetable("server")
|
2018-12-21 15:20:20 +00:00
|
|
|
local redirect_ports = luci.http.formvaluetable("redirect_ports")
|
2019-01-07 06:54:18 +00:00
|
|
|
for server, _ in pairs(servers) do
|
2019-09-07 22:46:18 +00:00
|
|
|
local redirectports = luci.http.formvalue("redirect_ports.%s" % server) or "0"
|
|
|
|
ucic:set("openmptcprouter",server,"redirect_ports",redirectports)
|
2019-10-01 17:43:36 +00:00
|
|
|
local nofwredirect = luci.http.formvalue("nofwredirect.%s" % server) or "0"
|
|
|
|
ucic:set("openmptcprouter",server,"nofwredirect",nofwredirect)
|
2018-12-21 15:20:20 +00:00
|
|
|
end
|
2018-11-27 14:21:47 +00:00
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
-- 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)
|
2018-06-13 06:36:20 +00:00
|
|
|
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)
|
2018-07-22 13:23:02 +00:00
|
|
|
|
|
|
|
-- Set tcp_fin_timeout
|
|
|
|
local tcp_fin_timeout = luci.http.formvalue("tcp_fin_timeout")
|
2018-12-17 15:59:48 +00:00
|
|
|
luci.sys.exec("sysctl -w net.ipv4.tcp_fin_timeout=%s" % tcp_fin_timeout)
|
2018-07-22 13:23:02 +00:00
|
|
|
luci.sys.exec("sed -i 's:^net.ipv4.tcp_fin_timeout=[0-9]*:net.ipv4.tcp_fin_timeout=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % tcp_fin_timeout)
|
2018-12-23 13:14:28 +00:00
|
|
|
|
|
|
|
-- Set tcp_syn_retries
|
|
|
|
local tcp_syn_retries = luci.http.formvalue("tcp_syn_retries")
|
|
|
|
luci.sys.exec("sysctl -w net.ipv4.tcp_syn_retries=%s" % tcp_syn_retries)
|
|
|
|
luci.sys.exec("sed -i 's:^net.ipv4.tcp_syn_retries=[0-9]*:net.ipv4.tcp_syn_retries=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % tcp_syn_retries)
|
2018-04-12 13:18:56 +00:00
|
|
|
|
2019-01-17 19:43:53 +00:00
|
|
|
-- Set tcp_fastopen
|
|
|
|
local tcp_fastopen = luci.http.formvalue("tcp_fastopen")
|
2019-07-25 07:24:45 +00:00
|
|
|
local disablefastopen = luci.http.formvalue("disablefastopen") or "0"
|
|
|
|
if disablefastopen == "1" then
|
2019-07-15 20:36:24 +00:00
|
|
|
tcp_fastopen = "0"
|
2019-07-25 07:24:45 +00:00
|
|
|
elseif tcp_fastopen == "0" and disablefastopen == "0" then
|
2019-07-15 20:36:24 +00:00
|
|
|
tcp_fastopen = "3"
|
|
|
|
end
|
2019-01-17 19:43:53 +00:00
|
|
|
luci.sys.exec("sysctl -w net.ipv4.tcp_fastopen=%s" % tcp_fastopen)
|
|
|
|
luci.sys.exec("sed -i 's:^net.ipv4.tcp_fastopen=[0-3]*:net.ipv4.tcp_fastopen=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % tcp_fastopen)
|
2019-09-29 17:34:01 +00:00
|
|
|
ucic:set("openmptcprouter", "settings","disable_fastopen", disablefastopen)
|
2019-01-17 19:43:53 +00:00
|
|
|
|
2018-04-12 13:18:56 +00:00
|
|
|
-- Disable IPv6
|
2019-02-05 20:06:16 +00:00
|
|
|
local disable_ipv6 = luci.http.formvalue("enableipv6") or "1"
|
2019-10-04 19:30:57 +00:00
|
|
|
local dump = require("luci.util").ubus("openmptcprouter", "disableipv6", { disable_ipv6 = tonumber(disable_ipv6)})
|
2018-07-09 12:55:42 +00:00
|
|
|
|
2019-04-15 20:14:35 +00:00
|
|
|
-- Enable/disable external check
|
|
|
|
local externalcheck = luci.http.formvalue("externalcheck") or "1"
|
|
|
|
ucic:set("openmptcprouter","settings","external_check",externalcheck)
|
|
|
|
|
2019-07-22 15:47:48 +00:00
|
|
|
-- Enable/disable external check
|
|
|
|
local savevnstat = luci.http.formvalue("savevnstat") or "0"
|
|
|
|
luci.sys.exec("uci -q set vnstat.@vnstat[0].backup=%s" % savevnstat)
|
2019-08-16 08:33:38 +00:00
|
|
|
ucic:commit("vnstat")
|
|
|
|
|
|
|
|
-- Enable/disable gateway ping
|
|
|
|
local disablegwping = luci.http.formvalue("disablegwping") or "0"
|
|
|
|
ucic:set("openmtpcprouter","settings","disablegwping",disablegwping)
|
|
|
|
|
|
|
|
-- Enable/disable server ping
|
|
|
|
local disableserverping = luci.http.formvalue("disableserverping") or "0"
|
|
|
|
ucic:set("openmtpcprouter","settings","disableserverping",disableserverping)
|
2019-07-22 15:47:48 +00:00
|
|
|
|
2019-07-15 20:36:24 +00:00
|
|
|
-- Enable/disable fast open
|
2019-07-25 07:24:45 +00:00
|
|
|
local disablefastopen = luci.http.formvalue("disablefastopen") or "0"
|
|
|
|
if disablefastopen == "0" then
|
|
|
|
fastopen = "1"
|
|
|
|
else
|
|
|
|
fastopen = "0"
|
|
|
|
end
|
2019-07-15 20:36:24 +00:00
|
|
|
ucic:foreach("shadowsocks-libev", "ss_redir", function (section)
|
|
|
|
ucic:set("shadowsocks-libev",section[".name"],"fast_open",fastopen)
|
|
|
|
end)
|
|
|
|
ucic:foreach("shadowsocks-libev", "ss_local", function (section)
|
|
|
|
ucic:set("shadowsocks-libev",section[".name"],"fast_open",fastopen)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2018-11-02 19:20:53 +00:00
|
|
|
-- Enable/disable obfs
|
2019-02-19 18:46:08 +00:00
|
|
|
local obfs = luci.http.formvalue("obfs") or "0"
|
2019-01-26 12:51:53 +00:00
|
|
|
local obfs_plugin = luci.http.formvalue("obfs_plugin") or "v2ray"
|
2019-04-15 20:14:35 +00:00
|
|
|
local obfs_type = luci.http.formvalue("obfs_type") or "http"
|
2019-06-17 16:30:39 +00:00
|
|
|
ucic:foreach("shadowsocks-libev", "server", function (section)
|
2018-07-09 12:55:42 +00:00
|
|
|
ucic:set("shadowsocks-libev",section[".name"],"obfs",obfs)
|
2019-01-26 12:51:53 +00:00
|
|
|
ucic:set("shadowsocks-libev",section[".name"],"obfs_plugin",obfs_plugin)
|
2019-04-15 20:14:35 +00:00
|
|
|
ucic:set("shadowsocks-libev",section[".name"],"obfs_type",obfs_type)
|
2018-07-09 12:55:42 +00:00
|
|
|
end)
|
2018-04-25 10:27:07 +00:00
|
|
|
ucic:save("shadowsocks-libev")
|
|
|
|
ucic:commit("shadowsocks-libev")
|
2018-10-31 11:39:40 +00:00
|
|
|
|
|
|
|
-- Set master to dynamic or static
|
|
|
|
local master_type = luci.http.formvalue("master_type") or "static"
|
|
|
|
ucic:set("openmptcprouter","settings","master",master_type)
|
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
end
|
2018-04-17 12:48:55 +00:00
|
|
|
|
2018-10-31 11:39:40 +00:00
|
|
|
ucic:save("openmptcprouter")
|
|
|
|
ucic:commit("openmptcprouter")
|
|
|
|
|
2018-11-02 19:20:53 +00:00
|
|
|
-- Apply all settings
|
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-12-06 12:50:56 +00:00
|
|
|
function update_vps()
|
|
|
|
-- Update VPS
|
|
|
|
local update_vps = luci.http.formvalue("flash") or ""
|
|
|
|
if update_vps ~= "" then
|
2019-08-09 15:19:05 +00:00
|
|
|
local ut = require "luci.util"
|
|
|
|
local result = ut.ubus("openmptcprouter", "update_vps", {})
|
2018-07-24 15:08:27 +00:00
|
|
|
end
|
2019-10-29 19:09:20 +00:00
|
|
|
return
|
2018-05-03 13:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-10-09 16:40:05 +00:00
|
|
|
function backupgr()
|
|
|
|
local get_backup = luci.http.formvalue("restore") or ""
|
|
|
|
if get_backup ~= "" then
|
|
|
|
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_get >/dev/null 2>/dev/null")
|
|
|
|
end
|
|
|
|
local send_backup = luci.http.formvalue("save") or ""
|
|
|
|
if send_backup ~= "" then
|
|
|
|
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_send >/dev/null 2>/dev/null")
|
|
|
|
end
|
2019-10-29 19:09:20 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/backup"))
|
|
|
|
return
|
2019-10-09 16:40:05 +00:00
|
|
|
end
|
|
|
|
|
2018-06-15 20:40:10 +00:00
|
|
|
function get_device(interface)
|
|
|
|
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
|
|
|
|
return dump['l3_device']
|
|
|
|
end
|
|
|
|
|
2019-11-07 08:41:09 +00:00
|
|
|
-- This function come from modules/luci-bbase/luasrc/tools/status.lua from old OpenWrt
|
|
|
|
-- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
|
|
|
|
-- Licensed to the public under the Apache License 2.0.
|
|
|
|
local function dhcp_leases_common(family)
|
|
|
|
local rv = { }
|
|
|
|
local nfs = require "nixio.fs"
|
|
|
|
local sys = require "luci.sys"
|
|
|
|
local leasefile = "/tmp/dhcp.leases"
|
|
|
|
|
|
|
|
ucic: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"
|
|
|
|
ucic: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
|
|
|
|
|
2018-03-28 08:57:02 +00:00
|
|
|
function interfaces_status()
|
2019-08-07 21:09:02 +00:00
|
|
|
local ut = require "luci.util"
|
2019-08-09 15:19:05 +00:00
|
|
|
local mArray = ut.ubus("openmptcprouter", "status", {}) or {_=0}
|
2018-06-18 21:58:02 +00:00
|
|
|
|
2019-08-26 19:07:36 +00:00
|
|
|
if mArray ~= nil and mArray.openmptcprouter ~= nil then
|
2019-08-17 18:21:10 +00:00
|
|
|
mArray.openmptcprouter["remote_addr"] = luci.http.getenv("REMOTE_ADDR") or ""
|
|
|
|
mArray.openmptcprouter["remote_from_lease"] = false
|
2019-11-07 08:41:09 +00:00
|
|
|
local leases=dhcp_leases_common(4)
|
2019-08-17 18:21:10 +00:00
|
|
|
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
|
2018-03-28 08:57:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
|
|
|
luci.http.write_json(mArray)
|
2018-05-18 07:40:50 +00:00
|
|
|
end
|