From 58b6bc34f9f2b82556ebf40fb9fd2c4b04f0b177 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Sun, 19 Nov 2017 13:04:49 +0100 Subject: [PATCH] helpers/api: Fix MAC search This fixes searching for MAC addresses in the router list and via api/get_router_by_mac/ Additionally, regex is enabled for MAC addresses. Signed-off-by: Adrian Schmutzler --- ffmap/web/api.py | 2 +- ffmap/web/helpers.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ffmap/web/api.py b/ffmap/web/api.py index ba6b9b1..00e93e9 100755 --- a/ffmap/web/api.py +++ b/ffmap/web/api.py @@ -67,7 +67,7 @@ def get_router_by_mac(mac): """,(mac.lower(),)) mysql.close() if len(res_routers) != 1: - return redirect(url_for("router_list", q="netifs.mac:%s" % mac)) + return redirect(url_for("router_list", q="mac:%s" % mac)) else: return redirect(url_for("router_info", dbid=res_routers[0]["id"])) diff --git a/ffmap/web/helpers.py b/ffmap/web/helpers.py index b060ed2..f2e3abc 100644 --- a/ffmap/web/helpers.py +++ b/ffmap/web/helpers.py @@ -41,6 +41,7 @@ def parse_router_list_search_query(args): if key in allowed_filters: query_usr[key] = query_usr.get(key, "") + value s = "" + j = "" t = [] i = 0 for key, value in query_usr.items(): @@ -59,7 +60,8 @@ def parse_router_list_search_query(args): elif value == "EXISTS_NOT": k = key + ' = "" OR ' + key + " IS NULL" elif key == 'mac': - k = no + "mac = %s" + j += " INNER JOIN ( SELECT router, mac FROM router_netif GROUP BY router, mac) AS j ON router.id = j.router " + k = "mac {} REGEXP %s".format(no) t.append(value.lower()) elif (key == 'hardware') or (key == 'hood'): k = key + " {} REGEXP %s".format(no) @@ -75,7 +77,8 @@ def parse_router_list_search_query(args): t.append(value) i += 1 s += prefix + k - return (s, tuple(t), format_query(query_usr)) + where = j + " " + s + return (where, tuple(t), format_query(query_usr)) def send_email(recipient, subject, content, sender="FFF Monitoring "): msg = MIMEText(content)