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