diff --git a/actions/ejabberd b/actions/ejabberd index 2e685c824..78f505ff9 100755 --- a/actions/ejabberd +++ b/actions/ejabberd @@ -20,6 +20,7 @@ Configuration helper for the ejabberd service """ import argparse +import json import os import pathlib import shutil @@ -46,6 +47,10 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') + # Get configuration + subparsers.add_parser('get-configuration', + help='Return the current configuration') + # Preseed debconf values before packages are installed. pre_install = subparsers.add_parser( 'pre-install', @@ -93,6 +98,14 @@ def parse_arguments(): return parser.parse_args() +def subcommand_get_configuration(_): + """Return the current configuration, specifically domains configured.""" + with open(EJABBERD_CONFIG, 'r') as file_handle: + conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True) + + print(json.dumps({'domains': conf['hosts']})) + + def subcommand_pre_install(arguments): """Preseed debconf values before packages are installed.""" domainname = arguments.domainname diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index bac011f6e..8c6e0462c 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -18,6 +18,7 @@ FreedomBox app to configure ejabberd server. """ +import json import logging import pathlib @@ -196,8 +197,11 @@ def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs): def on_domain_added(sender, domain_type, name, description='', services=None, **kwargs): """Update ejabberd config after domain name change.""" - actions.superuser_run('ejabberd', ['add-domain', '--domainname', name]) - app.get_component('letsencrypt-ejabberd').setup_certificates() + conf = actions.superuser_run('ejabberd', ['get-configuration']) + conf = json.loads(conf) + if name not in conf['domains']: + actions.superuser_run('ejabberd', ['add-domain', '--domainname', name]) + app.get_component('letsencrypt-ejabberd').setup_certificates() def diagnose():