Provide possibility to ban routers
If routers are supposed to be removed from the Monitoring permanently, they can now be banned based on their MAC address. All admins can do that via the web interface. ATTENTION: This requires a database update! Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
818dc79b7d
commit
20e71afeb0
|
@ -8,6 +8,18 @@ from ffmap.mysqltools import FreifunkMySQL
|
|||
|
||||
mysql = FreifunkMySQL()
|
||||
|
||||
mysql.execute("""
|
||||
CREATE TABLE banned (
|
||||
`mac` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`added` datetime NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
""")
|
||||
|
||||
mysql.execute("""
|
||||
ALTER TABLE `banned`
|
||||
ADD PRIMARY KEY (`mac`);
|
||||
""")
|
||||
|
||||
mysql.execute("""
|
||||
CREATE TABLE router (
|
||||
`id` int(11) NOT NULL,
|
||||
|
|
|
@ -29,7 +29,18 @@ def delete_router(mysql,dbid):
|
|||
mysql.execute("DELETE FROM router_stats_netif WHERE router = %s",(dbid,))
|
||||
mysql.commit()
|
||||
|
||||
def import_nodewatcher_xml(mysql, mac, xml):
|
||||
def ban_router(mysql,dbid):
|
||||
mac = mysql.findone("""
|
||||
SELECT mac
|
||||
FROM router_netif
|
||||
WHERE router = %s AND netif = 'br-mesh'
|
||||
""",(dbid,),"mac")
|
||||
added = mysql.utcnow()
|
||||
if mac:
|
||||
mysql.execute("INSERT INTO banned (mac, added) VALUES (%s, %s)",(mac,added,))
|
||||
mysql.commit()
|
||||
|
||||
def import_nodewatcher_xml(mysql, mac, xml, banned):
|
||||
global router_rate_limit_list
|
||||
|
||||
t = utcnow()
|
||||
|
@ -51,6 +62,12 @@ def import_nodewatcher_xml(mysql, mac, xml):
|
|||
try:
|
||||
findrouter = mysql.findone("SELECT router FROM router_netif WHERE mac = %s LIMIT 1",(mac.lower(),))
|
||||
router_update = parse_nodewatcher_xml(xml)
|
||||
|
||||
# cancel if banned mac found
|
||||
for n in router_update["netifs"]:
|
||||
if n["mac"] in banned:
|
||||
return
|
||||
|
||||
if router_update["status"] == "wrongpos":
|
||||
router_update["status"] = "unknown"
|
||||
status_comment = "Coordinates are wrong"
|
||||
|
|
|
@ -83,6 +83,9 @@ def alfred():
|
|||
#import cProfile, pstats, io
|
||||
#pr = cProfile.Profile()
|
||||
#pr.enable()
|
||||
banned = mysql.fetchall("""
|
||||
SELECT mac FROM banned
|
||||
""",(),"mac")
|
||||
if request.method == 'POST':
|
||||
alfred_data = request.get_json()
|
||||
|
||||
|
@ -90,7 +93,7 @@ def alfred():
|
|||
# load router status xml data
|
||||
i = 1
|
||||
for mac, xml in alfred_data.get("64", {}).items():
|
||||
import_nodewatcher_xml(mysql, mac, xml)
|
||||
import_nodewatcher_xml(mysql, mac, xml, banned)
|
||||
if (i%500 == 0):
|
||||
mysql.commit()
|
||||
i += 1
|
||||
|
|
|
@ -9,7 +9,7 @@ from ffmap.web.filters import filters
|
|||
from ffmap.mysqltools import FreifunkMySQL
|
||||
from ffmap import stattools
|
||||
from ffmap.usertools import *
|
||||
from ffmap.routertools import delete_router
|
||||
from ffmap.routertools import delete_router, ban_router
|
||||
from ffmap.web.helpers import *
|
||||
from ffmap.config import CONFIG
|
||||
from ffmap.misc import writelog, writefulllog
|
||||
|
@ -153,6 +153,18 @@ def router_info(dbid):
|
|||
return redirect(url_for("index"))
|
||||
else:
|
||||
flash("<b>You are not authorized to perform this action!</b>", "danger")
|
||||
elif request.form.get("act") == "ban":
|
||||
if session.get('admin'):
|
||||
if mac:
|
||||
ban_router(mysql,dbid)
|
||||
delete_router(mysql,dbid)
|
||||
flash("<b>Router <i>%s</i> banned!</b>" % router["hostname"], "success")
|
||||
mysql.close()
|
||||
return redirect(url_for("index"))
|
||||
else:
|
||||
flash("<b>Router has no br-mesh and thus cannot be banned!</b>", "danger")
|
||||
else:
|
||||
flash("<b>You are not authorized to perform this action!</b>", "danger")
|
||||
mysql.close()
|
||||
else:
|
||||
mysql.close()
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
<ul class="dropdown-menu">
|
||||
{# FIXME: If authorized #}
|
||||
<li><a href="#" onclick="$('#act').val('delete'); $('#actform').submit()">Delete Router</a></li>
|
||||
<li><a href="#" onclick="$('#act').val('ban'); $('#actform').submit()">Ban Router</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue