portal: refactor bridges views into modules
This commit is contained in:
parent
22f850cf6b
commit
9987c996c9
7 changed files with 173 additions and 153 deletions
37
app/portal/bridge.py
Normal file
37
app/portal/bridge.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from flask import render_template, Response, flash, redirect, url_for, Blueprint
|
||||
|
||||
from app.extensions import db
|
||||
from app.models.bridges import Bridge
|
||||
from app.portal.forms import LifecycleForm
|
||||
|
||||
bp = Blueprint("bridge", __name__)
|
||||
|
||||
|
||||
@bp.route("/list")
|
||||
def bridge_list():
|
||||
bridges = Bridge.query.filter(Bridge.destroyed == None).all()
|
||||
return render_template("list.html.j2",
|
||||
section="bridge",
|
||||
title="Tor Bridges",
|
||||
item="bridge",
|
||||
items=bridges)
|
||||
|
||||
|
||||
@bp.route("/block/<bridge_id>", methods=['GET', 'POST'])
|
||||
def bridge_blocked(bridge_id):
|
||||
bridge: Bridge = Bridge.query.filter(Bridge.id == bridge_id, Bridge.destroyed == None).first()
|
||||
if bridge is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
header="404 Proxy Not Found",
|
||||
message="The requested bridge could not be found."))
|
||||
form = LifecycleForm()
|
||||
if form.validate_on_submit():
|
||||
bridge.deprecate(reason="manual")
|
||||
db.session.commit()
|
||||
flash("Bridge will be shortly replaced.", "success")
|
||||
return redirect(url_for("portal.edit_bridgeconf", bridgeconf_id=bridge.conf_id))
|
||||
return render_template("lifecycle.html.j2",
|
||||
header=f"Mark bridge {bridge.hashed_fingerprint} as blocked?",
|
||||
message=bridge.hashed_fingerprint,
|
||||
section="bridge",
|
||||
form=form)
|
Loading…
Add table
Add a link
Reference in a new issue