mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add support of VPS failover to wizard
This commit is contained in:
parent
e7d3130a6f
commit
43e0d63063
3 changed files with 99 additions and 15 deletions
|
@ -77,16 +77,73 @@ function wizard_add()
|
|||
end
|
||||
ucic:save("network")
|
||||
ucic:commit("network")
|
||||
|
||||
local server_ip = luci.http.formvalue("server_ip")
|
||||
|
||||
-- Get VPN set by default
|
||||
local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp"
|
||||
local vpn_port
|
||||
if default_vpn:match("^glorytun.*") then
|
||||
vpn_port = 65001
|
||||
elseif default_vpn == "mlvpn" then
|
||||
vpn_port = 65201
|
||||
elseif default_vpn == "openvpn" then
|
||||
vpn_port = 65301
|
||||
end
|
||||
|
||||
-- Get all servers ips
|
||||
local server_ip = luci.http.formvalue("server_ip")
|
||||
-- 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 (type(server_ip) == "table") then
|
||||
local ss_servers = {}
|
||||
local vpn_servers = {}
|
||||
local k = 0
|
||||
for _, ip in pairs(server_ip) do
|
||||
if k == 0 then
|
||||
table.insert(ss_servers,ip .. ":65101 max_fails=3 fail_timeout=30s")
|
||||
table.insert(vpn_servers,ip .. ":65001 max_fails=3 fail_timeout=30s")
|
||||
ucic:set("qos","serverin","srchost",ip)
|
||||
ucic:set("qos","serverout","dsthost",ip)
|
||||
ucic:save("qos")
|
||||
ucic:commit("qos")
|
||||
else
|
||||
table.insert(ss_servers,ip .. ":65101 backup")
|
||||
table.insert(vpn_servers,ip .. ":65001 backup")
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
ucic:set("nginx-ha","ShadowSocks","enable","1")
|
||||
ucic:set("nginx-ha","VPN","enable","1")
|
||||
ucic:set("nginx-ha","ShadowSocks","upstreams",ss_servers)
|
||||
ucic:set("nginx-ha","VPN","upstreams",vpn_servers)
|
||||
ucic:save("nginx-ha")
|
||||
ucic:commit("nginx-ha")
|
||||
server_ip = "127.0.0.1"
|
||||
else
|
||||
ucic:set("nginx-ha","ShadowSocks","enable","0")
|
||||
ucic:set("nginx-ha","VPN","enable","0")
|
||||
ucic:set("qos","serverin","srchost",server_ip)
|
||||
ucic:set("qos","serverout","dsthost",server_ip)
|
||||
ucic:save("qos")
|
||||
ucic:commit("qos")
|
||||
end
|
||||
ucic:set("shadowsocks-libev","sss0","server",server_ip)
|
||||
ucic:save("shadowsocks-libev")
|
||||
ucic:commit("shadowsocks-libev")
|
||||
ucic:set("glorytun","vpn","host",server_ip)
|
||||
ucic:save("glorytun")
|
||||
ucic:commit("glorytun")
|
||||
ucic:set("mlvpn","general","host",server_ip)
|
||||
ucic:save("mlvpn")
|
||||
ucic:commit("mlvpn")
|
||||
luci.sys.call("uci -q del openvpn.omr.remote")
|
||||
luci.sys.call("uci -q add_list openvpn.omr.remote=" .. server_ip)
|
||||
ucic:save("openvpn")
|
||||
ucic:commit("openvpn")
|
||||
ucic:set("qos","serverin","srchost",server_ip)
|
||||
ucic:set("qos","serverout","dsthost",server_ip)
|
||||
ucic:save("qos")
|
||||
ucic:commit("qos")
|
||||
end
|
||||
|
||||
-- Set ShadowSocks settings
|
||||
|
@ -105,9 +162,6 @@ function wizard_add()
|
|||
ucic:commit("shadowsocks-libev")
|
||||
end
|
||||
|
||||
-- Get VPN set by default
|
||||
local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp"
|
||||
|
||||
-- Set Glorytun settings
|
||||
if default_vpn:match("^glorytun.*") then
|
||||
ucic:set("glorytun","vpn","enable",1)
|
||||
|
|
|
@ -4,8 +4,19 @@
|
|||
local uci = require("luci.model.uci").cursor()
|
||||
local net = require "luci.model.network".init()
|
||||
local ifaces = net:get_interfaces()
|
||||
local servers_ip = {}
|
||||
local server_ip = uci:get("shadowsocks-libev","sss0","server")
|
||||
if server_ip == '127.0.0.1' then
|
||||
local upstreams = uci:get("nginx-ha","ShadowSocks","upstreams")
|
||||
for _, up in pairs(upstreams) do
|
||||
local a = up:match("^([^:]+):")
|
||||
table.insert(servers_ip,a)
|
||||
end
|
||||
else
|
||||
table.insert(servers_ip,server_ip)
|
||||
end
|
||||
%>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js" data-strings="{"path":{"resource":"\/luci-static\/resources","browser":"\/cgi-bin\/luci\/admin\/filebrowser"}}"></script>
|
||||
|
||||
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
|
||||
<form class="inline" method="post" action="<%=url('admin/system/openmptcprouter/wizard_add')%>" enctype="multipart/form-data">
|
||||
|
@ -14,17 +25,27 @@
|
|||
<fieldset class="cbi-section" id="server">
|
||||
<legend><%:Server settings%></legend>
|
||||
<div class="cbi-section-descr"><%:Put the values given by OpenMPTCProuter VPS script.%></div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title"><%:Server IP%></label>
|
||||
<div class="cbi-value cbi-value-last" id="server_ip" data-depends="[]" data-index="0">
|
||||
<label class="cbi-value-title" for="server_ip"><%:Server IP%></label>
|
||||
<div class="cbi-value-field">
|
||||
<input type="text" name="server_ip" placeholder="Server IP" class="cbi-input-text" value="<%=uci:get("shadowsocks-libev","sss0","server")%>" data-type="ip4addr">
|
||||
<div data-prefix="server_ip" data-browser-path="" data-dynlist="[[],[],null,false]" data-placeholder="123.123.123.123">
|
||||
<%
|
||||
local k = 0
|
||||
for _,server in ipairs(servers_ip) do
|
||||
k = k+1
|
||||
%>
|
||||
<input name="server_ip" id="server_ip.<%=k%>" placeholder="Server IP" class="cbi-input-text" value="<%=server%>" data-type="ip4addr">
|
||||
<br />
|
||||
<div class="cbi-value-description">
|
||||
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
|
||||
<%:Server IP will be set for ShadowSocks, Glorytun, OpenVPN and MLVPN%>
|
||||
</div>
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</div>
|
||||
<div class="cbi-value-description">
|
||||
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
|
||||
<%:Server IP will be set for ShadowSocks, Glorytun, OpenVPN and MLVPN%>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title"><%:ShadowSocks key%></label>
|
||||
<div class="cbi-value-field">
|
||||
|
@ -152,5 +173,5 @@
|
|||
<button class="btn" type="submit">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">cbi_init();</script>
|
||||
<%+footer%>
|
||||
|
|
|
@ -4,4 +4,13 @@ uci -q batch <<-EOF
|
|||
add ucitrack openmptcprouter
|
||||
set ucitrack.@openmptcprouter[-1].init=openmptcprouter
|
||||
commit ucitrack
|
||||
EOF
|
||||
EOF
|
||||
if [ "$(uci -q get qos.serverin)" = "" ]; then
|
||||
uci -q batch <<-EOF
|
||||
set qos.serverin=classify
|
||||
set qos.serverin.targer='Priority'
|
||||
set qos.serverout=classify
|
||||
set qos.serverout.targer='Priority'
|
||||
commit qos
|
||||
EOF
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue