From ff0aeca1aac0b880861662b12f25499abba33211 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Fri, 12 Jan 2018 18:09:53 +0100 Subject: [PATCH] helpers: Enable search for gateways based on batX interface MACs Introduces two new query parameters: bat: looks for routers being aware of the specified gateway batselected: looks for routers CONNECTED to the specified gw Both variants support regex. Signed-off-by: Adrian Schmutzler --- ffmap/web/helpers.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ffmap/web/helpers.py b/ffmap/web/helpers.py index 0e0913e..caf62f5 100644 --- a/ffmap/web/helpers.py +++ b/ffmap/web/helpers.py @@ -29,6 +29,8 @@ allowed_filters = ( 'neighbour', 'gw', 'selected', + 'bat', + 'batselected', ) def parse_router_list_search_query(args): @@ -76,6 +78,24 @@ def parse_router_list_search_query(args): j += " INNER JOIN router_gw ON router.id = router_gw.router " k = "router_gw.mac {} REGEXP %s AND router_gw.selected = TRUE".format(no) t.append(value.lower()) + elif (key == 'bat'): + j += """ INNER JOIN router_gw ON router.id = router_gw.router + INNER JOIN ( + gw_netif AS n1 + INNER JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw + ) ON router_gw.mac = n1.mac + """ + k = "n2.mac {} REGEXP %s".format(no) + t.append(value.lower()) + elif (key == 'batselected'): + j += """ INNER JOIN router_gw ON router.id = router_gw.router + INNER JOIN ( + gw_netif AS n1 + INNER JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw + ) ON router_gw.mac = n1.mac + """ + k = "n2.mac {} REGEXP %s AND router_gw.selected = TRUE".format(no) + t.append(value.lower()) elif (key == 'neighbor') or (key == 'neighbour'): j += " INNER JOIN ( SELECT router, mac FROM router_neighbor GROUP BY router, mac) AS j ON router.id = j.router " k = "mac {} REGEXP %s".format(no)