summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-05-24 19:28:04 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-05-24 19:28:04 +0000
commit6ca3b275fc9bd83ccc9a4decf6d04d819f0efcf9 (patch)
treea971d885ecee5b0a5b4871f4d54e4ba3870d6869 /modules/freifunk
parentee690abb0f482f0fd3f0b744f98b05699c08c8e4 (diff)
modules/freifunk: implement map update for GlobalMap
applications/luci-ffwizard-leipzig: add lat and lon fields
Diffstat (limited to 'modules/freifunk')
-rwxr-xr-xmodules/freifunk/root/etc/init.d/freifunk4
-rwxr-xr-xmodules/freifunk/root/usr/sbin/ff_mapupdate49
2 files changed, 53 insertions, 0 deletions
diff --git a/modules/freifunk/root/etc/init.d/freifunk b/modules/freifunk/root/etc/init.d/freifunk
index d90e3ff5e..3a668b11f 100755
--- a/modules/freifunk/root/etc/init.d/freifunk
+++ b/modules/freifunk/root/etc/init.d/freifunk
@@ -23,6 +23,10 @@ boot() {
echo "0 */4 * * * /usr/sbin/ff_rdate" >> /etc/crontabs/root
}
+ grep -q '/usr/sbin/ff_mapupdate' /etc/crontabs/root || {
+ echo "17 * * * * /usr/sbin/ff_mapupdate >> /etc/crontabs/root
+ }
+
[ -f /etc/rc.local ] && . /etc/rc.local
[ -d /etc/rc.local.d ] && {
for file in /etc/rc.local.d/*; do
diff --git a/modules/freifunk/root/usr/sbin/ff_mapupdate b/modules/freifunk/root/usr/sbin/ff_mapupdate
new file mode 100755
index 000000000..132546c6b
--- /dev/null
+++ b/modules/freifunk/root/usr/sbin/ff_mapupdate
@@ -0,0 +1,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&note=%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