xmpp: Remove account registration and in-band configuration.

This commit is contained in:
James Valleroy 2015-07-19 21:49:03 -04:00 committed by Sunil Mohan Adapa
parent b840875c16
commit 6bbc622b1a
5 changed files with 1 additions and 299 deletions

View File

@ -53,18 +53,6 @@ def parse_arguments():
# Setup jwchat apache conf
subparsers.add_parser('setup', help='Setup jwchat apache conf')
# Get whether inband registration is enabled
subparsers.add_parser('is-inband-enabled',
help='Get whether inband registration is enabled')
# Enable inband registration
subparsers.add_parser('enable-inband',
help='Enable inband registration')
# Disable inband registration
subparsers.add_parser('disable-inband',
help='Disable inband registration')
# Prepare ejabberd for hostname change
pre_hostname_change = subparsers.add_parser(
'pre-change-hostname',
@ -88,21 +76,6 @@ def parse_arguments():
help='Update ejabberd and jwchat with new domainname')
domainname_change.add_argument('--domainname', help='New domainname')
# 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('--vhost',
help='Virtual host to register the new user in')
register.add_argument('--password',
help='Password for the new user account')
return parser.parse_args()
@ -150,49 +123,6 @@ def subcommand_setup(_):
webserver_change.enable('jwchat-plinth')
def subcommand_is_inband_enabled(_):
"""Get whether inband registration is enabled"""
conffile = open(EJABBERD_CONFIG, 'r')
conf = yaml.safe_load(conffile)
print('all' in conf['modules']['mod_register']['ip_access'])
def subcommand_enable_inband(_):
"""Enable inband registration"""
with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines:
if 'ip_access' in line:
conffile.write(line.replace('trusted_network', 'all'))
else:
conffile.write(line)
try:
subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err:
print('Failed to restart ejabberd with new configuration: %s', err)
def subcommand_disable_inband(_):
"""Disable inband registration"""
with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines:
if 'ip_access' in line:
conffile.write(line.replace('all', 'trusted_network'))
else:
conffile.write(line)
try:
subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err:
print('Failed to restart ejabberd with new configuration: %s', err)
def subcommand_pre_change_hostname(arguments):
"""Prepare ejabberd for hostname change"""
old_hostname = arguments.old_hostname
@ -277,25 +207,6 @@ def subcommand_change_domainname(arguments):
action_utils.service_start('ejabberd')
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."""
username = arguments.username
vhost = arguments.vhost
password = arguments.password
try:
output = subprocess.check_output(['ejabberdctl', 'register',
username, vhost, password])
print(output.decode())
except subprocess.CalledProcessError as e:
print('Failed to register XMPP account:', e.output.decode())
def main():
"""Parse arguments and perform all duties"""
arguments = parse_arguments()

View File

@ -1,34 +0,0 @@
{% extends "base.html" %}
{% comment %}
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block content %}
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary btn-md" value="Update setup"/>
</form>
{% endblock %}

View File

@ -1,43 +0,0 @@
{% extends "base.html" %}
{% comment %}
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block content %}
<form class="form" method="post">
{% csrf_token %}
<div class='row'>
<div class='col-sm-4'>
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary" value="Register XMPP Account"/>
</div>
</div>
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_xmpp-username').focus();
</script>
{% endblock %}

View File

@ -25,6 +25,4 @@ from django.conf.urls import patterns, url
urlpatterns = patterns( # pylint: disable-msg=C0103
'plinth.modules.xmpp.xmpp',
url(r'^apps/xmpp/$', 'index', name='index'),
url(r'^apps/xmpp/configure/$', 'configure', name='configure'),
url(r'^apps/xmpp/register/$', 'register', name='register')
)

View File

@ -17,7 +17,6 @@
from django import forms
from django.contrib import messages
from django.core.urlresolvers import reverse_lazy
from django.template.response import TemplateResponse
from gettext import gettext as _
import logging
@ -33,13 +32,6 @@ from plinth.signals import domainname_change
logger = logging.getLogger(__name__)
subsubmenu = [{'url': reverse_lazy('xmpp:index'),
'text': _('About')},
{'url': reverse_lazy('xmpp:configure'),
'text': _('Configure XMPP Server')},
{'url': reverse_lazy('xmpp:register'),
'text': _('Register XMPP Account')}]
def init():
"""Initialize the XMPP module"""
@ -80,129 +72,7 @@ def on_install():
def index(request):
"""Serve XMPP page"""
return TemplateResponse(request, 'xmpp.html',
{'title': _('XMPP Server'),
'subsubmenu': subsubmenu})
class ConfigureForm(forms.Form): # pylint: disable-msg=W0232
"""Configuration form"""
inband_enabled = forms.BooleanField(
label=_('Allow In-Band Registration'), required=False,
help_text=_('When enabled, anyone who can reach this server will be \
allowed to register an account through an XMPP client'))
def configure(request):
"""Serve the configuration form"""
status = get_status()
form = None
if request.method == 'POST':
form = ConfigureForm(request.POST, prefix='xmpp')
# pylint: disable-msg=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ConfigureForm(initial=status, prefix='xmpp')
else:
form = ConfigureForm(initial=status, prefix='xmpp')
return TemplateResponse(request, 'xmpp_configure.html',
{'title': _('Configure XMPP Server'),
'form': form,
'subsubmenu': subsubmenu})
def get_status():
"""Return the current status"""
output = actions.run('xmpp', ['is-inband-enabled'])
inband_enabled = 'True' in output.split()
return {'inband_enabled': inband_enabled}
def _apply_changes(request, old_status, new_status):
"""Apply the form changes"""
logger.info('Status - %s, %s', old_status, new_status)
setting_changed = False
if not old_status['inband_enabled'] and new_status['inband_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['enable-inband'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('Inband registration enabled'))
elif old_status['inband_enabled'] and not new_status['inband_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['disable-inband'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('Inband registration disabled'))
if not setting_changed:
messages.info(request, _('Setting unchanged'))
class RegisterForm(forms.Form): # pylint: disable-msg=W0232
"""Configuration form."""
username = forms.CharField(label=_('Username'))
vhost = forms.ChoiceField(
label=_('Host'), choices=(),
help_text=_('The new user will be able to login as: username@host'))
password = forms.CharField(
label=_('Password'), widget=forms.PasswordInput())
def __init__(self, vhosts, *args, **kwargs):
"""Set the list of possible values for hosts."""
super(RegisterForm, self).__init__(*args, **kwargs)
self.fields['vhost'].choices = ((vhost, '@' + vhost)
for vhost in vhosts)
def register(request):
"""Serve the registration form."""
form = None
vhosts = actions.run('xmpp', ['get-vhosts']).split()
if request.method == 'POST':
form = RegisterForm(vhosts, request.POST, prefix='xmpp')
# pylint: disable-msg=E1101
if form.is_valid():
_register_user(request, form.cleaned_data)
form = RegisterForm(vhosts, prefix='xmpp')
else:
form = RegisterForm(vhosts, prefix='xmpp')
return TemplateResponse(request, 'xmpp_register.html',
{'title': _('Register XMPP Account'),
'form': form,
'subsubmenu': subsubmenu})
def _register_user(request, data):
"""Register a new XMPP user"""
output = actions.superuser_run(
'xmpp',
['register',
'--username', data['username'],
'--vhost', data['vhost'],
'--password', data['password']])
if 'successfully registered' in output:
messages.success(request, _('Registered account %s@%s') %
(data['username'], data['vhost']))
else:
messages.error(request,
_('Failed to register account %s@%s: %s') %
(data['username'], data['vhost'], output))
{'title': _('XMPP Server')})
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):