From fafd28e90ad97ce0f4d7891ba89949122ecf4dbb Mon Sep 17 00:00:00 2001 From: Hemanth Kumar Veeranki Date: Tue, 31 Jul 2018 09:20:39 +0530 Subject: [PATCH] Remove deprecated settings from already existing config files Signed-off-by: Hemanth Kumar Veeranki Reviewed-by: James Valleroy --- actions/ejabberd | 42 +++++++++++++++++++++++++++-- plinth/modules/ejabberd/__init__.py | 3 ++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/actions/ejabberd b/actions/ejabberd index c9a8692e7..8a0ae8291 100755 --- a/actions/ejabberd +++ b/actions/ejabberd @@ -28,6 +28,7 @@ import stat import subprocess import sys import ruamel.yaml +from distutils.version import LooseVersion as LV from plinth import action_utils from plinth.modules import config @@ -38,6 +39,8 @@ EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml' EJABBERD_BACKUP = '/var/log/ejabberd/ejabberd.dump' EJABBERD_BACKUP_NEW = '/var/log/ejabberd/ejabberd_new.dump' EJABBERD_ORIG_CERT = '/etc/ejabberd/ejabberd.pem' +IQDISC_DEPRECATED_VERSION = LV('18.03') +MOD_IRC_DEPRECATED_VERSION = LV('18.06') def parse_arguments(): @@ -94,6 +97,8 @@ def parse_arguments(): letsencrypt.add_argument('command', choices=('add', 'drop'), help=help_LE) letsencrypt.add_argument('--domain', help='Domain name to drop.') + subparsers.add_parser('fix-config', help='Fix the deprecated config files') + subparsers.required = True return parser.parse_args() @@ -289,7 +294,7 @@ def subcommand_letsencrypt(arguments): sys.exit(1) if arguments.command == 'add' and arguments.domain is not None \ - and arguments.domain != current_domain: + and arguments.domain != current_domain: print('Aborted: Only certificate of current domain "%s" can be added.' % current_domain) sys.exit(2) @@ -339,7 +344,7 @@ def subcommand_letsencrypt(arguments): for listen_port in conf['listen']: if 'certfile' in listen_port \ - and listen_port['certfile'] == cert_file: + and listen_port['certfile'] == cert_file: listen_port['certfile'] = orig_cert_file if conf['s2s_certfile'] == cert_file: @@ -355,6 +360,39 @@ def subcommand_letsencrypt(arguments): action_utils.service_restart('ejabberd') +def subcommand_fix_config(_): + """ Fix the config file by removing deprecated settings""" + current_version = _get_version() + if not current_version: + print('Unable to get the version. Check if ejabberd is installed') + return + + with open(EJABBERD_CONFIG, 'r') as file_handle: + conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True) + + # Check if `iqdisc` is present and remove it + if 'mod_mam' in conf['modules'] and current_version > IQDISC_DEPRECATED_VERSION: + conf['modules']['mod_mam'].pop('iqdisc', None) + + # check if mod_irc is present in modules and remove it + if 'mod_irc' in conf['modules'] and current_version > MOD_IRC_DEPRECATED_VERSION: + conf['modules'].pop('mod_irc') + + # Write changes back to the file + with open(EJABBERD_CONFIG, 'w') as file_handle: + ruamel.yaml.round_trip_dump(conf, file_handle) + + +def _get_version(): + """ Get the current ejabberd version """ + output = subprocess.check_output(['ejabberdctl', 'status']).decode('utf-8') + version_info = output.strip().split('\n')[-1].split() + if version_info: + version = str(version_info[1]) + return LV(version) + return None + + def main(): """Parse arguments and perform all duties""" arguments = parse_arguments() diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 3cf06c474..f7d69b7d6 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -33,7 +33,7 @@ from plinth.utils import format_lazy from .manifest import backup, clients -version = 1 +version = 2 managed_services = ['ejabberd'] @@ -97,6 +97,7 @@ def setup(helper, old_version=None): ['pre-install', '--domainname', domainname]) helper.install(managed_packages) helper.call('post', actions.superuser_run, 'ejabberd', ['setup']) + actions.superuser_run('ejabberd', ['fix-config']) global service if service is None: service = service_module.Service(