* luci/app/openvpn: controller, model and template updates
[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(option[1], option[2])
65 o.optional = true
66
67 if option[1] == DummyValue then
68 o.value = option[3]
69 else
70 if option[1] == DynamicList then
71 o.cast = nil
72 function o.cfgvalue(...)
73 local val = AbstractValue.cfgvalue(...)
74 return ( val and type(val) ~= "table" ) and { val } or val
75 end
76 end
77
78 if type(option[3]) == "table" then
79 if o.optional then o:value("", "-- remove --") end
80 for _, v in ipairs(option[3]) do
81 v = tostring(v)
82 o:value(v)
83 end
84 o.default = tostring(option[3][1])
85 else
86 o.default = tostring(option[3])
87 end
88 end
89
90 for i=5,#option do
91 if type(option[i]) == "table" then
92 o:depends(option[i])
93 end
94 end
95 end
96
97 return m