Add alfred_leagcy_provider

It gets a list of pre-0.5.1 routers from netmon mysql db,
crawls them and sends the results to a (patched) alfred master.
This commit is contained in:
Dominik Heidler 2016-02-29 19:16:49 +01:00
parent 19329ef85c
commit b3a0131b63
8 changed files with 99 additions and 1 deletions

View File

@ -0,0 +1 @@
macs.txt

View File

@ -0,0 +1,29 @@
From: Dominik Heidler <dominik@heidler.eu>
Date: Mon, 29 Feb 2016 19:07:00 +0100
Subject: [PATCH] Allow setting the source mac via unix sock
The server will only overwrite the mac if it is zero.
The alfred client sets the mac to zero by default
so this shouldn't break existing behaviour.
---
unix_sock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/unix_sock.c b/unix_sock.c
index 3c7e583..12a10e6 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -119,7 +119,9 @@ static int unix_sock_add_data(struct globals *globals,
data = push->data;
data_len = ntohs(data->header.length);
- memcpy(data->source, &interface->hwaddr, sizeof(interface->hwaddr));
+ static const char zero[ETH_ALEN] = { 0 };
+ if (!memcmp(zero, data->source, sizeof(data->source)))
+ memcpy(data->source, &interface->hwaddr, sizeof(interface->hwaddr));
if ((int)(data_len + sizeof(*data)) > len)
goto err;
--
1.7.10.4

View File

@ -0,0 +1,49 @@
#!/usr/bin/python3
import sys
import subprocess
import re
import pyalfred
CONFIG = {
#"crawl_outgoing_netif": "br-mesh",
# this old system sucks
"crawl_outgoing_netif": "25%s" % open("/sys/class/net/br-mesh/ifindex").read().strip(),
}
def mac_to_ipv6_linklocal(mac):
# Remove the most common delimiters; dots, dashes, etc.
mac_bare = re.sub('[%s]+' % re.escape(' .:-'), '', mac)
mac_value = int(mac_bare, 16)
# Split out the bytes that slot into the IPv6 address
# XOR the most significant byte with 0x02, inverting the
# Universal / Local bit
high2 = mac_value >> 32 & 0xffff ^ 0x0200
high1 = mac_value >> 24 & 0xff
low1 = mac_value >> 16 & 0xff
low2 = mac_value & 0xffff
return 'fe80::{:04x}:{:02x}ff:fe{:02x}:{:04x}'.format(high2, high1, low1, low2)
mac = sys.argv[1]
fe80_ip = mac_to_ipv6_linklocal(mac)
node_data = subprocess.check_output(["curl", "-s", "--max-time", "5", "-g", "http://[%s%%%s]/node.data" % (
fe80_ip,
CONFIG["crawl_outgoing_netif"]
)])
try:
node_data = gzip.decompress(node_data)
except:
pass
assert "<TITLE>404" not in str(node_data).upper()
#print(node_data)
ac = pyalfred.AlfredConnection()
ac.send(64, node_data.decode("UTF-8", errors="replace"), mac, gzip_data=True)

View File

@ -0,0 +1,6 @@
#!/bin/bash
for mac in `cat /home/dominik/alfred_legacy_provider/macs.txt` ; do
echo "Crawling $mac"
/home/dominik/alfred_legacy_provider/crawl.py $mac
done

View File

@ -0,0 +1,3 @@
#!/bin/bash
/home/dominik/alfred_legacy_provider/list_old.sh 2>/dev/null | grep br-mesh | awk -F ' ' '{print $NF}' > /home/dominik/alfred_legacy_provider/macs.txt

View File

@ -0,0 +1,4 @@
#!/bin/bash
MYSQL_PWD="`grep mysql_password /var/www/netmon/config/config.local.inc.php | cut -d '"' -f 2`"
mysql -u netmon -"p$MYSQL_PWD" netmon -e 'SELECT r.id, r.hostname, c.firmware_version, i.name, i.mac_addr FROM routers r JOIN crawl_routers c ON c.id = (SELECT MAX(id) FROM crawl_routers WHERE router_id = r.id) LEFT JOIN crawl_interfaces i ON i.id = (SELECT MAX(id) FROM crawl_interfaces WHERE router_id = r.id AND name = "br-mesh") WHERE c.status = "online" AND c.firmware_version <= "0.5.0" ORDER BY r.id;';

View File

@ -0,0 +1,4 @@
#!/bin/bash
./get_macs.sh
./crawl_all.sh

View File

@ -9,7 +9,9 @@
</div>
<div class="col-xs-8 col-sm-8"><p>
Monitoring f&uuml;r das Freifunk Franken Funknetzwerk.<br />
Hier werden nur Daten von Routern ab Firmware 0.5.1 angezeigt.<br />
Hier werden Daten von Routern ab Firmware 0.5.1 direkt angezeigt.<br />
Die alten Router werden &uuml;ber den <a href="https://github.com/asdil12/fff-monitoring/tree/master/contrib/alfred_legacy_provider">Alfred Legacy Provider</a> abgefragt,<br />
sodass sie ebenfalls hier angezeigt werden k&ouml;nnen.<br />
Der Quellcode für diese Webanwendung steht unter der GPL und kann <a href="https://github.com/asdil12/fff-monitoring">hier</a>
heruntergeladen werden.
</p></div>