mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 14:23:38 +00:00
luci-app-openvpn-server: tidy up luci (#8217)
This commit is contained in:
parent
f31188e2f2
commit
298dfb71b8
@ -5,17 +5,14 @@
|
|||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-openvpn-server
|
||||||
|
PKG_VERSION:=2.0
|
||||||
|
PKG_RELEASE:=19
|
||||||
|
|
||||||
LUCI_TITLE:=LuCI support for OpenVPN Server
|
LUCI_TITLE:=LuCI support for OpenVPN Server
|
||||||
LUCI_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa +kmod-tun
|
LUCI_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa +kmod-tun
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
PKG_NAME:=luci-app-openvpn-server
|
|
||||||
PKG_VERSION:=2.0
|
|
||||||
PKG_RELEASE:=18
|
|
||||||
|
|
||||||
include $(TOPDIR)/feeds/luci/luci.mk
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
# call BuildPackage - OpenWrt buildroot signature
|
# call BuildPackage - OpenWrt buildroot signature
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module("luci.controller.openvpn-server", package.seeall)
|
module("luci.controller.openvpn-server", package.seeall)
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
@ -7,13 +6,15 @@ function index()
|
|||||||
end
|
end
|
||||||
|
|
||||||
entry({"admin", "vpn"}, firstchild(), "VPN", 45).dependent = false
|
entry({"admin", "vpn"}, firstchild(), "VPN", 45).dependent = false
|
||||||
entry({"admin", "vpn", "openvpn-server"}, cbi("openvpn-server/openvpn-server"), _("OpenVPN Server"), 80).dependent = false
|
entry({"admin", "vpn", "openvpn-server"}, alias("admin", "vpn", "openvpn-server", "basic"), _("OpenVPN Server"), 80).dependent = true
|
||||||
|
entry({"admin", "vpn", "openvpn-server", "basic"}, cbi("openvpn-server/basic"), _("Base Setting"), 1).leaf = true
|
||||||
|
entry({"admin", "vpn", "openvpn-server", "code"}, cbi("openvpn-server/code"), _("Special Code"), 2).leaf = true
|
||||||
entry({"admin", "vpn", "openvpn-server", "status"}, call("act_status")).leaf = true
|
entry({"admin", "vpn", "openvpn-server", "status"}, call("act_status")).leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function act_status()
|
function act_status()
|
||||||
local e={}
|
local e = {}
|
||||||
e.running=luci.sys.call("pgrep openvpn >/dev/null")==0
|
e.running = luci.sys.call("pgrep openvpn >/dev/null") == 0
|
||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
luci.http.write_json(e)
|
luci.http.write_json(e)
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
mp = Map("openvpn")
|
||||||
|
mp.title = translate("OpenVPN Server")
|
||||||
|
mp.description = translate("An easy config OpenVPN Server Web-UI")
|
||||||
|
|
||||||
|
mp:section(SimpleSection).template = "openvpn-server/openvpn-server_status"
|
||||||
|
|
||||||
|
s = mp:section(TypedSection, "openvpn")
|
||||||
|
s.anonymous = true
|
||||||
|
s.addremove = false
|
||||||
|
|
||||||
|
o = s:option(Flag, "enabled", translate("Enable"))
|
||||||
|
|
||||||
|
proto = s:option(Value, "proto", translate("Proto"))
|
||||||
|
proto:value("tcp4", translate("TCP Server IPv4"))
|
||||||
|
proto:value("udp4", translate("UDP Server IPv4"))
|
||||||
|
proto:value("tcp6", translate("TCP Server IPv6"))
|
||||||
|
proto:value("udp6", translate("UDP Server IPv6"))
|
||||||
|
|
||||||
|
port = s:option(Value, "port", translate("Port"))
|
||||||
|
port.datatype = "range(1,65535)"
|
||||||
|
|
||||||
|
ddns = s:option(Value, "ddns", translate("WAN DDNS or IP"))
|
||||||
|
ddns.datatype = "string"
|
||||||
|
ddns.default = "exmple.com"
|
||||||
|
ddns.rmempty = false
|
||||||
|
|
||||||
|
localnet = s:option(Value, "server", translate("Client Network"))
|
||||||
|
localnet.datatype = "string"
|
||||||
|
localnet.description = translate("VPN Client Network IP with subnet")
|
||||||
|
|
||||||
|
list = s:option(DynamicList, "push")
|
||||||
|
list.title = translate("Client Settings")
|
||||||
|
list.datatype = "string"
|
||||||
|
list.description = translate("Set route 192.168.0.0 255.255.255.0 and dhcp-option DNS 192.168.0.1 base on your router")
|
||||||
|
|
||||||
|
o = s:option(Button, "certificate", translate("OpenVPN Client config file"))
|
||||||
|
o.inputtitle = translate("Download .ovpn file")
|
||||||
|
o.description = translate("If you are using IOS client, please download this .ovpn file and send it via QQ or Email to your IOS device")
|
||||||
|
o.inputstyle = "reload"
|
||||||
|
o.write = function()
|
||||||
|
luci.sys.call("sh /etc/genovpn.sh 2>&1 >/dev/null")
|
||||||
|
Download()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Download()
|
||||||
|
local t,e
|
||||||
|
t = nixio.open("/tmp/my.ovpn","r")
|
||||||
|
luci.http.header('Content-Disposition','attachment; filename="my.ovpn"')
|
||||||
|
luci.http.prepare_content("application/octet-stream")
|
||||||
|
while true do
|
||||||
|
e = t:read(nixio.const.buffersize)
|
||||||
|
if (not e) or (#e==0) then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
luci.http.write(e)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
t:close()
|
||||||
|
luci.http.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local pid = luci.util.exec("/usr/bin/pgrep openvpn")
|
||||||
|
|
||||||
|
function openvpn_process_status()
|
||||||
|
local status = "OpenVPN is not running now "
|
||||||
|
|
||||||
|
if pid ~= "" then
|
||||||
|
status = "OpenVPN is running with the PID " .. pid .. ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local status = { status = status }
|
||||||
|
local table = { pid = status }
|
||||||
|
return table
|
||||||
|
end
|
||||||
|
|
||||||
|
return mp
|
@ -0,0 +1,27 @@
|
|||||||
|
mp = Map("openvpn")
|
||||||
|
|
||||||
|
s = mp:section(TypedSection, "openvpn")
|
||||||
|
s.anonymous = true
|
||||||
|
s.addremove = false
|
||||||
|
|
||||||
|
local conf = "/etc/ovpnadd.conf"
|
||||||
|
local NXFS = require "nixio.fs"
|
||||||
|
|
||||||
|
o = s:option(TextValue, "conf")
|
||||||
|
o.description = translate("(!)Special Code you know that add in to client .ovpn file")
|
||||||
|
o.rows = 13
|
||||||
|
o.wrap = "off"
|
||||||
|
o.cfgvalue = function(self, section)
|
||||||
|
return NXFS.readfile(conf) or ""
|
||||||
|
end
|
||||||
|
o.write = function(self, section, value)
|
||||||
|
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
||||||
|
end
|
||||||
|
|
||||||
|
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("/etc/openvpncert.sh > /dev/null")
|
||||||
|
os.execute("/etc/init.d/openvpn restart")
|
||||||
|
end
|
||||||
|
|
||||||
|
return mp
|
@ -1,106 +0,0 @@
|
|||||||
|
|
||||||
--require("luci.tools.webadmin")
|
|
||||||
|
|
||||||
mp = Map("openvpn", "OpenVPN Server",translate("An easy config OpenVPN Server Web-UI"))
|
|
||||||
|
|
||||||
mp:section(SimpleSection).template = "openvpn/openvpn_status"
|
|
||||||
|
|
||||||
s = mp:section(TypedSection, "openvpn")
|
|
||||||
s.anonymous = true
|
|
||||||
s.addremove = false
|
|
||||||
|
|
||||||
s:tab("basic", translate("Base Setting"))
|
|
||||||
|
|
||||||
o = s:taboption("basic", Flag, "enabled", translate("Enable"))
|
|
||||||
|
|
||||||
proto = s:taboption("basic",Value,"proto", translate("Proto"))
|
|
||||||
proto:value("tcp4", translate("TCP Server IPv4"))
|
|
||||||
proto:value("udp4", translate("UDP Server IPv4"))
|
|
||||||
proto:value("tcp6", translate("TCP Server IPv6"))
|
|
||||||
proto:value("udp6", translate("UDP Server IPv6"))
|
|
||||||
|
|
||||||
port = s:taboption("basic", Value, "port", translate("Port"))
|
|
||||||
port.datatype = "range(1,65535)"
|
|
||||||
|
|
||||||
ddns = s:taboption("basic", Value, "ddns", translate("WAN DDNS or IP"))
|
|
||||||
ddns.datatype = "string"
|
|
||||||
ddns.default = "exmple.com"
|
|
||||||
ddns.rmempty = false
|
|
||||||
|
|
||||||
localnet = s:taboption("basic", Value, "server", translate("Client Network"))
|
|
||||||
localnet.datatype = "string"
|
|
||||||
localnet.description = translate("VPN Client Network IP with subnet")
|
|
||||||
|
|
||||||
list = s:taboption("basic", DynamicList, "push")
|
|
||||||
list.title = translate("Client Settings")
|
|
||||||
list.datatype = "string"
|
|
||||||
list.description = translate("Set route 192.168.0.0 255.255.255.0 and dhcp-option DNS 192.168.0.1 base on your router")
|
|
||||||
|
|
||||||
|
|
||||||
local o
|
|
||||||
o = s:taboption("basic", Button,"certificate",translate("OpenVPN Client config file"))
|
|
||||||
o.inputtitle = translate("Download .ovpn file")
|
|
||||||
o.description = translate("If you are using IOS client, please download this .ovpn file and send it via QQ or Email to your IOS device")
|
|
||||||
o.inputstyle = "reload"
|
|
||||||
o.write = function()
|
|
||||||
luci.sys.call("sh /etc/genovpn.sh 2>&1 >/dev/null")
|
|
||||||
Download()
|
|
||||||
end
|
|
||||||
|
|
||||||
s:tab("code", translate("Special Code"))
|
|
||||||
|
|
||||||
local conf = "/etc/ovpnadd.conf"
|
|
||||||
local NXFS = require "nixio.fs"
|
|
||||||
o = s:taboption("code", TextValue, "conf")
|
|
||||||
o.description = translate("(!)Special Code you know that add in to client .ovpn file")
|
|
||||||
o.rows = 13
|
|
||||||
o.wrap = "off"
|
|
||||||
o.cfgvalue = function(self, section)
|
|
||||||
return NXFS.readfile(conf) or ""
|
|
||||||
end
|
|
||||||
o.write = function(self, section, value)
|
|
||||||
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local pid = luci.util.exec("/usr/bin/pgrep openvpn")
|
|
||||||
|
|
||||||
function openvpn_process_status()
|
|
||||||
local status = "OpenVPN is not running now "
|
|
||||||
|
|
||||||
if pid ~= "" then
|
|
||||||
status = "OpenVPN is running with the PID " .. pid .. ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local status = { status=status }
|
|
||||||
local table = { pid=status }
|
|
||||||
return table
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Download()
|
|
||||||
local t,e
|
|
||||||
t=nixio.open("/tmp/my.ovpn","r")
|
|
||||||
luci.http.header('Content-Disposition','attachment; filename="my.ovpn"')
|
|
||||||
luci.http.prepare_content("application/octet-stream")
|
|
||||||
while true do
|
|
||||||
e=t:read(nixio.const.buffersize)
|
|
||||||
if(not e)or(#e==0)then
|
|
||||||
break
|
|
||||||
else
|
|
||||||
luci.http.write(e)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
t:close()
|
|
||||||
luci.http.close()
|
|
||||||
end
|
|
||||||
|
|
||||||
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("/etc/openvpncert.sh > /dev/null")
|
|
||||||
os.execute("/etc/init.d/openvpn restart")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return mp
|
|
@ -1,7 +1,7 @@
|
|||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">//<![CDATA[
|
||||||
XHR.poll(3, '<%=url([[admin]], [[vpn]], [[openvpn-server]], [[status]])%>', null,
|
XHR.poll(3, '<%=url([[admin]], [[vpn]], [[openvpn-server]], [[status]])%>', null,
|
||||||
function(x, data) {
|
function(x, data) {
|
||||||
var tb = document.getElementById('openvpn_status');
|
var tb = document.getElementById('openvpn-server_status');
|
||||||
if (data && tb) {
|
if (data && tb) {
|
||||||
if (data.running) {
|
if (data.running) {
|
||||||
var links = '<em><b><font color=green>OpenVPN Server <%:RUNNING%></font></b></em>';
|
var links = '<em><b><font color=green>OpenVPN Server <%:RUNNING%></font></b></em>';
|
||||||
@ -16,7 +16,7 @@ XHR.poll(3, '<%=url([[admin]], [[vpn]], [[openvpn-server]], [[status]])%>', null
|
|||||||
</script>
|
</script>
|
||||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||||
<fieldset class="cbi-section">
|
<fieldset class="cbi-section">
|
||||||
<p id="openvpn_status">
|
<p id="openvpn-server_status">
|
||||||
<em><%:Collecting data...%></em>
|
<em><%:Collecting data...%></em>
|
||||||
</p>
|
</p>
|
||||||
</fieldset>
|
</fieldset>
|
@ -16,21 +16,18 @@ msgstr "端口"
|
|||||||
msgid "WAN DDNS or IP"
|
msgid "WAN DDNS or IP"
|
||||||
msgstr "WAN口的 DDNS域名 或者 IP"
|
msgstr "WAN口的 DDNS域名 或者 IP"
|
||||||
|
|
||||||
|
|
||||||
msgid "Client Network"
|
msgid "Client Network"
|
||||||
msgstr "客户端网段"
|
msgstr "客户端网段"
|
||||||
|
|
||||||
msgid "VPN Client Network IP with subnet"
|
msgid "VPN Client Network IP with subnet"
|
||||||
msgstr "客户端分配的网段地址(默认为 10.8.0.0 255.255.255.0)"
|
msgstr "客户端分配的网段地址(默认为 10.8.0.0 255.255.255.0)"
|
||||||
|
|
||||||
|
|
||||||
msgid "Client Settings"
|
msgid "Client Settings"
|
||||||
msgstr "客户端推送配置"
|
msgstr "客户端推送配置"
|
||||||
|
|
||||||
msgid "OpenVPN Client config file"
|
msgid "OpenVPN Client config file"
|
||||||
msgstr "OpenVPN 客户端配置文件"
|
msgstr "OpenVPN 客户端配置文件"
|
||||||
|
|
||||||
|
|
||||||
msgid "Download .ovpn file"
|
msgid "Download .ovpn file"
|
||||||
msgstr "一键下载 .ovpn 文件"
|
msgstr "一键下载 .ovpn 文件"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user