diff --git a/INSTALL b/INSTALL index 14b9dd327..45f30f9f2 100644 --- a/INSTALL +++ b/INSTALL @@ -7,7 +7,7 @@ $ sudo apt-get install libjs-jquery libjs-modernizr \ libjs-bootstrap make pandoc python3 python3-cherrypy3 \ python3-coverage python3-django python3-bootstrapform \ - python3-gi python3-setuptools gir1.2-packagekitglib-1.0 + python3-gi python3-setuptools python3-yaml gir1.2-packagekitglib-1.0 2. Install Plinth: diff --git a/actions/xmpp b/actions/xmpp index 115fe375c..b55961f10 100755 --- a/actions/xmpp +++ b/actions/xmpp @@ -26,6 +26,7 @@ import subprocess import os import socket import re +import yaml JWCHAT_CONFIG = '/etc/jwchat/config.js' EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml' @@ -62,11 +63,16 @@ 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') + # 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('--password', help='Password for the new user account') @@ -117,8 +123,10 @@ def subcommand_change_hostname(arguments): def subcommand_change_domainname(arguments): """Update ejabberd and jwchat with new domainname""" - domainname = arguments.domainname - fqdn = socket.gethostname() + '.' + domainname + server = arguments.domainname.strip("'") + if not server: + # If new domainname is blank, use hostname instead. + server = socket.gethostname() # update jwchat's sitename, if it's installed if os.path.exists(JWCHAT_CONFIG): @@ -127,37 +135,54 @@ 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 = "' + fqdn + '";\n') + conffile.write('var SITENAME = "' + server + '";\n') else: conffile.write(line) else: print('Skipping configuring jwchat sitename: %s not found', JWCHAT_CONFIG) + # Check if new domainname is already in ejabberd hosts list. + conffile = open(EJABBERD_CONFIG, 'r') + conf = yaml.load(conffile) + if server in conf['hosts']: + return + subprocess.call(['service', 'ejabberd', 'stop']) subprocess.call(['pkill', '-u', 'ejabberd']) - # add updated FQDN to top of ejabberd hosts list + # Add updated domainname to ejabberd hosts list. with open(EJABBERD_CONFIG, 'r') as conffile: lines = conffile.readlines() with open(EJABBERD_CONFIG, 'w') as conffile: for line in lines: conffile.write(line) if re.match(r'\s*hosts:', line): - conffile.write(' - "' + fqdn + '"\n') + conffile.write(' - "' + server + '"\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_register(arguments): """Register a new user account""" username = arguments.username + server = arguments.server password = arguments.password - fqdn = socket.getfqdn() try: output = subprocess.check_output(['ejabberdctl', 'register', - username, fqdn, password]) + username, server, 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 7bad2de5e..0052fe3be 100644 --- a/plinth/modules/xmpp/templates/xmpp_register.html +++ b/plinth/modules/xmpp/templates/xmpp_register.html @@ -27,7 +27,12 @@
- {{ form|bootstrap }} + + @{{ server }} + + {% include 'bootstrapform/field.html' with field=form.username %} + {% include 'bootstrapform/field.html' with field=form.password %}
diff --git a/plinth/modules/xmpp/xmpp.py b/plinth/modules/xmpp/xmpp.py index 125ea3448..d44226fb0 100644 --- a/plinth/modules/xmpp/xmpp.py +++ b/plinth/modules/xmpp/xmpp.py @@ -136,7 +136,6 @@ def _apply_changes(request, old_status, new_status): class RegisterForm(forms.Form): # pylint: disable-msg=W0232 """Configuration form""" username = forms.CharField(label=_('Username')) - password = forms.CharField( label=_('Password'), widget=forms.PasswordInput()) @@ -145,12 +144,13 @@ class RegisterForm(forms.Form): # pylint: disable-msg=W0232 def register(request): """Serve the registration form""" form = None + server = actions.run('xmpp', ['get-server']).strip() if request.method == 'POST': form = RegisterForm(request.POST, prefix='xmpp') # pylint: disable-msg=E1101 if form.is_valid(): - _register_user(request, form.cleaned_data) + _register_user(request, form.cleaned_data, server) form = RegisterForm(prefix='xmpp') else: form = RegisterForm(prefix='xmpp') @@ -158,15 +158,17 @@ def register(request): return TemplateResponse(request, 'xmpp_register.html', {'title': _('Register XMPP Account'), 'form': form, - 'subsubmenu': subsubmenu}) + 'subsubmenu': subsubmenu, + 'server': server}) -def _register_user(request, data): +def _register_user(request, data, server): """Register a new XMPP user""" output = actions.superuser_run( 'xmpp', ['register', '--username', data['username'], + '--server', server, '--password', data['password']]) if 'successfully registered' in output: