diff --git a/package/lean/luci-app-openvpn-server/Makefile b/package/lean/luci-app-openvpn-server/Makefile index 4e51de644..76146570f 100644 --- a/package/lean/luci-app-openvpn-server/Makefile +++ b/package/lean/luci-app-openvpn-server/Makefile @@ -5,17 +5,14 @@ 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_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa +kmod-tun LUCI_PKGARCH:=all -PKG_NAME:=luci-app-openvpn-server -PKG_VERSION:=2.0 -PKG_RELEASE:=18 include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature - - - - diff --git a/package/lean/luci-app-openvpn-server/luasrc/controller/openvpn-server.lua b/package/lean/luci-app-openvpn-server/luasrc/controller/openvpn-server.lua index ddcda3d52..e0bf919d7 100644 --- a/package/lean/luci-app-openvpn-server/luasrc/controller/openvpn-server.lua +++ b/package/lean/luci-app-openvpn-server/luasrc/controller/openvpn-server.lua @@ -1,4 +1,3 @@ - module("luci.controller.openvpn-server", package.seeall) function index() @@ -7,13 +6,15 @@ function index() end 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 end function act_status() - local e={} - e.running=luci.sys.call("pgrep openvpn >/dev/null")==0 + local e = {} + e.running = luci.sys.call("pgrep openvpn >/dev/null") == 0 luci.http.prepare_content("application/json") luci.http.write_json(e) -end \ No newline at end of file +end diff --git a/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/basic.lua b/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/basic.lua new file mode 100644 index 000000000..8ac33d9cd --- /dev/null +++ b/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/basic.lua @@ -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 diff --git a/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/code.lua b/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/code.lua new file mode 100644 index 000000000..a025063c1 --- /dev/null +++ b/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/code.lua @@ -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 diff --git a/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/openvpn-server.lua b/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/openvpn-server.lua deleted file mode 100644 index 50e661426..000000000 --- a/package/lean/luci-app-openvpn-server/luasrc/model/cbi/openvpn-server/openvpn-server.lua +++ /dev/null @@ -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 diff --git a/package/lean/luci-app-openvpn-server/luasrc/view/openvpn/openvpn_status.htm b/package/lean/luci-app-openvpn-server/luasrc/view/openvpn-server/openvpn-server_status.htm similarity index 84% rename from package/lean/luci-app-openvpn-server/luasrc/view/openvpn/openvpn_status.htm rename to package/lean/luci-app-openvpn-server/luasrc/view/openvpn-server/openvpn-server_status.htm index 752abd4d0..ec1f2ce35 100644 --- a/package/lean/luci-app-openvpn-server/luasrc/view/openvpn/openvpn_status.htm +++ b/package/lean/luci-app-openvpn-server/luasrc/view/openvpn-server/openvpn-server_status.htm @@ -1,7 +1,7 @@
-

+

<%:Collecting data...%>

-
\ No newline at end of file + diff --git a/package/lean/luci-app-openvpn-server/po/zh-cn/openvpn-server.po b/package/lean/luci-app-openvpn-server/po/zh-cn/openvpn-server.po index b13d6a896..8d45f0f47 100644 --- a/package/lean/luci-app-openvpn-server/po/zh-cn/openvpn-server.po +++ b/package/lean/luci-app-openvpn-server/po/zh-cn/openvpn-server.po @@ -16,21 +16,18 @@ msgstr "端口" msgid "WAN DDNS or IP" msgstr "WAN口的 DDNS域名 或者 IP" - msgid "Client Network" msgstr "客户端网段" msgid "VPN Client Network IP with subnet" msgstr "客户端分配的网段地址(默认为 10.8.0.0 255.255.255.0)" - msgid "Client Settings" msgstr "客户端推送配置" msgid "OpenVPN Client config file" msgstr "OpenVPN 客户端配置文件" - msgid "Download .ovpn file" msgstr "一键下载 .ovpn 文件"