luci-app-openvpn: create base directory if not available 5164/head
authorDirk Brenken <dev@brenken.org>
Fri, 2 Jul 2021 18:14:10 +0000 (20:14 +0200)
committerDirk Brenken <dev@brenken.org>
Fri, 2 Jul 2021 18:14:10 +0000 (20:14 +0200)
* trivial fix for never ending ticket #3454

Signed-off-by: Dirk Brenken <dev@brenken.org>
applications/luci-app-openvpn/luasrc/controller/openvpn.lua

index 2d57e8d3ad8b2a4c258831682ad07d8573be2c04..a30ac81a99df60970b1bfb1c630a209cf2c74883 100644 (file)
@@ -13,13 +13,18 @@ function index()
 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   = http.formvalue("instance_name2")
-       local file   = "/etc/openvpn/" ..name.. ".ovpn"
+       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    = http.formvalue("instance_name2")
+       local basedir = "/etc/openvpn"
+       local file    = basedir.. "/" ..name.. ".ovpn"
+
+       if not fs.stat(basedir) then
+               fs.mkdir(basedir)
+       end
 
        if name and upload then
                local fp