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
12 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 },
13 translate("Set output verbosity") },
17 translate("Change process priority") },
21 translate("TCP/UDP port # for both local and remote") },
25 translate("Type of used device") },
28 "10.200.200.3 10.200.200.1",
29 translate("Set tun/tap adapter parameters") },
32 "10.200.200.0 255.255.255.0",
33 translate("Configure server mode") },
36 "192.168.1.1 255.255.255.0 192.168.1.128 192.168.1.254",
37 translate("Configure server bridge") },
41 translate("Do not bind to local address and port") },
44 {"yes","no","adaptive"},
45 translate("Use fast LZO compression") },
49 translate("Helper directive to simplify the expression of --ping and --ping-restart in server mode configurations") },
53 translate("Configure client mode") },
57 translate("Allow client-to-client traffic") },
60 "vpnserver.example.org",
61 translate("Remote host name or ip address") },
64 "/etc/openvpn/secret.key",
65 translate("Enable Static Key encryption mode (non-TLS)") },
69 translate("The key direction for 'tls-auth' and 'secret' options") },
72 "/etc/easy-rsa/keys/some-client.pk12",
73 translate("PKCS#12 file containing keys") },
76 "/etc/easy-rsa/keys/ca.crt",
77 translate("Certificate authority") },
80 "/etc/easy-rsa/keys/dh1024.pem",
81 translate("Diffie Hellman parameters") },
84 "/etc/easy-rsa/keys/some-client.crt",
85 translate("Local certificate") },
88 "/etc/easy-rsa/keys/some-client.key",
89 translate("Local private key") },
92 local has_ipv6 = fs.access("/proc/net/ipv6_route")
94 table.insert( basicParams, { ListValue,
96 { "udp", "tcp-client", "tcp-server", "udp6", "tcp6-client", "tcp6-server" },
97 translate("Use protocol")
100 table.insert( basicParams, { ListValue,
102 { "udp", "tcp-client", "tcp-server" },
103 translate("Use protocol")
107 local m = Map("openvpn")
108 m.redirect = luci.dispatcher.build_url("admin", "vpn", "openvpn")
109 m.apply_on_parse = true
111 local p = m:section( SimpleSection )
112 p.template = "openvpn/pageswitch"
117 local s = m:section( NamedSection, arg[1], "openvpn" )
119 for _, option in ipairs(basicParams) do
121 option[1], option[2],
127 if option[1] == DummyValue then
129 elseif option[1] == FileUpload then
131 function o.cfgvalue(self, section)
132 local cfg_val = AbstractValue.cfgvalue(self, section)
139 function o.formvalue(self, section)
140 local sel_val = AbstractValue.formvalue(self, section)
141 local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
143 if sel_val and sel_val ~= "" then
147 if txt_val and txt_val ~= "" then
152 function o.remove(self, section)
153 local cfg_val = AbstractValue.cfgvalue(self, section)
154 local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
156 if cfg_val and fs.access(cfg_val) and txt_val == "" then
159 return AbstractValue.remove(self, section)
161 elseif option[1] == Flag then
164 if option[1] == DynamicList then
165 function o.cfgvalue(...)
166 local val = AbstractValue.cfgvalue(...)
167 return ( val and type(val) ~= "table" ) and { val } or val
171 if type(option[3]) == "table" then
172 if o.optional then o:value("", "-- remove --") end
173 for _, v in ipairs(option[3]) do
177 o.default = tostring(option[3][1])
179 o.default = tostring(option[3])
184 if type(option[i]) == "table" then