2022-05-04 13:31:14 +01:00
|
|
|
from flask import render_template, Response, flash, redirect, url_for, Blueprint
|
|
|
|
from sqlalchemy import desc
|
|
|
|
|
|
|
|
from app.extensions import db
|
|
|
|
from app.models.mirrors import Proxy
|
|
|
|
from app.portal.forms import LifecycleForm
|
|
|
|
|
|
|
|
bp = Blueprint("proxy", __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/list")
|
|
|
|
def proxy_list():
|
|
|
|
proxies = Proxy.query.filter(Proxy.destroyed == None).order_by(desc(Proxy.added)).all()
|
|
|
|
return render_template("list.html.j2",
|
|
|
|
section="proxy",
|
|
|
|
title="Proxies",
|
|
|
|
item="proxy",
|
|
|
|
items=proxies)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/block/<proxy_id>", methods=['GET', 'POST'])
|
|
|
|
def proxy_block(proxy_id):
|
|
|
|
proxy = Proxy.query.filter(Proxy.id == proxy_id, Proxy.destroyed == None).first()
|
|
|
|
if proxy is None:
|
|
|
|
return Response(render_template("error.html.j2",
|
|
|
|
header="404 Proxy Not Found",
|
|
|
|
message="The requested proxy could not be found. It may have already been "
|
|
|
|
"destroyed."))
|
|
|
|
form = LifecycleForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
proxy.deprecate(reason="manual")
|
|
|
|
db.session.commit()
|
|
|
|
flash("Proxy will be shortly replaced.", "success")
|
2022-05-04 13:46:52 +01:00
|
|
|
return redirect(url_for("portal.origin.origin_edit", origin_id=proxy.origin.id))
|
2022-05-04 13:31:14 +01:00
|
|
|
return render_template("lifecycle.html.j2",
|
|
|
|
header=f"Mark proxy for {proxy.origin.domain_name} as blocked?",
|
|
|
|
message=proxy.url,
|
|
|
|
section="proxy",
|
|
|
|
form=form)
|