mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-17 11:10:23 +00:00
- __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
52 lines
1.2 KiB
Python
Executable File
52 lines
1.2 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
EXIT_SYNTAX = 10
|
|
EXIT_PERM = 20
|
|
|
|
|
|
def reserved_for_root(fun):
|
|
def wrapped(*args, **kwargs):
|
|
if os.getuid() != 0:
|
|
logger.critical('This action is reserved for root')
|
|
sys.exit(EXIT_PERM)
|
|
return fun(*args, **kwargs)
|
|
return wrapped
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('ipc', nargs=3)
|
|
arguments = parser.parse_args()
|
|
subcommand_ipc(arguments)
|
|
|
|
|
|
@reserved_for_root
|
|
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)
|
|
|
|
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__':
|
|
main()
|