From 38507b2e1be890f2d7603b5401d245f64613bfed Mon Sep 17 00:00:00 2001 From: Florent Daigniere Date: Sun, 20 Nov 2022 10:19:28 +0100 Subject: [PATCH] Close #2372: Implement a GUI for WILDCARD_SENDERS --- core/admin/mailu/internal/views/postfix.py | 3 ++- core/admin/mailu/models.py | 1 + core/admin/mailu/ui/forms.py | 1 + .../admin/mailu/ui/templates/user/create.html | 1 + .../migrations/versions/7ac252f2bbbf_.py | 22 +++++++++++++++++++ docs/webadministration.rst | 4 +++- towncrier/newsfragments/2372.feature | 1 + 7 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 core/admin/migrations/versions/7ac252f2bbbf_.py create mode 100644 towncrier/newsfragments/2372.feature diff --git a/core/admin/mailu/internal/views/postfix.py b/core/admin/mailu/internal/views/postfix.py index 8188270c..c0a17319 100644 --- a/core/admin/mailu/internal/views/postfix.py +++ b/core/admin/mailu/internal/views/postfix.py @@ -145,8 +145,9 @@ def postfix_sender_login(sender): localpart = localpart[:next((i for i, ch in enumerate(localpart) if ch in flask.current_app.config.get('RECIPIENT_DELIMITER')), None)] destinations = models.Email.resolve_destination(localpart, domain_name, True) or [] destinations.extend(wildcard_senders) + destinations.extend(i[0] for i in models.User.query.filter_by(allow_spoofing=True).with_entities(models.User.email).all()) if destinations: - return flask.jsonify(",".join(idna_encode(destinations))) + return flask.jsonify(",".join(idna_encode(list(set(destinations))))) return flask.abort(404) @internal.route("/postfix/sender/rate/") diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 48ce8b33..1c57c8be 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -501,6 +501,7 @@ class User(Base, Email): # Features enable_imap = db.Column(db.Boolean, nullable=False, default=True) enable_pop = db.Column(db.Boolean, nullable=False, default=True) + allow_spoofing = db.Column(db.Boolean, nullable=False, default=False) # Filters forward_enabled = db.Column(db.Boolean, nullable=False, default=False) diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index beb44092..3882064d 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -84,6 +84,7 @@ class UserForm(flask_wtf.FlaskForm): quota_bytes = fields_.IntegerSliderField(_('Quota'), default=10**9) enable_imap = fields.BooleanField(_('Allow IMAP access'), default=True) enable_pop = fields.BooleanField(_('Allow POP3 access'), default=True) + allow_spoofing = fields.BooleanField(_('Allow the user to spoof the sender (send email as anyone)'), default=False) displayed_name = fields.StringField(_('Displayed name')) comment = fields.StringField(_('Comment')) enabled = fields.BooleanField(_('Enabled'), default=True) diff --git a/core/admin/mailu/ui/templates/user/create.html b/core/admin/mailu/ui/templates/user/create.html index 9a32243d..7e1c9122 100644 --- a/core/admin/mailu/ui/templates/user/create.html +++ b/core/admin/mailu/ui/templates/user/create.html @@ -25,6 +25,7 @@ prepend=' GB') }} {{ macros.form_field(form.enable_imap) }} {{ macros.form_field(form.enable_pop) }} + {{ macros.form_field(form.allow_spoofing) }} {%- endcall %} {{ macros.form_field(form.submit) }} diff --git a/core/admin/migrations/versions/7ac252f2bbbf_.py b/core/admin/migrations/versions/7ac252f2bbbf_.py new file mode 100644 index 00000000..0be19d88 --- /dev/null +++ b/core/admin/migrations/versions/7ac252f2bbbf_.py @@ -0,0 +1,22 @@ +"""empty message + +Revision ID: 7ac252f2bbbf +Revises: 8f9ea78776f4 +Create Date: 2022-11-20 08:57:16.879152 + +""" + +# revision identifiers, used by Alembic. +revision = '7ac252f2bbbf' +down_revision = '8f9ea78776f4' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('allow_spoofing', sa.Boolean(), nullable=False)) + + +def downgrade(): + op.drop_column('user', 'allow_spoofing') diff --git a/docs/webadministration.rst b/docs/webadministration.rst index e17d12f0..2e0de745 100644 --- a/docs/webadministration.rst +++ b/docs/webadministration.rst @@ -321,7 +321,7 @@ This page also shows an overview of the following settings of an user: * Email. The email address of the user. -* Features. Shows if IMAP or POP3 access is enabled. +* Features. Shows if IMAP or POP3 access is enabled and whether the user should be allowed to spoof emails. * Storage quota. Shows how much assigned storage has been consumed. @@ -357,6 +357,8 @@ For adding a new user the following options can be configured. * Allow POP3 access. When ticked, allows email retrieval via the POP3 protocol. +* Allow the user to spoof the sender. When ticked, allows the user to send email as anyone. + Aliases ``````` diff --git a/towncrier/newsfragments/2372.feature b/towncrier/newsfragments/2372.feature new file mode 100644 index 00000000..ec2c5bef --- /dev/null +++ b/towncrier/newsfragments/2372.feature @@ -0,0 +1 @@ +Create a GUI for WILDCARD_SENDERS