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