applications: add radvd frontend
[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(Value, "interface", translate("Interface"),
39         translate("Specifies the logical interface name this section belongs to"))
40
41 o.template = "cbi/network_netlist"
42 o.nocreate = true
43 o.optional = false
44
45 function o.formvalue(...)
46         return Value.formvalue(...) or "-"
47 end
48
49 function o.validate(self, value)
50         if value == "-" then
51                 return nil, translate("Interface required")
52         end
53         return value
54 end
55
56 function o.write(self, section, value)
57         m.uci:set("radvd", section, "ignore", 0)
58         m.uci:set("radvd", section, "interface", value)
59 end
60
61
62 o = s:option(Value, "prefix", translate("Prefix"),
63         translate("Advertised IPv6 prefix"))
64
65 o.rmempty = false
66 o.datatype = "ip6addr"
67
68
69 o = s:option(Value, "AdvRouteLifetime", translate("Lifetime"),
70         translate("Specifies the lifetime associated with the route in seconds. Use 0 to specify an infinite lifetime"))
71
72 o.datatype = "uinteger"
73 o.placeholder = 1800
74
75 function o.cfgvalue(self, section)
76         local v = Value.cfgvalue(self, section)
77         if v == "infinity" then
78                 return 0
79         else
80                 return v
81         end
82 end
83
84 function o.write(self, section, value)
85         if value == "0" then
86                 Value.write(self, section, "infinity")
87         else
88                 Value.write(self, section, value)
89         end
90 end
91
92
93 o = s:option(ListValue, "AdvRoutePreference", translate("Preference"),
94         translate("Specifies the preference associated with the default router"))
95
96 o.default = "medium"
97 o:value("low",    translate("low"))
98 o:value("medium", translate("medium"))
99 o:value("high",   translate("high"))
100
101
102 return m