luci-app-openvpn: Handle missing openvpn config file.
authorMilad Mohtashamirad <[email protected]>
Mon, 18 Nov 2024 03:09:53 +0000 (14:09 +1100)
committerPaul Donald <[email protected]>
Sat, 30 Nov 2024 04:00:04 +0000 (05:00 +0100)
With this change if the specified config file (from UCI) doesn't exist,
it won't error out. instead it treats it as an empty file.
Previously, when clicking edit on the custom_config option in the UI, it
will show an error because the file doesn't exist there by default. As a
result, a user can't easily add (paste) a config file content.

Signed-off-by: Milad Mohtashamirad <[email protected]>
applications/luci-app-openvpn/luasrc/model/cbi/openvpn-file.lua

index 7197f45ef6854a6e3df7e5e842b784dad3c56b2a..25d69e0cc25136cbf76f6e1882a0508014766f64 100644 (file)
@@ -18,15 +18,7 @@ local function makeForm(id, title, desc)
        return f
 end
 
-if not cfg_file or not fs.access(cfg_file) then
-       local f = makeForm("error", nil, translatef("The OVPN config file (%s) could not be found, please check your configuration.", cfg_file or "n/a"))
-       f:append(Template("openvpn/ovpn_css"))
-       f.reset = false
-       f.submit = false
-       return f
-end
-
-if fs.stat(cfg_file).size >= 102400 then
+if fs.access(cfg_file) and fs.stat(cfg_file).size >= 102400 then
        local f = makeForm("error", nil,
                translatef("The size of the OVPN config file (%s) is too large for online editing in LuCI (&ge; 100 KB). ", cfg_file)
                .. translate("Please edit this file directly in a terminal session."))