diff options
author | Dirk Brenken <dev@brenken.org> | 2018-10-20 21:22:49 +0200 |
---|---|---|
committer | Dirk Brenken <dev@brenken.org> | 2018-10-23 21:17:22 +0200 |
commit | 0b04912f8d495ea836d565f3536b59d030225cfa (patch) | |
tree | 143498433847d1e42e59dcc66652fbef2a3a4bbb /applications/luci-app-openvpn/luasrc/controller/openvpn.lua | |
parent | a0cc0769d8faf38172312a376d33aec241c19126 (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/controller/openvpn.lua')
-rw-r--r-- | applications/luci-app-openvpn/luasrc/controller/openvpn.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/applications/luci-app-openvpn/luasrc/controller/openvpn.lua b/applications/luci-app-openvpn/luasrc/controller/openvpn.lua index 2e48a469a1..2c153c4cd5 100644 --- a/applications/luci-app-openvpn/luasrc/controller/openvpn.lua +++ b/applications/luci-app-openvpn/luasrc/controller/openvpn.lua @@ -8,4 +8,47 @@ function index() entry( {"admin", "services", "openvpn"}, cbi("openvpn"), _("OpenVPN") ) entry( {"admin", "services", "openvpn", "basic"}, cbi("openvpn-basic"), nil ).leaf = true entry( {"admin", "services", "openvpn", "advanced"}, cbi("openvpn-advanced"), nil ).leaf = true + entry( {"admin", "services", "openvpn", "file"}, form("openvpn-file"), nil ).leaf = true + entry( {"admin", "services", "openvpn", "upload"}, call("ovpn_upload")) +end + +function ovpn_upload() + local fs = require("nixio.fs") + local http = require("luci.http") + local util = require("luci.util") + local uci = require("luci.model.uci").cursor() + local upload = http.formvalue("ovpn_file") + local name = util.shellquote(http.formvalue("instance_name2")) + local file = "/etc/openvpn/" ..name.. ".ovpn" + + if name and upload then + local fp + + http.setfilehandler( + function(meta, chunk, eof) + local data = util.trim(chunk:gsub("\r\n", "\n")) .. "\n" + data = util.trim(data:gsub("[\128-\255]", "")) + + if not fp and meta and meta.name == "ovpn_file" then + fp = io.open(file, "w") + end + if fp and data then + fp:write(data) + end + if fp and eof then + fp:close() + end + end + ) + + if fs.access(file) then + if not uci:get_first("openvpn", name) then + uci:set("openvpn", name, "openvpn") + uci:set("openvpn", name, "config", file) + uci:save("openvpn") + uci:commit("openvpn") + end + end + end + http.redirect(luci.dispatcher.build_url('admin/services/openvpn')) end |