2022-05-16 11:44:03 +01:00
|
|
|
from typing import Optional
|
2022-05-04 15:36:36 +01:00
|
|
|
|
2024-12-06 13:34:44 +00:00
|
|
|
from flask import redirect, Blueprint
|
2022-05-16 11:44:03 +01:00
|
|
|
from flask.typing import ResponseReturnValue
|
2022-05-04 15:36:36 +01:00
|
|
|
|
|
|
|
from app.models.onions import Onion
|
|
|
|
from app.portal.util import response_404, view_lifecycle
|
|
|
|
|
|
|
|
bp = Blueprint("onion", __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/new", methods=['GET', 'POST'])
|
|
|
|
@bp.route("/new/<group_id>", methods=['GET', 'POST'])
|
2022-05-16 11:44:03 +01:00
|
|
|
def onion_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
2024-12-02 00:00:05 +00:00
|
|
|
return redirect("/ui/web/onions/new")
|
2022-05-04 15:36:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/edit/<onion_id>', methods=['GET', 'POST'])
|
2022-05-16 11:44:03 +01:00
|
|
|
def onion_edit(onion_id: int) -> ResponseReturnValue:
|
2024-12-06 13:34:44 +00:00
|
|
|
return redirect("/ui/web/onions/edit/{}".format(onion_id))
|
2022-05-04 15:36:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/list")
|
2022-05-16 11:44:03 +01:00
|
|
|
def onion_list() -> ResponseReturnValue:
|
2024-12-02 00:00:05 +00:00
|
|
|
return redirect("/ui/web/onions")
|
2022-05-04 15:36:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/destroy/<onion_id>", methods=['GET', 'POST'])
|
2024-12-02 00:00:05 +00:00
|
|
|
def onion_destroy(onion_id: str) -> ResponseReturnValue:
|
|
|
|
onion = Onion.query.filter(Onion.id == int(onion_id), Onion.destroyed.is_(None)).first()
|
2022-05-04 15:36:36 +01:00
|
|
|
if onion is None:
|
|
|
|
return response_404("The requested onion service could not be found.")
|
|
|
|
return view_lifecycle(
|
|
|
|
header=f"Destroy onion service {onion.onion_name}",
|
|
|
|
message=onion.description,
|
2022-11-09 15:16:39 +00:00
|
|
|
success_message="Successfully removed onion service.",
|
2022-05-04 15:36:36 +01:00
|
|
|
success_view="portal.onion.onion_list",
|
|
|
|
section="onion",
|
|
|
|
resource=onion,
|
|
|
|
action="destroy"
|
|
|
|
)
|