aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@srv.freifunk.in-kiel.de>2014-12-29 17:53:41 +0100
committerroot <root@srv.freifunk.in-kiel.de>2014-12-29 17:53:41 +0100
commit5f4b213b24930ab948f53d05a9ea0eef6ec02afd (patch)
treec716ecf29ea7521caa92cdf1c67a344f87448424
parent6cf55b922b8067635b015e32c1b665f1a9034f41 (diff)
Dies sind die alle aenderungen seit 29.09.2014
das ist nicht gut, bitte immer alle kleinen aenderungen zumindest lokal committen!
-rwxr-xr-x[-rw-r--r--]alfred.py12
-rwxr-xr-xbat2nodes.py46
-rwxr-xr-xbatman.py42
-rw-r--r--crontab8
-rwxr-xr-xmkmap.sh7
-rw-r--r--nodedb.py2
6 files changed, 62 insertions, 55 deletions
diff --git a/alfred.py b/alfred.py
index b956026..f85888f 100644..100755
--- a/alfred.py
+++ b/alfred.py
@@ -3,12 +3,10 @@ import subprocess
import json
class alfred:
- def __init__(self,request_data_type = 158):
- self.request_data_type = request_data_type
+ def __init__(self):
+ pass
- def aliases(self):
- output = subprocess.check_output(["alfred-json","-r",str(self.request_data_type),"-f","json","-z"])
- alfred_data = json.loads(output.decode("utf-8"))
+ def aliases(alfred_data):
alias = {}
for mac,node in alfred_data.items():
node_alias = {}
@@ -37,6 +35,6 @@ class alfred:
return alias
if __name__ == "__main__":
- ad = alfred()
- al = ad.aliases()
+ import sys
+ al = alfred.aliases(sys.argv[1])
print(al)
diff --git a/bat2nodes.py b/bat2nodes.py
index 73329bc..ea78aaa 100755
--- a/bat2nodes.py
+++ b/bat2nodes.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+# bitte immer alle kleinen aenderungen zumindest lokat committen!
import json
import fileinput
@@ -23,19 +24,29 @@ import sys
parser = argparse.ArgumentParser()
+parser.add_argument('-A', '--alfred',
+ help='retrieve aliases from alfred',
+ action='append',
+ metavar='FILE',
+ )
+
parser.add_argument('-a', '--aliases',
help='read aliases from FILE',
action='append',
- metavar='FILE')
+ metavar='FILE',
+ )
-parser.add_argument('-m', '--mesh', action='append',
- help='batman mesh interface')
+parser.add_argument('-d', '--destination-directory',
+ help='destination directory for generated files',
+ action='store',
+ required=True,
+ )
-parser.add_argument('-A', '--alfred', action='store_true',
- help='retrieve aliases from alfred')
-
-parser.add_argument('-d', '--destination-directory', action='store',
- help='destination directory for generated files',required=True)
+parser.add_argument('-m', '--mesh',
+ help='read batman vis data from FILE',
+ action='append',
+ metavar='FILE',
+ )
args = parser.parse_args()
@@ -44,24 +55,19 @@ options = vars(args)
db = NodeDB(int(time.time()))
if options['mesh']:
- for mesh_interface in options['mesh']:
- bm = batman(mesh_interface)
+ for f in options['mesh']:
+ bm = batman(json.load(open(f,encoding='utf-8',errors='replace')))
db.parse_vis_data(bm.vis_data(options['alfred']))
for gw in bm.gateway_list():
- db.mark_gateways(gw['mac'])
-else:
- bm = batman()
- db.parse_vis_data(bm.vis_data(options['alfred']))
- for gw in bm.gateway_list():
- db.mark_gateways([gw['mac']])
+ db.mark_gateways([gw['mac']])
if options['aliases']:
- for aliases in options['aliases']:
- db.import_aliases(json.load(open(aliases,encoding='utf-8',errors='replace')))
+ for f in options['aliases']:
+ db.import_aliases(json.load(open(f,encoding='utf-8',errors='replace')))
if options['alfred']:
- af = alfred()
- db.import_aliases(af.aliases())
+ for f in options['alfred']:
+ db.import_aliases(alfred.aliases(json.load(open(f,encoding='utf-8',errors='replace'))))
db.load_state("json/state.json")
diff --git a/batman.py b/batman.py
index 119a44e..c6e3077 100755
--- a/batman.py
+++ b/batman.py
@@ -2,13 +2,14 @@
import subprocess
import json
import re
+import base64
+import gzip
class batman:
""" Bindings for B.A.T.M.A.N. advanced batctl tool
"""
- def __init__(self, mesh_interface = "bat0", batctl = "/usr/sbin/batctl"):
- self.mesh_interface = mesh_interface
- self.batctl = batctl
+ def __init__(self, mesh_data):
+ self.mesh_data = mesh_data
def vis_data(self,batadv_vis=False):
vds = self.vis_data_batctl_legacy()
@@ -20,34 +21,35 @@ class batman:
vd = []
for line in lines:
try:
- utf8_line = line.decode("utf-8")
- vd.append(json.loads(utf8_line))
- except e:
+ vd.append(json.loads(line))
+ except:
+ print("error in vd.append(): '%s'" % line)
pass
return vd
def vis_data_batctl_legacy(self):
- """ Parse "batctl -m <mesh_interface> vd json -n" into an array of dictionaries.
- """
- output = subprocess.check_output(["batctl","-m",self.mesh_interface,"vd","json","-n"])
- lines = output.splitlines()
+ output = self.mesh_data["vd"]
+ output = base64.b64decode(output)
+ output = gzip.decompress(output)
+ output_utf8 = output.decode("utf-8")
+ lines = output_utf8.splitlines()
vds = self.vis_data_helper(lines)
return vds
def vis_data_batadv_vis(self):
- """ Parse "batadv-vis -i <mesh_interface> -f json" into an array of dictionaries.
- """
- output = subprocess.check_output(["batadv-vis","-i",self.mesh_interface,"-f","json"])
- lines = output.splitlines()
+ output = self.mesh_data["vis"]
+ output = base64.b64decode(output)
+ output = gzip.decompress(output)
+ output_utf8 = output.decode("utf-8")
+ lines = output_utf8.splitlines()
return self.vis_data_helper(lines)
def gateway_list(self):
- """ Parse "batctl -m <mesh_interface> gwl -n" into an array of dictionaries.
- """
- output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gwl","-n"])
+ output = self.mesh_data["gwl"]
+ output = base64.b64decode(output)
output_utf8 = output.decode("utf-8")
- # TODO Parse information
lines = output_utf8.splitlines()
+ # TODO Parse information
own_mac = re.match(r"^.*MainIF/MAC: [^/]+/([0-9a-f:]+).*$",lines[0]).group(1)
# Remove header line
del lines[0]
@@ -67,8 +69,8 @@ class batman:
def gateway_mode(self):
""" Parse "batctl -m <mesh_interface> gw"
"""
- output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gw"])
- elements = output.decode("utf-8").split()
+ output_utf8 = self.mesh_data["gw"]
+ elements = output_utf8.split()
mode = elements[0]
if mode == "server":
return {'mode': 'server', 'bandwidth': elements[3]}
diff --git a/crontab b/crontab
index 33be193..b967f41 100644
--- a/crontab
+++ b/crontab
@@ -2,13 +2,9 @@ MAILTO=ffki-noc@in-kiel.de
# Freifunk Map Updates
-PATH=/opt/alfred/vis:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-
-* * * * * root (DEBUG=1 /opt/ffmap-backend/get-nodes.pl && /usr/local/sbin/fastd-update > /dev/null ) ; /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/
-* * * * * root (DEBUG=1 /usr/local/sbin/fastd-update > /dev/null ) ; /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/
-
-* * * * * root /usr/local/bin/check-gateway
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+* * * * * root /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/ > /dev/null 2>&1
0 0 * * * root find /opt/ffmap-backend/nodedb/ -name '*.rrd' -ctime 8 -execdir rm '{}' +
0 1 * * * root find /opt/ffmap-backend/nodeplots/ -name '*.png' -ctime 1 -execdir rm '{}' +
diff --git a/mkmap.sh b/mkmap.sh
index 3613a87..dd46a24 100755
--- a/mkmap.sh
+++ b/mkmap.sh
@@ -9,4 +9,9 @@ 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
-./bat2nodes.py -A -a json/aliases.json -d $DEST
+wget -q -O json/alfred.158.json "http://vpn0.freifunk.in-kiel.de/alfred.cgi?158"
+wget -q -O json/alfred.159.json "http://vpn0.freifunk.in-kiel.de/alfred.cgi?159"
+wget -q -O json/batman.json "http://vpn0.freifunk.in-kiel.de/batman.cgi"
+
+./bat2nodes.py --alfred json/alfred.158.json --aliases json/aliases.json --mesh json/batman.json -d $DEST
+
diff --git a/nodedb.py b/nodedb.py
index a45c7a1..0f1065c 100644
--- a/nodedb.py
+++ b/nodedb.py
@@ -225,7 +225,7 @@ class NodeDB:
try:
node = self.maybe_node_by_mac((gateway, ))
except:
- print("WARNING: did not find gateway '",gateway,"' in node list")
+ print("WARNING: did not find gateway '%s' in node list" % gateway)
continue
node.flags['gateway'] = True