From 0dba497383777d9b22af94c62747e47b2b91f5b6 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 1 Aug 2019 21:04:04 -0700 Subject: [PATCH] ejabberd: Use domain added signal for listening to domain changes In the action, the new domain is always extended to the list of domain names accepted by ejabberd. To simplify domain handling simply use the domain_added signal. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/ejabberd | 13 +++++-------- plinth/modules/ejabberd/__init__.py | 16 ++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/actions/ejabberd b/actions/ejabberd index aea8b312a..8e7fb4fbe 100755 --- a/actions/ejabberd +++ b/actions/ejabberd @@ -73,10 +73,10 @@ def parse_arguments(): hostname_change.add_argument('--old-hostname', help='Previous hostname') hostname_change.add_argument('--new-hostname', help='New hostname') - # Update ejabberd with new domainname - domainname_change = subparsers.add_parser( - 'change-domainname', help='Update ejabberd with new domainname') - domainname_change.add_argument('--domainname', help='New domainname') + # Add a domain name to ejabberd + add_domain = subparsers.add_parser('add-domain', + help='Add a domain name to ejabberd') + add_domain.add_argument('--domainname', help='New domain name') # Switch/check Message Archive Management (MAM) in ejabberd config help_MAM = 'Switch or check Message Archive Management (MAM).' @@ -219,16 +219,13 @@ def subcommand_change_hostname(arguments): EJABBERD_BACKUP_NEW) -def subcommand_change_domainname(arguments): +def subcommand_add_domain(arguments): """Update ejabberd with new domainname""" if not shutil.which('ejabberdctl'): print('ejabberdctl not found. Is ejabberd installed?') return domainname = arguments.domainname - if not domainname: - # If new domainname is blank, use hostname instead. - domainname = socket.gethostname() # Add updated domainname to ejabberd hosts list. with open(EJABBERD_CONFIG, 'r') as file_handle: diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 0085a8f10..53718072c 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -32,11 +32,11 @@ from plinth.modules import config from plinth.modules.apache.components import Webserver from plinth.modules.firewall.components import Firewall from plinth.modules.letsencrypt.components import LetsEncrypt -from plinth.signals import (domainname_change, post_hostname_change, +from plinth.signals import (domain_added, post_hostname_change, pre_hostname_change) from plinth.utils import format_lazy -from .manifest import backup, clients # noqa, pylint: disable=unused-import +from .manifest import backup, clients # noqa, pylint: disable=unused-import version = 3 @@ -132,7 +132,7 @@ def init(): pre_hostname_change.connect(on_pre_hostname_change) post_hostname_change.connect(on_post_hostname_change) - domainname_change.connect(on_domainname_change) + domain_added.connect(on_domain_added) def setup(helper, old_version=None): @@ -189,14 +189,10 @@ def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs): ], run_in_background=True) -def on_domainname_change(sender, old_domainname, new_domainname, **kwargs): +def on_domain_added(sender, domain_type, name, description='', services=None, + **kwargs): """Update ejabberd config after domain name change.""" - del sender # Unused - del old_domainname # Unused - del kwargs # Unused - - actions.superuser_run( - 'ejabberd', ['change-domainname', '--domainname', new_domainname]) + actions.superuser_run('ejabberd', ['add-domain', '--domainname', name]) app.get_component('letsencrypt-ejabberd').setup_certificates()