applications/luci-radvd: expose ignore option, assign column widths
[project/luci.git] / applications / luci-radvd / luasrc / model / cbi / radvd / prefix.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2010 Jo-Philipp Wich <xm@subsignal.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 local sid = arg[1]
16
17 m = Map("radvd", translatef("Radvd - Prefix"),
18         translate("Radvd is a router advertisement daemon for IPv6. " ..
19                 "It listens to router solicitations and sends router advertisements " ..
20                 "as described in RFC 4861."))
21
22 m.redirect = luci.dispatcher.build_url("admin/network/radvd")
23
24 if m.uci:get("radvd", sid) ~= "prefix" then
25         luci.http.redirect(m.redirect)
26         return
27 end
28
29
30 s = m:section(NamedSection, sid, "interface", translate("Prefix Configuration"))
31 s.addremove = false
32
33 s:tab("general", translate("General"))
34 s:tab("advanced",  translate("Advanced"))
35
36
37 --
38 -- General
39 --
40
41 o = s:taboption("general", Flag, "ignore", translate("Enable"))
42 o.rmempty = false
43
44 function o.cfgvalue(...)
45         local v = Flag.cfgvalue(...)
46         return v == "1" and "0" or "1"
47 end
48
49 function o.write(self, section, value)
50         Flag.write(self, section, value == "1" and "0" or "1")
51 end
52
53
54 o = s:taboption("general", Value, "interface", translate("Interface"),
55         translate("Specifies the logical interface name this section belongs to"))
56
57 o.template = "cbi/network_netlist"
58 o.nocreate = true
59 o.optional = false
60
61 function o.formvalue(...)
62         return Value.formvalue(...) or "-"
63 end
64
65 function o.validate(self, value)
66         if value == "-" then
67                 return nil, translate("Interface required")
68         end
69         return value
70 end
71
72 function o.write(self, section, value)
73         m.uci:set("radvd", section, "ignore", 0)
74         m.uci:set("radvd", section, "interface", value)
75 end
76
77
78 o = s:taboption("general", Value, "prefix", translate("Prefix"),
79         translate("Advertised IPv6 prefix. If empty, the current interface prefix is used"))
80
81 o.optional = true
82 o.datatype = "ip6addr"
83
84
85 o = s:taboption("general", Flag, "AdvOnLink", translate("On-link determination"),
86         translate("Indicates that this prefix can be used for on-link determination (RFC4861)"))
87
88 o.rmempty = false
89 o.default = "1"
90
91
92 o = s:taboption("general", Flag, "AdvAutonomous", translate("Autonomous"),
93         translate("Indicates that this prefix can be used for autonomous address configuration (RFC4862)"))
94
95 o.rmempty = false
96 o.default = "1"
97
98
99 --
100 -- Advanced
101 --
102
103 o = s:taboption("advanced", Flag, "AdvRouterAddr", translate("Advertise router address"),
104         translate("Indicates that the address of interface is sent instead of network prefix, as is required by Mobile IPv6"))
105
106
107 o = s:taboption("advanced", Value, "AdvValidLifetime", translate("Valid lifetime"),
108         translate("Advertises the length of time in seconds that the prefix is valid for the purpose of on-link determination. Use 0 to specify an infinite lifetime"))
109
110 o.datatype = "uinteger"
111 o.placeholder = 86400
112
113 function o.cfgvalue(self, section)
114         local v = Value.cfgvalue(self, section)
115         if v == "infinity" then
116                 return 0
117         else
118                 return v
119         end
120 end
121
122 function o.write(self, section, value)
123         if value == "0" then
124                 Value.write(self, section, "infinity")
125         else
126                 Value.write(self, section, value)
127         end
128 end
129
130
131 o = s:taboption("advanced", Value, "AdvPreferredLifetime", translate("Preferred lifetime"),
132         translate("Advertises the length of time in seconds that addresses generated from the prefix via stateless address autoconfiguration remain preferred. Use 0 to specify an infinite lifetime"))
133
134 o.datatype = "uinteger"
135 o.placeholder = 14400
136
137 function o.cfgvalue(self, section)
138         local v = Value.cfgvalue(self, section)
139         if v == "infinity" then
140                 return 0
141         else
142                 return v
143         end
144 end
145
146 function o.write(self, section, value)
147         if value == "0" then
148                 Value.write(self, section, "infinity")
149         else
150                 Value.write(self, section, value)
151         end
152 end
153
154
155 o = s:taboption("advanced", Value, "Base6to4Interface", translate("6to4 interface"),
156         translate("Specifies a logical interface name to derive a 6to4 prefix from. The interfaces public IPv4 address is combined with 2002::/3 and the value of the prefix option"))
157
158 o.template = "cbi/network_netlist"
159 o.nocreate = true
160 o.unspecified = true
161
162
163 return m