1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local fs = require("nixio.fs")
8 -- Widget, Name, Default(s), Description
10 { ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, translate("Set output verbosity") },
11 { Value, "nice",0, translate("Change process priority") },
12 { Value,"port",1194, translate("TCP/UDP port # for both local and remote") },
13 { ListValue,"dev_type",{ "tun", "tap" }, translate("Type of used device") },
15 { Value,"ifconfig","10.200.200.3 10.200.200.1", translate("Set tun/tap adapter parameters") },
16 { Value,"server","10.200.200.0 255.255.255.0", translate("Configure server mode") },
17 { Value,"server_bridge","192.168.1.1 255.255.255.0 192.168.1.128 192.168.1.254", translate("Configure server bridge") },
18 { Flag,"nobind",0, translate("Do not bind to local address and port") },
20 { Value,"keepalive","10 60", translate("Helper directive to simplify the expression of --ping and --ping-restart in server mode configurations") },
22 { ListValue,"proto",{ "udp", "tcp-client", "tcp-server" }, translate("Use protocol") },
24 { Flag,"client",0, translate("Configure client mode") },
25 { Flag,"client_to_client",0, translate("Allow client-to-client traffic") },
26 { DynamicList,"remote","vpnserver.example.org", translate("Remote host name or ip address") },
28 { FileUpload,"secret","/etc/openvpn/secret.key", translate("Enable Static Key encryption mode (non-TLS)") },
29 { ListValue,"key_direction", { 0, 1 }, translate("The key direction for 'tls-auth' and 'secret' options") },
30 { FileUpload,"pkcs12","/etc/easy-rsa/keys/some-client.pk12", translate("PKCS#12 file containing keys") },
31 { FileUpload,"ca","/etc/easy-rsa/keys/ca.crt", translate("Certificate authority") },
32 { FileUpload,"dh","/etc/easy-rsa/keys/dh1024.pem", translate("Diffie Hellman parameters") },
33 { FileUpload,"cert","/etc/easy-rsa/keys/some-client.crt", translate("Local certificate") },
34 { FileUpload,"key","/etc/easy-rsa/keys/some-client.key", translate("Local private key") },
35 { Value,"config","/etc/openvpn/ovpn-file.ovpn", translate("Local OVPN configuration file") },
39 local m = Map("openvpn")
40 local p = m:section( SimpleSection )
42 m.apply_on_parse = true
45 p.template = "openvpn/pageswitch"
50 local s = m:section( NamedSection, arg[1], "openvpn" )
52 for _, option in ipairs(basicParams) do
60 if option[1] == DummyValue then
62 elseif option[1] == FileUpload then
64 function o.cfgvalue(self, section)
65 local cfg_val = AbstractValue.cfgvalue(self, section)
72 function o.formvalue(self, section)
73 local sel_val = AbstractValue.formvalue(self, section)
74 local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
76 if sel_val and sel_val ~= "" then
80 if txt_val and txt_val ~= "" then
85 function o.remove(self, section)
86 local cfg_val = AbstractValue.cfgvalue(self, section)
87 local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
89 if cfg_val and fs.access(cfg_val) and txt_val == "" then
92 return AbstractValue.remove(self, section)
95 if option[1] == DynamicList then
96 function o.cfgvalue(...)
97 local val = AbstractValue.cfgvalue(...)
98 return ( val and type(val) ~= "table" ) and { val } or val
102 if type(option[3]) == "table" then
103 if o.optional then o:value("", "-- remove --") end
104 for _, v in ipairs(option[3]) do
108 o.default = tostring(option[3][1])
110 o.default = tostring(option[3])
115 if type(option[i]) == "table" then