diff --git a/actions/xmpp b/actions/xmpp index b55961f10..9cf6709c7 100755 --- a/actions/xmpp +++ b/actions/xmpp @@ -42,16 +42,15 @@ def parse_arguments(): # Prepare ejabberd for hostname change pre_hostname_change = subparsers.add_parser( 'pre-change-hostname', - help='Prepare ejabberd for hostname change') + help='Prepare ejabberd for nodename change') pre_hostname_change.add_argument('--old-hostname', help='Previous hostname') pre_hostname_change.add_argument('--new-hostname', help='New hostname') - # Update ejabberd and jwchat with new hostname - hostname_change = subparsers.add_parser( - 'change-hostname', - help='Update ejabberd and jwchat with new hostname') + # Update ejabberd nodename + hostname_change = subparsers.add_parser('change-hostname', + help='Update ejabberd nodename') hostname_change.add_argument('--old-hostname', help='Previous hostname') hostname_change.add_argument('--new-hostname', @@ -63,16 +62,18 @@ def parse_arguments(): help='Update ejabberd and jwchat with new domainname') domainname_change.add_argument('--domainname', help='New domainname') - # Get the current server name used by jwchat - subparsers.add_parser('get-server', help='Get server name') + # Get the list of all virtual hosts configured in ejabberd + subparsers.add_parser( + 'get-vhosts', + help='Get the list of all virtual hosts configured in ejabberd') # Register a new user account register = subparsers.add_parser('register', help='Register a new user account') register.add_argument('--username', help='Username for the new user account') - register.add_argument('--server', - help='Virtual host for the new user account') + register.add_argument('--vhost', + help='Virtual host to register the new user in') register.add_argument('--password', help='Password for the new user account') @@ -123,10 +124,10 @@ def subcommand_change_hostname(arguments): def subcommand_change_domainname(arguments): """Update ejabberd and jwchat with new domainname""" - server = arguments.domainname.strip("'") - if not server: + domainname = arguments.domainname.strip("'") + if not domainname: # If new domainname is blank, use hostname instead. - server = socket.gethostname() + domainname = socket.gethostname() # update jwchat's sitename, if it's installed if os.path.exists(JWCHAT_CONFIG): @@ -135,7 +136,7 @@ def subcommand_change_domainname(arguments): with open(JWCHAT_CONFIG, 'w') as conffile: for line in lines: if re.match(r'\s*var\s+SITENAME', line): - conffile.write('var SITENAME = "' + server + '";\n') + conffile.write('var SITENAME = "' + domainname + '";\n') else: conffile.write(line) else: @@ -144,8 +145,8 @@ def subcommand_change_domainname(arguments): # Check if new domainname is already in ejabberd hosts list. conffile = open(EJABBERD_CONFIG, 'r') - conf = yaml.load(conffile) - if server in conf['hosts']: + conf = yaml.safe_load(conffile) + if domainname in conf['hosts']: return subprocess.call(['service', 'ejabberd', 'stop']) @@ -158,31 +159,25 @@ def subcommand_change_domainname(arguments): for line in lines: conffile.write(line) if re.match(r'\s*hosts:', line): - conffile.write(' - "' + server + '"\n') + conffile.write(' - "' + domainname + '"\n') subprocess.call(['service', 'ejabberd', 'start']) -def subcommand_get_server(_): - """Get the current server name used by jwchat""" - if os.path.exists(JWCHAT_CONFIG): - with open(JWCHAT_CONFIG, 'r') as conffile: - lines = conffile.readlines() - for line in lines: - if re.match(r'\s*var\s+SITENAME', line): - print(line.split('"')[1]) - return +def subcommand_get_vhosts(_): + """Get list of all virtual hosts configured in ejabbered.""" + subprocess.call(['ejabberdctl', 'registered_vhosts']) def subcommand_register(arguments): - """Register a new user account""" + """Register a new user account.""" username = arguments.username - server = arguments.server + vhost = arguments.vhost password = arguments.password try: output = subprocess.check_output(['ejabberdctl', 'register', - username, server, password]) + username, vhost, password]) print(output.decode()) except subprocess.CalledProcessError as e: print('Failed to register XMPP account:', e.output.decode()) diff --git a/plinth/modules/xmpp/templates/xmpp_register.html b/plinth/modules/xmpp/templates/xmpp_register.html index 0052fe3be..7bad2de5e 100644 --- a/plinth/modules/xmpp/templates/xmpp_register.html +++ b/plinth/modules/xmpp/templates/xmpp_register.html @@ -27,12 +27,7 @@