1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-12 18:41:51 +00:00

Support 2 IPs on server

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-01-28 20:43:01 +01:00
parent 1518776a8b
commit 4f6b1d263e
2 changed files with 68 additions and 12 deletions

View file

@ -66,7 +66,8 @@ function wizard_add()
ucic:foreach("openmptcprouter", "server", function(s)
local servername = s[".name"]
nbserver = nbserver + 1
server_ip = ucic:get("openmptcprouter",servername,"ip")
server_ips = ucic:get_list("openmptcprouter",servername,"ip")
server_ip = server_ips[1]
end)
if nbserver == 1 and server_ip ~= "" and server_ip ~= nil then
ucic:set("shadowsocks-libev","sss0","server",server_ip)
@ -425,8 +426,14 @@ function wizard_add()
local disablednb = 0
local servers = luci.http.formvaluetable("server")
for server, _ in pairs(servers) do
local server_ip = {}
server_ip[1] = luci.http.formvalue("%s.server_ip" % server) or ""
local serverips = luci.http.formvaluetable("%s.serverip" % server) or {}
local aserverips = {}
for _, ip in pairs(serverips) do
if ip ~= "" and ip ~= nil then
table.insert(aserverips,ip)
end
end
local master = luci.http.formvalue("master") or ""
-- OpenMPTCProuter VPS
@ -447,14 +454,14 @@ function wizard_add()
if openmptcprouter_vps_disabled == "1" then
disablednb = disablednb + 1
end
if server_ip[1] ~= "" then
if next(aserverips) ~= nil then
serversnb = serversnb + 1
end
ucic:set("openmptcprouter",server,"server")
ucic:set("openmptcprouter",server,"username",openmptcprouter_vps_username)
ucic:set("openmptcprouter",server,"password",openmptcprouter_vps_key)
ucic:set("openmptcprouter",server,"disabled",openmptcprouter_vps_disabled)
ucic:set_list("openmptcprouter",server,"ip",server_ip)
ucic:set_list("openmptcprouter",server,"ip",aserverips)
ucic:set("openmptcprouter",server,"port","65500")
ucic:save("openmptcprouter")
end
@ -488,6 +495,13 @@ function wizard_add()
ucic:save("shadowsocks-libev")
ucic:save("v2ray")
ucic:foreach("shadowsocks-libev","server", function(s)
local sectionname = s[".name"]
if sectionname:match("^sss.*") then
ucic:delete("shadowsocks-libev",sectionname,"ip")
ucic:set("shadowsocks-libev",sectionname,"disabled","1")
end
end)
local ss_servers_nginx = {}
local ss_servers_ha = {}
@ -497,14 +511,20 @@ function wizard_add()
for server, _ in pairs(servers) do
local master = luci.http.formvalue("master") or ""
local server_ip = luci.http.formvalue("%s.server_ip" % server) or ""
local server_ips = luci.http.formvaluetable("%s.serverip" % server) or {}
local server_ip = ""
for _, ip in pairs(server_ips) do
if server_ip == "" and ip ~= "" and ip ~= nil then
server_ip=ip
end
end
-- We have an IP, so set it everywhere
if server_ip ~= "" and luci.http.formvalue("%s.openmptcprouter_vps_disabled" % server) ~= "1" then
if server_ip ~= "" and server_ip ~= nil and luci.http.formvalue("%s.openmptcprouter_vps_disabled" % server) ~= "1" then
-- Check if we have more than one IP, in this case use Nginx HA
if serversnb > 1 then
if master == server then
ss_ip=server_ip
ucic:set("shadowsocks-libev","sss0","server",server_ip)
--ucic:set("shadowsocks-libev","sss0","server",server_ip)
ucic:set("glorytun","vpn","host",server_ip)
ucic:set("glorytun-udp","vpn","host",server_ip)
ucic:set("dsvpn","vpn","host",server_ip)
@ -516,6 +536,14 @@ function wizard_add()
luci.sys.call("uci -q add_list openvpn.omr.remote=" .. server_ip)
ucic:set("qos","serverin","srchost",server_ip)
ucic:set("qos","serverout","dsthost",server_ip)
local nbip = 0
for _, ssip in pairs(server_ips) do
ucic:set("shadowsocks-libev","sss" .. nbip,"server",ssip)
if default_proxy == "shadowsocks" then
ucic:set("shadowsocks-libev","sss" .. nbip,"disabled","0")
end
nbip = nbip + 1
end
end
k = k + 1
ucic:set("nginx-ha","ShadowSocks","enable","0")
@ -526,7 +554,7 @@ function wizard_add()
ucic:set("openmptcprouter","settings","ha","0")
ucic:set("nginx-ha","ShadowSocks","enable","0")
ucic:set("nginx-ha","VPN","enable","0")
ucic:set("shadowsocks-libev","sss0","server",server_ip)
--ucic:set("shadowsocks-libev","sss0","server",server_ip)
ucic:set("glorytun","vpn","host",server_ip)
ucic:set("glorytun-udp","vpn","host",server_ip)
ucic:set("dsvpn","vpn","host",server_ip)
@ -538,6 +566,14 @@ function wizard_add()
luci.sys.call("uci -q add_list openvpn.omr.remote=" .. server_ip)
ucic:set("qos","serverin","srchost",server_ip)
ucic:set("qos","serverout","dsthost",server_ip)
local nbip = 0
for _, ssip in pairs(server_ips) do
ucic:set("shadowsocks-libev","sss" .. nbip,"server",ssip)
if default_proxy == "shadowsocks" then
ucic:set("shadowsocks-libev","sss" .. nbip,"disabled","0")
end
nbip = nbip + 1
end
end
end
end

