mumble: Add new module for installing, enabling/disabling

This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2015-03-28 16:02:39 -04:00
1 parent 475ddd0c72
commit 2028a63deb
9 files changed
+381

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
#
# 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 Mumble server
"""
from gettext import gettext as _
from plinth import actions
from plinth import cfg
from plinth import service as service_module
depends = ['plinth.modules.apps']
service = None
def init():
"""Intialize the Mumble module."""
menu = cfg.main_menu.get('apps:index')
menu.add_urlname(_('Voice Chat (Mumble)'), 'glyphicon-headphones',
'mumble:index', 50)
output = actions.run('mumble', ['get-enabled'])
enabled = (output.strip() == 'yes')
global service
service = service_module.Service(
'mumble-plinth', _('Mumble Voice Chat Server'),
is_external=True, enabled=enabled)
+30
View File
@@ -0,0 +1,30 @@
#
# 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/>.
#
"""
Forms for configuring Mumble
"""
from django import forms
from gettext import gettext as _
class MumbleForm(forms.Form):
"""Mumble configuration form."""
enabled = forms.BooleanField(
label=_('Enable Mumble daemon'),
required=False)
@@ -0,0 +1,55 @@
{% 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 %}
<h2>Voice Chat (Mumble)</h2>
<p>Mumble is an open source, low-latency, encrypted, high quality voice chat
software.</p>
<p>You can connect to your Mumble server on the regular Mumble port 64738.
<a href="http://mumble.info">Clients</a> to connect to Mumble from your
desktop and Android devices are available.</p>
<h3>Status</h3>
<p>
{% if status.is_running %}
<span class='running-status active'></span> Mumble server is running
{% else %}
<span class='running-status inactive'></span> Mumble server is not running
{% endif %}
</p>
<h3>Configuration</h3>
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary" value="Update setup"/>
</form>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
#
# 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 Mumble module
"""
from django.conf.urls import patterns, url
urlpatterns = patterns(
'plinth.modules.mumble.views',
url(r'^apps/mumble/$', 'index', name='index'),
)
+87
View File
@@ -0,0 +1,87 @@
#
# 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 for configuring Mumble Server
"""
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.template.response import TemplateResponse
from gettext import gettext as _
import logging
from .forms import MumbleForm
from plinth import actions
from plinth import package
from plinth.modules import mumble
logger = logging.getLogger(__name__)
@login_required
@package.required('mumble-server')
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = MumbleForm(request.POST, prefix='mumble')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = MumbleForm(initial=status, prefix='mumble')
else:
form = MumbleForm(initial=status, prefix='mumble')
return TemplateResponse(request, 'mumble.html',
{'title': _('Voice Chat (Mumble)'),
'status': status,
'form': form})
def get_status():
"""Get the current settings from server."""
output = actions.run('mumble', ['get-enabled'])
enabled = (output.strip() == 'yes')
output = actions.superuser_run('mumble', ['is-running'])
is_running = (output.strip() == 'yes')
status = {'enabled': enabled,
'is_running': is_running}
return status
def _apply_changes(request, old_status, new_status):
"""Apply the changes."""
modified = False
if old_status['enabled'] != new_status['enabled']:
sub_command = 'enable' if new_status['enabled'] else 'disable'
actions.superuser_run('mumble', [sub_command])
mumble.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))