1 -- Licensed to the public under the Apache License 2.0.
3 local ip = require("luci.ip")
4 local fs = require("nixio.fs")
5 local util = require("luci.util")
6 local uci = require("luci.model.uci").cursor()
7 local cfg_file = uci:get("openvpn", arg[1], "config")
9 local m = Map("openvpn")
11 local p = m:section( SimpleSection )
12 p.template = "openvpn/pageswitch"
16 if not cfg_file or not fs.access(cfg_file) then
17 local f = SimpleForm("error", nil, translatef("The OVPN config file (%s) could not be found, please check your configuration.", cfg_file or "n/a"))
18 f:append(Template("openvpn/ovpn_css"))
24 if fs.stat(cfg_file).size >= 102400 then
25 f = SimpleForm("error", nil,
26 translatef("The size of the OVPN config file (%s) is too large for online editing in LuCI (≥ 100 KB). ", cfg_file)
27 .. translate("Please edit this file directly in a terminal session."))
28 f:append(Template("openvpn/ovpn_css"))
34 f = SimpleForm("cfg", nil)
35 f:append(Template("openvpn/ovpn_css"))
36 f.submit = translate("Save")
39 s = f:section(SimpleSection, nil, translatef("This form allows you to modify the content of the OVPN config file (%s). ", cfg_file))
40 file = s:option(TextValue, "data")
41 file.datatype = "string"
45 function file.cfgvalue()
46 return fs.readfile(cfg_file) or ""
49 function file.write(self, section, data)
50 return fs.writefile(cfg_file, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
53 function file.remove(self, section, value)
54 return fs.writefile(cfg_file, "")
57 function s.handle(self, state, data)