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