mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +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_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():
|
||||
"""Return the list of domains configured."""
|
||||
|
||||
@ -2,16 +2,10 @@
|
||||
configurations"""
|
||||
# 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.postconf as postconf
|
||||
from plinth import actions
|
||||
|
||||
from . import models
|
||||
|
||||
default_config = {
|
||||
'smtpd_sasl_auth_enable':
|
||||
'yes',
|
||||
@ -55,91 +49,31 @@ default_smtps_options = {
|
||||
|
||||
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():
|
||||
"""Tries to repair SASL, mail submission, and user lookup settings
|
||||
|
||||
Recommended endpoint name:
|
||||
POST /audit/ldap/repair
|
||||
"""
|
||||
"""Tries to repair SASL, mail submission, and user lookup settings."""
|
||||
aliases.first_setup()
|
||||
actions.superuser_run('email', ['ldap', 'set_up'])
|
||||
actions.superuser_run('email', ['ldap', 'setup'])
|
||||
|
||||
|
||||
def action_set_up():
|
||||
action_set_sasl()
|
||||
action_set_submission()
|
||||
action_set_ulookup()
|
||||
def action_setup():
|
||||
postconf.set_many_unsafe(default_config)
|
||||
_setup_submission()
|
||||
_setup_alias_maps()
|
||||
|
||||
|
||||
def check_sasl(title=''):
|
||||
diagnosis = models.MainCfDiagnosis(title)
|
||||
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"""
|
||||
def _setup_submission():
|
||||
"""Update configuration for smtps and smtp-submission."""
|
||||
postconf.set_master_cf_options(service_flags=submission_flags,
|
||||
options=default_submission_options)
|
||||
postconf.set_master_cf_options(service_flags=smtps_flags,
|
||||
options=default_smtps_options)
|
||||
|
||||
|
||||
def check_alias_maps(title=''):
|
||||
"""Check the ability to mail to usernames and user aliases"""
|
||||
diagnosis = models.MainCfDiagnosis(title)
|
||||
|
||||
def _setup_alias_maps():
|
||||
"""Setup alias maps to include an sqlite DB."""
|
||||
alias_maps = postconf.get_unsafe('alias_maps').replace(',', ' ').split(' ')
|
||||
if SQLITE_ALIASES not in alias_maps:
|
||||
diagnosis.flag_once('alias_maps', user=alias_maps)
|
||||
diagnosis.critical('Required maps not in list')
|
||||
alias_maps.append(SQLITE_ALIASES)
|
||||
|
||||
return diagnosis
|
||||
|
||||
|
||||
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())
|
||||
postconf.set_many_unsafe({'alias_maps': ' '.join(alias_maps)})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user