GUI: allow deleting external peers from client list
This commit is contained in:
21
gui/app.py
21
gui/app.py
@@ -444,6 +444,27 @@ def peer_delete(peer_id: int):
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/peers/delete-by-key")
|
||||||
|
def peer_delete_by_key():
|
||||||
|
pk = (request.form.get("public_key") or "").strip()
|
||||||
|
if not pk:
|
||||||
|
flash("Не найден public key", "error")
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
try:
|
||||||
|
run(["/usr/local/sbin/wg-peerctl", "remove", "--client-public-key", pk])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with db_conn() as conn:
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("DELETE FROM peers WHERE public_key = ?", (pk,))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
flash("Peer удален", "ok")
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/scripts")
|
@app.route("/scripts")
|
||||||
def scripts():
|
def scripts():
|
||||||
commands = {
|
commands = {
|
||||||
|
|||||||
@@ -28,7 +28,10 @@
|
|||||||
<button type="submit" class="danger">Удалить</button>
|
<button type="submit" class="danger">Удалить</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
-
|
<form method="post" action="{{ url_for('peer_delete_by_key') }}" style="display:inline" onsubmit="return confirm('Удалить peer?')">
|
||||||
|
<input type="hidden" name="public_key" value="{{ p.public_key }}" />
|
||||||
|
<button type="submit" class="danger">Удалить</button>
|
||||||
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user