applications/luci-radvd: expose ignore option, assign column widths
[project/luci.git] / applications / luci-radvd / luasrc / model / cbi / radvd / route.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 - Route"),
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) ~= "route" then
25         luci.http.redirect(m.redirect)
26         return
27 end
28
29
30 s = m:section(NamedSection, sid, "interface", translate("Route Configuration"))
31 s.addremove = false
32
33
34 --
35 -- General
36 --
37
38 o = s:option(Flag, "ignore", translate("Enable"))
39 o.rmempty = false
40
41 function o.cfgvalue(...)
42         local v = Flag.cfgvalue(...)
43         return v == "1" and "0" or "1"
44 end
45
46 function o.write(self, section, value)
47         Flag.write(self, section, value == "1" and "0" or "1")
48 end
49
50
51 o = s:option(Value, "interface", translate("Interface"),
52         translate("Specifies the logical interface name this section belongs to"))
53
54 o.template = "cbi/network_netlist"
55 o.nocreate = true
56 o.optional = false
57
58 function o.formvalue(...)
59         return Value.formvalue(...) or "-"
60 end
61
62 function o.validate(self, value)
63         if value == "-" then
64                 return nil, translate("Interface required")
65         end
66         return value
67 end
68
69 function o.write(self, section, value)
70         m.uci:set("radvd", section, "ignore", 0)
71         m.uci:set("radvd", section, "interface", value)
72 end
73
74
75 o = s:option(Value, "prefix", translate("Prefix"),
76         translate("Advertised IPv6 prefix"))
77
78 o.rmempty = false
79 o.datatype = "ip6addr"
80
81
82 o = s:option(Value, "AdvRouteLifetime", translate("Lifetime"),
83         translate("Specifies the lifetime associated with the route in seconds. Use 0 to specify an infinite lifetime"))
84
85 o.datatype = "uinteger"
86 o.placeholder = 1800
87
88 function o.cfgvalue(self, section)
89         local v = Value.cfgvalue(self, section)
90         if v == "infinity" then
91                 return 0
92         else
93                 return v
94         end
95 end
96
97 function o.write(self, section, value)
98         if value == "0" then
99                 Value.write(self, section, "infinity")
100         else
101                 Value.write(self, section, value)
102         end
103 end
104
105
106 o = s:option(ListValue, "AdvRoutePreference", translate("Preference"),
107         translate("Specifies the preference associated with the default router"))
108
109 o.default = "medium"
110 o:value("low",    translate("low"))
111 o:value("medium", translate("medium"))
112 o:value("high",   translate("high"))
113
114
115 return m