2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 Copyright 2011 Patrick Grimm <patrick@pberg.freifunk.net>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
19 local uci = require "luci.model.uci".cursor()
20 local uci_state = require "luci.model.uci".cursor_state()
21 local tools = require "luci.tools.ffwizard"
22 local util = require "luci.util"
23 local sys = require "luci.sys"
24 local ip = require "luci.ip"
25 local fs = require "nixio.fs"
27 local has_pptp = fs.access("/usr/sbin/pptp")
28 local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")()
29 local has_l2gvpn = fs.access("/usr/sbin/node")
30 local has_radvd = fs.access("/etc/config/radvd")
31 local has_rom = fs.access("/rom/etc")
32 local has_autoipv6 = fs.access("/usr/bin/auto-ipv6")
33 local has_qos = fs.access("/etc/init.d/qos")
34 local has_ipv6 = fs.access("/proc/sys/net/ipv6")
35 local has_hb = fs.access("/sbin/heartbeat")
37 luci.i18n.loadc("freifunk")
40 if string.find(ix, "radio") then
41 ix = string.gsub(ix,"radio", 'wlan')
43 local mac = fs.readfile("/sys/class/net/" .. ix .. "/address")
45 mac = luci.util.exec("ifconfig " .. ix)
46 mac = mac and mac:match(" ([A-F0-9:]+)%s*\n")
50 if mac and #mac > 0 then
55 function get_ula(imac)
56 if string.len(imac) == 17 then
57 local mac1 = string.sub(imac,4,8)
58 local mac2 = string.sub(imac,10,14)
59 local mac3 = string.sub(imac,16,17)
60 return 'fdca:ffee:babe::02'..mac1..'ff:fe'..mac2..mac3..'/64'
66 -------------------- View --------------------
67 f = SimpleForm("ffwizward", "Freifunkassistent",
68 "Dieser Assistent unterstützt Sie bei der Einrichtung des Routers für das Freifunknetz.")
70 local newpsswd = has_rom and sys.exec("diff /rom/etc/passwd /etc/passwd")
71 if newpsswd ~= "" then
72 pw = f:field(Flag, "pw", "Router Passwort", "Setzen Sie den Haken, um Ihr Passwort zu ändern.")
73 function pw.cfgvalue(self, section)
78 pw1 = f:field(Value, "pw1", translate("password"))
82 pw2 = f:field(Value, "pw2", translate("confirmation"))
86 function pw2.validate(self, value, section)
87 return pw1:formvalue(section) == value and value
90 if newpsswd ~= "" then
91 pw1:depends("pw", "1")
92 pw2:depends("pw", "1")
95 net = f:field(ListValue, "net", "Freifunk Community", "Nutzen Sie die Einstellungen der Freifunk Gemeinschaft in ihrer Nachbarschaft.")
98 uci:foreach("freifunk", "community", function(s)
99 net:value(s[".name"], "%s (%s)" % {s.name, s.mesh_network or "?"})
101 function net.cfgvalue(self, section)
102 return uci:get("freifunk", "wizard", "net")
104 function net.write(self, section, value)
105 uci:set("freifunk", "wizard", "net", value)
108 net_lat = f:field(ListValue, "net_lat", "", "")
109 net_lat:depends("net", "0")
110 net_lon = f:field(ListValue, "net_lon", "", "")
111 net_lon:depends("net", "0")
113 uci:foreach("freifunk", "community", function(s)
115 net_lat:value(s[".name"], "%s" % {s.latitude or "?"})
118 net_lon:value(s[".name"], "%s" % {s.longitude or "?"})
123 hostname = f:field(Value, "hostname", "Knoten Name", "Geben Sie Ihrem Freifunk Router einen Namen. Wenn Sie dieses Feld leer lassen, wird der Name automatisch aus der Mesh IP generiert.")
124 hostname.rmempty = true
125 hostname.optional = false
126 function hostname.cfgvalue(self, section)
127 return sys.hostname()
129 function hostname.write(self, section, value)
130 uci:set("freifunk", "wizard", "hostname", value)
133 function hostname.validate(self, value)
134 if (#value > 16) then
136 elseif (string.find(value, "[^%w%_%-]")) then
144 location = f:field(Value, "location", "Standort", "Geben Sie den Standort ihres Gerätes an")
145 location.rmempty = false
146 location.optional = false
147 function location.cfgvalue(self, section)
148 return uci:get("freifunk", "contact", "location")
150 function location.write(self, section, value)
151 uci:set("freifunk", "contact", "location", value)
156 mail = f:field(Value, "mail", "E-Mail", "Bitte hinterlegen Sie eine Kontaktadresse.")
158 mail.optional = false
159 function mail.cfgvalue(self, section)
160 return uci:get("freifunk", "contact", "mail")
162 function mail.write(self, section, value)
163 uci:set("freifunk", "contact", "mail", value)
167 main = f:field(Flag, "netconfig", "Netzwerk einrichten", "Setzen Sie den Haken, wenn Sie Ihr Freifunk Netzwerk einrichten wollen.")
168 uci:foreach("wireless", "wifi-device",
170 local device = section[".name"]
171 local dev = f:field(Flag, "device_" .. device , "<b>Drahtloses Netzwerk \"" .. device:upper() .. "\"</b> ", "Konfigurieren Sie Ihre drahtlose " .. device:upper() .. "Schnittstelle (WLAN).")
172 dev:depends("netconfig", "1")
174 function dev.cfgvalue(self, section)
175 return uci:get("freifunk", "wizard", "device_" .. device)
177 function dev.write(self, sec, value)
179 uci:set("freifunk", "wizard", "device_" .. device, value)
183 local chan = f:field(ListValue, "chan_" .. device, device:upper() .. " Freifunk Kanal einrichten", "Ihr Gerät und benachbarte Freifunk Knoten müssen auf demselben Kanal senden. Je nach Gerätetyp können Sie zwischen verschiedenen 2,4Ghz und 5Ghz Kanälen auswählen.")
184 chan:depends("device_" .. device, "1")
186 function chan.cfgvalue(self, section)
187 return uci:get("freifunk", "wizard", "chan_" .. device)
189 chan:value('default')
196 for i = 100, 140, 4 do
199 function chan.write(self, sec, value)
201 uci:set("freifunk", "wizard", "chan_" .. device, value)
205 local meship = f:field(Value, "meship_" .. device, device:upper() .. " Mesh IP Adresse einrichten", "Ihre Mesh IP Adresse erhalten Sie von der Freifunk Gemeinschaft in Ihrer Nachbarschaft. Es ist eine netzweit eindeutige Identifikation, z.B. 104.1.1.1.")
206 meship:depends("device_" .. device, "1")
207 meship.rmempty = true
208 function meship.cfgvalue(self, section)
209 return uci:get("freifunk", "wizard", "meship_" .. device)
211 function meship.validate(self, value)
212 local x = ip.IPv4(value)
213 return ( x and x:prefix() == 32 ) and x:string() or ""
215 function meship.write(self, sec, value)
216 uci:set("freifunk", "wizard", "meship_" .. device, value)
217 local new_ip = ip.IPv4(value)
219 local new_hostname = new_ip:string():gsub("%.", "-")
220 uci:set("freifunk", "wizard", "hostname", new_hostname)
225 local meship6 = f:field(Value, "meship6_" .. device, device:upper() .. " Mesh IPv6 Adresse einrichten", "Ihre Mesh IP Adresse wird automatisch berechnet")
226 meship6:depends("device_" .. device, "1")
227 meship6.rmempty = true
228 function meship6.cfgvalue(self, section)
229 return get_ula(get_mac(device))
233 local client = f:field(Flag, "client_" .. device, device:upper() .. " DHCP anbieten", "DHCP weist verbundenen Benutzern automatisch eine Adresse zu. Diese Option sollten Sie unbedingt aktivieren, wenn Sie Nutzer an der drahtlosen Schnittstelle erwarten.")
234 client:depends("device_" .. device, "1")
235 client.rmempty = false
236 function client.cfgvalue(self, section)
237 return uci:get("freifunk", "wizard", "client_" .. device)
239 function client.write(self, sec, value)
240 uci:set("freifunk", "wizard", "client_" .. device, value)
243 local dhcpmesh = f:field(Value, "dhcpmesh_" .. device, device:upper() .. " Mesh DHCP anbieten", "Bestimmen Sie den Adressbereich aus dem Ihre Nutzer IP Adressen erhalten. Es wird empfohlen einen Adressbereich aus Ihrer lokalen Freifunk Gemeinschaft zu nutzen. Der Adressbereich ist ein netzweit eindeutiger Netzbereich. z.B. 104.1.2.1/28")
244 dhcpmesh:depends("client_" .. device, "1")
245 dhcpmesh.rmempty = true
246 function dhcpmesh.cfgvalue(self, section)
247 return uci:get("freifunk", "wizard", "dhcpmesh_" .. device)
249 function dhcpmesh.validate(self, value)
250 local x = ip.IPv4(value)
251 return ( x and x:minhost()) and x:string() or ""
253 function dhcpmesh.write(self, sec, value)
254 uci:set("freifunk", "wizard", "dhcpmesh_" .. device, value)
257 local hwtype = section.type
258 if hwtype == "atheros" then
259 local vap = f:field(Flag, "vap_" .. device , "Virtueller Drahtloser Zugangspunkt", "Konfigurieren Sie Ihren Virtuellen AP")
260 vap:depends("client_" .. device, "1")
262 function vap.cfgvalue(self, section)
263 return uci:get("freifunk", "wizard", "vap_" .. device)
265 function vap.write(self, sec, value)
266 uci:set("freifunk", "wizard", "vap_" .. device, value)
272 uci:foreach("network", "interface",
274 local device = section[".name"]
275 local ifname = uci_state:get("network",device,"ifname")
276 if device ~= "loopback" and not string.find(device, "gvpn") and not string.find(device, "wifi") and not string.find(device, "wl") and not string.find(device, "wlan") and not string.find(device, "wireless") and not string.find(device, "radio") then
277 dev = f:field(Flag, "device_" .. device , "<b>Drahtgebundenes Netzwerk \"" .. device:upper() .. "\"</b>", "Konfigurieren Sie Ihre drahtgebunde " .. device:upper() .. " Schnittstelle (LAN).")
278 dev:depends("netconfig", "1")
280 function dev.cfgvalue(self, section)
281 return uci:get("freifunk", "wizard", "device_" .. device)
283 function dev.write(self, sec, value)
284 uci:set("freifunk", "wizard", "device_" .. device, value)
287 meship = f:field(Value, "meship_" .. device, device:upper() .. " Mesh IP Adresse einrichten", "Ihre Mesh IP Adresse erhalten Sie von der Freifunk Gemeinschaft in Ihrer Nachbarschaft. Es ist eine netzweit eindeutige Identifikation, z.B. 104.1.1.1.")
288 meship:depends("device_" .. device, "1")
289 meship.rmempty = true
290 function meship.cfgvalue(self, section)
291 return uci:get("freifunk", "wizard", "meship_" .. device)
293 function meship.validate(self, value)
294 local x = ip.IPv4(value)
295 return ( x and x:prefix() == 32 ) and x:string() or ""
297 function meship.write(self, sec, value)
298 uci:set("freifunk", "wizard", "meship_" .. device, value)
301 meship6 = f:field(Value, "meship6_" .. device, device:upper() .. " Mesh IPv6 Adresse einrichten", "Ihre Mesh IP Adresse wird automatisch berechnet")
302 meship6:depends("device_" .. device, "1")
303 meship6.rmempty = true
304 function meship6.cfgvalue(self, section)
305 return get_ula(get_mac(ifname))
309 client = f:field(Flag, "client_" .. device, device:upper() .. " DHCP anbieten","DHCP weist verbundenen Benutzern automatisch eine Adresse zu. Diese Option sollten Sie unbedingt aktivieren, wenn Sie Nutzer an der drahtlosen Schnittstelle erwarten.")
310 client:depends("device_" .. device, "1")
311 client.rmempty = false
312 function client.cfgvalue(self, section)
313 return uci:get("freifunk", "wizard", "client_" .. device)
315 function client.write(self, sec, value)
316 uci:set("freifunk", "wizard", "client_" .. device, value)
319 dhcpmesh = f:field(Value, "dhcpmesh_" .. device, device:upper() .. " Mesh DHCP anbieten ", "Bestimmen Sie den Adressbereich aus dem Ihre Nutzer IP Adressen erhalten. Es wird empfohlen einen Adressbereich aus Ihrer lokalen Freifunk Gemeinschaft zu nutzen. Der Adressbereich ist ein netzweit eindeutiger Netzbereich. z.B. 104.1.2.1/28")
320 dhcpmesh:depends("client_" .. device, "1")
321 dhcpmesh.rmempty = true
322 function dhcpmesh.cfgvalue(self, section)
323 return uci:get("freifunk", "wizard", "dhcpmesh_" .. device)
325 function dhcpmesh.validate(self, value)
326 local x = ip.IPv4(value)
327 return ( x and x:prefix() <= 30 and x:minhost()) and x:string() or ""
329 function dhcpmesh.write(self, sec, value)
330 uci:set("freifunk", "wizard", "dhcpmesh_" .. device, value)
337 local syslat = uci:get("freifunk", "wizard", "latitude") or 52
338 local syslon = uci:get("freifunk", "wizard", "longitude") or 10
339 uci:foreach("system", "system", function(s)
347 uci:foreach("olsrd", "LoadPlugin", function(s)
348 if s.library == "olsrd_nameservice.so.0.3" then
358 lat = f:field(Value, "lat", "geographischer Breitengrad", "Setzen Sie den Breitengrad (Latitude) Ihres Geräts.")
359 lat:depends("netconfig", "1")
360 function lat.cfgvalue(self, section)
363 function lat.write(self, section, value)
364 uci:set("freifunk", "wizard", "latitude", value)
368 lon = f:field(Value, "lon", "geograpischer Längengrad", "Setzen Sie den Längengrad (Longitude) Ihres Geräts.")
369 lon:depends("netconfig", "1")
370 function lon.cfgvalue(self, section)
373 function lon.write(self, section, value)
374 uci:set("freifunk", "wizard", "longitude", value)
379 *Opens an OpenStreetMap iframe or popup
380 *Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
381 (is that the right place for files like these?)
384 local class = util.class
386 OpenStreetMapLonLat = class(AbstractValue)
388 function OpenStreetMapLonLat.__init__(self, ...)
389 AbstractValue.__init__(self, ...)
390 self.template = "cbi/osmll_value"
396 self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
399 self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
400 self.hidetext="X" -- text on button, that hides OSMap
403 osm = f:field(OpenStreetMapLonLat, "latlon", "Geokoordinaten mit OpenStreetMap ermitteln:", "Klicken Sie auf Ihren Standort in der Karte. Diese Karte funktioniert nur, wenn das Gerät bereits eine Verbindung zum Internet hat.")
404 osm:depends("netconfig", "1")
407 osm.centerlat = syslat
408 osm.centerlon = syslon
412 syslatlengh = string.len(syslat)
413 if syslatlengh > 7 then
415 elseif syslatlengh > 5 then
420 osm.displaytext="OpenStreetMap anzeigen"
421 osm.hidetext="OpenStreetMap verbergen"
423 share = f:field(Flag, "sharenet", "Eigenen Internetzugang freigeben", "Geben Sie Ihren Internetzugang im Freifunknetz frei.")
424 share.rmempty = false
425 share:depends("netconfig", "1")
426 function share.cfgvalue(self, section)
427 return uci:get("freifunk", "wizard", "share")
429 function share.write(self, section, value)
430 uci:set("freifunk", "wizard", "share", value)
434 wanproto = f:field(ListValue, "wanproto", "Protokoll des Internetzugangs", "Geben Sie das Protokol an ueber das eine Internet verbindung hergestellt werden kann.")
435 wanproto:depends("sharenet", "1")
436 wanproto:value("static", translate("manual", "manual"))
437 wanproto:value("dhcp", translate("automatic", "automatic"))
438 if has_pppoe then wanproto:value("pppoe", "PPPoE") end
439 if has_pptp then wanproto:value("pptp", "PPTP") end
440 function wanproto.cfgvalue(self, section)
441 return uci:get("network", "wan", "proto") or "dhcp"
443 function wanproto.write(self, section, value)
444 uci:set("network", "wan", "proto", value)
447 wanip = f:field(Value, "wanipaddr", translate("ipaddress"))
448 wanip:depends("wanproto", "static")
449 function wanip.cfgvalue(self, section)
450 return uci:get("network", "wan", "ipaddr")
452 function wanip.write(self, section, value)
453 uci:set("network", "wan", "ipaddr", value)
456 wannm = f:field(Value, "wannetmask", translate("netmask"))
457 wannm:depends("wanproto", "static")
458 function wannm.cfgvalue(self, section)
459 return uci:get("network", "wan", "netmask")
461 function wannm.write(self, section, value)
462 uci:set("network", "wan", "netmask", value)
465 wangw = f:field(Value, "wangateway", translate("gateway"))
466 wangw:depends("wanproto", "static")
468 function wangw.cfgvalue(self, section)
469 return uci:get("network", "wan", "gateway")
471 function wangw.write(self, section, value)
472 uci:set("network", "wan", "gateway", value)
475 wandns = f:field(Value, "wandns", translate("dnsserver"))
476 wandns:depends("wanproto", "static")
477 wandns.rmempty = true
478 function wandns.cfgvalue(self, section)
479 return uci:get("network", "wan", "dns")
481 function wandns.write(self, section, value)
482 uci:set("network", "wan", "dns", value)
485 wanusr = f:field(Value, "wanusername", translate("username"))
486 wanusr:depends("wanproto", "pppoe")
487 wanusr:depends("wanproto", "pptp")
488 function wanusr.cfgvalue(self, section)
489 return uci:get("network", "wan", "username")
491 function wanusr.write(self, section, value)
492 uci:set("network", "wan", "username", value)
495 wanpwd = f:field(Value, "wanpassword", translate("password"))
496 wanpwd.password = true
497 wanpwd:depends("wanproto", "pppoe")
498 wanpwd:depends("wanproto", "pptp")
499 function wanpwd.cfgvalue(self, section)
500 return uci:get("network", "wan", "password")
502 function wanpwd.write(self, section, value)
503 uci:set("network", "wan", "password", value)
507 wansec = f:field(Flag, "wansec", "WAN-Zugriff auf Gateway beschränken", "Verbieten Sie Zugriffe auf Ihr lokales Netzwerk aus dem Freifunknetz.")
508 wansec.rmempty = false
509 wansec:depends("wanproto", "static")
510 wansec:depends("wanproto", "dhcp")
511 function wansec.cfgvalue(self, section)
512 return uci:get("freifunk", "wizard", "wan_security")
514 function wansec.write(self, section, value)
515 uci:set("freifunk", "wizard", "wan_security", value)
519 wanqosdown = f:field(Value, "wanqosdown", "Download Bandbreite begrenzen", "kb/s")
520 wanqosdown:depends("sharenet", "1")
521 function wanqosdown.cfgvalue(self, section)
522 return uci:get("qos", "wan", "download")
524 function wanqosdown.write(self, section, value)
525 uci:set("qos", "wan", "download", value)
528 wanqosup = f:field(Value, "wanqosup", "Upload Bandbreite begrenzen", "kb/s")
529 wanqosup:depends("sharenet", "1")
530 function wanqosup.cfgvalue(self, section)
531 return uci:get("qos", "wan", "upload")
533 function wanqosup.write(self, section, value)
534 uci:set("qos", "wan", "upload", value)
540 gvpn = f:field(Flag, "gvpn", "Freifunk Internet Tunnel", "Verbinden Sie ihren Router ueber das Internet mit anderen Freifunknetzen.")
542 gvpn:depends("sharenet", "1")
543 function gvpn.cfgvalue(self, section)
544 return uci:get("freifunk", "wizard", "gvpn")
546 function gvpn.write(self, section, value)
547 uci:set("freifunk", "wizard", "gvpn", value)
550 gvpnip = f:field(Value, "gvpnipaddr", translate("ipaddress"))
551 gvpnip:depends("gvpn", "1")
552 function gvpnip.cfgvalue(self, section)
553 return uci:get("l2gvpn", "bbb", "ip") or uci:get("network", "gvpn", "ipaddr")
555 function gvpnip.validate(self, value)
556 local x = ip.IPv4(value)
557 return ( x and x:prefix() == 32 ) and x:string() or ""
562 hb = f:field(Flag, "hb", "Heartbeat aktivieren","Dem Gerät erlauben anonyme Statistiken zu übertragen. (empfohlen)")
564 hb:depends("netconfig", "1")
565 function hb.cfgvalue(self, section)
566 return uci:get("freifunk", "wizard", "hb")
568 function hb.write(self, section, value)
569 uci:set("freifunk", "wizard", "hb", value)
574 -------------------- Control --------------------
575 function f.handle(self, state, data)
576 if state == FORM_VALID then
577 local debug = uci:get("freifunk", "wizard", "debug")
580 local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
582 f.message = translate("a_s_changepw_changed")
584 f.errmessage = translate("unknownerror")
589 luci.http.redirect(luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path), "system", "system"))
592 local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
594 -- f.message = translate("a_s_changepw_changed")
596 -- f.errmessage = translate("unknownerror")
600 uci:commit("freifunk")
601 uci:commit("wireless")
602 uci:commit("network")
604 uci:commit("luci_splash")
605 uci:commit("firewall")
609 uci:commit("manager")
611 uci:commit("autoipv6")
622 -- the following line didn't work without admin-mini, for now i just replaced it with sys.exec... soma
623 -- luci.http.redirect(luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path), "system", "reboot") .. "?reboot=1")
627 elseif state == FORM_INVALID then
628 self.errmessage = "Ungültige Eingabe: Bitte die Formularfelder auf Fehler prüfen."
633 local function _strip_internals(tbl)
635 for k, v in pairs(tbl) do
636 if k:sub(1, 1) == "." then
642 -- Configure Freifunk checked
643 function main.write(self, section, value)
645 uci:set("freifunk", "wizard", "netconfig", "0")
649 -- Collect IP-Address
650 local community = net:formvalue(section)
651 suffix = uci:get("freifunk", community, "suffix") or "olsr"
654 if not community then
655 net.tag_missing[section] = true
659 uci:set("freifunk", "wizard", "netconfig", "1")
663 external = uci:get("freifunk", community, "external") or ""
665 local netname = "wireless"
667 network = ip.IPv4(uci:get("freifunk", community, "mesh_network") or "104.0.0.0/8")
669 -- Tune community settings
670 if community and uci:get("freifunk", community) then
671 uci:tset("freifunk", "community", uci:get_all("freifunk", community))
675 uci:delete_all("firewall","zone", {name="freifunk"})
676 uci:delete_all("firewall","forwarding", {dest="freifunk"})
677 uci:delete_all("firewall","forwarding", {src="freifunk"})
678 uci:delete_all("firewall","rule", {dest="freifunk"})
679 uci:delete_all("firewall","rule", {src="freifunk"})
681 -- Create firewall zone and add default rules (first time)
682 -- firewall_create_zone("name" , "input" , "output", "forward ", Masqurade)
683 local newzone = tools.firewall_create_zone("freifunk", "ACCEPT", "ACCEPT", "REJECT" , true)
685 uci:foreach("freifunk", "fw_forwarding", function(section)
686 uci:section("firewall", "forwarding", nil, section)
688 uci:foreach(external, "fw_forwarding", function(section)
689 uci:section("firewall", "forwarding", nil, section)
692 uci:foreach("freifunk", "fw_rule", function(section)
693 uci:section("firewall", "rule", nil, section)
695 uci:foreach(external, "fw_rule", function(section)
696 uci:section("firewall", "rule", nil, section)
701 uci:delete("manager", "heartbeat", "interface")
705 uci:delete_all("olsrd", "olsrd")
707 olsrbase = uci:get_all("freifunk", "olsrd") or {}
708 util.update(olsrbase, uci:get_all(external, "olsrd") or {})
710 olsrbase.IpVersion='6and4'
712 olsrbase.IpVersion='4'
714 uci:section("olsrd", "olsrd", nil, olsrbase)
715 -- Delete olsrdv4 old p2pd settings
716 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_mdns.so.1.0.0"})
717 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_p2pd.so.0.1.0"})
718 -- Write olsrdv4 new p2pd settings
719 uci:section("olsrd", "LoadPlugin", nil, {
720 library = "olsrd_p2pd.so.0.1.0",
722 UdpDestPort = "224.0.0.251 5353",
725 -- Delete http plugin
726 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_httpinfo.so.0.1"})
728 -- Delete olsrdv4 old interface
729 uci:delete_all("olsrd", "Interface")
730 uci:delete_all("olsrd", "Hna4")
731 -- Create wireless ip4/ip6 and firewall config
732 uci:foreach("wireless", "wifi-device",
734 local device = sec[".name"]
735 if not luci.http.formvalue("cbid.ffwizward.1.device_" .. device) then
738 node_ip = luci.http.formvalue("cbid.ffwizward.1.meship_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.meship_" .. device))
740 node_ip6 = luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device) and ip.IPv6(luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device))
742 if not node_ip or not network or not network:contains(node_ip) then
743 meship.tag_missing[section] = true
747 -- rename the wireless interface s/wifi/wireless/
749 if string.find(device, "wifi") then
750 nif = string.gsub(device,"wifi", netname)
751 elseif string.find(device, "wl") then
752 nif = string.gsub(device,"wl", netname)
753 elseif string.find(device, "wlan") then
754 nif = string.gsub(device,"wlan", netname)
755 elseif string.find(device, "radio") then
756 nif = string.gsub(device,"radio", netname)
759 tools.wifi_delete_ifaces(device)
760 -- tools.network_remove_interface(device)
761 uci:delete("network", device .. "dhcp")
762 uci:delete("network", device)
763 tools.firewall_zone_remove_interface("freifunk", device)
764 -- tools.network_remove_interface(nif)
765 uci:delete("network", nif .. "dhcp")
766 uci:delete("network", nif)
767 tools.firewall_zone_remove_interface("freifunk", nif)
769 uci:delete("dhcp", device)
770 uci:delete("dhcp", device .. "dhcp")
771 uci:delete("dhcp", nif)
772 uci:delete("dhcp", nif .. "dhcp")
774 uci:delete_all("luci_splash", "iface", {network=device.."dhcp", zone="freifunk"})
775 uci:delete_all("luci_splash", "iface", {network=nif.."dhcp", zone="freifunk"})
778 uci:delete_all("radvd", "interface", {interface=nif.."dhcp"})
779 uci:delete_all("radvd", "interface", {interface=nif})
780 uci:delete_all("radvd", "prefix", {interface=nif.."dhcp"})
781 uci:delete_all("radvd", "prefix", {interface=nif})
785 local ssiduci = uci:get("freifunk", community, "ssid")
786 local ssiddot = string.find(ssiduci,'%..*')
789 ssidshort = string.sub(ssiduci,ssiddot)
793 local devconfig = uci:get_all("freifunk", "wifi_device")
794 util.update(devconfig, uci:get_all(external, "wifi_device") or {})
795 local ssid = uci:get("freifunk", community, "ssid")
796 local channel = luci.http.formvalue("cbid.ffwizward.1.chan_" .. device)
797 local hwmode = "11bg"
798 local bssid = "02:CA:FF:EE:BA:BE"
800 if channel and channel ~= "default" then
801 if devconfig.channel ~= channel then
802 devconfig.channel = channel
803 local chan = tonumber(channel)
804 if chan >= 0 and chan < 10 then
805 bssid = channel .. "2:CA:FF:EE:BA:BE"
806 ssid = "ch" .. channel .. ssidshort
807 elseif chan == 10 then
808 bssid = "02:CA:FF:EE:BA:BE"
809 ssid = "ch" .. channel .. ssidshort
810 elseif chan >= 11 and chan <= 14 then
811 bssid = string.format("%X",channel) .. "2:CA:FF:EE:BA:BE"
812 ssid = "ch" .. channel .. ssidshort
813 elseif chan >= 36 and chan <= 64 then
817 bssid = "00:" .. channel ..":CA:FF:EE:EE"
818 ssid = "ch" .. channel .. ssidshort
819 elseif chan >= 100 and chan <= 140 then
823 bssid = "01:" .. string.sub(channel, 2) .. ":CA:FF:EE:EE"
824 ssid = "ch" .. channel .. ssidshort
826 devconfig.hwmode = hwmode
827 devconfig.outdoor = outdoor
830 uci:tset("wireless", device, devconfig)
832 local ifconfig = uci:get_all("freifunk", "wifi_iface")
833 util.update(ifconfig, uci:get_all(external, "wifi_iface") or {})
834 ifconfig.device = device
835 ifconfig.network = nif
837 -- See Table https://kifuse02.pberg.freifunk.net/moin/channel-bssid-essid
840 ifconfig.ssid = "olsr.freifunk.net"
842 -- See Table https://kifuse02.pberg.freifunk.net/moin/channel-bssid-essid
843 ifconfig.bssid = bssid
844 ifconfig.encryption="none"
846 local netconfig = uci:get_all("freifunk", "interface")
847 util.update(netconfig, uci:get_all(external, "interface") or {})
848 netconfig.proto = "static"
849 netconfig.ipaddr = node_ip:string()
851 netconfig.ip6addr = node_ip6:string()
853 uci:section("network", "interface", nif, netconfig)
855 uci:section("radvd", "interface", nil, {
859 AdvOtherConfigFlag =0,
862 uci:section("radvd", "prefix", nil, {
871 local new_hostname = node_ip:string():gsub("%.", "-")
872 uci:set("freifunk", "wizard", "hostname", new_hostname)
874 tools.firewall_zone_add_interface("freifunk", nif)
876 -- Write new olsrv4 interface
877 local olsrifbase = uci:get_all("freifunk", "olsr_interface")
878 util.update(olsrifbase, uci:get_all(external, "olsr_interface") or {})
879 olsrifbase.interface = nif
880 olsrifbase.ignore = "0"
881 uci:section("olsrd", "Interface", nil, olsrifbase)
882 -- Collect MESH DHCP IP NET
883 local client = luci.http.formvalue("cbid.ffwizward.1.client_" .. device)
885 local dhcpmeshnet = luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device))
887 local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
888 table.insert(ifacelist,nif .. "dhcp")
889 uci:set_list("manager", "heartbeat", "interface", ifacelist)
893 if not dhcpmeshnet:minhost() or not dhcpmeshnet:mask() then
894 dhcpmesh.tag_missing[section] = true
898 dhcp_ip = dhcpmeshnet:minhost():string()
899 dhcp_mask = dhcpmeshnet:mask():string()
900 dhcp_network = dhcpmeshnet:network():string()
901 uci:section("olsrd", "Hna4", nil, {
903 netaddr = dhcp_network
905 uci:foreach("olsrd", "LoadPlugin",
907 if s.library == "olsrd_p2pd.so.0.1.0" then
908 uci:set("olsrd", s['.name'], "ignore", "0")
909 local nonolsr = uci:get("olsrd", s['.name'], "NonOlsrIf") or ""
910 vap = luci.http.formvalue("cbid.ffwizward.1.vap_" .. device)
912 nonolsr = nif.."dhcp "..nonolsr
914 nonolsr = nif.." "..nonolsr
916 uci:set("olsrd", s['.name'], "NonOlsrIf", nonolsr)
920 local subnet_prefix = tonumber(uci:get("freifunk", community, "splash_prefix")) or 27
921 local pool_network = uci:get("freifunk", community, "splash_network") or "10.104.0.0/16"
922 local pool = luci.ip.IPv4(pool_network)
923 local ip = tostring(node_ip)
925 local hosts_per_subnet = 2^(32 - subnet_prefix)
926 local number_of_subnets = (2^pool:prefix())/hosts_per_subnet
927 local seed1, seed2 = ip:match("(%d+)%.(%d+)$")
928 if seed1 and seed2 then
929 math.randomseed(seed1 * seed2)
931 local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets))
932 dhcp_ip = subnet:network(subnet_prefix):add(1):string()
933 dhcp_mask = subnet:mask(subnet_prefix):string()
936 if dhcp_ip and dhcp_mask then
938 local aliasbase = uci:get_all("freifunk", "alias")
939 util.update(aliasbase, uci:get_all(external, "alias") or {})
940 aliasbase.ipaddr = dhcp_ip
941 aliasbase.netmask = dhcp_mask
942 aliasbase.proto = "static"
943 vap = luci.http.formvalue("cbid.ffwizward.1.vap_" .. device)
945 uci:section("network", "interface", nif .. "dhcp", aliasbase)
946 uci:section("wireless", "wifi-iface", nil, {
950 network =nif.."dhcp",
951 ssid ="AP"..ssidshort
954 uci:section("radvd", "interface", nil, {
955 interface =nif .. "dhcp",
958 AdvOtherConfigFlag =0,
961 uci:section("radvd", "prefix", nil, {
962 interface =nif .. "dhcp",
970 tools.firewall_zone_add_interface("freifunk", nif .. "dhcp")
972 ifconfig.mcast_rate = nil
973 ifconfig.encryption="none"
975 aliasbase.interface = nif
976 uci:section("network", "alias", nif .. "dhcp", aliasbase)
979 local dhcpbase = uci:get_all("freifunk", "dhcp")
980 util.update(dhcpbase, uci:get_all(external, "dhcp") or {})
981 dhcpbase.interface = nif .. "dhcp"
983 uci:section("dhcp", "dhcp", nif .. "dhcp", dhcpbase)
984 uci:set_list("dhcp", nif .. "dhcp", "dhcp_option", "119,olsr")
985 -- Create firewall settings
986 uci:delete_all("firewall", "rule", {
991 uci:section("firewall", "rule", nil, {
997 uci:delete_all("firewall", "rule", {
1003 uci:section("firewall", "rule", nil, {
1010 uci:delete_all("firewall", "rule", {
1015 uci:section("firewall", "rule", nil, {
1022 uci:section("luci_splash", "iface", nil, {network=nif.."dhcp", zone="freifunk"})
1023 uci:save("luci_splash")
1024 -- Make sure that luci_splash is enabled
1025 sys.init.enable("luci_splash")
1028 -- Delete old splash
1029 uci:delete_all("luci_splash", "iface", {network=device.."dhcp", zone="freifunk"})
1031 --Write Ad-Hoc wifi section after AP wifi section
1032 uci:section("wireless", "wifi-iface", nil, ifconfig)
1034 uci:save("wireless")
1036 uci:save("firewall")
1039 -- Create wired ip and firewall config
1040 uci:foreach("network", "interface",
1042 local device = sec[".name"]
1043 if not luci.http.formvalue("cbid.ffwizward.1.device_" .. device) then
1046 if device ~= "loopback" and not string.find(device, "wifi") and not string.find(device, "wl") and not string.find(device, "wlan") and not string.find(device, "wireless") and not string.find(device, "radio") then
1048 node_ip = luci.http.formvalue("cbid.ffwizward.1.meship_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.meship_" .. device))
1050 node_ip6 = luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device) and ip.IPv6(luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device))
1052 if not node_ip or not network or not network:contains(node_ip) then
1053 meship.tag_missing[section] = true
1058 tools.firewall_zone_remove_interface(device, device)
1059 uci:delete_all("firewall","zone", {name=device})
1060 uci:delete_all("firewall","forwarding", {src=device})
1061 uci:delete_all("firewall","forwarding", {dest=device})
1062 uci:delete("network", device .. "dhcp")
1064 uci:delete("dhcp", device)
1065 uci:delete("dhcp", device .. "dhcp")
1066 -- Delete old splash
1067 uci:delete_all("luci_splash", "iface", {network=device.."dhcp", zone="freifunk"})
1069 uci:delete_all("radvd", "interface", {interface=device.."dhcp"})
1070 uci:delete_all("radvd", "interface", {interface=device})
1071 uci:delete_all("radvd", "prefix", {interface=device.."dhcp"})
1072 uci:delete_all("radvd", "prefix", {interface=device})
1075 local netconfig = uci:get_all("freifunk", "interface")
1076 util.update(netconfig, uci:get_all(external, "interface") or {})
1077 netconfig.proto = "static"
1078 netconfig.ipaddr = node_ip:string()
1080 netconfig.ip6addr = node_ip6:string()
1082 uci:section("network", "interface", device, netconfig)
1085 uci:section("radvd", "interface", nil, {
1089 AdvOtherConfigFlag =0,
1092 uci:section("radvd", "prefix", nil, {
1101 local new_hostname = node_ip:string():gsub("%.", "-")
1102 uci:set("freifunk", "wizard", "hostname", new_hostname)
1103 uci:save("freifunk")
1104 tools.firewall_zone_add_interface("freifunk", device)
1105 uci:save("firewall")
1106 -- Write new olsrv4 interface
1107 local olsrifbase = uci:get_all("freifunk", "olsr_interface")
1108 util.update(olsrifbase, uci:get_all(external, "olsr_interface") or {})
1109 olsrifbase.interface = device
1110 olsrifbase.ignore = "0"
1111 uci:section("olsrd", "Interface", nil, olsrifbase)
1112 olsrifbase.Mode = 'ether'
1113 -- Collect MESH DHCP IP NET
1114 local client = luci.http.formvalue("cbid.ffwizward.1.client_" .. device)
1116 local dhcpmeshnet = luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device))
1118 local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
1119 table.insert(ifacelist,device .. "dhcp")
1120 uci:set_list("manager", "heartbeat", "interface", ifacelist)
1124 if not dhcpmeshnet:minhost() or not dhcpmeshnet:mask() then
1125 dhcpmesh.tag_missing[section] = true
1129 dhcp_ip = dhcpmeshnet:minhost():string()
1130 dhcp_mask = dhcpmeshnet:mask():string()
1131 dhcp_network = dhcpmeshnet:network():string()
1132 uci:section("olsrd", "Hna4", nil, {
1133 netmask = dhcp_mask,
1134 netaddr = dhcp_network
1136 uci:foreach("olsrd", "LoadPlugin",
1138 if s.library == "olsrd_p2pd.so.0.1.0" then
1139 uci:set("olsrd", s['.name'], "ignore", "0")
1140 local nonolsr = uci:get("olsrd", s['.name'], "NonOlsrIf") or ""
1141 uci:set("olsrd", s['.name'], "NonOlsrIf", device .." ".. nonolsr)
1145 local subnet_prefix = tonumber(uci:get("freifunk", community, "splash_prefix")) or 27
1146 local pool_network = uci:get("freifunk", community, "splash_network") or "10.104.0.0/16"
1147 local pool = luci.ip.IPv4(pool_network)
1148 local ip = tostring(node_ip)
1150 local hosts_per_subnet = 2^(32 - subnet_prefix)
1151 local number_of_subnets = (2^pool:prefix())/hosts_per_subnet
1152 local seed1, seed2 = ip:match("(%d+)%.(%d+)$")
1153 if seed1 and seed2 then
1154 math.randomseed(seed1 * seed2)
1156 local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets))
1157 dhcp_ip = subnet:network(subnet_prefix):add(1):string()
1158 dhcp_mask = subnet:mask(subnet_prefix):string()
1161 if dhcp_ip and dhcp_mask then
1163 local aliasbase = uci:get_all("freifunk", "alias")
1164 util.update(aliasbase, uci:get_all(external, "alias") or {})
1165 aliasbase.interface = device
1166 aliasbase.ipaddr = dhcp_ip
1167 aliasbase.netmask = dhcp_mask
1168 aliasbase.proto = "static"
1169 uci:section("network", "alias", device .. "dhcp", aliasbase)
1171 local dhcpbase = uci:get_all("freifunk", "dhcp")
1172 util.update(dhcpbase, uci:get_all(external, "dhcp") or {})
1173 dhcpbase.interface = device .. "dhcp"
1175 uci:section("dhcp", "dhcp", device .. "dhcp", dhcpbase)
1176 uci:set_list("dhcp", device .. "dhcp", "dhcp_option", "119,olsr")
1177 -- Create firewall settings
1178 uci:delete_all("firewall", "rule", {
1183 uci:section("firewall", "rule", nil, {
1189 uci:delete_all("firewall", "rule", {
1195 uci:section("firewall", "rule", nil, {
1202 uci:delete_all("firewall", "rule", {
1207 uci:section("firewall", "rule", nil, {
1214 uci:section("luci_splash", "iface", nil, {network=device.."dhcp", zone="freifunk"})
1215 uci:save("luci_splash")
1216 -- Make sure that luci_splash is enabled
1217 sys.init.enable("luci_splash")
1220 uci:save("wireless")
1222 uci:save("firewall")
1228 sys.init.enable("radvd")
1230 -- Enforce firewall include
1231 local has_include = false
1232 uci:foreach("firewall", "include",
1234 if section.path == "/etc/firewall.freifunk" then
1239 if not has_include then
1240 uci:section("firewall", "include", nil,
1241 { path = "/etc/firewall.freifunk" })
1243 -- Allow state: invalid packets
1244 uci:foreach("firewall", "defaults",
1246 uci:set("firewall", section[".name"], "drop_invalid", "0")
1249 -- Prepare advanced config
1250 local has_advanced = false
1251 uci:foreach("firewall", "advanced",
1252 function(section) has_advanced = true end)
1254 if not has_advanced then
1255 uci:section("firewall", "advanced", nil,
1256 { tcp_ecn = "0", ip_conntrack_max = "8192", tcp_westwood = "1" })
1258 uci:save("wireless")
1260 uci:save("firewall")
1263 local new_hostname = uci:get("freifunk", "wizard", "hostname")
1264 local old_hostname = sys.hostname()
1267 local dhcphb = hb:formvalue(section)
1269 uci:set("manager", "heartbeat", "enabled", "1")
1270 -- Make sure that heartbeat is enabled
1271 sys.init.enable("machash")
1273 uci:set("manager", "heartbeat", "enabled", "0")
1274 -- Make sure that heartbeat is enabled
1275 sys.init.disable("machash")
1280 local custom_hostname = hostname:formvalue(section)
1281 uci:foreach("system", "system",
1283 -- Make crond silent
1284 uci:set("system", s['.name'], "cronloglevel", "10")
1285 -- Make set timzone and zonename
1286 uci:set("system", s['.name'], "zonename", "Europe/Berlin")
1287 uci:set("system", s['.name'], "timezone", 'CET-1CEST,M3.5.0,M10.5.0/3')
1289 if custom_hostname then
1290 uci:set("system", s['.name'], "hostname", custom_hostname)
1291 sys.hostname(custom_hostname)
1293 if new_hostname then
1294 if old_hostname == "OpenWrt" or old_hostname:match("^%d+-%d+-%d+-%d+$") then
1295 uci:set("system", s['.name'], "hostname", new_hostname)
1296 sys.hostname(new_hostname)
1302 -- Create time rdate_servers
1303 local rdate = uci:get_all("freifunk", "time")
1304 uci:delete_all("system", "time")
1305 uci:section("system", "time", "rdate_servers", rdate)
1306 rdate.server = rdate.rdate_servers
1307 rdate.rdate_servers = ""
1308 uci:delete_all("system", "rdate", nil)
1309 uci:section("system", "rdate", nil, rdate)
1312 -- Create http splash port 8082
1313 uci:set_list("uhttpd","main","listen_http",{"80"})
1314 uci:set_list("uhttpd","main","listen_https",{"443"})
1318 local latval = tonumber(lat:formvalue(section))
1319 local lonval = tonumber(lon:formvalue(section))
1321 -- Save latlon to system too
1322 if latval and lonval then
1323 uci:foreach("system", "system", function(s)
1324 uci:set("system", s[".name"], "latlon",string.format("%.15f %.15f", latval, lonval))
1325 uci:set("system", s[".name"], "latitude",string.format("%.15f", latval))
1326 uci:set("system", s[".name"], "longitude",string.format("%.15f", lonval))
1329 uci:foreach("system", "system", function(s)
1330 uci:delete("system", s[".name"], "latlon")
1331 uci:delete("system", s[".name"], "latitude")
1332 uci:delete("system", s[".name"], "longitude")
1335 -- Delete old watchdog settings
1336 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_watchdog.so.0.1"})
1337 -- Write new watchdog settings
1338 uci:section("olsrd", "LoadPlugin", nil, {
1339 library = "olsrd_watchdog.so.0.1",
1340 file = "/var/run/olsrd.watchdog",
1344 -- Delete old nameservice settings
1345 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_nameservice.so.0.3"})
1346 -- Write new nameservice settings
1347 uci:section("olsrd", "LoadPlugin", nil, {
1348 library = "olsrd_nameservice.so.0.3",
1349 suffix = "." .. suffix ,
1350 hosts_file = "/var/etc/hosts.olsr",
1351 latlon_file = "/var/run/latlon.js",
1352 lat = latval and string.format("%.15f", latval) or "",
1353 lon = lonval and string.format("%.15f", lonval) or "",
1354 services_file = "/var/etc/services.olsr"
1357 -- Import hosts and set domain
1358 uci:foreach("dhcp", "dnsmasq", function(s)
1359 uci:set_list("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
1360 uci:set("dhcp", s[".name"], "local", "/" .. suffix .. "/")
1361 uci:set("dhcp", s[".name"], "domain", suffix)
1364 -- Make sure that OLSR is enabled
1365 sys.init.enable("olsrd")
1369 -- Import hosts and set domain
1371 uci:foreach("dhcp", "dnsmasq", function(s)
1372 uci:set_list("dhcp", s[".name"], "addnhosts", {"/var/etc/hosts.olsr","/var/etc/hosts.olsr.ipv6"})
1375 uci:foreach("dhcp", "dnsmasq", function(s)
1376 uci:set_list("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
1383 local share_value = share:formvalue(section)
1384 if share_value == "1" then
1385 uci:set("freifunk", "wizard", "netconfig", "1")
1386 uci:section("firewall", "forwarding", nil, {src="freifunk", dest="wan"})
1388 if has_autoipv6 then
1389 -- Set autoipv6 tunnel mode
1390 uci:set("autoipv6", "olsr_node", "enable", "0")
1391 uci:set("autoipv6", "tunnel", "enable", "1")
1392 uci:save("autoipv6")
1395 -- Delete/Disable gateway plugin
1396 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_dyn_gw.so.0.5"})
1397 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_dyn_gw_plain.so.0.4"})
1398 -- Enable gateway_plain plugin
1399 uci:section("olsrd", "LoadPlugin", nil, {library="olsrd_dyn_gw_plain.so.0.4"})
1400 sys.exec("chmod +x /etc/init.d/freifunk-p2pblock")
1401 sys.init.enable("freifunk-p2pblock")
1402 sys.init.enable("qos")
1403 sys.exec('grep wan /etc/crontabs/root >/dev/null || echo "0 6 * * * ifup wan" >> /etc/crontabs/root')
1405 if wansec:formvalue(section) == "1" then
1406 uci:foreach("firewall", "zone",
1408 if s.name == "wan" then
1409 uci:set("firewall", s['.name'], "local_restrict", "1")
1415 uci:set("freifunk", "wizard", "netconfig", "0")
1416 uci:save("freifunk")
1417 if has_autoipv6 then
1418 -- Set autoipv6 olsrd mode
1419 uci:set("autoipv6", "olsr_node", "enable", "1")
1420 uci:set("autoipv6", "tunnel", "enable", "0")
1421 uci:save("autoipv6")
1423 -- Delete gateway plugins
1424 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_dyn_gw.so.0.5"})
1425 uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_dyn_gw_plain.so.0.4"})
1426 -- Disable gateway_plain plugin
1427 uci:section("olsrd", "LoadPlugin", nil, {
1428 library = "olsrd_dyn_gw_plain.so.0.4",
1431 sys.init.disable("freifunk-p2pblock")
1432 sys.init.disable("qos")
1433 sys.exec("chmod -x /etc/init.d/freifunk-p2pblock")
1434 uci:delete_all("firewall", "forwarding", {src="freifunk", dest="wan"})
1435 uci:foreach("firewall", "zone",
1437 if s.name == "wan" then
1438 uci:delete("firewall", s['.name'], "local_restrict")
1443 -- Write gvpn dummy interface
1446 local vpn = gvpn:formvalue(section)
1448 uci:delete_all("l2gvpn", "l2gvpn")
1449 uci:delete_all("l2gvpn", "node")
1450 uci:delete_all("l2gvpn", "supernode")
1451 -- Write olsr tunnel interface options
1452 local olsr_gvpnifbase = uci:get_all("freifunk", "olsr_gvpninterface")
1453 util.update(olsr_gvpnifbase, uci:get_all(external, "olsr_gvpninterface") or {})
1454 uci:section("olsrd", "Interface", nil, olsr_gvpnifbase)
1455 local vpnip = gvpnip:formvalue(section)
1456 local gvpnif = uci:get_all("freifunk", "gvpn_node")
1457 util.update(gvpnif, uci:get_all(external, "gvpn_node") or {})
1458 if gvpnif and gvpnif.tundev and vpnip then
1459 uci:section("network", "interface", gvpnif.tundev, {
1460 ifname =gvpnif.tundev ,
1463 netmask =gvpnif.subnet or "255.255.255.192" ,
1469 gvpnif.mac="00:00:48:"..string.format("%X",string.gsub( vpnip, ".*%." , "" ))..":00:00"
1470 tools.firewall_zone_add_interface("freifunk", gvpnif.tundev)
1471 uci:section("l2gvpn", "node" , gvpnif.community , gvpnif)
1474 uci:save("firewall")
1476 sys.init.enable("l2gvpn")
1480 sys.exec("/etc/init.d/l2gvpn stop")
1481 sys.init.disable("l2gvpn")
1486 uci:save("freifunk")
1487 uci:save("firewall")