mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-07-20 18:36:59 +08:00
add udp server support to openvpn luci
This commit is contained in:
parent
97686ea24c
commit
30b413b43a
@ -10,7 +10,7 @@ LUCI_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa +kmod-tun
|
|||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
PKG_NAME:=luci-app-openvpn-server
|
PKG_NAME:=luci-app-openvpn-server
|
||||||
PKG_VERSION:=2.0
|
PKG_VERSION:=2.0
|
||||||
PKG_RELEASE:=17
|
PKG_RELEASE:=18
|
||||||
|
|
||||||
include $(TOPDIR)/feeds/luci/luci.mk
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
@ -11,4 +11,12 @@ function index()
|
|||||||
local page
|
local page
|
||||||
|
|
||||||
entry({"admin", "vpn", "openvpn-server"}, cbi("openvpn-server/openvpn-server"), _("OpenVPN Server"), 80).dependent=false
|
entry({"admin", "vpn", "openvpn-server"}, cbi("openvpn-server/openvpn-server"), _("OpenVPN Server"), 80).dependent=false
|
||||||
|
entry({"admin", "vpn", "openvpn-server","status"},call("act_status")).leaf=true
|
||||||
|
end
|
||||||
|
|
||||||
|
function act_status()
|
||||||
|
local e={}
|
||||||
|
e.running=luci.sys.call("pgrep openvpn >/dev/null")==0
|
||||||
|
luci.http.prepare_content("application/json")
|
||||||
|
luci.http.write_json(e)
|
||||||
end
|
end
|
@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
--require("luci.tools.webadmin")
|
--require("luci.tools.webadmin")
|
||||||
|
|
||||||
mp = Map("openvpn", "OpenVPN Server","")
|
mp = Map("openvpn", "OpenVPN Server",translate("An easy config OpenVPN Server Web-UI"))
|
||||||
|
|
||||||
s = mp:section(TypedSection, "openvpn", "", translate("An easy config OpenVPN Server Web-UI"))
|
mp:section(SimpleSection).template = "openvpn/openvpn_status"
|
||||||
|
|
||||||
|
s = mp:section(TypedSection, "openvpn")
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
s.addremove = false
|
s.addremove = false
|
||||||
|
|
||||||
@ -11,6 +13,10 @@ s:tab("basic", translate("Base Setting"))
|
|||||||
|
|
||||||
o = s:taboption("basic", Flag, "enabled", translate("Enable"))
|
o = s:taboption("basic", Flag, "enabled", translate("Enable"))
|
||||||
|
|
||||||
|
proto = s:taboption("basic",Value,"proto", translate("Proto"))
|
||||||
|
proto:value("tcp-server", translate("TCP Server"))
|
||||||
|
proto:value("udp", translate("UDP Server"))
|
||||||
|
|
||||||
port = s:taboption("basic", Value, "port", translate("Port"))
|
port = s:taboption("basic", Value, "port", translate("Port"))
|
||||||
port.datatype = "range(1,65535)"
|
port.datatype = "range(1,65535)"
|
||||||
|
|
||||||
@ -88,44 +94,10 @@ function Download()
|
|||||||
luci.http.close()
|
luci.http.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
t = mp:section(Table, openvpn_process_status())
|
|
||||||
t.anonymous = true
|
|
||||||
|
|
||||||
t:option(DummyValue, "status", translate("OpenVPN status"))
|
|
||||||
|
|
||||||
if pid == "" then
|
|
||||||
start = t:option(Button, "_start", translate("Start"))
|
|
||||||
start.inputstyle = "apply"
|
|
||||||
function start.write(self, section)
|
|
||||||
luci.util.exec("uci set openvpn.myvpn.enabled=='1' && uci commit openvpn")
|
|
||||||
message = luci.util.exec("/etc/init.d/openvpn start 2>&1")
|
|
||||||
luci.util.exec("sleep 2")
|
|
||||||
luci.http.redirect(
|
|
||||||
luci.dispatcher.build_url("admin", "vpn", "openvpn-server") .. "?message=" .. message
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
stop = t:option(Button, "_stop", translate("Stop"))
|
|
||||||
stop.inputstyle = "reset"
|
|
||||||
function stop.write(self, section)
|
|
||||||
luci.util.exec("uci set openvpn.myvpn.enabled=='0' && uci commit openvpn")
|
|
||||||
luci.util.exec("/etc/init.d/openvpn stop")
|
|
||||||
luci.util.exec("sleep 2")
|
|
||||||
luci.http.redirect(
|
|
||||||
luci.dispatcher.build_url("admin", "vpn", "openvpn-server")
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function mp.on_after_commit(self)
|
function mp.on_after_commit(self)
|
||||||
os.execute("uci set firewall.openvpn.dest_port=$(uci get openvpn.myvpn.port) && uci commit firewall && /etc/init.d/firewall restart")
|
os.execute("uci set firewall.openvpn.dest_port=$(uci get openvpn.myvpn.port) && uci commit firewall && /etc/init.d/firewall restart")
|
||||||
os.execute("/etc/init.d/openvpn restart")
|
os.execute("/etc/init.d/openvpn restart")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--local apply = luci.http.formvalue("cbi.apply")
|
|
||||||
--if apply then
|
|
||||||
-- os.execute("/etc/init.d/openvpn restart")
|
|
||||||
--end
|
|
||||||
|
|
||||||
return mp
|
return mp
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
XHR.poll(3, '<%=url([[admin]], [[vpn]], [[openvpn-server]], [[status]])%>', null,
|
||||||
|
function(x, data) {
|
||||||
|
var tb = document.getElementById('openvpn_status');
|
||||||
|
if (data && tb) {
|
||||||
|
if (data.running) {
|
||||||
|
var links = '<em><b><font color=green>OpenVPN Server <%:RUNNING%></font></b></em>';
|
||||||
|
tb.innerHTML = links;
|
||||||
|
} else {
|
||||||
|
tb.innerHTML = '<em><b><font color=red>OpenVPN Server <%:NOT RUNNING%></font></b></em>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
|
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||||
|
<fieldset class="cbi-section">
|
||||||
|
<p id="openvpn_status">
|
||||||
|
<em><%:Collecting data...%></em>
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
@ -48,3 +48,6 @@ msgstr "根据路由的实际LAN IP 修改 route 192.168.0.0 255.255.255.0 和 d
|
|||||||
|
|
||||||
msgid "OpenVPN status"
|
msgid "OpenVPN status"
|
||||||
msgstr "OpenVPN 服务器运行状态"
|
msgstr "OpenVPN 服务器运行状态"
|
||||||
|
|
||||||
|
msgid "Proto"
|
||||||
|
msgstr "协议"
|
||||||
|
@ -12,7 +12,7 @@ uci rename firewall.@rule[-1]="openvpn"
|
|||||||
uci set firewall.@rule[-1].name="openvpn"
|
uci set firewall.@rule[-1].name="openvpn"
|
||||||
uci set firewall.@rule[-1].target="ACCEPT"
|
uci set firewall.@rule[-1].target="ACCEPT"
|
||||||
uci set firewall.@rule[-1].src="wan"
|
uci set firewall.@rule[-1].src="wan"
|
||||||
uci set firewall.@rule[-1].proto="tcp"
|
uci set firewall.@rule[-1].proto="tcp udp"
|
||||||
uci set firewall.@rule[-1].dest_port="1194"
|
uci set firewall.@rule[-1].dest_port="1194"
|
||||||
|
|
||||||
uci delete firewall.vpn
|
uci delete firewall.vpn
|
||||||
|
Loading…
x
Reference in New Issue
Block a user