root/luci/trunk/applications/luci-radvd/luasrc/model/cbi/radvd.lua @ 6530

Revision 6530, 6.2 KB (checked in by jow, 3 years ago)

applications/luci-radvd: fix removal of section in overview page

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12$Id$
13]]--
14
15m = Map("radvd", translate("Radvd"),
16    translate("Radvd is a router advertisement daemon for IPv6. " ..
17        "It listens to router solicitations and sends router advertisements " ..
18        "as described in RFC 4861."))
19
20local nm = require "luci.model.network".init(m.uci)
21
22
23--
24-- Interfaces
25--
26
27s = m:section(TypedSection, "interface", translate("Interfaces"))
28s.template = "cbi/tblsection"
29s.extedit  = luci.dispatcher.build_url("admin/network/radvd/interface/%s")
30s.anonymous = true
31s.addremove = true
32
33function s.create(...)
34    local id = TypedSection.create(...)
35    luci.http.redirect(s.extedit % id)
36end
37
38function s.remove(self, section)
39    if m.uci:get("radvd", section) == "interface" then
40        local iface = m.uci:get("radvd", section, "interface")
41        if iface then
42            m.uci:delete_all("radvd", "prefix",
43                function(s) return s.interface == iface end)
44
45            m.uci:delete_all("radvd", "route",
46                function(s) return s.interface == iface end)
47
48            m.uci:delete_all("radvd", "rdnss",
49                function(s) return s.interface == iface end)
50        end
51    end
52
53    return TypedSection.remove(self, section)
54end
55
56
57o = s:option(DummyValue, "interface", translate("Interface"))
58o.template = "cbi/network_netinfo"
59
60o = s:option(DummyValue, "UnicastOnly", translate("Multicast"))
61function o.cfgvalue(...)
62    local v = Value.cfgvalue(...)
63    return v == "1" and translate("no") or translate("yes")
64end
65
66o = s:option(DummyValue, "AdvSendAdvert", translate("Advertising"))
67function o.cfgvalue(...)
68    local v = Value.cfgvalue(...)
69    return v == "1" and translate("yes") or translate("no")
70end
71
72o = s:option(DummyValue, "MaxRtrAdvInterval", translate("Max. interval"))
73function o.cfgvalue(...)
74    local v = Value.cfgvalue(...) or "600"
75    return v .. "s"
76end
77
78o = s:option(DummyValue, "AdvHomeAgentFlag", translate("Mobile IPv6"))
79function o.cfgvalue(...)
80    local v = Value.cfgvalue(...)
81    return v == "1" and translate("yes") or translate("no")
82end
83
84o = s:option(DummyValue, "AdvDefaultPreference", translate("Preference"))
85function o.cfgvalue(...)
86    local v = Value.cfgvalue(...) or "medium"
87    return translate(v)
88end
89
90
91--
92-- Prefixes
93--
94
95s2 = m:section(TypedSection, "prefix", translate("Prefixes"))
96s2.template = "cbi/tblsection"
97s2.extedit  = luci.dispatcher.build_url("admin/network/radvd/prefix/%s")
98s2.addremove = true
99s2.anonymous = true
100
101function s2.create(...)
102    local id = TypedSection.create(...)
103    luci.http.redirect(s2.extedit % id)
104end
105
106
107o = s2:option(DummyValue, "interface", translate("Interface"))
108o.template = "cbi/network_netinfo"
109
110o = s2:option(DummyValue, "prefix", translate("Prefix"))
111function o.cfgvalue(self, section)
112    local v = Value.cfgvalue(self, section)
113    if not v then
114        local net = nm:get_network(m.uci:get("radvd", section, "interface"))
115        if net then
116            local ifc = nm:get_interface(net:ifname())
117            if ifc then
118                local adr
119                local lla = luci.ip.IPv6("fe80::/10")
120                for _, adr in ipairs(ifc:ip6addrs()) do
121                    if not lla:contains(adr) then
122                        v = adr:string()
123                        break
124                    end
125                end
126            end
127        end
128    else
129        v = luci.ip.IPv6(v)
130        v = v and v:string()
131    end
132
133    return v or "?"
134end
135
136o = s2:option(DummyValue, "AdvAutonomous", translate("Autonomous"))
137function o.cfgvalue(...)
138    local v = Value.cfgvalue(...)
139    return v == "1" and translate("yes") or translate("no")
140end
141
142o = s2:option(DummyValue, "AdvOnLink", translate("On-link"))
143function o.cfgvalue(...)
144    local v = Value.cfgvalue(...)
145    return v == "1" and translate("yes") or translate("no")
146end
147
148o = s2:option(DummyValue, "AdvValidLifetime", translate("Validity time"))
149function o.cfgvalue(...)
150    local v = Value.cfgvalue(...) or "86400"
151    return translate(v)
152end
153
154
155--
156-- Routes
157--
158
159s3 = m:section(TypedSection, "route", translate("Routes"))
160s3.template = "cbi/tblsection"
161s3.extedit  = luci.dispatcher.build_url("admin/network/radvd/route/%s")
162s3.addremove = true
163s3.anonymous = true
164
165function s3.create(...)
166    local id = TypedSection.create(...)
167    luci.http.redirect(s3.extedit % id)
168end
169
170
171o = s3:option(DummyValue, "interface", translate("Interface"))
172o.template = "cbi/network_netinfo"
173
174o = s3:option(DummyValue, "prefix", translate("Prefix"))
175function o.cfgvalue(self, section)
176    local v = Value.cfgvalue(self, section)
177    if v then
178        v = luci.ip.IPv6(v)
179        v = v and v:string()
180    end
181    return v or "?"
182end
183
184o = s3:option(DummyValue, "AdvRouteLifetime", translate("Lifetime"))
185function o.cfgvalue(self, section)
186    local v = Value.cfgvalue(self, section) or "1800"
187    return translate(v)
188end
189
190o = s3:option(DummyValue, "AdvRoutePreference", translate("Preference"))
191function o.cfgvalue(self, section)
192    local v = Value.cfgvalue(self, section) or "medium"
193    return translate(v)
194end
195
196
197--
198-- RDNSS
199--
200
201s4 = m:section(TypedSection, "rdnss", translate("RDNSS"))
202s4.template = "cbi/tblsection"
203s4.extedit  = luci.dispatcher.build_url("admin/network/radvd/rdnss/%s")
204s4.addremove = true
205s4.anonymous = true
206
207function s.create(...)
208    local id = TypedSection.create(...)
209    luci.http.redirect(s4.extedit % id)
210end
211
212
213o = s4:option(DummyValue, "interface", translate("Interface"))
214o.template = "cbi/network_netinfo"
215
216o = s4:option(DummyValue, "addr", translate("Address"))
217function o.cfgvalue(self, section)
218    local v = Value.cfgvalue(self, section)
219    if not v then
220        local net = nm:get_network(m.uci:get("radvd", section, "interface"))
221        if net then
222            local ifc = nm:get_interface(net:ifname())
223            if ifc then
224                local adr
225                local lla = luci.ip.IPv6("fe80::/10")
226                for _, adr in ipairs(ifc:ip6addrs()) do
227                    if not lla:contains(adr) then
228                        v = adr:network(128):string()
229                        break
230                    end
231                end
232            end
233        end
234    else
235        v = luci.ip.IPv6(v)
236        v = v and v:network(128):string()
237    end
238
239    return v or "?"
240end
241
242o = s4:option(DummyValue, "AdvRDNSSOpen", translate("Open"))
243function o.cfgvalue(self, section)
244    local v = Value.cfgvalue(self, section)
245    return v == "1" and translate("yes") or translate("no")
246end
247
248o = s4:option(DummyValue, "AdvRDNSSLifetime", translate("Lifetime"))
249function o.cfgvalue(self, section)
250    local v = Value.cfgvalue(self, section) or "1200"
251    return translate(v)
252end
253
254
255return m
Note: See TracBrowser for help on using the browser.