aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--[-rwxr-xr-x]alfred.py0
-rwxr-xr-xbat2nodes.py12
-rwxr-xr-xbatman.py7
-rw-r--r--crontab15
-rwxr-xr-xget-nodes.pl116
-rwxr-xr-xmkmap.sh11
7 files changed, 152 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 0f42dec..46b6ddc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
*.pyc
aliases.json
-nodedb/
+nosuchnode.rrd
+nodedb
+nodeplots
diff --git a/alfred.py b/alfred.py
index 6d926bb..6d926bb 100755..100644
--- a/alfred.py
+++ b/alfred.py
diff --git a/bat2nodes.py b/bat2nodes.py
index 921b548..7119464 100755
--- a/bat2nodes.py
+++ b/bat2nodes.py
@@ -58,7 +58,15 @@ else:
if options['aliases']:
for aliases in options['aliases']:
- db.import_aliases(json.load(open(aliases)))
+ db.import_aliases(json.load(open(aliases,encoding='utf-8',errors='replace')))
+
+if options['alfred']:
+ af = alfred()
+ db.import_aliases(af.aliases())
+
+if options['alfred']:
+ af = alfred()
+ db.import_aliases(af.aliases())
if options['alfred']:
af = alfred()
@@ -83,4 +91,4 @@ os.rename(options['destination_directory'] + '/nodes.json.new',options['destinat
rrd = rrd(scriptdir + "/nodedb/", options['destination_directory'] + "/nodes")
rrd.update_database(db)
-rrd.update_images()
+#rrd.update_images()
diff --git a/batman.py b/batman.py
index c9b3db6..05a4380 100755
--- a/batman.py
+++ b/batman.py
@@ -6,8 +6,9 @@ import re
class batman:
""" Bindings for B.A.T.M.A.N. advanced batctl tool
"""
- def __init__(self, mesh_interface = "bat0"):
+ def __init__(self, mesh_interface = "bat0", batctl = "/usr/sbin/batctl"):
self.mesh_interface = mesh_interface
+ self.batctl = batctl
def vis_data(self,batadv_vis=False):
vds = self.vis_data_batctl_legacy()
@@ -45,7 +46,7 @@ class batman:
def gateway_list(self):
""" Parse "batctl -m <mesh_interface> gwl -n" into an array of dictionaries.
"""
- output = subprocess.check_output(["batctl","-m",self.mesh_interface,"gwl","-n"])
+ output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gwl","-n"])
output_utf8 = output.decode("utf-8")
# TODO Parse information
lines = output_utf8.splitlines()
@@ -68,7 +69,7 @@ class batman:
def gateway_mode(self):
""" Parse "batctl -m <mesh_interface> gw"
"""
- output = subprocess.check_output(["batctl","-m",self.mesh_interface,"gw"])
+ output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gw"])
elements = output.decode("utf-8").split()
mode = elements[0]
if mode == "server":
diff --git a/crontab b/crontab
new file mode 100644
index 0000000..c65e08f
--- /dev/null
+++ b/crontab
@@ -0,0 +1,15 @@
+# Freifunk Map Updates
+
+PATH=/opt/alfred/vis:/opt/alfred-json:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+* * * * * root (DEBUG=1 /opt/ffmap/get-nodes.pl && /usr/local/sbin/fastd-update > /dev/null ) ; /opt/ffmap/mkmap.sh /var/www/ffmap/
+
+* * * * * root /usr/local/bin/check-gateway
+
+*/5 * * * * root /usr/local/bin/update-vnstat.sh
+
+0 0 * * * root find /opt/ffmap/nodedb/ -name '*.rrd' -ctime 8 -execdir rm '{}' +
+0 1 * * * root find /opt/ffmap/nodeplots/ -name '*.png' -ctime 1 -execdir rm '{}' +
+
+# EOF
+
diff --git a/get-nodes.pl b/get-nodes.pl
new file mode 100755
index 0000000..5f6dc39
--- /dev/null
+++ b/get-nodes.pl
@@ -0,0 +1,116 @@
+#!/usr/bin/perl -wT
+use strict;
+use warnings;
+use utf8;
+use JSON;
+use MediaWiki::API;
+use Text::Unidecode;
+
+binmode STDERR, ':utf8';
+
+$ENV{HOME} =~ m!\A(/.+)\Z!;
+my $HOME = $1;
+
+my $DEBUG = (defined($ENV{DEBUG}) && $ENV{DEBUG} =~ m!\A(\d+)\Z!) ? $1 : 0;
+
+my $nodes;
+
+sub debug {
+ return unless $_[0] <= $DEBUG;
+ shift;
+ print STDERR join(" ",@_), "\n";
+}
+
+my $mw = MediaWiki::API->new( { api_url => 'http://freifunk.in-kiel.de/mediawiki/api.php' } );
+
+sub handle_node {
+ my($node) = @_;
+ my($title,$name,$gps,$mac,$vpn,$fastd,$fn,$f);
+
+ debug(2, "title:", $node->{title});
+
+ $node->{title} =~ m!\ANodes/([ \w-]+)\Z! && ($title = $1);
+
+ unless (defined($title)) {
+ debug(1, "no valid title:", $node->{title});
+ next;
+ }
+
+ ($name = lc(unidecode($title))) =~ s/\s/_/g;
+
+ unless ($name =~ /\A[0-9a-z_-]+\Z/) {
+ debug(1, "invalid name:", $name);
+ next;
+ }
+
+ my $tmp = $mw->get_page({ title => $node->{title} }) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+ $tmp = $tmp->{'*'};
+ debug(4, "tmp:", $tmp);
+
+ next unless $tmp =~ m!{{Node\s*(\|.+?)}}!sm;
+ $tmp = $1;
+
+ debug(5, "tmp:", $tmp);
+
+ my %fields = (Node => split /^\|(\w+)\s*=\s*/m, $tmp, -1);
+
+ foreach my $k (qw/GPS MAC VPN FASTD/) {
+ next unless defined $fields{$k};
+ $fields{$k} =~ s/\A\s+//mg;
+ $fields{$k} =~ s/\s+\Z//mg;
+ debug(3, ">>>",$k, " = ", $fields{$k}, "<<<");
+ }
+
+ (defined($fields{GPS})) && ($fields{GPS} gt "") && ($fields{GPS} =~ m!\A(\d{1,3}\.\d+)[\., /]+(\d{1,2}\.\d+)\Z!) && ($gps = "$1 $2");
+ (defined($fields{MAC})) && ($fields{MAC} gt "") && ($fields{MAC} =~ /\A(([0-9A-Fa-f]{2}:?){5}([0-9A-Fa-f]{2}))\Z/) && ($mac = lc($1)); # && ($mac =~ s/\A([0-9a-f]{2}:?){5}([0-9a-f]{2})\Z/$1:$2:$3:$4:$5:$6/e);
+ (defined($fields{VPN})) && ($fields{VPN} gt "") && ($vpn = $fields{VPN});
+ # deactivated 2014-06-05 wonka
+ #(defined($fields{FASTD})) && ($fields{FASTD} gt "") && ($fields{FASTD} =~ /\Akey\s*"[0-9a-f]{64}";\Z/m) && ($fastd = $fields{FASTD}) && ($fastd =~ s/key\s*"/key "/g);
+
+ if (defined($fastd)) {
+ $fn = "/etc/fastd/ffki/peers/$name";
+ unless (-f $fn) {
+ open($f,">",$fn);
+ binmode $f, ':utf8';
+ print $f $fastd."\n";
+ close($f);
+ }
+ }
+
+ if (defined ($mac)) {
+ my $node;
+ $node->{'name'} = $title if defined $title;
+ $node->{'gps'} = $gps if defined $gps;
+ $node->{'vpn'} = 'true' if defined $vpn;
+ $nodes->{$mac} = $node;
+ }
+}
+
+sub handle_nodes {
+ my ($ref) = @_;
+ foreach my $node (@$ref) {
+ &handle_node($node);
+ }
+}
+
+$mw->list (
+ {
+ action => 'query',
+ list => 'embeddedin',
+ einamespace => 0,
+ eilimit => 'max',
+ eifilterredir => 'nonredirects',
+ eititle => 'Template:Node'
+ }, {
+ max => 'max',
+ hook => \&handle_nodes
+ }
+) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+
+open(my $f,">","/opt/ffmap/aliases.json.new");
+print $f encode_json($nodes);
+close($f);
+
+rename "/opt/ffmap/aliases.json.new", "/opt/ffmap/aliases.json";
+
+__END__
diff --git a/mkmap.sh b/mkmap.sh
index ce3b162..e503a5e 100755
--- a/mkmap.sh
+++ b/mkmap.sh
@@ -1,15 +1,12 @@
-#!/bin/bash
-
-set -e
-
-DEST=$1
+#!/bin/bash -e
+DEST="$1"
[ "$DEST" ] || exit 1
cd "$(dirname "$0")"/
-./ffhlwiki.py http://freifunk.metameute.de/wiki/Knoten > aliases_hl.json
-./ffhlwiki.py http://freifunk.metameute.de/wiki/Moelln:Knoten > aliases_moelln.json
+#./ffhlwiki.py http://freifunk.metameute.de/wiki/Knoten > aliases_hl.json
+#./ffhlwiki.py http://freifunk.metameute.de/wiki/Moelln:Knoten > aliases_moelln.json
./bat2nodes.py -A -a aliases.json -a aliases_hl.json -a aliases_moelln.json -d $DEST