luci-app-openvpn: fix proto param selection in basic
[project/luci.git] / applications / luci-app-openvpn / luasrc / model / cbi / openvpn-basic.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 require("luci.ip")
5 require("luci.model.uci")
6
7
8 local basicParams = {
9         --                                                              
10         -- Widget, Name, Default(s), Description
11         --
12                                         
13         { ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, translate("Set output verbosity") },
14         { Value, "nice",0, translate("Change process priority") },
15         { Value,"port",1194, translate("TCP/UDP port # for both local and remote") },
16         { ListValue,"dev_type",{ "tun", "tap" }, translate("Type of used device") },
17         { Flag,"tun_ipv6",0, translate("Make tun device IPv6 capable") },
18
19         { Value,"ifconfig","10.200.200.3 10.200.200.1", translate("Set tun/tap adapter parameters") },
20         { Value,"server","10.200.200.0 255.255.255.0", translate("Configure server mode") },
21         { Value,"server_bridge","192.168.1.1 255.255.255.0 192.168.1.128 192.168.1.254", translate("Configure server bridge") },
22         { Flag,"nobind",0, translate("Do not bind to local address and port") },
23
24         { ListValue,"comp_lzo",{"yes","no","adaptive"}, translate("Use fast LZO compression") },
25         { Value,"keepalive","10 60", translate("Helper directive to simplify the expression of --ping and --ping-restart in server mode configurations") },
26
27         { ListValue,"proto",{ "udp", "tcp-client", "tcp-server" }, translate("Use protocol") },
28
29         { Flag,"client",0, translate("Configure client mode") },
30         { Flag,"client_to_client",0, translate("Allow client-to-client traffic") },
31         { DynamicList,"remote","vpnserver.example.org", translate("Remote host name or ip address") },
32
33         { FileUpload,"secret","/etc/openvpn/secret.key", translate("Enable Static Key encryption mode (non-TLS)") },
34         { Value,"key_direction","1", translate("The key direction for 'tls-auth' and 'secret' options") },
35         { FileUpload,"pkcs12","/etc/easy-rsa/keys/some-client.pk12", translate("PKCS#12 file containing keys") },
36         { FileUpload,"ca","/etc/easy-rsa/keys/ca.crt", translate("Certificate authority") },
37         { FileUpload,"dh","/etc/easy-rsa/keys/dh1024.pem", translate("Diffie Hellman parameters") },
38         { FileUpload,"cert","/etc/easy-rsa/keys/some-client.crt", translate("Local certificate") },
39         { FileUpload,"key","/etc/easy-rsa/keys/some-client.key", translate("Local private key") },
40 }
41
42
43 local m = Map("openvpn")
44 local p = m:section( SimpleSection )
45
46 p.template = "openvpn/pageswitch"
47 p.mode     = "basic"
48 p.instance = arg[1]
49
50
51 local s = m:section( NamedSection, arg[1], "openvpn" )
52
53 for _, option in ipairs(basicParams) do
54         local o = s:option(
55                 option[1], option[2],
56                 option[2], option[4]
57         )
58         
59         o.optional = true
60
61         if option[1] == DummyValue then
62                 o.value = option[3]
63         else
64                 if option[1] == DynamicList then
65                         function o.cfgvalue(...)
66                                 local val = AbstractValue.cfgvalue(...)
67                                 return ( val and type(val) ~= "table" ) and { val } or val
68                         end
69                 end
70
71                 if type(option[3]) == "table" then
72                         if o.optional then o:value("", "-- remove --") end
73                         for _, v in ipairs(option[3]) do
74                                 v = tostring(v)
75                                 o:value(v)
76                         end
77                         o.default = tostring(option[3][1])
78                 else
79                         o.default = tostring(option[3])
80                 end
81         end
82
83         for i=5,#option do
84                 if type(option[i]) == "table" then
85                         o:depends(option[i])
86                 end
87         end
88 end
89
90 return m
91