mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
email: Address some code review comments
- __init__.py: Changed email server description - audit module: Added module docstring - email_server action: - Used argparse - Replaced "wrapper functions" with a getattr based lookup method
This commit is contained in:
parent
81c9632f5a
commit
758c8791f1
@ -1,12 +1,11 @@
|
||||
#!/usr/bin/python3
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import plinth.modules.email_server.audit as audit
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
EXIT_SYNTAX = 10
|
||||
@ -23,23 +22,29 @@ def reserved_for_root(fun):
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit(EXIT_SYNTAX)
|
||||
if sys.argv[1] != 'ipc':
|
||||
sys.exit(EXIT_SYNTAX)
|
||||
|
||||
function_name = 'ipc_' + sys.argv[2]
|
||||
globals()[function_name]()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('ipc', nargs=3)
|
||||
arguments = parser.parse_args()
|
||||
subcommand_ipc(arguments)
|
||||
|
||||
|
||||
@reserved_for_root
|
||||
def ipc_set_sasl():
|
||||
audit.ldap.action_set_sasl()
|
||||
def subcommand_ipc(arguments):
|
||||
import plinth.modules.email_server.audit as audit
|
||||
|
||||
_, module_name, action_name = arguments.ipc
|
||||
# We only run actions defined in the audit module
|
||||
if module_name not in audit.__all__:
|
||||
logger.critical('Bad module name: %r', module_name)
|
||||
sys.exit(EXIT_SYNTAX)
|
||||
|
||||
@reserved_for_root
|
||||
def ipc_set_submission():
|
||||
audit.ldap.action_set_submission()
|
||||
module = getattr(audit, module_name)
|
||||
function = getattr(module, 'action_' + action_name, None)
|
||||
if function is None:
|
||||
logger.critical('Bad action: %s/%r', module_name, action_name)
|
||||
sys.exit(EXIT_SYNTAX)
|
||||
|
||||
function()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -33,7 +33,7 @@ class EmailServerApp(plinth.app.App):
|
||||
app_id=self.app_id,
|
||||
version=version,
|
||||
name=_('Email Server'),
|
||||
short_description=_('An email server for FreedomBox'),
|
||||
short_description=_('Powered by Postfix, Dovecot & Rspamd'),
|
||||
manual_page='EmailServer',
|
||||
clients=manifest.clients,
|
||||
donation_url='https://freedomboxfoundation.org/donate/'
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Provides diagnosis and repair of email server configuration issues
|
||||
"""
|
||||
|
||||
from . import ldap
|
||||
from . import domain
|
||||
|
||||
|
||||
@ -64,13 +64,11 @@ def repair():
|
||||
POST /audit/ldap/repair
|
||||
"""
|
||||
logger.debug('Updating postconf: %r', default_config)
|
||||
actions.superuser_run('email_server', ['ipc', 'set_sasl'])
|
||||
actions.superuser_run('email_server', ['ipc', 'ldap', 'set_sasl'])
|
||||
|
||||
logger.debug('Setting up postfix %s service in master.cf: %r',
|
||||
submission_flags.service, default_submission_options)
|
||||
logger.debug('And postfix %s service: %r', smtps_flags.service,
|
||||
default_smtps_options)
|
||||
actions.superuser_run('email_server', ['ipc', 'set_submission'])
|
||||
logger.debug('Setting up postfix services:\n %r\n %r',
|
||||
default_submission_options, default_smtps_options)
|
||||
actions.superuser_run('email_server', ['ipc', 'ldap', 'set_submission'])
|
||||
|
||||
|
||||
def action_set_sasl():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user