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 <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2017-11-19 13:04:49 +01:00
parent b2541fe40e
commit 58b6bc34f9
2 changed files with 6 additions and 3 deletions

View File

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

View File

@ -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 <noreply@monitoring.freifunk-franken.de>"):
msg = MIMEText(content)