helpers: Enable search for gateways based on batX interface MACs

Introduces two new query parameters:
bat:<mac> looks for routers being aware of the specified gateway
batselected:<mac> looks for routers CONNECTED to the specified gw

Both variants support regex.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-01-12 18:09:53 +01:00
parent 669895cd7b
commit ff0aeca1aa
1 changed files with 20 additions and 0 deletions

View File

@ -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)