modules/freifunk: implement map update for GlobalMap
[project/luci.git] / applications / luci-ffwizard-leipzig / luasrc / model / cbi / ffwizard.lua
index f092a60..e823530 100644 (file)
@@ -80,10 +80,15 @@ client = f:field(Flag, "client", "WLAN-DHCP anbieten")
 client:depends("wifi", "1")
 client.rmempty = true
 
-
 olsr = f:field(Flag, "olsr", "OLSR einrichten")
 olsr.rmempty = true
 
+lat = f:field(Value, "lat", "Latitude")
+lat:depends("olsr", "1")
+
+lon = f:field(Value, "lon", "Longitude")
+lon:depends("olsr", "1")
+
 share = f:field(Flag, "sharenet", "Eigenen Internetzugang freigeben")
 share.rmempty = true
 
@@ -217,7 +222,7 @@ function main.write(self, section, value)
 
        if not has_advanced then
                uci:section("firewall", "advanced", nil,
-                       { tcp_ecn = "0" })
+                       { tcp_ecn = "0", ip_conntrack_max = "8192", tcp_westwood = "1" })
        end
 
        uci:save("firewall")
@@ -235,19 +240,22 @@ function main.write(self, section, value)
        tools.firewall_zone_add_interface("freifunk", device)
 
 
-       -- Set hostname
        local new_hostname = ip:gsub("%.", "-")
        local old_hostname = sys.hostname()
 
-       if old_hostname == "OpenWrt" or old_hostname:match("^%d+-%d+-%d+-%d+$") then
-               uci:foreach("system", "system",
-                       function(s)
+       uci:foreach("system", "system",
+               function(s)
+                       -- Make crond silent
+                       uci:set("system", s['.name'], "cronloglevel", "10")
+
+                       -- Set hostname
+                       if old_hostname == "OpenWrt" or old_hostname:match("^%d+-%d+-%d+-%d+$") then
                                uci:set("system", s['.name'], "hostname", new_hostname)
-                       end)
+                               sys.hostname(new_hostname)
+                       end
+               end)
 
-               sys.hostname(new_hostname)
-               uci:save("system")
-       end
+       uci:save("system")
 end
 
 
@@ -262,18 +270,9 @@ function olsr.write(self, section, value)
        local community = net:formvalue(section)
        local external  = community and uci:get("freifunk", community, "external") or ""
 
-       -- Configure nameservice
-       local hostname
-       uci:foreach("system", "system", function(s) hostname = s.hostname end)
-
-       if hostname then
-               uci:foreach("olsrd", "LoadPlugin",
-                       function(s)
-                               if s.library == "olsrd_nameservice.so.0.3" then
-                                       uci:set("olsrd", s['.name'], "name", hostname)
-                               end
-                       end)
-       end
+       local latval = tonumber(lat:formvalue(section))
+       local lonval = tonumber(lon:formvalue(section))
+
 
        -- Delete old interface
        uci:delete_all("olsrd", "Interface", {interface=device})
@@ -284,12 +283,46 @@ function olsr.write(self, section, value)
        olsrbase.interface = device
        olsrbase.ignore    = "0"
        uci:section("olsrd", "Interface", nil, olsrbase)
-       uci:save("olsrd")
+
+       -- Delete old watchdog settings
+       uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_watchdog.so.0.1"})
+
+       -- Write new watchdog settings
+       uci:section("olsrd", "LoadPlugin", nil, {
+               library  = "olsrd_watchdog.so.0.1",
+               file     = "/var/run/olsrd.watchdog",
+               interval = "30"
+       })
+
+       -- Delete old nameservice settings
+       uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_nameservice.so.0.3"})
+
+       -- Write new nameservice settings
+       uci:section("olsrd", "LoadPlugin", nil, {
+               library     = "olsrd_nameservice.so.0.3",
+               latlon_file = "/var/run/latlon.js",
+               lat         = latval and string.format("%.15f", latval) or "",
+               lon         = lonval and string.format("%.15f", lonval) or ""
+       })
+
+       -- Save latlon to system too
+       if latval and lonval then
+               uci:foreach("system", "system", function(s)
+                       uci:set("system", s[".name"], "latlon",
+                               string.format("%.15f %.15f", latval, lonval))
+               end)
+       else
+               uci:foreach("system", "system", function(s)
+                       uci:delete("system", s[".name"], "latlon")
+               end)
+       end
 
        -- Import hosts
        uci:foreach("dhcp", "dnsmasq", function(s)
                uci:set("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
        end)
+
+       uci:save("olsrd")
        uci:save("dhcp")
 end
 
@@ -304,6 +337,7 @@ function share.write(self, section, value)
        end
        uci:save("firewall")
        uci:save("olsrd")
+       uci:save("system")
 end
 
 
@@ -349,6 +383,7 @@ function client.write(self, section, value)
        dhcpbase.interface = device .. "dhcp"
        dhcpbase.start = dhcpbeg
        dhcpbase.limit = limit
+       dhcpbase.force = 1
 
        uci:section("dhcp", "dhcp", device .. "dhcp", dhcpbase)
        uci:save("dhcp")
@@ -389,13 +424,13 @@ function client.write(self, section, value)
                target="ACCEPT"
        })
 
-
+       uci:save("firewall")
 
        -- Delete old splash
-       uci:delete_all("luci_splash", "iface", {net=device, zone="freifunk"})
+       uci:delete_all("luci_splash", "iface", {network=device.."dhcp", zone="freifunk"})
 
        -- Register splash
-       uci:section("luci_splash", "iface", nil, {net=device, zone="freifunk"})
+       uci:section("luci_splash", "iface", nil, {network=device.."dhcp", zone="freifunk"})
        uci:save("luci_splash")
 end