mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
email: Parse command arguments with a mutually exclusive group
This commit is contained in:
parent
7166e63b02
commit
df14e74972
@ -23,16 +23,22 @@ def reserved_for_root(fun):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('ipc', nargs=3)
|
||||
arguments = parser.parse_args()
|
||||
subcommand_ipc(arguments)
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('-i', nargs=2, dest='ipc')
|
||||
group.add_argument('-t', nargs=1, dest='touch_file')
|
||||
|
||||
adict = vars(parser.parse_args())
|
||||
generator = (kv for kv in adict.items() if kv[1] is not None)
|
||||
subcommand, arguments = next(generator)
|
||||
|
||||
function = globals()['subcommand_' + subcommand]
|
||||
function(*arguments)
|
||||
|
||||
|
||||
@reserved_for_root
|
||||
def subcommand_ipc(arguments):
|
||||
def subcommand_ipc(module_name, action_name):
|
||||
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)
|
||||
@ -47,5 +53,16 @@ def subcommand_ipc(arguments):
|
||||
function()
|
||||
|
||||
|
||||
def subcommand_touch_file(path):
|
||||
import pathlib
|
||||
|
||||
if os.getuid == 0:
|
||||
logger.critical('Do not run as root')
|
||||
sys.exit(EXIT_PERM)
|
||||
|
||||
# mode is influenced by umask
|
||||
pathlib.Path(path).touch(mode=0o660, exist_ok=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@ -64,11 +64,11 @@ def repair():
|
||||
POST /audit/ldap/repair
|
||||
"""
|
||||
logger.debug('Updating postconf: %r', default_config)
|
||||
actions.superuser_run('email_server', ['ipc', 'ldap', 'set_sasl'])
|
||||
actions.superuser_run('email_server', ['-i', 'ldap', 'set_sasl'])
|
||||
|
||||
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'])
|
||||
actions.superuser_run('email_server', ['-i', 'ldap', 'set_submission'])
|
||||
|
||||
|
||||
def action_set_sasl():
|
||||
|
||||
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def repair():
|
||||
logger.debug('Updating postconf: %r', milter_config)
|
||||
actions.superuser_run('email_server', ['ipc', 'spam', 'set_filter'])
|
||||
actions.superuser_run('email_server', ['-i', 'spam', 'set_filter'])
|
||||
|
||||
|
||||
def action_set_filter():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user