mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
xmpp: Use new setup mechanism
This commit is contained in:
parent
bee0260af7
commit
30f0876c32
@ -20,6 +20,8 @@ Plinth module to configure XMPP server
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
import logging
|
||||||
|
import socket
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import action_utils
|
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
|
from plinth.signals import domainname_change
|
||||||
|
|
||||||
|
|
||||||
|
version = 1
|
||||||
|
|
||||||
depends = ['apps']
|
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 <a href=\'/jwchat\'>web '
|
||||||
|
'client</a> or any other '
|
||||||
|
'<a href=\'http://xmpp.org/xmpp-software/clients/\' target=\'_blank\''
|
||||||
|
'>XMPP client</a>.')
|
||||||
|
]
|
||||||
|
|
||||||
service = None
|
service = None
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initialize the XMPP module"""
|
"""Initialize the XMPP module"""
|
||||||
menu = cfg.main_menu.get('apps:index')
|
menu = cfg.main_menu.get('apps:index')
|
||||||
menu.add_urlname(_('Chat Server (XMPP)'), 'glyphicon-comment',
|
menu.add_urlname(title, 'glyphicon-comment', 'xmpp:index', 400)
|
||||||
'xmpp:index', 400)
|
|
||||||
|
|
||||||
global service
|
global service
|
||||||
service = service_module.Service(
|
service = service_module.Service(
|
||||||
'xmpp', _('Chat Server (XMPP)'),
|
'xmpp', title, ['xmpp-client', 'xmpp-server', 'xmpp-bosh'],
|
||||||
['xmpp-client', 'xmpp-server', 'xmpp-bosh'],
|
|
||||||
is_external=True, enabled=is_enabled())
|
is_external=True, enabled=is_enabled())
|
||||||
|
|
||||||
pre_hostname_change.connect(on_pre_hostname_change)
|
pre_hostname_change.connect(on_pre_hostname_change)
|
||||||
@ -51,6 +67,18 @@ def init():
|
|||||||
domainname_change.connect(on_domainname_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(['jwchat', 'ejabberd'])
|
||||||
|
helper.call('post', actions.superuser_run, 'xmpp', ['setup'])
|
||||||
|
helper.call('post', service.notify_enabled, None, True)
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return (action_utils.service_is_enabled('ejabberd') and
|
return (action_utils.service_is_enabled('ejabberd') and
|
||||||
@ -62,6 +90,12 @@ def is_running():
|
|||||||
return action_utils.service_is_running('ejabberd')
|
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):
|
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
|
||||||
"""
|
"""
|
||||||
Backup ejabberd database before hostname is changed.
|
Backup ejabberd database before hostname is changed.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "app.html" %}
|
||||||
{% comment %}
|
{% comment %}
|
||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of Plinth.
|
||||||
@ -21,24 +21,7 @@
|
|||||||
{% load bootstrap %}
|
{% load bootstrap %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block configuration %}
|
||||||
|
|
||||||
<h2>{% trans "Chat Server (XMPP)" %}</h2>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
{% blocktrans trimmed %}
|
|
||||||
XMPP is an open and standardized communication protocol. Here
|
|
||||||
you can run and configure your XMPP server, called ejabberd.
|
|
||||||
{% endblocktrans %}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
{% blocktrans trimmed %}
|
|
||||||
To actually communicate, you can use the <a href='/jwchat'>web
|
|
||||||
client</a> or any other <a href='http://xmpp.org/xmpp-software/clients/'
|
|
||||||
target='_blank'>XMPP client</a>.
|
|
||||||
{% endblocktrans %}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% url 'config:index' as index_url %}
|
{% url 'config:index' as index_url %}
|
||||||
|
|||||||
@ -23,39 +23,15 @@ from django.contrib import messages
|
|||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
|
|
||||||
from .forms import XmppForm
|
from .forms import XmppForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import package
|
|
||||||
from plinth.modules import xmpp
|
from plinth.modules import xmpp
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
def index(request):
|
||||||
"""Serve configuration page"""
|
"""Serve configuration page"""
|
||||||
status = get_status()
|
status = get_status()
|
||||||
@ -72,7 +48,8 @@ def index(request):
|
|||||||
form = XmppForm(initial=status, prefix='xmpp')
|
form = XmppForm(initial=status, prefix='xmpp')
|
||||||
|
|
||||||
return TemplateResponse(request, 'xmpp.html',
|
return TemplateResponse(request, 'xmpp.html',
|
||||||
{'title': _('Chat Server (XMPP)'),
|
{'title': xmpp.title,
|
||||||
|
'description': xmpp.description,
|
||||||
'status': status,
|
'status': status,
|
||||||
'form': form})
|
'form': form})
|
||||||
|
|
||||||
@ -81,7 +58,7 @@ def get_status():
|
|||||||
"""Get the current settings."""
|
"""Get the current settings."""
|
||||||
status = {'enabled': xmpp.is_enabled(),
|
status = {'enabled': xmpp.is_enabled(),
|
||||||
'is_running': xmpp.is_running(),
|
'is_running': xmpp.is_running(),
|
||||||
'domainname': get_domainname()}
|
'domainname': xmpp.get_domainname()}
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user