mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +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
|
#!/usr/bin/python3
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import plinth.modules.email_server.audit as audit
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
EXIT_SYNTAX = 10
|
EXIT_SYNTAX = 10
|
||||||
@ -23,23 +22,29 @@ def reserved_for_root(fun):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 3:
|
parser = argparse.ArgumentParser()
|
||||||
sys.exit(EXIT_SYNTAX)
|
parser.add_argument('ipc', nargs=3)
|
||||||
if sys.argv[1] != 'ipc':
|
arguments = parser.parse_args()
|
||||||
sys.exit(EXIT_SYNTAX)
|
subcommand_ipc(arguments)
|
||||||
|
|
||||||
function_name = 'ipc_' + sys.argv[2]
|
|
||||||
globals()[function_name]()
|
|
||||||
|
|
||||||
|
|
||||||
@reserved_for_root
|
@reserved_for_root
|
||||||
def ipc_set_sasl():
|
def subcommand_ipc(arguments):
|
||||||
audit.ldap.action_set_sasl()
|
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
|
module = getattr(audit, module_name)
|
||||||
def ipc_set_submission():
|
function = getattr(module, 'action_' + action_name, None)
|
||||||
audit.ldap.action_set_submission()
|
if function is None:
|
||||||
|
logger.critical('Bad action: %s/%r', module_name, action_name)
|
||||||
|
sys.exit(EXIT_SYNTAX)
|
||||||
|
|
||||||
|
function()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class EmailServerApp(plinth.app.App):
|
|||||||
app_id=self.app_id,
|
app_id=self.app_id,
|
||||||
version=version,
|
version=version,
|
||||||
name=_('Email Server'),
|
name=_('Email Server'),
|
||||||
short_description=_('An email server for FreedomBox'),
|
short_description=_('Powered by Postfix, Dovecot & Rspamd'),
|
||||||
manual_page='EmailServer',
|
manual_page='EmailServer',
|
||||||
clients=manifest.clients,
|
clients=manifest.clients,
|
||||||
donation_url='https://freedomboxfoundation.org/donate/'
|
donation_url='https://freedomboxfoundation.org/donate/'
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
"""
|
||||||
|
Provides diagnosis and repair of email server configuration issues
|
||||||
|
"""
|
||||||
|
|
||||||
from . import ldap
|
from . import ldap
|
||||||
from . import domain
|
from . import domain
|
||||||
|
|
||||||
|
|||||||
@ -64,13 +64,11 @@ def repair():
|
|||||||
POST /audit/ldap/repair
|
POST /audit/ldap/repair
|
||||||
"""
|
"""
|
||||||
logger.debug('Updating postconf: %r', default_config)
|
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',
|
logger.debug('Setting up postfix services:\n %r\n %r',
|
||||||
submission_flags.service, default_submission_options)
|
default_submission_options, default_smtps_options)
|
||||||
logger.debug('And postfix %s service: %r', smtps_flags.service,
|
actions.superuser_run('email_server', ['ipc', 'ldap', 'set_submission'])
|
||||||
default_smtps_options)
|
|
||||||
actions.superuser_run('email_server', ['ipc', 'set_submission'])
|
|
||||||
|
|
||||||
|
|
||||||
def action_set_sasl():
|
def action_set_sasl():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user