diff --git a/app/portal/__init__.py b/app/portal/__init__.py index 018e669..2a801b8 100644 --- a/app/portal/__init__.py +++ b/app/portal/__init__.py @@ -11,11 +11,13 @@ from app import Origin, Proxy from app.models.base import Group, MirrorList from app.portal.forms import NewOriginForm, EditOriginForm, LifecycleForm, \ NewBridgeConfForm, EditBridgeConfForm, NewMirrorListForm -from app.portal.group import group, NewGroupForm, EditGroupForm +from app.portal.group import bp as group +from app.portal.proxy import bp as proxy portal = Blueprint("portal", __name__, template_folder="templates", static_folder="static") portal.register_blueprint(group, url_prefix="/group") +portal.register_blueprint(proxy, url_prefix="/proxy") @portal.app_template_filter("mirror_expiry") @@ -111,35 +113,6 @@ def view_origins(): new_link=url_for("portal.new_origin"), items=origins) -@portal.route("/proxies") -def view_proxies(): - proxies = Proxy.query.filter(Proxy.destroyed == None).order_by(desc(Proxy.updated)).all() - return render_template("list.html.j2", - section="proxy", - title="Proxies", - item="proxy", - items=proxies) - - -@portal.route("/proxy/block/", methods=['GET', 'POST']) -def blocked_proxy(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.")) - form = LifecycleForm() - if form.validate_on_submit(): - proxy.deprecate(reason="manual") - db.session.commit() - flash("Proxy will be shortly replaced.", "success") - return redirect(url_for("portal.edit_origin", origin_id=proxy.origin.id)) - return render_template("lifecycle.html.j2", - header=f"Mark proxy for {proxy.origin.domain_name} as blocked?", - message=proxy.url, - section="proxy", - form=form) - @portal.route("/search") def search(): diff --git a/app/portal/group.py b/app/portal/group.py index ca944d0..63a3af0 100644 --- a/app/portal/group.py +++ b/app/portal/group.py @@ -9,7 +9,7 @@ from wtforms.validators import DataRequired from app.extensions import db from app.models.base import Group -group = Blueprint("group", __name__) +bp = Blueprint("group", __name__) class NewGroupForm(FlaskForm): @@ -25,7 +25,7 @@ class EditGroupForm(FlaskForm): submit = SubmitField('Save Changes', render_kw={"class": "btn btn-success"}) -@group.route("/list") +@bp.route("/list") def group_list(): groups = Group.query.order_by(Group.group_name).all() return render_template("list.html.j2", @@ -36,7 +36,7 @@ def group_list(): new_link=url_for("portal.group.group_new")) -@group.route("/new", methods=['GET', 'POST']) +@bp.route("/new", methods=['GET', 'POST']) def group_new(): form = NewGroupForm() if form.validate_on_submit(): @@ -58,7 +58,7 @@ def group_new(): return render_template("new.html.j2", section="group", form=form) -@group.route('/edit/', methods=['GET', 'POST']) +@bp.route('/edit/', methods=['GET', 'POST']) def group_edit(group_id): group = Group.query.filter(Group.id == group_id).first() if group is None: diff --git a/app/portal/proxy.py b/app/portal/proxy.py new file mode 100644 index 0000000..edffde8 --- /dev/null +++ b/app/portal/proxy.py @@ -0,0 +1,39 @@ +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/", 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") + return redirect(url_for("portal.edit_origin", origin_id=proxy.origin.id)) + return render_template("lifecycle.html.j2", + header=f"Mark proxy for {proxy.origin.domain_name} as blocked?", + message=proxy.url, + section="proxy", + form=form) diff --git a/app/portal/templates/base.html.j2 b/app/portal/templates/base.html.j2 index 701d613..8756266 100644 --- a/app/portal/templates/base.html.j2 +++ b/app/portal/templates/base.html.j2 @@ -107,7 +107,7 @@ diff --git a/app/portal/templates/tables.html.j2 b/app/portal/templates/tables.html.j2 index 5a063f7..8c7bd3b 100644 --- a/app/portal/templates/tables.html.j2 +++ b/app/portal/templates/tables.html.j2 @@ -146,7 +146,7 @@ Expiring in {{ proxy.deprecated | mirror_expiry }} {% else %} - Mark blocked {% endif %}