From 30f0876c32ece47d90bc7497a1dd0b81d6c8e252 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 12 Feb 2016 19:07:36 +0530 Subject: [PATCH] xmpp: Use new setup mechanism --- plinth/modules/xmpp/__init__.py | 42 ++++++++++++++++++++++--- plinth/modules/xmpp/templates/xmpp.html | 21 ++----------- plinth/modules/xmpp/views.py | 29 ++--------------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/plinth/modules/xmpp/__init__.py b/plinth/modules/xmpp/__init__.py index 65e8a3c19..1365f1d98 100644 --- a/plinth/modules/xmpp/__init__.py +++ b/plinth/modules/xmpp/__init__.py @@ -20,6 +20,8 @@ Plinth module to configure XMPP server """ from django.utils.translation import ugettext_lazy as _ +import logging +import socket from plinth import actions from plinth import action_utils @@ -29,21 +31,35 @@ from plinth.signals import pre_hostname_change, post_hostname_change from plinth.signals import domainname_change +version = 1 + depends = ['apps'] +title = _('Chat Server (XMPP)') + +description = [ + _('XMPP is an open and standardized communication protocol. Here ' + 'you can run and configure your XMPP server, called ejabberd.'), + + _('To actually communicate, you can use the web ' + 'client or any other ' + 'XMPP client.') +] + service = None +logger = logging.getLogger(__name__) + def init(): """Initialize the XMPP module""" menu = cfg.main_menu.get('apps:index') - menu.add_urlname(_('Chat Server (XMPP)'), 'glyphicon-comment', - 'xmpp:index', 400) + menu.add_urlname(title, 'glyphicon-comment', 'xmpp:index', 400) global service service = service_module.Service( - 'xmpp', _('Chat Server (XMPP)'), - ['xmpp-client', 'xmpp-server', 'xmpp-bosh'], + 'xmpp', title, ['xmpp-client', 'xmpp-server', 'xmpp-bosh'], is_external=True, enabled=is_enabled()) pre_hostname_change.connect(on_pre_hostname_change) @@ -51,6 +67,18 @@ def init(): domainname_change.connect(on_domainname_change) +def setup(helper, old_version=None): + """Install and configure the module.""" + domainname = get_domainname() + logger.info('XMPP service domainname - %s', domainname) + + helper.call('pre', actions.superuser_run, 'xmpp', + ['pre-install', '--domainname', domainname]) + helper.install(['jwchat', 'ejabberd']) + helper.call('post', actions.superuser_run, 'xmpp', ['setup']) + helper.call('post', service.notify_enabled, None, True) + + def is_enabled(): """Return whether the module is enabled.""" return (action_utils.service_is_enabled('ejabberd') and @@ -62,6 +90,12 @@ def is_running(): return action_utils.service_is_running('ejabberd') +def get_domainname(): + """Return the domainname""" + fqdn = socket.getfqdn() + return '.'.join(fqdn.split('.')[1:]) + + def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs): """ Backup ejabberd database before hostname is changed. diff --git a/plinth/modules/xmpp/templates/xmpp.html b/plinth/modules/xmpp/templates/xmpp.html index b0f3ac56b..31e387be2 100644 --- a/plinth/modules/xmpp/templates/xmpp.html +++ b/plinth/modules/xmpp/templates/xmpp.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "app.html" %} {% comment %} # # This file is part of Plinth. @@ -21,24 +21,7 @@ {% load bootstrap %} {% load i18n %} -{% block content %} - -

{% trans "Chat Server (XMPP)" %}

- -

- {% blocktrans trimmed %} - XMPP is an open and standardized communication protocol. Here - you can run and configure your XMPP server, called ejabberd. - {% endblocktrans %} -

- -

- {% blocktrans trimmed %} - To actually communicate, you can use the web - client or any other XMPP client. - {% endblocktrans %} -

+{% block configuration %}

{% url 'config:index' as index_url %} diff --git a/plinth/modules/xmpp/views.py b/plinth/modules/xmpp/views.py index 817417177..ca1841535 100644 --- a/plinth/modules/xmpp/views.py +++ b/plinth/modules/xmpp/views.py @@ -23,39 +23,15 @@ from django.contrib import messages from django.template.response import TemplateResponse from django.utils.translation import ugettext as _ import logging -import socket from .forms import XmppForm from plinth import actions -from plinth import package from plinth.modules import xmpp logger = logging.getLogger(__name__) -def get_domainname(): - """Return the domainname""" - fqdn = socket.getfqdn() - return '.'.join(fqdn.split('.')[1:]) - - -def before_install(): - """Preseed debconf values before the packages are installed.""" - domainname = get_domainname() - logger.info('XMPP service domainname - %s', domainname) - actions.superuser_run('xmpp', ['pre-install', '--domainname', domainname]) - - -def on_install(): - """Setup jwchat apache conf""" - actions.superuser_run('xmpp', ['setup']) - xmpp.service.notify_enabled(None, True) - - -@package.required(['jwchat', 'ejabberd'], - before_install=before_install, - on_install=on_install) def index(request): """Serve configuration page""" status = get_status() @@ -72,7 +48,8 @@ def index(request): form = XmppForm(initial=status, prefix='xmpp') return TemplateResponse(request, 'xmpp.html', - {'title': _('Chat Server (XMPP)'), + {'title': xmpp.title, + 'description': xmpp.description, 'status': status, 'form': form}) @@ -81,7 +58,7 @@ def get_status(): """Get the current settings.""" status = {'enabled': xmpp.is_enabled(), 'is_running': xmpp.is_running(), - 'domainname': get_domainname()} + 'domainname': xmpp.get_domainname()} return status