mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add OpenVPN support
This commit is contained in:
parent
acea842fbd
commit
4e858a0ff9
3 changed files with 65 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
local tools = require "luci.tools.status"
|
local tools = require "luci.tools.status"
|
||||||
local sys = require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
local json = require("luci.json")
|
local json = require("luci.json")
|
||||||
|
local fs = require("nixio.fs")
|
||||||
local ucic = luci.model.uci.cursor()
|
local ucic = luci.model.uci.cursor()
|
||||||
module("luci.controller.openmptcprouter", package.seeall)
|
module("luci.controller.openmptcprouter", package.seeall)
|
||||||
|
|
||||||
|
@ -76,6 +77,8 @@ function wizard_add()
|
||||||
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","vpn","host",server_ip)
|
||||||
ucic:set("mlvpn","general","host",server_ip)
|
ucic:set("mlvpn","general","host",server_ip)
|
||||||
|
luci.sys.call("uci -q del openvpn.omr.remote")
|
||||||
|
luci.sys.call("uci -q add_list openvpn.omr.remote=" .. server_ip)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set ShadowSocks settings
|
-- Set ShadowSocks settings
|
||||||
|
@ -95,7 +98,7 @@ function wizard_add()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get VPN set by default
|
-- Get VPN set by default
|
||||||
local default_vpn = luci.http.formvalue("default") or "glorytun_tcp"
|
local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp"
|
||||||
|
|
||||||
-- Set Glorytun TCP settings
|
-- Set Glorytun TCP settings
|
||||||
local glorytun_key = luci.http.formvalue("glorytun_key")
|
local glorytun_key = luci.http.formvalue("glorytun_key")
|
||||||
|
@ -144,6 +147,31 @@ function wizard_add()
|
||||||
ucic:commit("mlvpn")
|
ucic:commit("mlvpn")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local openvpn_key = luci.http.formvalue("openvpn_key")
|
||||||
|
if openvpn_key ~= "" then
|
||||||
|
local openvpn_key_path = "/etc/luci-uploads/openvpn.key"
|
||||||
|
local fp
|
||||||
|
luci.http.setfilehandler(
|
||||||
|
function(meta, chunk, eof)
|
||||||
|
if not fp and meta and meta.name == "openvpn_key" then
|
||||||
|
fp = io.open(openvpn_key_path, "w")
|
||||||
|
end
|
||||||
|
if fp and chunk then
|
||||||
|
fp:write(chunk)
|
||||||
|
end
|
||||||
|
if fp and eof then
|
||||||
|
fp:close()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
ucic:set("openvpn","omr","secret",openvpn_key_path)
|
||||||
|
ucic:commit("openvpn")
|
||||||
|
end
|
||||||
|
|
||||||
|
if default_vpn == "openvpn" then
|
||||||
|
ucic:set("openvpn","omr","enabled",1)
|
||||||
|
ucic:commit("openvpn")
|
||||||
|
end
|
||||||
|
|
||||||
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
|
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
|
||||||
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
|
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
|
||||||
luci.sys.call("/etc/init.d/mlvpn restart >/dev/null 2>/dev/null")
|
luci.sys.call("/etc/init.d/mlvpn restart >/dev/null 2>/dev/null")
|
||||||
|
@ -279,7 +307,7 @@ function interfaces_status()
|
||||||
|
|
||||||
-- Check openmptcprouter service are running
|
-- Check openmptcprouter service are running
|
||||||
mArray.openmptcprouter["tun_service"] = false
|
mArray.openmptcprouter["tun_service"] = false
|
||||||
if string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?glorytun(-udp)?$'"), "%d+") then
|
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+") then
|
||||||
mArray.openmptcprouter["tun_service"] = true
|
mArray.openmptcprouter["tun_service"] = true
|
||||||
mArray.openmptcprouter["tun_ip"] = get_ip("omrvpn")
|
mArray.openmptcprouter["tun_ip"] = get_ip("omrvpn")
|
||||||
local tun_dev = uci:get("network","omrvpn","ifname")
|
local tun_dev = uci:get("network","omrvpn","ifname")
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% if nixio.fs.access("/usr/sbin/glorytun") or nixio.fs.access("/usr/sbin/glorytun-udp") then %>
|
||||||
<div class="cbi-value">
|
<div class="cbi-value">
|
||||||
<label class="cbi-value-title"><%:Glorytun key%></label>
|
<label class="cbi-value-title"><%:Glorytun key%></label>
|
||||||
<div class="cbi-value-field">
|
<div class="cbi-value-field">
|
||||||
|
@ -47,6 +48,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if nixio.fs.access("/usr/sbin/mlvpn") then %>
|
||||||
<div class="cbi-value">
|
<div class="cbi-value">
|
||||||
<label class="cbi-value-title"><%:MLVPN password%></label>
|
<label class="cbi-value-title"><%:MLVPN password%></label>
|
||||||
<div class="cbi-value-field">
|
<div class="cbi-value-field">
|
||||||
|
@ -58,13 +61,29 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if nixio.fs.access("/usr/sbin/openvpn") then %>
|
||||||
|
<div class="cbi-value">
|
||||||
|
<label class="cbi-value-title"><%:OpenVPN key%></label>
|
||||||
|
<div class="cbi-value-field">
|
||||||
|
<input type="file" name="openvpn_key" class="cbi-input-file">
|
||||||
|
<input type="text" class="cbi-input-text" data-update="change" value="<%=uci:get("openvpn","omr","secret")%>" />
|
||||||
|
<br />
|
||||||
|
<div class="cbi-value-description">
|
||||||
|
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
|
||||||
|
<%:You need to upload OpenVPN key file generated by OpenMPTCProuter VPS script to use OpenVPN TCP%>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
<div class="cbi-value">
|
<div class="cbi-value">
|
||||||
<label class="cbi-value-title"><%:Default VPN%></label>
|
<label class="cbi-value-title"><%:Default VPN%></label>
|
||||||
<div class="cbi-value-field">
|
<div class="cbi-value-field">
|
||||||
<select class="cbi-input-select" name="default_vpn" size="1">
|
<select class="cbi-input-select" name="default_vpn" size="1">
|
||||||
<option value="glorytun_tcp" <% if uci:get("glorytun","vpn","enable") == "1" and uci:get("glorytun","vpn","proto") == "tcp" then %>selected="selected"<% end %>>Glorytun TCP</option>
|
<% if nixio.fs.access("/usr/sbin/glorytun") then %><option value="glorytun_tcp" <% if uci:get("glorytun","vpn","enable") == "1" and uci:get("glorytun","vpn","proto") == "tcp" then %>selected="selected"<% end %>>Glorytun TCP</option><% end %>
|
||||||
<option value="glorytun_udp" <% if uci:get("glorytun","vpn","enable") == "1" and uci:get("glorytun","vpn","proto") == "udp" then %>selected="selected"<% end %>>Glorytun UDP</option>
|
<% if nixio.fs.access("/usr/sbin/glorytun-udp") then %><option value="glorytun_udp" <% if uci:get("glorytun","vpn","enable") == "1" and uci:get("glorytun","vpn","proto") == "udp" then %>selected="selected"<% end %>>Glorytun UDP</option><% end %>
|
||||||
<option value="mlvpn" <% if uci:get("mlvpn","general","enable") == "1" then %>selected="selected"<% end %>>MLVPN</option>
|
<% if nixio.fs.access("/usr/sbin/mlvpn") then %><option value="mlvpn" <% if uci:get("mlvpn","general","enable") == "1" then %>selected="selected"<% end %>>MLVPN</option><% end %>
|
||||||
|
<% if nixio.fs.access("/usr/sbin/openvpn") then %><option value="openvpn" <% if uci:get("openvpn","omr","enabled") == "1" then %>selected="selected"<% end %>>OpenVPN</option><% end %>
|
||||||
</select>
|
</select>
|
||||||
<br />
|
<br />
|
||||||
<div class="cbi-value-description">
|
<div class="cbi-value-description">
|
||||||
|
@ -133,4 +152,5 @@
|
||||||
<button class="btn" type="submit">Submit</button>
|
<button class="btn" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<%+footer%>
|
<%+footer%>
|
||||||
|
|
|
@ -15,6 +15,18 @@ if [ "$(uci -q get network.omrvpn)" = "" ]; then
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$(uci -q get openvpn.omr)" = "" ]; then
|
||||||
|
uci -q batch <<-EOF >/dev/null
|
||||||
|
set openvpn.omr=openvpn
|
||||||
|
set openvpn.omr.dev=tun0
|
||||||
|
set openvpn.omr.port=65301
|
||||||
|
set openvpn.omr.cipher=AES-256-CBC
|
||||||
|
set openvpn.omr.proto=tcp-client
|
||||||
|
set openvpn.omr.compress=lz4
|
||||||
|
commit openvpn
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$(uci -q show firewall | grep omrvpn)" = "" ]; then
|
if [ "$(uci -q show firewall | grep omrvpn)" = "" ]; then
|
||||||
uci -q batch <<-EOF >/dev/null
|
uci -q batch <<-EOF >/dev/null
|
||||||
add_list firewall.zone_vpn.network=omrvpn
|
add_list firewall.zone_vpn.network=omrvpn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue