onion: remove onion key column, prod forms
This commit is contained in:
parent
890ce3077f
commit
e1394f71d6
4 changed files with 68 additions and 20 deletions
|
@ -4,9 +4,10 @@ from typing import Optional
|
|||
from flask import flash, redirect, url_for, render_template, Response, Blueprint
|
||||
from flask.typing import ResponseReturnValue
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileAllowed, FileRequired
|
||||
from flask_wtf.file import FileRequired
|
||||
from sqlalchemy import exc
|
||||
from wtforms import StringField, SelectField, SubmitField, FileField
|
||||
from wtforms import StringField, SelectField, SubmitField
|
||||
from flask_wtf.file import FileField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
from app.extensions import db
|
||||
|
@ -19,8 +20,6 @@ bp = Blueprint("onion", __name__)
|
|||
|
||||
class NewOnionForm(FlaskForm): # type: ignore
|
||||
domain_name = StringField('Domain Name', validators=[DataRequired()])
|
||||
# onion_name = StringField('Onion Name', validators=[DataRequired(), Length(min=56, max=56)],
|
||||
# description="Onion service hostname, excluding the .onion suffix")
|
||||
description = StringField('Description', validators=[DataRequired()])
|
||||
onion_private_key = FileField('Onion Private Key', validators=[FileRequired()])
|
||||
onion_public_key = FileField('Onion Public Key',
|
||||
|
@ -37,9 +36,6 @@ class NewOnionForm(FlaskForm): # type: ignore
|
|||
class EditOnionForm(FlaskForm): # type: ignore
|
||||
description = StringField('Description', validators=[DataRequired()])
|
||||
group = SelectField('Group', validators=[DataRequired()])
|
||||
onion_private_key = FileField('Onion Private Key')
|
||||
onion_public_key = FileField('Onion Public Key',
|
||||
description="The onion hostname will be automatically calculated from the public key.")
|
||||
tls_private_key = FileField('TLS Private Key (PEM format)',
|
||||
description="If no file is submitted, the TLS key will remain unchanged.")
|
||||
tls_public_key = FileField('TLS Certificate (PEM format)',
|
||||
|
@ -56,17 +52,16 @@ def onion_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
|||
onion = Onion()
|
||||
onion.group_id = form.group.data
|
||||
onion.domain_name = form.domain_name.data
|
||||
# onion.onion_name = form.onion_name.data
|
||||
for at in [
|
||||
"onion_private_key",
|
||||
"onion_public_key",
|
||||
"tls_private_key",
|
||||
"tls_public_key"
|
||||
]:
|
||||
print(f"testing {at}")
|
||||
if form.__getattribute__(at).data is not None:
|
||||
print(f"Setting {at}")
|
||||
onion.__setattr__(at, form.__getattribute__(at).data.read())
|
||||
if form.__getattribute__(at).data is None:
|
||||
flash(f"Failed to create new onion. {at} was not provided.", "danger")
|
||||
return redirect(url_for("portal.onion.onion_list"))
|
||||
onion.__setattr__(at, form.__getattribute__(at).data.read())
|
||||
onion.description = form.description.data
|
||||
onion.created = datetime.utcnow()
|
||||
onion.updated = datetime.utcnow()
|
||||
|
@ -99,14 +94,10 @@ def onion_edit(onion_id: int) -> ResponseReturnValue:
|
|||
onion.group_id = form.group.data
|
||||
onion.description = form.description.data
|
||||
for at in [
|
||||
"onion_private_key",
|
||||
"onion_public_key",
|
||||
"tls_private_key",
|
||||
"tls_public_key"
|
||||
]:
|
||||
print(f"testing {at}")
|
||||
if form.__getattribute__(at).data is not None:
|
||||
print(f"Setting {at}")
|
||||
onion.__setattr__(at, form.__getattribute__(at).data.read())
|
||||
onion.updated = datetime.utcnow()
|
||||
try:
|
||||
|
@ -138,7 +129,7 @@ def onion_destroy(onion_id: int) -> ResponseReturnValue:
|
|||
return view_lifecycle(
|
||||
header=f"Destroy onion service {onion.onion_name}",
|
||||
message=onion.description,
|
||||
success_message="You will need to manually remove this from the EOTK configuration.",
|
||||
success_message="Successfully removed onion service.",
|
||||
success_view="portal.onion.onion_list",
|
||||
section="onion",
|
||||
resource=onion,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue