summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
diff options
context:
space:
mode:
authorDirk Brenken <dev@brenken.org>2018-10-20 21:22:49 +0200
committerDirk Brenken <dev@brenken.org>2018-10-23 21:17:22 +0200
commit0b04912f8d495ea836d565f3536b59d030225cfa (patch)
tree143498433847d1e42e59dcc66652fbef2a3a4bbb /applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
parenta0cc0769d8faf38172312a376d33aec241c19126 (diff)
luci-app-openvpn: add ovpn upload support & more
* add the ability to upload ovpn files directly, incl. appropriate uci entry in openvpn config * add the ability to edit ovpn files directly ('file' mode), beside the 'basic' and 'advanced' modes for normal setups * client side checks to validate instance name & template selection, incl. online error reporting * automatically remove non-ascii characters & windows line endings from transfered ovpn file * change from after_commit to after_apply hook * remove misleading default values for Port & Protocol in Overview Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua')
-rw-r--r--applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua35
1 files changed, 20 insertions, 15 deletions
diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
index e17aa4085b..8f4859c0e5 100644
--- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
+++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
@@ -4,7 +4,7 @@
local fs = require "nixio.fs"
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
-local testfullps = luci.sys.exec("ps --help 2>&1 | grep BusyBox") --check which ps do we have
+local testfullps = sys.exec("ps --help 2>&1 | grep BusyBox") --check which ps do we have
local psstring = (string.len(testfullps)>0) and "ps w" or "ps axfw" --set command we use to get pid
local m = Map("openvpn", translate("OpenVPN"))
@@ -13,9 +13,16 @@ s.template = "cbi/tblsection"
s.template_addremove = "openvpn/cbi-select-input-add"
s.addremove = true
s.add_select_options = { }
-s.extedit = luci.dispatcher.build_url(
- "admin", "services", "openvpn", "basic", "%s"
-)
+
+file_cfg = s:option(DummyValue, "config")
+function file_cfg.cfgvalue(self, section)
+ local file_cfg = self.map:get(section, "config")
+ if file_cfg then
+ s.extedit = luci.dispatcher.build_url("admin", "services", "openvpn", "file", "%s")
+ else
+ s.extedit = luci.dispatcher.build_url("admin", "services", "openvpn", "basic", "%s")
+ end
+end
uci:load("openvpn_recipes")
uci:foreach( "openvpn_recipes", "openvpn_recipe",
@@ -61,10 +68,10 @@ function s.create(self, name)
if s then
local options = uci:get_all("openvpn_recipes", recipe)
for k, v in pairs(options) do
- uci:set("openvpn", name, k, v)
+ if k ~= "_role" and k ~= "_description" then
+ uci:set("openvpn", name, k, v)
+ end
end
- uci:delete("openvpn", name, "_role")
- uci:delete("openvpn", name, "_description")
uci:save("openvpn")
luci.http.redirect( self.extedit:format(name) )
end
@@ -75,7 +82,6 @@ function s.create(self, name)
return 0
end
-
s:option( Flag, "enabled", translate("Enabled") )
local active = s:option( DummyValue, "_active", translate("Started") )
@@ -106,28 +112,27 @@ function updown.cfgvalue(self, section)
end
function updown.write(self, section, value)
if self.option == "stop" then
- luci.sys.call("/etc/init.d/openvpn stop %s" % section)
+ sys.call("/etc/init.d/openvpn stop %s" % section)
else
- luci.sys.call("/etc/init.d/openvpn start %s" % section)
+ sys.call("/etc/init.d/openvpn start %s" % section)
end
luci.http.redirect( self.redirect )
end
-
local port = s:option( DummyValue, "port", translate("Port") )
function port.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)
- return val or "1194"
+ return val or "-"
end
local proto = s:option( DummyValue, "proto", translate("Protocol") )
function proto.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)
- return val or "udp"
+ return val or "-"
end
-function m.on_after_commit(self,map)
- require("luci.sys").call('/etc/init.d/openvpn reload')
+function m.on_after_apply(self,map)
+ sys.call('/etc/init.d/openvpn reload')
end
return m