View file

@ -55,9 +55,19 @@
<h3><%=servername%></h3>
<div class="cbi-section-node" id="cbi-omr-wizard-<%=servername%>">
<div class="cbi-value">
<label class="cbi-value-title" for="server_ip"><%:Server IP%></label>
<label class="cbi-value-title" for="server_ip.1"><%:Server IP%></label>
<div class="cbi-value-field">
<input name="<%=servername%>.server_ip" id="<%=servername%>.server_ip" placeholder="<%:Server IP%>" class="cbi-input-text" value="<%=uci:get_list("openmptcprouter",servername,"ip")[1]%>" data-optional="false">
<input name="<%=servername%>.server_ip.1" id="<%=servername%>.server_ip.1" placeholder="<%:Server IP%>" class="cbi-input-text" value="<%=uci:get_list("openmptcprouter",servername,"ip")[1]%>" data-optional="false">
<div class="cbi-value-description">
<%:Server IP will be set for proxy and VPN%>
</div>
</div>
</div>
<br />
<div class="cbi-value">
<label class="cbi-value-title" for="server_ip.2"><%:Server IP%></label>
<div class="cbi-value-field">
<input name="<%=servername%>.server_ip.2" id="<%=servername%>.server_ip.2" placeholder="<%:Server IP%>" class="cbi-input-text" value="<%=uci:get_list("openmptcprouter",servername,"ip")[2]%>" data-optional="false">
<div class="cbi-value-description">
<%:Server IP will be set for proxy and VPN%>
</div>
@ -147,7 +157,10 @@
<div class="cbi-value">
<label class="cbi-value-title"><%:Enable IPv6%></label>
<div class="cbi-value-field">
<input class="cbi-input-checkbox" type="checkbox" id="enableipv6" name="enableipv6" value="0" <% if uci:get("openmptcprouter","settings","disable_ipv6") == "0" then %>checked<% end %> />
<select class="cbi-input-select" name="enableipv6" size="1">
<option value="1" <% if uci:get("openmptcprouter","settings","disable_ipv6") ~= "0" then %>selected="selected"<% end %>><%:Disabled%></option>
<option value="0" <% if uci:get("openmptcprouter","settings","disable_ipv6") == "0" then %>selected="selected"<% end %>><%:Enabled%></option>
</select>
<br />
<div class="cbi-value-description">
<%:You should disable IPv6 here if server doesn't provide IPv6.%>
@ -874,6 +887,13 @@
if not (ifacea == "lo" or ifacea == "6in4-omr6in4" or ifacea == "mlvpn0" or ifacea:match("^ifb.*") or ifacea:match("^sit.*") or ifacea:match("^gre.*") or ifacea:match("^ip6.*") or ifacea:match("^teql.*") or ifacea:match("^erspan.*")) and device_notvirtual(ifacea) then
%>
<option value="<%=ifacea%>"><%=ifacea%></option>
<%
end
end
for _, ifacea in ipairs(net:get_networks()) do
if not (ifacea:name() == "loopback" or ifacea:name() == "omr6in4" or ifacea:name() == "omrvpn" or ifacea:name():match("^omrip.*")) then
%>
<option value="<%='@' .. ifacea:name()%>"><%='@' .. ifacea:name() .. ' (alias)'%></option>
<%
end
end