root/luci/trunk/modules/freifunk/root/usr/sbin/ff_mapupdate @ 4599

Revision 4599, 1.4 KB (checked in by jow, 4 years ago)

modules/freifunk: implement map update for GlobalMap?
applications/luci-ffwizard-leipzig: add lat and lon fields

  • Property svn:executable set to *
Line 
1#!/usr/bin/lua
2
3local uci = require "luci.model.uci"
4local x = uci.cursor()
5
6local update_url = "http://www.layereight.de/freifunkmap.php?update=%.15f,%.15f&olsrip=%s&note=%s&robot=%s"
7local update_all = ( arg[1] and arg[1] == "all" ) and true or false
8
9local file
10x:foreach("olsrd", "LoadPlugin", function(s)
11    if s.library == "olsrd_nameservice.so.0.3" then
12        file = io.open(s.latlon_file)
13    end
14end)
15
16if file then
17    local ln
18    local count = 0
19    while true do
20        ln = file:read("*l")
21        if not ln then break end
22        if update_all and ln:match("^Node%(") then
23            local ip, lat, lon, note = ln:match("Node%('(%S+)',([%d%.]+),([%d%.]+),%d+,'%S+','(%S+)'%)")
24            lat = tonumber(lat)
25            lon = tonumber(lon)
26       
27            if ip and lat ~= 0.0 and lon ~= 0.0 and note then
28                note = note:gsub("[^%w%-%.]+", "_")
29                os.execute("wget -qO/dev/null %q" % string.format(update_url, lat, lon, ip, note, "luci-massupdate"))
30                count = count + 1
31            end
32
33        elseif ln:match("^Self%(") then
34            local ip, lat, lon, note = ln:match("Self%('(%S+)',([%d%.]+),([%d%.]+),%d+,'%S+','(%S+)'%)")
35            lat = tonumber(lat)
36            lot = tonumber(lon)
37           
38            if ip and lat ~= 0.0 and lon ~= 0.0 and note then
39                note = note:gsub("[^%w%-%.]+", "_")
40                os.execute("wget -qO/dev/null %q" % string.format(update_url, lat, lon, ip, note, "luci-selfupdate"))
41                count = count + 1
42            end
43        end
44    end
45
46    os.execute("logger -t 'mapupdate' 'Updated %d entries in freifunk map'" % count)
47
48    file:close()
49end
Note: See TracBrowser for help on using the browser.