mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
Use domainname as ejabberd host.
Only use hostname when domainname is blank.
This commit is contained in:
parent
be838a30c1
commit
dae7abd00f
2
INSTALL
2
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:
|
||||
|
||||
|
||||
39
actions/xmpp
39
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())
|
||||
|
||||
@ -27,7 +27,12 @@
|
||||
|
||||
<div class='row'>
|
||||
<div class='col-sm-4'>
|
||||
{{ form|bootstrap }}
|
||||
<span class="btn btn-default btn-xs pull-right"
|
||||
title="The server where the new XMPP account will be created.">
|
||||
@{{ server }}
|
||||
</span>
|
||||
{% include 'bootstrapform/field.html' with field=form.username %}
|
||||
{% include 'bootstrapform/field.html' with field=form.password %}
|
||||
<input type="submit" class="btn btn-primary" value="Register XMPP Account"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user