xmpp: Separated jsxc and ejabberd

This commit is contained in:
Swapnil Gupta 2016-12-29 02:20:15 +05:30 committed by James Valleroy
parent 85b87268b4
commit bfe273ff7c
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
17 changed files with 314 additions and 13 deletions

View File

@ -16,15 +16,14 @@
#
"""
URLs for the XMPP module
URL for the Ejabberd module
"""
from django.conf.urls import url
from .views import EjabberdServiceView, JsxcView
from .views import EjabberdServiceView
urlpatterns = [
url(r'^apps/xmpp/$', EjabberdServiceView.as_view(), name='index'),
url(r'^apps/xmpp/jsxc/$', JsxcView.as_view(), name='jsxc'),
url(r'^apps/xmpp/ejabberd/$', EjabberdServiceView.as_view(), name='index')
]

View File

@ -0,0 +1,40 @@
#
# 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/>.
#
"""
Views for the Ejabberd module
"""
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from stronghold.decorators import public
from plinth.modules import ejabberd
from plinth.views import ServiceView
class EjabberdServiceView(ServiceView):
"""Show ejabberd as a service."""
service_id = ejabberd.managed_services[0]
template_name = 'ejabberd.html'
description = ejabberd.description
diagnostics_module_name = 'ejabberd'
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['domainname'] = ejabberd.get_domainname()
return context

View File

@ -0,0 +1,185 @@
#
# 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/>.
#
"""
Plinth module to configure XMPP server
"""
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
import logging
import socket
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
from plinth.signals import pre_hostname_change, post_hostname_change
from plinth.signals import domainname_change
version = 2
depends = ['apps']
managed_services = ['ejabberd']
managed_packages = ['libjs-jsxc', 'ejabberd']
title = _('Chat Server \n (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 '
'<a href=\'http://xmpp.org/xmpp-software/clients/\' target=\'_blank\''
'>XMPP client</a>.'),
]
service = None
logger = logging.getLogger(__name__)
def init():
"""Initialize the XMPP module"""
menu = cfg.main_menu.get('apps:index')
menu.add_urlname(title, 'glyphicon-comment', 'xmpp:index')
global service
setup_helper = globals()['setup_helper']
if setup_helper.get_state() != 'needs-setup':
service = service_module.Service(
'ejabberd', title,
ports=['xmpp-client', 'xmpp-server', 'xmpp-bosh'],
is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable)
if is_enabled():
add_shortcut()
pre_hostname_change.connect(on_pre_hostname_change)
post_hostname_change.connect(on_post_hostname_change)
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(managed_packages)
helper.call('post', actions.superuser_run, 'xmpp', ['setup'])
global service
if service is None:
service = service_module.Service(
'ejabberd', title,
ports=['xmpp-client', 'xmpp-server', 'xmpp-bosh'],
is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable)
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('jsxc', _('Chat Client \n (jsxc)'),
url=reverse_lazy('xmpp:jsxc'),
login_required=True)
frontpage.add_shortcut('xmpp', title,
details=description,
configure_url=reverse_lazy('xmpp:index'),
login_required=True)
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('ejabberd') and
action_utils.webserver_is_enabled('jwchat-plinth'))
def get_domainname():
"""Return the domainname"""
fqdn = socket.getfqdn()
return '.'.join(fqdn.split('.')[1:])
def enable():
"""Enable the module."""
actions.superuser_run('xmpp', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('xmpp', ['disable'])
frontpage.remove_shortcut('jsxc')
frontpage.remove_shortcut('xmpp')
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
"""
Backup ejabberd database before hostname is changed.
"""
del sender # Unused
del kwargs # Unused
actions.superuser_run('xmpp',
['pre-change-hostname',
'--old-hostname', old_hostname,
'--new-hostname', new_hostname])
def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs):
"""Update ejabberd config after hostname change."""
del sender # Unused
del kwargs # Unused
actions.superuser_run('xmpp',
['change-hostname',
'--old-hostname', old_hostname,
'--new-hostname', new_hostname],
async=True)
def on_domainname_change(sender, old_domainname, new_domainname, **kwargs):
"""Update ejabberd config after domain name change."""
del sender # Unused
del old_domainname # Unused
del kwargs # Unused
actions.superuser_run('xmpp',
['change-domainname',
'--domainname', new_domainname],
async=True)
def diagnose():
"""Run diagnostics and return the results."""
results = []
results.append(action_utils.diagnose_port_listening(5222, 'tcp4'))
results.append(action_utils.diagnose_port_listening(5222, 'tcp6'))
results.append(action_utils.diagnose_port_listening(5269, 'tcp4'))
results.append(action_utils.diagnose_port_listening(5269, 'tcp6'))
results.append(action_utils.diagnose_port_listening(5280, 'tcp4'))
results.append(action_utils.diagnose_port_listening(5280, 'tcp6'))
results.extend(
action_utils.diagnose_url_on_all('http://{host}/http-bind/'))
return results

View File

@ -0,0 +1,48 @@
{% extends "service.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 i18n %}
{% block description %}
{% for paragraph in description %}
<p>{{ paragraph|safe }}</p>
{% endfor %}
<p>
{% url 'config:index' as index_url %}
{% if domainname %}
{% blocktrans trimmed with domainname=domainname %}
Your XMPP server domain is set to <b>{{ domainname }}</b>. User
IDs will look like <i>username@{{ domainname }}</i>. You
can setup your domain on the system
<a href="{{ index_url }}">Configure</a> page.
{% endblocktrans %}
{% else %}
Your XMPP server domain is not set. You can setup your domain on
the system <a href="{{ index_url }}">Configure</a> page.
{% endif %}
</p>
<p>
<a href='{% url "xmpp:jsxc" %}' target='_blank' class='btn btn-primary'>
{% trans "Launch web client" %}</a>
</p>
{% endblock %}

View File

View File

@ -0,0 +1,29 @@
#
# 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/>.
#
"""
URLs for the JSXC module
"""
from django.conf.urls import url
from .views import JSXCServiceView, JsxcView
urlpatterns = [
url(r'^apps/jsxc/$', JsxcView.as_view(), name='jsxc'),
]

View File

@ -16,27 +16,27 @@
#
"""
Views for the XMPP module
Views for the JSXC module
"""
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from stronghold.decorators import public
from plinth.modules import xmpp
from plinth.modules import jsxc
from plinth.views import ServiceView
class EjabberdServiceView(ServiceView):
class JSXCServiceView(ServiceView):
"""Show ejabberd as a service."""
service_id = xmpp.managed_services[0]
template_name = 'xmpp.html'
description = xmpp.description
diagnostics_module_name = 'xmpp'
service_id = jsxc.managed_services[0]
template_name = 'jsxc.html'
description = jsxc.description
diagnostics_module_name = 'jsxc'
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['domainname'] = xmpp.get_domainname()
context['domainname'] = jsxc.get_domainname()
return context
@ -52,5 +52,5 @@ class JsxcView(TemplateView):
def get_context_data(self, *args, **kwargs):
"""Add domain information to view context."""
context = super().get_context_data(*args, **kwargs)
context['domainname'] = xmpp.get_domainname()
context['domainname'] = jsxc.get_domainname()
return context