1
0
Fork 0
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:
Ycarus 2018-06-12 19:22:55 +02:00
parent acea842fbd
commit 4e858a0ff9
3 changed files with 65 additions and 5 deletions

View file

@ -1,6 +1,7 @@
local tools = require "luci.tools.status"
local sys = require "luci.sys"
local json = require("luci.json")
local fs = require("nixio.fs")
local ucic = luci.model.uci.cursor()
module("luci.controller.openmptcprouter", package.seeall)
@ -76,6 +77,8 @@ function wizard_add()
ucic:set("shadowsocks-libev","sss0","server",server_ip)
ucic:set("glorytun","vpn","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
-- Set ShadowSocks settings
@ -95,7 +98,7 @@ function wizard_add()
end
-- 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
local glorytun_key = luci.http.formvalue("glorytun_key")
@ -144,6 +147,31 @@ function wizard_add()
ucic:commit("mlvpn")
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("/etc/init.d/glorytun 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
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_ip"] = get_ip("omrvpn")
local tun_dev = uci:get("network","omrvpn","ifname")

View file

@ -36,6 +36,7 @@
</div>
</div>
</div>
<% if nixio.fs.access("/usr/sbin/glorytun") or nixio.fs.access("/usr/sbin/glorytun-udp") then %>
<div class="cbi-value">
<label class="cbi-value-title"><%:Glorytun key%></label>
<div class="cbi-value-field">
@ -47,6 +48,8 @@
</div>
</div>
</div>
<% end %>
<% if nixio.fs.access("/usr/sbin/mlvpn") then %>
<div class="cbi-value">
<label class="cbi-value-title"><%:MLVPN password%></label>
<div class="cbi-value-field">
@ -58,13 +61,29 @@
</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">
<label class="cbi-value-title"><%:Default VPN%></label>
<div class="cbi-value-field">
<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>
<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>
<option value="mlvpn" <% if uci:get("mlvpn","general","enable") == "1" then %>selected="selected"<% end %>>MLVPN</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 %>
<% 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 %>
<% 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>
<br />
<div class="cbi-value-description">
@ -133,4 +152,5 @@
<button class="btn" type="submit">Submit</button>
</div>
</form>
<%+footer%>