mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +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 \
|
$ sudo apt-get install libjs-jquery libjs-modernizr \
|
||||||
libjs-bootstrap make pandoc python3 python3-cherrypy3 \
|
libjs-bootstrap make pandoc python3 python3-cherrypy3 \
|
||||||
python3-coverage python3-django python3-bootstrapform \
|
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:
|
2. Install Plinth:
|
||||||
|
|
||||||
|
|||||||
39
actions/xmpp
39
actions/xmpp
@ -26,6 +26,7 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
|
import yaml
|
||||||
|
|
||||||
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
||||||
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
||||||
@ -62,11 +63,16 @@ def parse_arguments():
|
|||||||
help='Update ejabberd and jwchat with new domainname')
|
help='Update ejabberd and jwchat with new domainname')
|
||||||
domainname_change.add_argument('--domainname', help='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 a new user account
|
||||||
register = subparsers.add_parser('register',
|
register = subparsers.add_parser('register',
|
||||||
help='Register a new user account')
|
help='Register a new user account')
|
||||||
register.add_argument('--username',
|
register.add_argument('--username',
|
||||||
help='Username for the new user account')
|
help='Username for the new user account')
|
||||||
|
register.add_argument('--server',
|
||||||
|
help='Virtual host for the new user account')
|
||||||
register.add_argument('--password',
|
register.add_argument('--password',
|
||||||
help='Password for the new user account')
|
help='Password for the new user account')
|
||||||
|
|
||||||
@ -117,8 +123,10 @@ def subcommand_change_hostname(arguments):
|
|||||||
|
|
||||||
def subcommand_change_domainname(arguments):
|
def subcommand_change_domainname(arguments):
|
||||||
"""Update ejabberd and jwchat with new domainname"""
|
"""Update ejabberd and jwchat with new domainname"""
|
||||||
domainname = arguments.domainname
|
server = arguments.domainname.strip("'")
|
||||||
fqdn = socket.gethostname() + '.' + domainname
|
if not server:
|
||||||
|
# If new domainname is blank, use hostname instead.
|
||||||
|
server = socket.gethostname()
|
||||||
|
|
||||||
# update jwchat's sitename, if it's installed
|
# update jwchat's sitename, if it's installed
|
||||||
if os.path.exists(JWCHAT_CONFIG):
|
if os.path.exists(JWCHAT_CONFIG):
|
||||||
@ -127,37 +135,54 @@ def subcommand_change_domainname(arguments):
|
|||||||
with open(JWCHAT_CONFIG, 'w') as conffile:
|
with open(JWCHAT_CONFIG, 'w') as conffile:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if re.match(r'\s*var\s+SITENAME', line):
|
if re.match(r'\s*var\s+SITENAME', line):
|
||||||
conffile.write('var SITENAME = "' + fqdn + '";\n')
|
conffile.write('var SITENAME = "' + server + '";\n')
|
||||||
else:
|
else:
|
||||||
conffile.write(line)
|
conffile.write(line)
|
||||||
else:
|
else:
|
||||||
print('Skipping configuring jwchat sitename: %s not found',
|
print('Skipping configuring jwchat sitename: %s not found',
|
||||||
JWCHAT_CONFIG)
|
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(['service', 'ejabberd', 'stop'])
|
||||||
subprocess.call(['pkill', '-u', 'ejabberd'])
|
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:
|
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||||
lines = conffile.readlines()
|
lines = conffile.readlines()
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
with open(EJABBERD_CONFIG, 'w') as conffile:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
conffile.write(line)
|
conffile.write(line)
|
||||||
if re.match(r'\s*hosts:', line):
|
if re.match(r'\s*hosts:', line):
|
||||||
conffile.write(' - "' + fqdn + '"\n')
|
conffile.write(' - "' + server + '"\n')
|
||||||
|
|
||||||
subprocess.call(['service', 'ejabberd', 'start'])
|
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):
|
def subcommand_register(arguments):
|
||||||
"""Register a new user account"""
|
"""Register a new user account"""
|
||||||
username = arguments.username
|
username = arguments.username
|
||||||
|
server = arguments.server
|
||||||
password = arguments.password
|
password = arguments.password
|
||||||
fqdn = socket.getfqdn()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['ejabberdctl', 'register',
|
output = subprocess.check_output(['ejabberdctl', 'register',
|
||||||
username, fqdn, password])
|
username, server, password])
|
||||||
print(output.decode())
|
print(output.decode())
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print('Failed to register XMPP account:', e.output.decode())
|
print('Failed to register XMPP account:', e.output.decode())
|
||||||
|
|||||||
@ -27,7 +27,12 @@
|
|||||||
|
|
||||||
<div class='row'>
|
<div class='row'>
|
||||||
<div class='col-sm-4'>
|
<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"/>
|
<input type="submit" class="btn btn-primary" value="Register XMPP Account"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -136,7 +136,6 @@ def _apply_changes(request, old_status, new_status):
|
|||||||
class RegisterForm(forms.Form): # pylint: disable-msg=W0232
|
class RegisterForm(forms.Form): # pylint: disable-msg=W0232
|
||||||
"""Configuration form"""
|
"""Configuration form"""
|
||||||
username = forms.CharField(label=_('Username'))
|
username = forms.CharField(label=_('Username'))
|
||||||
|
|
||||||
password = forms.CharField(
|
password = forms.CharField(
|
||||||
label=_('Password'), widget=forms.PasswordInput())
|
label=_('Password'), widget=forms.PasswordInput())
|
||||||
|
|
||||||
@ -145,12 +144,13 @@ class RegisterForm(forms.Form): # pylint: disable-msg=W0232
|
|||||||
def register(request):
|
def register(request):
|
||||||
"""Serve the registration form"""
|
"""Serve the registration form"""
|
||||||
form = None
|
form = None
|
||||||
|
server = actions.run('xmpp', ['get-server']).strip()
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = RegisterForm(request.POST, prefix='xmpp')
|
form = RegisterForm(request.POST, prefix='xmpp')
|
||||||
# pylint: disable-msg=E1101
|
# pylint: disable-msg=E1101
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
_register_user(request, form.cleaned_data)
|
_register_user(request, form.cleaned_data, server)
|
||||||
form = RegisterForm(prefix='xmpp')
|
form = RegisterForm(prefix='xmpp')
|
||||||
else:
|
else:
|
||||||
form = RegisterForm(prefix='xmpp')
|
form = RegisterForm(prefix='xmpp')
|
||||||
@ -158,15 +158,17 @@ def register(request):
|
|||||||
return TemplateResponse(request, 'xmpp_register.html',
|
return TemplateResponse(request, 'xmpp_register.html',
|
||||||
{'title': _('Register XMPP Account'),
|
{'title': _('Register XMPP Account'),
|
||||||
'form': form,
|
'form': form,
|
||||||
'subsubmenu': subsubmenu})
|
'subsubmenu': subsubmenu,
|
||||||
|
'server': server})
|
||||||
|
|
||||||
|
|
||||||
def _register_user(request, data):
|
def _register_user(request, data, server):
|
||||||
"""Register a new XMPP user"""
|
"""Register a new XMPP user"""
|
||||||
output = actions.superuser_run(
|
output = actions.superuser_run(
|
||||||
'xmpp',
|
'xmpp',
|
||||||
['register',
|
['register',
|
||||||
'--username', data['username'],
|
'--username', data['username'],
|
||||||
|
'--server', server,
|
||||||
'--password', data['password']])
|
'--password', data['password']])
|
||||||
|
|
||||||
if 'successfully registered' in output:
|
if 'successfully registered' in output:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user