1d4cc4d7acc3068425513818290173398c96c7aa
[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 { FileUpload, "secret", "/etc/openvpn/secret.key 1" },
46 { FileUpload, "pkcs12", "/etc/easy-rsa/keys/some-client.pk12" },
47 { FileUpload, "ca", "/etc/easy-rsa/keys/ca.crt" },
48 { FileUpload, "dh", "/etc/easy-rsa/keys/dh1024.pem" },
49 { FileUpload, "cert", "/etc/easy-rsa/keys/some-client.crt" },
50 { FileUpload, "key", "/etc/easy-rsa/keys/some-client.key" },
51 }
52
53
54 local m = Map("openvpn")
55 local p = m:section( SimpleSection )
56
57 p.template = "openvpn/pageswitch"
58 p.mode = "basic"
59 p.instance = arg[1]
60
61
62 local s = m:section( NamedSection, arg[1], "openvpn" )
63
64 for _, option in ipairs(basicParams) do
65 local o = s:option(
66 option[1], option[2],
67 translate("openvpn_param_%s" % option[2]),
68 translate("openvpn_param_%s_desc" % option[2])
69 )
70
71 o.optional = true
72
73 if option[1] == DummyValue then
74 o.value = option[3]
75 else
76 if option[1] == DynamicList then
77 o.cast = nil
78 function o.cfgvalue(...)
79 local val = AbstractValue.cfgvalue(...)
80 return ( val and type(val) ~= "table" ) and { val } or val
81 end
82 end
83
84 if type(option[3]) == "table" then
85 if o.optional then o:value("", "-- remove --") end
86 for _, v in ipairs(option[3]) do
87 v = tostring(v)
88 o:value(v)
89 end
90 o.default = tostring(option[3][1])
91 else
92 o.default = tostring(option[3])
93 end
94 end
95
96 for i=5,#option do
97 if type(option[i]) == "table" then
98 o:depends(option[i])
99 end
100 end
101 end
102
103 return m