mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
email: Simplify setting up postfix
- Reduce complexity by removing the diagnosis approach. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
bbd0b629f3
commit
c8d1f614da
@ -147,12 +147,6 @@ class EmailApp(plinth.app.App):
|
|||||||
domain_added.connect(on_domain_added)
|
domain_added.connect(on_domain_added)
|
||||||
domain_removed.connect(on_domain_removed)
|
domain_removed.connect(on_domain_removed)
|
||||||
|
|
||||||
def diagnose(self):
|
|
||||||
"""Run diagnostics and return the results"""
|
|
||||||
results = super().diagnose()
|
|
||||||
results.extend([r.summarize() for r in audit.ldap.get()])
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def get_domains():
|
def get_domains():
|
||||||
"""Return the list of domains configured."""
|
"""Return the list of domains configured."""
|
||||||
|
|||||||
@ -2,16 +2,10 @@
|
|||||||
configurations"""
|
configurations"""
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
import plinth.modules.email.aliases as aliases
|
import plinth.modules.email.aliases as aliases
|
||||||
import plinth.modules.email.postconf as postconf
|
import plinth.modules.email.postconf as postconf
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
|
||||||
from . import models
|
|
||||||
|
|
||||||
default_config = {
|
default_config = {
|
||||||
'smtpd_sasl_auth_enable':
|
'smtpd_sasl_auth_enable':
|
||||||
'yes',
|
'yes',
|
||||||
@ -55,91 +49,31 @@ default_smtps_options = {
|
|||||||
|
|
||||||
SQLITE_ALIASES = 'sqlite:/etc/postfix/freedombox-aliases.cf'
|
SQLITE_ALIASES = 'sqlite:/etc/postfix/freedombox-aliases.cf'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get():
|
|
||||||
"""Compare current values with the default. Generate an audit report
|
|
||||||
|
|
||||||
Recommended endpoint name:
|
|
||||||
GET /audit/ldap
|
|
||||||
"""
|
|
||||||
translation_table = [
|
|
||||||
(check_sasl, _('Postfix-Dovecot SASL integration')),
|
|
||||||
(check_alias_maps, _('Postfix alias maps')),
|
|
||||||
]
|
|
||||||
results = []
|
|
||||||
with postconf.mutex.lock_all():
|
|
||||||
for check, title in translation_table:
|
|
||||||
results.append(check(title))
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def repair():
|
def repair():
|
||||||
"""Tries to repair SASL, mail submission, and user lookup settings
|
"""Tries to repair SASL, mail submission, and user lookup settings."""
|
||||||
|
|
||||||
Recommended endpoint name:
|
|
||||||
POST /audit/ldap/repair
|
|
||||||
"""
|
|
||||||
aliases.first_setup()
|
aliases.first_setup()
|
||||||
actions.superuser_run('email', ['ldap', 'set_up'])
|
actions.superuser_run('email', ['ldap', 'setup'])
|
||||||
|
|
||||||
|
|
||||||
def action_set_up():
|
def action_setup():
|
||||||
action_set_sasl()
|
postconf.set_many_unsafe(default_config)
|
||||||
action_set_submission()
|
_setup_submission()
|
||||||
action_set_ulookup()
|
_setup_alias_maps()
|
||||||
|
|
||||||
|
|
||||||
def check_sasl(title=''):
|
def _setup_submission():
|
||||||
diagnosis = models.MainCfDiagnosis(title)
|
"""Update configuration for smtps and smtp-submission."""
|
||||||
diagnosis.compare(default_config, postconf.get_many_unsafe)
|
|
||||||
return diagnosis
|
|
||||||
|
|
||||||
|
|
||||||
def fix_sasl(diagnosis):
|
|
||||||
diagnosis.apply_changes(postconf.set_many_unsafe)
|
|
||||||
|
|
||||||
|
|
||||||
def action_set_sasl():
|
|
||||||
"""Handles email -i ldap set_sasl"""
|
|
||||||
with postconf.mutex.lock_all():
|
|
||||||
fix_sasl(check_sasl())
|
|
||||||
|
|
||||||
|
|
||||||
def action_set_submission():
|
|
||||||
"""Handles email -i ldap set_submission"""
|
|
||||||
postconf.set_master_cf_options(service_flags=submission_flags,
|
postconf.set_master_cf_options(service_flags=submission_flags,
|
||||||
options=default_submission_options)
|
options=default_submission_options)
|
||||||
postconf.set_master_cf_options(service_flags=smtps_flags,
|
postconf.set_master_cf_options(service_flags=smtps_flags,
|
||||||
options=default_smtps_options)
|
options=default_smtps_options)
|
||||||
|
|
||||||
|
|
||||||
def check_alias_maps(title=''):
|
def _setup_alias_maps():
|
||||||
"""Check the ability to mail to usernames and user aliases"""
|
"""Setup alias maps to include an sqlite DB."""
|
||||||
diagnosis = models.MainCfDiagnosis(title)
|
|
||||||
|
|
||||||
alias_maps = postconf.get_unsafe('alias_maps').replace(',', ' ').split(' ')
|
alias_maps = postconf.get_unsafe('alias_maps').replace(',', ' ').split(' ')
|
||||||
if SQLITE_ALIASES not in alias_maps:
|
if SQLITE_ALIASES not in alias_maps:
|
||||||
diagnosis.flag_once('alias_maps', user=alias_maps)
|
alias_maps.append(SQLITE_ALIASES)
|
||||||
diagnosis.critical('Required maps not in list')
|
|
||||||
|
|
||||||
return diagnosis
|
postconf.set_many_unsafe({'alias_maps': ' '.join(alias_maps)})
|
||||||
|
|
||||||
|
|
||||||
def fix_alias_maps(diagnosis):
|
|
||||||
|
|
||||||
def fix_value(alias_maps):
|
|
||||||
if SQLITE_ALIASES not in alias_maps:
|
|
||||||
alias_maps.append(SQLITE_ALIASES)
|
|
||||||
|
|
||||||
return ' '.join(alias_maps)
|
|
||||||
|
|
||||||
diagnosis.repair('alias_maps', fix_value)
|
|
||||||
diagnosis.apply_changes(postconf.set_many_unsafe)
|
|
||||||
|
|
||||||
|
|
||||||
def action_set_ulookup():
|
|
||||||
"""Handles email -i ldap set_ulookup"""
|
|
||||||
with postconf.mutex.lock_all():
|
|
||||||
fix_alias_maps(check_alias_maps())
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user