From 55dc7b4ad5cc2a4cde23ae54f3b25f4bd70daa9b Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Fri, 29 Dec 2017 19:23:22 +0100 Subject: [PATCH] Rename net_if from router_neighbor table to netif This includes various changes throughout the code. Additionally, some fields are reordered. This requires a change of the MySQL table router_neighbor! Signed-off-by: Adrian Schmutzler --- contrib/crawl.py | 2 +- ffmap/db/routers.py | 2 +- ffmap/routertools.py | 10 +++++----- ffmap/web/api.py | 2 +- ffmap/web/application.py | 2 +- ffmap/web/static/js/graph.js | 2 +- ffmap/web/static/js/map.js | 2 +- ffmap/web/templates/router.html | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/crawl.py b/contrib/crawl.py index 1c1f3fe..c761590 100755 --- a/contrib/crawl.py +++ b/contrib/crawl.py @@ -117,8 +117,8 @@ def crawl(router): continue neighbour = { "mac": o_mac.lower(), + "netif": o_out_if, "quality": int(o_link_quality), - "net_if": o_out_if, } try: neighbour_router = db.routers.find_one({"netifs.mac": neighbour["mac"]}) diff --git a/ffmap/db/routers.py b/ffmap/db/routers.py index d30344f..132fed7 100755 --- a/ffmap/db/routers.py +++ b/ffmap/db/routers.py @@ -126,8 +126,8 @@ mysql.execute(""" CREATE TABLE router_neighbor ( `router` mediumint(8) UNSIGNED NOT NULL, `mac` char(17) COLLATE utf8_unicode_ci NOT NULL, + `netif` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `quality` smallint(6) NOT NULL, - `net_if` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `type` varchar(10) COLLATE utf8_unicode_ci DEFAULT 'l2' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci """) diff --git a/ffmap/routertools.py b/ffmap/routertools.py index c21cbfc..ba71fbe 100644 --- a/ffmap/routertools.py +++ b/ffmap/routertools.py @@ -221,14 +221,14 @@ def import_nodewatcher_xml(mysql, mac, xml, banned, netifdict): nbdata = [] for n in router_update["neighbours"]: - nbdata.append((router_id,n["mac"],n["quality"],n["net_if"],n["type"],)) + nbdata.append((router_id,n["mac"],n["netif"],n["quality"],n["type"],)) mysql.executemany(""" - INSERT INTO router_neighbor (router, mac, quality, net_if, type) + INSERT INTO router_neighbor (router, mac, netif, quality, type) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE + netif=VALUES(netif), quality=VALUES(quality), - net_if=VALUES(net_if), type=VALUES(type) """,nbdata) @@ -669,8 +669,8 @@ def parse_nodewatcher_xml(xml): continue neighbour = { "mac": o_mac.lower(), + "netif": o_out_if, "quality": int(o_link_quality), - "net_if": o_out_if, "type": "l2" } router_update["neighbours"].append(neighbour) @@ -691,8 +691,8 @@ def get_l3_neighbours(tree): out_if = neighbour.xpath("outgoing_interface/text()")[0] neighbour = { "mac": get_mac_from_v6_link_local(v6_fe80).lower(), + "netif": out_if, "quality": -1, - "net_if": out_if, "type": "l3" } l3_neighbours.append(neighbour) diff --git a/ffmap/web/api.py b/ffmap/web/api.py index f0cec07..d2084dd 100755 --- a/ffmap/web/api.py +++ b/ffmap/web/api.py @@ -54,7 +54,7 @@ def get_nearest_router(): """,(lat,lng,lat,)) res_router["neighbours"] = mysql.fetchall(""" - SELECT nb.mac, nb.quality, nb.net_if, r.hostname, r.id + SELECT nb.mac, nb.netif, nb.quality, r.hostname, r.id FROM router_neighbor AS nb INNER JOIN ( SELECT router, mac FROM router_netif GROUP BY mac, router diff --git a/ffmap/web/application.py b/ffmap/web/application.py index e40b2f9..11814bc 100755 --- a/ffmap/web/application.py +++ b/ffmap/web/application.py @@ -107,7 +107,7 @@ def router_info(dbid): mac = n["mac"] router["neighbours"] = mysql.fetchall(""" - SELECT nb.mac, nb.quality, nb.net_if, r.hostname, r.id + SELECT nb.mac, nb.netif, nb.quality, r.hostname, r.id FROM router_neighbor AS nb LEFT JOIN ( SELECT router, mac FROM router_netif GROUP BY mac, router diff --git a/ffmap/web/static/js/graph.js b/ffmap/web/static/js/graph.js index 0e66995..7224c68 100644 --- a/ffmap/web/static/js/graph.js +++ b/ffmap/web/static/js/graph.js @@ -109,7 +109,7 @@ function neighbour_graph(neighbours) { var k; for(k=0; k"; popup_html += ''+escapeHTML(neighbour.hostname)+''; popup_html += ""+neighbour.quality+""; - popup_html += ""+escapeHTML(neighbour.net_if)+""; + popup_html += ""+escapeHTML(neighbour.netif)+""; popup_html += ""; } } diff --git a/ffmap/web/templates/router.html b/ffmap/web/templates/router.html index 63af4e4..1457a9a 100644 --- a/ffmap/web/templates/router.html +++ b/ffmap/web/templates/router.html @@ -208,7 +208,7 @@ {%- if neighbour.hostname -%}{{ neighbour.hostname }}{%- else -%}---{%- endif -%} {{ neighbour.mac }} {{ neighbour.quality }} - {{ neighbour.net_if }} + {{ neighbour.netif }} {%- endfor %} @@ -344,7 +344,7 @@ var neigh_stats = {{ neighstats|statbson2json|safe }}; var neighbours = [ {%- for neighbour in router.neighbours %} - {"name": "{{ neighbour.hostname or neighbour.mac }}", "mac": "{{ neighbour.mac }}", "net_if": "{{ neighbour.net_if }}"}, + {"name": "{{ neighbour.hostname or neighbour.mac }}", "mac": "{{ neighbour.mac }}", "netif": "{{ neighbour.netif }}"}, {%- endfor %} ]; $(document).ready(function() {