diff --git a/plinth/modules/xmpp/__init__.py b/plinth/modules/ejabberd/__init__.py similarity index 100% rename from plinth/modules/xmpp/__init__.py rename to plinth/modules/ejabberd/__init__.py diff --git a/plinth/modules/xmpp/templates/xmpp.html b/plinth/modules/ejabberd/templates/ejabberd.html similarity index 100% rename from plinth/modules/xmpp/templates/xmpp.html rename to plinth/modules/ejabberd/templates/ejabberd.html diff --git a/plinth/modules/xmpp/tests/__init__.py b/plinth/modules/ejabberd/tests/__init__.py similarity index 100% rename from plinth/modules/xmpp/tests/__init__.py rename to plinth/modules/ejabberd/tests/__init__.py diff --git a/plinth/modules/xmpp/urls.py b/plinth/modules/ejabberd/urls.py similarity index 78% rename from plinth/modules/xmpp/urls.py rename to plinth/modules/ejabberd/urls.py index 6b0b8daba..433feb691 100644 --- a/plinth/modules/xmpp/urls.py +++ b/plinth/modules/ejabberd/urls.py @@ -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') ] diff --git a/plinth/modules/ejabberd/views.py b/plinth/modules/ejabberd/views.py new file mode 100644 index 000000000..778b96ddd --- /dev/null +++ b/plinth/modules/ejabberd/views.py @@ -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 . +# + +""" +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 diff --git a/plinth/modules/jsxc/__init__.py b/plinth/modules/jsxc/__init__.py new file mode 100644 index 000000000..785540a26 --- /dev/null +++ b/plinth/modules/jsxc/__init__.py @@ -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 . +# + +""" +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 ' + 'XMPP client.'), +] + +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 diff --git a/plinth/modules/xmpp/static/img b/plinth/modules/jsxc/static/img similarity index 100% rename from plinth/modules/xmpp/static/img rename to plinth/modules/jsxc/static/img diff --git a/plinth/modules/xmpp/static/jsxc-plinth.css b/plinth/modules/jsxc/static/jsxc-plinth.css similarity index 100% rename from plinth/modules/xmpp/static/jsxc-plinth.css rename to plinth/modules/jsxc/static/jsxc-plinth.css diff --git a/plinth/modules/xmpp/static/jsxc-plinth.js b/plinth/modules/jsxc/static/jsxc-plinth.js similarity index 100% rename from plinth/modules/xmpp/static/jsxc-plinth.js rename to plinth/modules/jsxc/static/jsxc-plinth.js diff --git a/plinth/modules/xmpp/static/libjs-jsxc/jsxc.css b/plinth/modules/jsxc/static/libjs-jsxc/jsxc.css similarity index 100% rename from plinth/modules/xmpp/static/libjs-jsxc/jsxc.css rename to plinth/modules/jsxc/static/libjs-jsxc/jsxc.css diff --git a/plinth/modules/xmpp/static/libjs-jsxc/lib b/plinth/modules/jsxc/static/libjs-jsxc/lib similarity index 100% rename from plinth/modules/xmpp/static/libjs-jsxc/lib rename to plinth/modules/jsxc/static/libjs-jsxc/lib diff --git a/plinth/modules/xmpp/static/libjs-jsxc/sound b/plinth/modules/jsxc/static/libjs-jsxc/sound similarity index 100% rename from plinth/modules/xmpp/static/libjs-jsxc/sound rename to plinth/modules/jsxc/static/libjs-jsxc/sound diff --git a/plinth/modules/jsxc/templates/jsxc.html b/plinth/modules/jsxc/templates/jsxc.html new file mode 100644 index 000000000..4e546c455 --- /dev/null +++ b/plinth/modules/jsxc/templates/jsxc.html @@ -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 . +# +{% endcomment %} + +{% load i18n %} + +{% block description %} + + {% for paragraph in description %} +

{{ paragraph|safe }}

+ {% endfor %} + +

+ {% url 'config:index' as index_url %} + {% if domainname %} + {% blocktrans trimmed with domainname=domainname %} + Your XMPP server domain is set to {{ domainname }}. User + IDs will look like username@{{ domainname }}. You + can setup your domain on the system + Configure page. + {% endblocktrans %} + {% else %} + Your XMPP server domain is not set. You can setup your domain on + the system Configure page. + {% endif %} +

+ +

+ + {% trans "Launch web client" %} +

+{% endblock %} diff --git a/plinth/modules/xmpp/templates/jsxc.html b/plinth/modules/jsxc/templates/jsxc_launch.html similarity index 100% rename from plinth/modules/xmpp/templates/jsxc.html rename to plinth/modules/jsxc/templates/jsxc_launch.html diff --git a/plinth/modules/jsxc/tests/__init__.py b/plinth/modules/jsxc/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plinth/modules/jsxc/urls.py b/plinth/modules/jsxc/urls.py new file mode 100644 index 000000000..59d714e50 --- /dev/null +++ b/plinth/modules/jsxc/urls.py @@ -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 . +# + +""" +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'), +] diff --git a/plinth/modules/xmpp/views.py b/plinth/modules/jsxc/views.py similarity index 81% rename from plinth/modules/xmpp/views.py rename to plinth/modules/jsxc/views.py index 61b4c351f..deda837f3 100644 --- a/plinth/modules/xmpp/views.py +++ b/plinth/modules/jsxc/views.py @@ -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