| 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 | m = 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 | |
|---|
| 20 | local nm = require "luci.model.network".init(m.uci) |
|---|
| 21 | local ut = require "luci.util" |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | -- |
|---|
| 25 | -- Interfaces |
|---|
| 26 | -- |
|---|
| 27 | |
|---|
| 28 | s = m:section(TypedSection, "interface", translate("Interfaces")) |
|---|
| 29 | s.template = "cbi/tblsection" |
|---|
| 30 | s.extedit = luci.dispatcher.build_url("admin/network/radvd/interface/%s") |
|---|
| 31 | s.anonymous = true |
|---|
| 32 | s.addremove = true |
|---|
| 33 | |
|---|
| 34 | function s.create(...) |
|---|
| 35 | local id = TypedSection.create(...) |
|---|
| 36 | luci.http.redirect(s.extedit % id) |
|---|
| 37 | end |
|---|
| 38 | |
|---|
| 39 | function s.remove(self, section) |
|---|
| 40 | if m.uci:get("radvd", section) == "interface" then |
|---|
| 41 | local iface = m.uci:get("radvd", section, "interface") |
|---|
| 42 | if iface then |
|---|
| 43 | m.uci:delete_all("radvd", "prefix", |
|---|
| 44 | function(s) return s.interface == iface end) |
|---|
| 45 | |
|---|
| 46 | m.uci:delete_all("radvd", "route", |
|---|
| 47 | function(s) return s.interface == iface end) |
|---|
| 48 | |
|---|
| 49 | m.uci:delete_all("radvd", "rdnss", |
|---|
| 50 | function(s) return s.interface == iface end) |
|---|
| 51 | end |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | return TypedSection.remove(self, section) |
|---|
| 55 | end |
|---|
| 56 | |
|---|
| 57 | o = s:option(Flag, "ignore", translate("Enable")) |
|---|
| 58 | o.rmempty = false |
|---|
| 59 | o.width = "30px" |
|---|
| 60 | function o.cfgvalue(...) |
|---|
| 61 | local v = Flag.cfgvalue(...) |
|---|
| 62 | return v == "1" and "0" or "1" |
|---|
| 63 | end |
|---|
| 64 | function o.write(self, section, value) |
|---|
| 65 | Flag.write(self, section, value == "1" and "0" or "1") |
|---|
| 66 | end |
|---|
| 67 | |
|---|
| 68 | o = s:option(DummyValue, "interface", translate("Interface")) |
|---|
| 69 | o.template = "cbi/network_netinfo" |
|---|
| 70 | o.width = "10%" |
|---|
| 71 | |
|---|
| 72 | o = s:option(DummyValue, "UnicastOnly", translate("Multicast")) |
|---|
| 73 | function o.cfgvalue(self, section) |
|---|
| 74 | local v = Value.cfgvalue(self, section) |
|---|
| 75 | local v2 = m.uci:get("radvd", section, "client") |
|---|
| 76 | return (v == "1" or (v2 and #v2 > 0)) and translate("no") or translate("yes") |
|---|
| 77 | end |
|---|
| 78 | |
|---|
| 79 | o = s:option(DummyValue, "AdvSendAdvert", translate("Advertising")) |
|---|
| 80 | function o.cfgvalue(...) |
|---|
| 81 | local v = Value.cfgvalue(...) |
|---|
| 82 | return v == "1" and translate("yes") or translate("no") |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | o = s:option(DummyValue, "MaxRtrAdvInterval", translate("Max. interval")) |
|---|
| 86 | function o.cfgvalue(...) |
|---|
| 87 | local v = Value.cfgvalue(...) or "600" |
|---|
| 88 | return v .. "s" |
|---|
| 89 | end |
|---|
| 90 | |
|---|
| 91 | o = s:option(DummyValue, "AdvHomeAgentFlag", translate("Mobile IPv6")) |
|---|
| 92 | function o.cfgvalue(...) |
|---|
| 93 | local v = Value.cfgvalue(...) |
|---|
| 94 | return v == "1" and translate("yes") or translate("no") |
|---|
| 95 | end |
|---|
| 96 | |
|---|
| 97 | o = s:option(DummyValue, "AdvDefaultPreference", translate("Preference")) |
|---|
| 98 | function o.cfgvalue(...) |
|---|
| 99 | local v = Value.cfgvalue(...) or "medium" |
|---|
| 100 | return translate(v) |
|---|
| 101 | end |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | -- |
|---|
| 105 | -- Prefixes |
|---|
| 106 | -- |
|---|
| 107 | |
|---|
| 108 | s2 = m:section(TypedSection, "prefix", translate("Prefixes")) |
|---|
| 109 | s2.template = "cbi/tblsection" |
|---|
| 110 | s2.extedit = luci.dispatcher.build_url("admin/network/radvd/prefix/%s") |
|---|
| 111 | s2.addremove = true |
|---|
| 112 | s2.anonymous = true |
|---|
| 113 | |
|---|
| 114 | function s2.create(...) |
|---|
| 115 | local id = TypedSection.create(...) |
|---|
| 116 | luci.http.redirect(s2.extedit % id) |
|---|
| 117 | end |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | o = s2:option(Flag, "ignore", translate("Enable")) |
|---|
| 121 | o.rmempty = false |
|---|
| 122 | o.width = "30px" |
|---|
| 123 | function o.cfgvalue(...) |
|---|
| 124 | local v = Flag.cfgvalue(...) |
|---|
| 125 | return v == "1" and "0" or "1" |
|---|
| 126 | end |
|---|
| 127 | function o.write(self, section, value) |
|---|
| 128 | Flag.write(self, section, value == "1" and "0" or "1") |
|---|
| 129 | end |
|---|
| 130 | |
|---|
| 131 | o = s2:option(DummyValue, "interface", translate("Interface")) |
|---|
| 132 | o.template = "cbi/network_netinfo" |
|---|
| 133 | o.width = "10%" |
|---|
| 134 | |
|---|
| 135 | o = s2:option(DummyValue, "prefix", translate("Prefix")) |
|---|
| 136 | o.width = "60%" |
|---|
| 137 | function o.cfgvalue(self, section) |
|---|
| 138 | local v = m.uci:get_list("radvd", section, "prefix") |
|---|
| 139 | local l = { } |
|---|
| 140 | |
|---|
| 141 | if not v then |
|---|
| 142 | local net = nm:get_network(m.uci:get("radvd", section, "interface")) |
|---|
| 143 | if net then |
|---|
| 144 | local ifc = nm:get_interface(net:ifname()) |
|---|
| 145 | if ifc then |
|---|
| 146 | local adr |
|---|
| 147 | for _, adr in ipairs(ifc:ip6addrs()) do |
|---|
| 148 | if not adr:is6linklocal() then |
|---|
| 149 | v = adr:string() |
|---|
| 150 | break |
|---|
| 151 | end |
|---|
| 152 | end |
|---|
| 153 | end |
|---|
| 154 | end |
|---|
| 155 | end |
|---|
| 156 | |
|---|
| 157 | for v in ut.imatch(v) do |
|---|
| 158 | v = luci.ip.IPv6(v) |
|---|
| 159 | if v then |
|---|
| 160 | l[#l+1] = v:string() |
|---|
| 161 | end |
|---|
| 162 | end |
|---|
| 163 | |
|---|
| 164 | if #l == 0 then |
|---|
| 165 | l[1] = "?" |
|---|
| 166 | end |
|---|
| 167 | |
|---|
| 168 | return table.concat(l, ", ") |
|---|
| 169 | end |
|---|
| 170 | |
|---|
| 171 | o = s2:option(DummyValue, "AdvAutonomous", translate("Autonomous")) |
|---|
| 172 | function o.cfgvalue(...) |
|---|
| 173 | local v = Value.cfgvalue(...) |
|---|
| 174 | return v == "1" and translate("yes") or translate("no") |
|---|
| 175 | end |
|---|
| 176 | |
|---|
| 177 | o = s2:option(DummyValue, "AdvOnLink", translate("On-link")) |
|---|
| 178 | function o.cfgvalue(...) |
|---|
| 179 | local v = Value.cfgvalue(...) |
|---|
| 180 | return v == "1" and translate("yes") or translate("no") |
|---|
| 181 | end |
|---|
| 182 | |
|---|
| 183 | o = s2:option(DummyValue, "AdvValidLifetime", translate("Validity time")) |
|---|
| 184 | function o.cfgvalue(...) |
|---|
| 185 | local v = Value.cfgvalue(...) or "86400" |
|---|
| 186 | return translate(v) |
|---|
| 187 | end |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | -- |
|---|
| 191 | -- Routes |
|---|
| 192 | -- |
|---|
| 193 | |
|---|
| 194 | s3 = m:section(TypedSection, "route", translate("Routes")) |
|---|
| 195 | s3.template = "cbi/tblsection" |
|---|
| 196 | s3.extedit = luci.dispatcher.build_url("admin/network/radvd/route/%s") |
|---|
| 197 | s3.addremove = true |
|---|
| 198 | s3.anonymous = true |
|---|
| 199 | |
|---|
| 200 | function s3.create(...) |
|---|
| 201 | local id = TypedSection.create(...) |
|---|
| 202 | luci.http.redirect(s3.extedit % id) |
|---|
| 203 | end |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | o = s3:option(Flag, "ignore", translate("Enable")) |
|---|
| 207 | o.rmempty = false |
|---|
| 208 | o.width = "30px" |
|---|
| 209 | function o.cfgvalue(...) |
|---|
| 210 | local v = Flag.cfgvalue(...) |
|---|
| 211 | return v == "1" and "0" or "1" |
|---|
| 212 | end |
|---|
| 213 | function o.write(self, section, value) |
|---|
| 214 | Flag.write(self, section, value == "1" and "0" or "1") |
|---|
| 215 | end |
|---|
| 216 | |
|---|
| 217 | o = s3:option(DummyValue, "interface", translate("Interface")) |
|---|
| 218 | o.template = "cbi/network_netinfo" |
|---|
| 219 | o.width = "10%" |
|---|
| 220 | |
|---|
| 221 | o = s3:option(DummyValue, "prefix", translate("Prefix")) |
|---|
| 222 | o.width = "60%" |
|---|
| 223 | function o.cfgvalue(self, section) |
|---|
| 224 | local v = m.uci:get_list("radvd", section, "prefix") |
|---|
| 225 | local l = { } |
|---|
| 226 | if v then |
|---|
| 227 | for v in ut.imatch(v) do |
|---|
| 228 | v = luci.ip.IPv6(v) |
|---|
| 229 | if v then |
|---|
| 230 | l[#l+1] = v:string() |
|---|
| 231 | end |
|---|
| 232 | end |
|---|
| 233 | end |
|---|
| 234 | |
|---|
| 235 | if #l == 0 then |
|---|
| 236 | l[1] = "?" |
|---|
| 237 | end |
|---|
| 238 | |
|---|
| 239 | return table.concat(l, ", ") |
|---|
| 240 | end |
|---|
| 241 | |
|---|
| 242 | o = s3:option(DummyValue, "AdvRouteLifetime", translate("Lifetime")) |
|---|
| 243 | function o.cfgvalue(self, section) |
|---|
| 244 | local v = Value.cfgvalue(self, section) or "1800" |
|---|
| 245 | return translate(v) |
|---|
| 246 | end |
|---|
| 247 | |
|---|
| 248 | o = s3:option(DummyValue, "AdvRoutePreference", translate("Preference")) |
|---|
| 249 | function o.cfgvalue(self, section) |
|---|
| 250 | local v = Value.cfgvalue(self, section) or "medium" |
|---|
| 251 | return translate(v) |
|---|
| 252 | end |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | -- |
|---|
| 256 | -- RDNSS |
|---|
| 257 | -- |
|---|
| 258 | |
|---|
| 259 | s4 = m:section(TypedSection, "rdnss", translate("RDNSS")) |
|---|
| 260 | s4.template = "cbi/tblsection" |
|---|
| 261 | s4.extedit = luci.dispatcher.build_url("admin/network/radvd/rdnss/%s") |
|---|
| 262 | s4.addremove = true |
|---|
| 263 | s4.anonymous = true |
|---|
| 264 | |
|---|
| 265 | function s4.create(...) |
|---|
| 266 | local id = TypedSection.create(...) |
|---|
| 267 | luci.http.redirect(s4.extedit % id) |
|---|
| 268 | end |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | o = s4:option(Flag, "ignore", translate("Enable")) |
|---|
| 272 | o.rmempty = false |
|---|
| 273 | o.width = "30px" |
|---|
| 274 | function o.cfgvalue(...) |
|---|
| 275 | local v = Flag.cfgvalue(...) |
|---|
| 276 | return v == "1" and "0" or "1" |
|---|
| 277 | end |
|---|
| 278 | function o.write(self, section, value) |
|---|
| 279 | Flag.write(self, section, value == "1" and "0" or "1") |
|---|
| 280 | end |
|---|
| 281 | |
|---|
| 282 | o = s4:option(DummyValue, "interface", translate("Interface")) |
|---|
| 283 | o.template = "cbi/network_netinfo" |
|---|
| 284 | o.width = "10%" |
|---|
| 285 | |
|---|
| 286 | o = s4:option(DummyValue, "addr", translate("Address")) |
|---|
| 287 | o.width = "60%" |
|---|
| 288 | function o.cfgvalue(self, section) |
|---|
| 289 | local v = m.uci:get_list("radvd", section, "addr") |
|---|
| 290 | local l = { } |
|---|
| 291 | if not v then |
|---|
| 292 | local net = nm:get_network(m.uci:get("radvd", section, "interface")) |
|---|
| 293 | if net then |
|---|
| 294 | local ifc = nm:get_interface(net:ifname()) |
|---|
| 295 | if ifc then |
|---|
| 296 | local adr |
|---|
| 297 | for _, adr in ipairs(ifc:ip6addrs()) do |
|---|
| 298 | if not adr:is6linklocal() then |
|---|
| 299 | v = adr:network(128):string() |
|---|
| 300 | break |
|---|
| 301 | end |
|---|
| 302 | end |
|---|
| 303 | end |
|---|
| 304 | end |
|---|
| 305 | end |
|---|
| 306 | |
|---|
| 307 | for v in ut.imatch(v) do |
|---|
| 308 | v = luci.ip.IPv6(v) |
|---|
| 309 | if v then |
|---|
| 310 | l[#l+1] = v:network(128):string() |
|---|
| 311 | end |
|---|
| 312 | end |
|---|
| 313 | |
|---|
| 314 | if #l == 0 then |
|---|
| 315 | l[1] = "?" |
|---|
| 316 | end |
|---|
| 317 | |
|---|
| 318 | return table.concat(l, ", ") |
|---|
| 319 | end |
|---|
| 320 | |
|---|
| 321 | o = s4:option(DummyValue, "AdvRDNSSLifetime", translate("Lifetime")) |
|---|
| 322 | function o.cfgvalue(self, section) |
|---|
| 323 | local v = Value.cfgvalue(self, section) or "1200" |
|---|
| 324 | return translate(v) |
|---|
| 325 | end |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | -- |
|---|
| 329 | -- DNSSL |
|---|
| 330 | -- |
|---|
| 331 | |
|---|
| 332 | s5 = m:section(TypedSection, "dnssl", translate("DNSSL")) |
|---|
| 333 | s5.template = "cbi/tblsection" |
|---|
| 334 | s5.extedit = luci.dispatcher.build_url("admin/network/radvd/dnssl/%s") |
|---|
| 335 | s5.addremove = true |
|---|
| 336 | s5.anonymous = true |
|---|
| 337 | |
|---|
| 338 | function s5.create(...) |
|---|
| 339 | local id = TypedSection.create(...) |
|---|
| 340 | luci.http.redirect(s5.extedit % id) |
|---|
| 341 | end |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | o = s5:option(Flag, "ignore", translate("Enable")) |
|---|
| 345 | o.rmempty = false |
|---|
| 346 | o.width = "30px" |
|---|
| 347 | function o.cfgvalue(...) |
|---|
| 348 | local v = Flag.cfgvalue(...) |
|---|
| 349 | return v == "1" and "0" or "1" |
|---|
| 350 | end |
|---|
| 351 | function o.write(self, section, value) |
|---|
| 352 | Flag.write(self, section, value == "1" and "0" or "1") |
|---|
| 353 | end |
|---|
| 354 | |
|---|
| 355 | o = s5:option(DummyValue, "interface", translate("Interface")) |
|---|
| 356 | o.template = "cbi/network_netinfo" |
|---|
| 357 | o.width = "10%" |
|---|
| 358 | |
|---|
| 359 | o = s5:option(DummyValue, "suffix", translate("Suffix")) |
|---|
| 360 | o.width = "60%" |
|---|
| 361 | function o.cfgvalue(self, section) |
|---|
| 362 | local v = m.uci:get_list("radvd", section, "suffix") |
|---|
| 363 | local l = { } |
|---|
| 364 | |
|---|
| 365 | for v in ut.imatch(v) do |
|---|
| 366 | l[#l+1] = v |
|---|
| 367 | end |
|---|
| 368 | |
|---|
| 369 | if #l == 0 then |
|---|
| 370 | l[1] = "?" |
|---|
| 371 | end |
|---|
| 372 | |
|---|
| 373 | return table.concat(l, ", ") |
|---|
| 374 | end |
|---|
| 375 | |
|---|
| 376 | o = s5:option(DummyValue, "AdvDNSSLLifetime", translate("Lifetime")) |
|---|
| 377 | function o.cfgvalue(self, section) |
|---|
| 378 | local v = Value.cfgvalue(self, section) or "1200" |
|---|
| 379 | return translate(v) |
|---|
| 380 | end |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | return m |
|---|