Sunil Mohan Adapa 8a53957b1e
email: Simplify and rename postfix configuration module
- Remove unnecessary complex crash handler needed due to setting the service
configuration in two steps. Merge the two step into one after which crash
handler is not needed.

- Drop '_unsafe' API and verify all keys and values for sanity.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-03-02 07:38:33 -05:00

80 lines
2.5 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Configure postfix to use auth and local delivery with dovecot. Start smtps and
submission services. Setup aliases database.
"""
from plinth import actions
from .. import aliases, postfix
default_config = {
'smtpd_sasl_auth_enable':
'yes',
'smtpd_sasl_type':
'dovecot',
'smtpd_sasl_path':
'private/auth',
'mailbox_transport':
'lmtp:unix:private/dovecot-lmtp',
'virtual_transport':
'lmtp:unix:private/dovecot-lmtp',
'smtpd_relay_restrictions':
','.join([
'permit_sasl_authenticated',
'defer_unauth_destination',
])
}
submission_options = {
'syslog_name': 'postfix/submission',
'smtpd_tls_security_level': 'encrypt',
'smtpd_client_restrictions': 'permit_sasl_authenticated,reject',
'smtpd_relay_restrictions': 'permit_sasl_authenticated,reject'
}
submission_service = postfix.Service(service='submission', type_='inet',
private='n', unpriv='-', chroot='y',
wakeup='-', maxproc='-', command='smtpd',
options=submission_options)
smtps_options = {
'syslog_name': 'postfix/smtps',
'smtpd_tls_wrappermode': 'yes',
'smtpd_sasl_auth_enable': 'yes',
'smtpd_relay_restrictions': 'permit_sasl_authenticated,reject'
}
smtps_service = postfix.Service(service='smtps', type_='inet', private='n',
unpriv='-', chroot='y', wakeup='-',
maxproc='-', command='smtpd',
options=smtps_options)
SQLITE_ALIASES = 'sqlite:/etc/postfix/freedombox-aliases.cf'
def repair():
"""Tries to repair SASL, mail submission, and user lookup settings."""
aliases.first_setup()
actions.superuser_run('email', ['ldap', 'setup'])
def action_setup():
postfix.set_config(default_config)
_setup_submission()
_setup_alias_maps()
def _setup_submission():
"""Update configuration for smtps and smtp-submission."""
postfix.set_master_config(submission_service)
postfix.set_master_config(smtps_service)
def _setup_alias_maps():
"""Setup alias maps to include an sqlite DB."""
alias_maps = postfix.get_config(['alias_maps'])['alias_maps']
alias_maps = alias_maps.replace(',', ' ').split(' ')
if SQLITE_ALIASES not in alias_maps:
alias_maps.append(SQLITE_ALIASES)
postfix.set_config({'alias_maps': ' '.join(alias_maps)})