| 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 | |
|---|
| 22 | |
|---|
| 23 | -- |
|---|
| 24 | -- Interfaces |
|---|
| 25 | -- |
|---|
| 26 | |
|---|
| 27 | s = m:section(TypedSection, "interface", translate("Interfaces")) |
|---|
| 28 | s.template = "cbi/tblsection" |
|---|
| 29 | s.extedit = luci.dispatcher.build_url("admin/network/radvd/interface/%s") |
|---|
| 30 | s.anonymous = true |
|---|
| 31 | s.addremove = true |
|---|
| 32 | |
|---|
| 33 | function s.create(...) |
|---|
| 34 | local id = TypedSection.create(...) |
|---|
| 35 | luci.http.redirect(s.extedit % id) |
|---|
| 36 | end |
|---|
| 37 | |
|---|
| 38 | function 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) |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | o = s:option(DummyValue, "interface", translate("Interface")) |
|---|
| 58 | o.template = "cbi/network_netinfo" |
|---|
| 59 | |
|---|
| 60 | o = s:option(DummyValue, "UnicastOnly", translate("Multicast")) |
|---|
| 61 | function o.cfgvalue(...) |
|---|
| 62 | local v = Value.cfgvalue(...) |
|---|
| 63 | return v == "1" and translate("no") or translate("yes") |
|---|
| 64 | end |
|---|
| 65 | |
|---|
| 66 | o = s:option(DummyValue, "AdvSendAdvert", translate("Advertising")) |
|---|
| 67 | function o.cfgvalue(...) |
|---|
| 68 | local v = Value.cfgvalue(...) |
|---|
| 69 | return v == "1" and translate("yes") or translate("no") |
|---|
| 70 | end |
|---|
| 71 | |
|---|
| 72 | o = s:option(DummyValue, "MaxRtrAdvInterval", translate("Max. interval")) |
|---|
| 73 | function o.cfgvalue(...) |
|---|
| 74 | local v = Value.cfgvalue(...) or "600" |
|---|
| 75 | return v .. "s" |
|---|
| 76 | end |
|---|
| 77 | |
|---|
| 78 | o = s:option(DummyValue, "AdvHomeAgentFlag", translate("Mobile IPv6")) |
|---|
| 79 | function o.cfgvalue(...) |
|---|
| 80 | local v = Value.cfgvalue(...) |
|---|
| 81 | return v == "1" and translate("yes") or translate("no") |
|---|
| 82 | end |
|---|
| 83 | |
|---|
| 84 | o = s:option(DummyValue, "AdvDefaultPreference", translate("Preference")) |
|---|
| 85 | function o.cfgvalue(...) |
|---|
| 86 | local v = Value.cfgvalue(...) or "medium" |
|---|
| 87 | return translate(v) |
|---|
| 88 | end |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | -- |
|---|
| 92 | -- Prefixes |
|---|
| 93 | -- |
|---|
| 94 | |
|---|
| 95 | s2 = m:section(TypedSection, "prefix", translate("Prefixes")) |
|---|
| 96 | s2.template = "cbi/tblsection" |
|---|
| 97 | s2.extedit = luci.dispatcher.build_url("admin/network/radvd/prefix/%s") |
|---|
| 98 | s2.addremove = true |
|---|
| 99 | s2.anonymous = true |
|---|
| 100 | |
|---|
| 101 | function s2.create(...) |
|---|
| 102 | local id = TypedSection.create(...) |
|---|
| 103 | luci.http.redirect(s2.extedit % id) |
|---|
| 104 | end |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | o = s2:option(DummyValue, "interface", translate("Interface")) |
|---|
| 108 | o.template = "cbi/network_netinfo" |
|---|
| 109 | |
|---|
| 110 | o = s2:option(DummyValue, "prefix", translate("Prefix")) |
|---|
| 111 | function 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 "?" |
|---|
| 134 | end |
|---|
| 135 | |
|---|
| 136 | o = s2:option(DummyValue, "AdvAutonomous", translate("Autonomous")) |
|---|
| 137 | function o.cfgvalue(...) |
|---|
| 138 | local v = Value.cfgvalue(...) |
|---|
| 139 | return v == "1" and translate("yes") or translate("no") |
|---|
| 140 | end |
|---|
| 141 | |
|---|
| 142 | o = s2:option(DummyValue, "AdvOnLink", translate("On-link")) |
|---|
| 143 | function o.cfgvalue(...) |
|---|
| 144 | local v = Value.cfgvalue(...) |
|---|
| 145 | return v == "1" and translate("yes") or translate("no") |
|---|
| 146 | end |
|---|
| 147 | |
|---|
| 148 | o = s2:option(DummyValue, "AdvValidLifetime", translate("Validity time")) |
|---|
| 149 | function o.cfgvalue(...) |
|---|
| 150 | local v = Value.cfgvalue(...) or "86400" |
|---|
| 151 | return translate(v) |
|---|
| 152 | end |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | -- |
|---|
| 156 | -- Routes |
|---|
| 157 | -- |
|---|
| 158 | |
|---|
| 159 | s3 = m:section(TypedSection, "route", translate("Routes")) |
|---|
| 160 | s3.template = "cbi/tblsection" |
|---|
| 161 | s3.extedit = luci.dispatcher.build_url("admin/network/radvd/route/%s") |
|---|
| 162 | s3.addremove = true |
|---|
| 163 | s3.anonymous = true |
|---|
| 164 | |
|---|
| 165 | function s3.create(...) |
|---|
| 166 | local id = TypedSection.create(...) |
|---|
| 167 | luci.http.redirect(s3.extedit % id) |
|---|
| 168 | end |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | o = s3:option(DummyValue, "interface", translate("Interface")) |
|---|
| 172 | o.template = "cbi/network_netinfo" |
|---|
| 173 | |
|---|
| 174 | o = s3:option(DummyValue, "prefix", translate("Prefix")) |
|---|
| 175 | function 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 "?" |
|---|
| 182 | end |
|---|
| 183 | |
|---|
| 184 | o = s3:option(DummyValue, "AdvRouteLifetime", translate("Lifetime")) |
|---|
| 185 | function o.cfgvalue(self, section) |
|---|
| 186 | local v = Value.cfgvalue(self, section) or "1800" |
|---|
| 187 | return translate(v) |
|---|
| 188 | end |
|---|
| 189 | |
|---|
| 190 | o = s3:option(DummyValue, "AdvRoutePreference", translate("Preference")) |
|---|
| 191 | function o.cfgvalue(self, section) |
|---|
| 192 | local v = Value.cfgvalue(self, section) or "medium" |
|---|
| 193 | return translate(v) |
|---|
| 194 | end |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | -- |
|---|
| 198 | -- RDNSS |
|---|
| 199 | -- |
|---|
| 200 | |
|---|
| 201 | s4 = m:section(TypedSection, "rdnss", translate("RDNSS")) |
|---|
| 202 | s4.template = "cbi/tblsection" |
|---|
| 203 | s4.extedit = luci.dispatcher.build_url("admin/network/radvd/rdnss/%s") |
|---|
| 204 | s4.addremove = true |
|---|
| 205 | s4.anonymous = true |
|---|
| 206 | |
|---|
| 207 | function s.create(...) |
|---|
| 208 | local id = TypedSection.create(...) |
|---|
| 209 | luci.http.redirect(s4.extedit % id) |
|---|
| 210 | end |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | o = s4:option(DummyValue, "interface", translate("Interface")) |
|---|
| 214 | o.template = "cbi/network_netinfo" |
|---|
| 215 | |
|---|
| 216 | o = s4:option(DummyValue, "addr", translate("Address")) |
|---|
| 217 | function 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 "?" |
|---|
| 240 | end |
|---|
| 241 | |
|---|
| 242 | o = s4:option(DummyValue, "AdvRDNSSOpen", translate("Open")) |
|---|
| 243 | function o.cfgvalue(self, section) |
|---|
| 244 | local v = Value.cfgvalue(self, section) |
|---|
| 245 | return v == "1" and translate("yes") or translate("no") |
|---|
| 246 | end |
|---|
| 247 | |
|---|
| 248 | o = s4:option(DummyValue, "AdvRDNSSLifetime", translate("Lifetime")) |
|---|
| 249 | function o.cfgvalue(self, section) |
|---|
| 250 | local v = Value.cfgvalue(self, section) or "1200" |
|---|
| 251 | return translate(v) |
|---|
| 252 | end |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | return m |
|---|