Introduce option to set routers as blocked by KeyXchange
This requires changes to the MySQL database! Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
94b9d92b8a
commit
4dab09748c
|
@ -20,6 +20,18 @@ mysql.execute("""
|
|||
ADD PRIMARY KEY (`mac`)
|
||||
""")
|
||||
|
||||
mysql.execute("""
|
||||
CREATE TABLE blocked (
|
||||
`mac` char(17) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`added` datetime NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
|
||||
""")
|
||||
|
||||
mysql.execute("""
|
||||
ALTER TABLE blocked
|
||||
ADD PRIMARY KEY (`mac`)
|
||||
""")
|
||||
|
||||
mysql.execute("""
|
||||
CREATE TABLE netifs (
|
||||
`id` smallint(6) UNSIGNED NOT NULL,
|
||||
|
|
|
@ -51,9 +51,15 @@ def router_list():
|
|||
mysql = FreifunkMySQL()
|
||||
|
||||
routers = mysql.fetchall("""
|
||||
SELECT router.id, hostname, status, hood, contact, nickname, hardware, router.created, sys_uptime, clients, reset
|
||||
SELECT router.id, hostname, status, hood, contact, nickname, hardware, router.created, sys_uptime, clients, reset, blocked
|
||||
FROM router
|
||||
LEFT JOIN users ON router.contact = users.email
|
||||
LEFT JOIN (
|
||||
SELECT router, blocked.mac AS blocked FROM router_netif
|
||||
INNER JOIN blocked ON router_netif.mac = blocked.mac
|
||||
WHERE netif = 'br-mesh'
|
||||
) AS b
|
||||
ON router.id = b.router
|
||||
{}
|
||||
ORDER BY hostname ASC
|
||||
""".format(where),tuple)
|
||||
|
@ -195,6 +201,17 @@ def router_info(dbid):
|
|||
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")
|
||||
elif request.form.get("act") == "changeblocked" and mac:
|
||||
if session.get('admin'):
|
||||
if request.form.get("blocked") == "true":
|
||||
added = mysql.utcnow()
|
||||
mysql.execute("INSERT INTO blocked (mac, added) VALUES (%s, %s)",(mac,added,))
|
||||
mysql.commit()
|
||||
else:
|
||||
mysql.execute("DELETE FROM blocked WHERE mac = %s",(mac,))
|
||||
mysql.commit()
|
||||
else:
|
||||
flash("<b>You are not authorized to perform this action!</b>", "danger")
|
||||
elif request.form.get("act") == "report":
|
||||
abusemails = mysql.fetchall("SELECT email FROM users WHERE abuse = 1")
|
||||
for a in abusemails:
|
||||
|
@ -208,11 +225,18 @@ def router_info(dbid):
|
|||
"Regards,\nFreifunk Franken Monitoring System"
|
||||
)
|
||||
flash("<b>Router reported to administrators!</b>", "success")
|
||||
mysql.close()
|
||||
else:
|
||||
mysql.close()
|
||||
return "Router not found"
|
||||
|
||||
router["blocked"] = mysql.findone("""
|
||||
SELECT blocked.mac
|
||||
FROM router_netif AS n
|
||||
LEFT JOIN blocked ON n.mac = blocked.mac
|
||||
WHERE n.router = %s AND n.netif = 'br-mesh'
|
||||
""",(dbid,),"mac")
|
||||
mysql.close()
|
||||
|
||||
return render_template("router.html",
|
||||
router = router,
|
||||
mac = mac,
|
||||
|
@ -320,8 +344,14 @@ def user_info(nickname):
|
|||
else:
|
||||
flash("<b>You are not authorized to perform this action!</b>", "danger")
|
||||
routers = mysql.fetchall("""
|
||||
SELECT id, hostname, status, hood, firmware, hardware, created, sys_uptime, clients, reset
|
||||
SELECT id, hostname, status, hood, firmware, hardware, created, sys_uptime, clients, reset, blocked
|
||||
FROM router
|
||||
LEFT JOIN (
|
||||
SELECT router, blocked.mac AS blocked FROM router_netif
|
||||
INNER JOIN blocked ON router_netif.mac = blocked.mac
|
||||
WHERE netif = 'br-mesh'
|
||||
) AS b
|
||||
ON router.id = b.router
|
||||
WHERE contact = %s
|
||||
ORDER BY hostname ASC
|
||||
""",(user["email"],))
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
{%- endif %}
|
||||
{%- if authadmin %}
|
||||
<li><a href="#" onclick="$('#act').val('ban'); $('#actform').submit()">Ban Router</a></li>
|
||||
<li><a href="#" onclick="$('#blockedform').submit()">Toggle blocked status</a></li>
|
||||
{%- endif %}
|
||||
<li><a href="#" onclick="$('#act').val('report'); $('#actform').submit()">Report abusive Router</a></li>
|
||||
</ul>
|
||||
|
@ -153,7 +154,11 @@
|
|||
</td></tr>
|
||||
{%- endif %}
|
||||
<tr><th>Hardware</th><td><span title="{{ router.chipset }}">{{ router.hardware }}</span></td></tr>
|
||||
<tr><th>WAN Uplink</th><td><span class="{{ "glyphicon glyphicon-ok" if router.wan_uplink else "glyphicon glyphicon-remove" }}"></span></td></tr>
|
||||
<tr><th>WAN Uplink</th><td><span class="{{ "glyphicon glyphicon-ok" if router.wan_uplink else "glyphicon glyphicon-remove" }}"></span>
|
||||
{%- if router.blocked %}
|
||||
<span style="color:#d90000"> - Router BLOCKED by KeyXchange!</span>
|
||||
{%- endif -%}
|
||||
</td></tr>
|
||||
<tr><th>Clients</th><td>{{ router.clients }}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -417,4 +422,11 @@
|
|||
network_graph("br-mesh");
|
||||
});
|
||||
</script>
|
||||
|
||||
{%- if session.admin %}
|
||||
<form method="post" id="blockedform">
|
||||
<input type="hidden" name="act" value="changeblocked" />
|
||||
<input type="hidden" name="blocked" value="{{ "false" if router.blocked else "true" }}" />
|
||||
</form>
|
||||
{%- endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -42,7 +42,9 @@
|
|||
<tbody>
|
||||
{%- for router in routers %}
|
||||
<tr>
|
||||
<td class="text-nowrap-responsive"><a href="{{ url_for("router_info", dbid=router.id) }}">{{ router.hostname }}</a>{%- if router.reset %} (Reset!){%- endif %}</td>
|
||||
<td class="text-nowrap-responsive"><a href="{{ url_for("router_info", dbid=router.id) }}">{{ router.hostname }}</a>
|
||||
{%- if router.reset %} - <span style="color:#d90000">Reset!</span>{%- endif %}{%- if router.blocked %} - <span style="color:#d90000">Blocked!</span>{%- endif %}
|
||||
</td>
|
||||
<td class="text-center"><span class="{{ router.status|status2css }}">{{ router.status }}</span></td>
|
||||
<td>{{ router.hood }}</td>
|
||||
<td>{{ router.nickname if router.nickname else "" }}</td>
|
||||
|
|
|
@ -103,7 +103,9 @@
|
|||
{%- set total_clients = 0 %}
|
||||
{%- for router in routers %}
|
||||
<tr>
|
||||
<td class="text-nowrap-responsive"><a href="{{ url_for("router_info", dbid=router.id) }}">{{ router.hostname }}</a>{%- if router.reset %} (Reset!){%- endif %}</td>
|
||||
<td class="text-nowrap-responsive"><a href="{{ url_for("router_info", dbid=router.id) }}">{{ router.hostname }}</a>
|
||||
{%- if router.reset %} - <span style="color:#d90000">Reset!</span>{%- endif %}{%- if router.blocked %} - <span style="color:#d90000">Blocked!</span>{%- endif %}
|
||||
</td>
|
||||
<td class="text-center"><span class="{{ router.status|status2css }}">{{ router.status }}</span></td>
|
||||
<td>{{ router.hood }}</td>
|
||||
<td>{{ router.firmware }}</td>
|
||||
|
|
Loading…
Reference in New Issue