cadf558bf732db8a55ffa605489dfb0ab0173c4a
[project/luci.git] / applications / luci-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.fs")
16 require("luci.ip")
17 require("luci.model.uci")
18
19
20 local basicParams = {
21 --
22 -- Widget Name Optn. Default(s)
23 --
24
25 { ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } },
26 { Value, "nice", 0 },
27 { Value, "port", 1194 },
28 { ListValue, "dev_type", { "tun", "tap" } },
29 { Flag, "tun_ipv6", 0 },
30
31 { Value, "ifconfig", "10.200.200.3 10.200.200.1" },
32 { Value, "server", "10.200.200.0 255.255.255.0" },
33 { Value, "server_bridge", "192.168.1.1 255.255.255.0 192.168.1.128 192.168.1.254" },
34 { Flag, "nobind", 0 },
35
36 { Flag, "comp_lzo", 0 },
37 { Value, "keepalive", "10 60" },
38
39 { ListValue, "proto", { "udp", "tcp" } },
40
41 { Flag, "client", 0 },
42 { Flag, "client_to_client", 0 },
43 { DynamicList, "remote", "vpnserver.example.org" },
44
45 { Value, "secret", "/etc/openvpn/secret.key 1" },
46 { Value, "ca", "/etc/easy-rsa/keys/ca.crt" },
47 { Value, "dh", "/etc/easy-rsa/keys/dh1024.pem" },
48 { Value, "cert", "/etc/easy-rsa/keys/some-client.crt" },
49 { Value, "key", "/etc/easy-rsa/keys/some-client.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 translate("openvpn_param_%s" % option[2]),
67 translate("openvpn_param_%s_desc" % option[2])
68 )
69
70 o.optional = true
71
72 if option[1] == DummyValue then
73 o.value = option[3]
74 else
75 if option[1] == DynamicList then
76 o.cast = nil
77 function o.cfgvalue(...)
78 local val = AbstractValue.cfgvalue(...)
79 return ( val and type(val) ~= "table" ) and { val } or val
80 end
81 end
82
83 if type(option[3]) == "table" then
84 if o.optional then o:value("", "-- remove --") end
85 for _, v in ipairs(option[3]) do
86 v = tostring(v)
87 o:value(v)
88 end
89 o.default = tostring(option[3][1])
90 else
91 o.default = tostring(option[3])
92 end
93 end
94
95 for i=5,#option do
96 if type(option[i]) == "table" then
97 o:depends(option[i])
98 end
99 end
100 end
101
102 return m