f48beea46db3188aaba2eac6c0fd7db60c931f85
[project/luci.git] / applications / luci-app-radvd / luasrc / model / cbi / radvd / rdnss.lua
1 -- Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local sid = arg[1]
5 local utl = require "luci.util"
6
7 m = Map("radvd", translatef("Radvd - RDNSS"),
8         translate("Radvd is a router advertisement daemon for IPv6. " ..
9                 "It listens to router solicitations and sends router advertisements " ..
10                 "as described in RFC 4861."))
11
12 m.redirect = luci.dispatcher.build_url("admin/network/radvd")
13
14 if m.uci:get("radvd", sid) ~= "rdnss" then
15         luci.http.redirect(m.redirect)
16         return
17 end
18
19
20 s = m:section(NamedSection, sid, "interface", translate("RDNSS Configuration"))
21 s.addremove = false
22
23
24 --
25 -- General
26 --
27
28 o = s:option(Flag, "ignore", translate("Enable"))
29 o.rmempty = false
30
31 function o.cfgvalue(...)
32         local v = Flag.cfgvalue(...)
33         return v == "1" and "0" or "1"
34 end
35
36 function o.write(self, section, value)
37         Flag.write(self, section, value == "1" and "0" or "1")
38 end
39
40
41 o = s:option(Value, "interface", translate("Interface"),
42         translate("Specifies the logical interface name this section belongs to"))
43
44 o.template = "cbi/network_netlist"
45 o.nocreate = true
46 o.optional = false
47
48 function o.formvalue(...)
49         return Value.formvalue(...) or "-"
50 end
51
52 function o.validate(self, value)
53         if value == "-" then
54                 return nil, translate("Interface required")
55         end
56         return value
57 end
58
59 function o.write(self, section, value)
60         m.uci:set("radvd", section, "ignore", 0)
61         m.uci:set("radvd", section, "interface", value)
62 end
63
64
65 o = s:option(DynamicList, "addr", translate("Addresses"),
66         translate("Advertised IPv6 RDNSS. If empty, the current IPv6 address of the interface is used"))
67
68 o.optional    = false
69 o.rmempty     = true
70 o.datatype    = "ip6addr"
71 o.placeholder = translate("default")
72 function o.cfgvalue(self, section)
73         local l = { }
74         local v = m.uci:get_list("radvd", section, "addr")
75         for v in utl.imatch(v) do
76                 l[#l+1] = v
77         end
78         return l
79 end
80
81
82 o = s:option(Value, "AdvRDNSSLifetime", translate("Lifetime"),
83         translate("Specifies the maximum duration how long the RDNSS entries are used for name resolution."))
84
85 o.datatype = 'or(uinteger,"infinity")'
86 o.placeholder = 1200
87
88
89 return m