Merge branch 'common-view'

This commit is contained in:
James Valleroy 2016-03-05 15:32:21 -05:00
commit b38859b0d3
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
75 changed files with 477 additions and 1591 deletions

View File

@ -16,15 +16,15 @@
#
"""
Forms for configuring ownCloud.
Common forms for use by modules.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class OwnCloudForm(forms.Form): # pylint: disable-msg=W0232
"""ownCloud configuration form"""
class ConfigurationForm(forms.Form):
"""Generic configuration form for simple modules."""
enabled = forms.BooleanField(
label=_('Enable ownCloud'),
label=_('Enable application'),
required=False)

View File

@ -23,8 +23,8 @@ from plinth import cfg
def init():
"""Initailize the apps module"""
cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt', 'apps:index',
80)
cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt',
'apps:index', 80)
def index(request):

View File

@ -21,6 +21,7 @@ Plinth module for service discovery.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@ -65,6 +66,12 @@ def setup(helper, old_version=False):
helper.install(['avahi-daemon'])
def get_status():
"""Get the current settings from server."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('avahi-daemon')
@ -73,3 +80,10 @@ def is_enabled():
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('avahi-daemon')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('avahi', [sub_command])
service.notify_enabled(None, should_enable)

View File

@ -1,30 +0,0 @@
#
# 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 service discovery forms.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class ServiceDiscoveryForm(forms.Form):
"""Service discovery form."""
enabled = forms.BooleanField(
label=_('Enable service discovery'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the service discovery module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^sys/avahi/$', views.index, name='index'),
url(r'^sys/avahi/$', ConfigurationView.as_view(module_name='avahi'),
name='index'),
]

View File

@ -1,75 +0,0 @@
#
# 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 service discovery views.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import ServiceDiscoveryForm
from plinth import actions
from plinth.modules import avahi
logger = logging.getLogger(__name__) # pylint: disable=C0103
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = ServiceDiscoveryForm(request.POST, prefix='avahi')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ServiceDiscoveryForm(initial=status, prefix='avahi')
else:
form = ServiceDiscoveryForm(initial=status, prefix='avahi')
return TemplateResponse(request, 'avahi.html',
{'title': avahi.title,
'description': avahi.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings from server."""
return {'enabled': avahi.is_enabled(),
'is_running': avahi.is_running()}
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'
modified = True
actions.superuser_run('avahi', [sub_command])
avahi.service.notify_enabled(None, new_status['enabled'])
messages.success(request, _('Configuration updated'))
if not modified:
messages.info(request, _('Setting unchanged'))

View File

@ -226,7 +226,7 @@ def _apply_changes(request, old_status, new_status):
request.session[translation.LANGUAGE_SESSION_KEY] = language
except Exception as exception:
messages.error(request, _('Error setting language: {exception}')
.format(exception=exception))
.format(exception=exception))
else:
messages.success(request, _('Language changed'))

View File

@ -59,6 +59,19 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings from server."""
return {'enabled': is_enabled(),
'is_running': is_running(),
'time_zone': get_current_time_zone()}
def get_current_time_zone():
"""Get current time zone."""
time_zone = open('/etc/timezone').read().rstrip()
return time_zone or 'none'
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('ntp')

View File

@ -21,8 +21,10 @@ URLs for the date and time module
from django.conf.urls import url
from . import views
from .views import ConfigurationView
urlpatterns = [
url(r'^sys/datetime/$', views.index, name='index'),
url(r'^sys/datetime/$', ConfigurationView.as_view(module_name='datetime'),
name='index'),
]

View File

@ -20,74 +20,43 @@ Plinth module for configuring date and time
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import DateTimeForm
from plinth import actions
from plinth import views
from plinth.modules import datetime
logger = logging.getLogger(__name__)
def index(request):
class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
status = get_status()
form_class = DateTimeForm
form = None
def apply_changes(self, old_status, new_status):
"""Apply the changes."""
modified = False
if request.method == 'POST':
form = DateTimeForm(request.POST, prefix='datetime')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = DateTimeForm(initial=status, prefix='datetime')
else:
form = DateTimeForm(initial=status, prefix='datetime')
if old_status['enabled'] != new_status['enabled']:
sub_command = 'enable' if new_status['enabled'] else 'disable'
modified = True
actions.superuser_run('datetime', [sub_command])
datetime.service.notify_enabled(None, new_status['enabled'])
messages.success(self.request, _('Configuration updated'))
return TemplateResponse(request, 'datetime.html',
{'title': datetime.title,
'description': datetime.description,
'status': status,
'form': form})
if old_status['time_zone'] != new_status['time_zone'] and \
new_status['time_zone'] != 'none':
modified = True
try:
actions.superuser_run(
'timezone-change', [new_status['time_zone']])
except Exception as exception:
messages.error(
self.request, _('Error setting time zone: {exception}')
.format(exception=exception))
else:
messages.success(self.request, _('Time zone set'))
def get_status():
"""Get the current settings from server."""
return {'enabled': datetime.is_enabled(),
'is_running': datetime.is_running(),
'time_zone': get_current_time_zone()}
def get_current_time_zone():
"""Get current time zone."""
time_zone = open('/etc/timezone').read().rstrip()
return time_zone or 'none'
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'
modified = True
actions.superuser_run('datetime', [sub_command])
datetime.service.notify_enabled(None, new_status['enabled'])
messages.success(request, _('Configuration updated'))
if old_status['time_zone'] != new_status['time_zone'] and \
new_status['time_zone'] != 'none':
modified = True
try:
actions.superuser_run('timezone-change', [new_status['time_zone']])
except Exception as exception:
messages.error(request, _('Error setting time zone: {exception}')
.format(exception=exception))
else:
messages.success(request, _('Time zone set'))
if not modified:
messages.info(request, _('Setting unchanged'))
return modified

View File

@ -63,6 +63,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.webserver_is_enabled('deluge-plinth') and
@ -74,6 +80,13 @@ def is_running():
return action_utils.service_is_running('deluge-web')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('deluge', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 Deluge web client.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class DelugeForm(forms.Form):
"""Deluge configuration form."""
enabled = forms.BooleanField(
label=_('Enable Deluge'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the Deluge module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/deluge/$', views.index, name='index'),
url(r'^apps/deluge/$', ConfigurationView.as_view(module_name='deluge'),
name='index'),
]

View File

@ -1,75 +0,0 @@
#
# 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 a Deluge web client.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import DelugeForm
from plinth import actions
from plinth.modules import deluge
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = DelugeForm(request.POST, prefix='deluge')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = DelugeForm(initial=status, prefix='deluge')
else:
form = DelugeForm(initial=status, prefix='deluge')
return TemplateResponse(request, 'deluge.html',
{'title': deluge.title,
'description': deluge.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings."""
status = {'enabled': deluge.is_enabled(),
'is_running': deluge.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('deluge', [sub_command])
deluge.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -26,7 +26,7 @@ import plinth.service as service_module
def index(request):
"""Serve introcution page"""
"""Serve introduction page"""
if not firewall.get_enabled_status():
return TemplateResponse(request, 'firewall.html',
{'title': firewall.title,

View File

@ -20,7 +20,6 @@ Help module for Plinth.
"""
import os
from gettext import gettext as _
from django.http import Http404
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _, ugettext_lazy

View File

@ -65,11 +65,23 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current setting."""
return {'enabled': is_enabled()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('ikiwiki-plinth')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('ikiwiki', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -23,13 +23,6 @@ from django import forms
from django.utils.translation import ugettext_lazy as _
class IkiwikiForm(forms.Form):
"""ikiwiki configuration form."""
enabled = forms.BooleanField(
label=_('Enable ikiwiki'),
required=False)
class IkiwikiCreateForm(forms.Form):
"""Form to create a wiki or blog."""
site_type = forms.ChoiceField(

View File

@ -25,7 +25,8 @@ from . import views
urlpatterns = [
url(r'^apps/ikiwiki/$', views.index, name='index'),
url(r'^apps/ikiwiki/$',
views.ConfigurationView.as_view(module_name='ikiwiki'), name='index'),
url(r'^apps/ikiwiki/manage/$', views.manage, name='manage'),
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', views.delete,
name='delete'),

View File

@ -25,9 +25,9 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _, ugettext_lazy
from .forms import IkiwikiForm, IkiwikiCreateForm
from .forms import IkiwikiCreateForm
from plinth import actions
from plinth.modules import ikiwiki
from plinth import views
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
@ -38,48 +38,14 @@ subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
'text': ugettext_lazy('Create')}]
def index(request):
class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
status = get_status()
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
if 'subsubmenu' not in kwargs:
kwargs['subsubmenu'] = subsubmenu
form = None
if request.method == 'POST':
form = IkiwikiForm(request.POST, prefix='ikiwiki')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = IkiwikiForm(initial=status, prefix='ikiwiki')
else:
form = IkiwikiForm(initial=status, prefix='ikiwiki')
return TemplateResponse(request, 'ikiwiki.html',
{'title': ikiwiki.title,
'description': ikiwiki.description,
'status': status,
'form': form,
'subsubmenu': subsubmenu})
def get_status():
"""Get the current setting."""
return {'enabled': ikiwiki.is_enabled()}
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('ikiwiki', [sub_command])
ikiwiki.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))
return super().get_context_data(**kwargs)
def manage(request):

View File

@ -21,6 +21,7 @@ Plinth module for minetest.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@ -61,6 +62,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current service status."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('minetest-server')
@ -71,6 +78,13 @@ def is_running():
return action_utils.service_is_running('minetest-server')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('minetest', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 the minetest module.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class MinetestForm(forms.Form):
"""Minetest configuration form."""
enabled = forms.BooleanField(
label=_('Enable Minetest server'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the minetest module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/minetest/$', views.index, name='index'),
url(r'^apps/minetest/$', ConfigurationView.as_view(module_name='minetest'),
name='index'),
]

View File

@ -1,72 +0,0 @@
#
# 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 minetest module.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import MinetestForm
from plinth import actions
from plinth.modules import minetest
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = MinetestForm(request.POST, prefix='minetest')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = MinetestForm(initial=status, prefix='minetest')
else:
form = MinetestForm(initial=status, prefix='minetest')
return TemplateResponse(request, 'minetest.html',
{'title': minetest.title,
'description': minetest.description,
'status': status,
'form': form})
def get_status():
"""Get the current service status."""
return {'enabled': minetest.is_enabled(),
'is_running': minetest.is_running()}
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('minetest', [sub_command])
minetest.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -21,6 +21,7 @@ Plinth module to configure Mumble server
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@ -60,6 +61,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings from server."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('mumble-server')
@ -70,6 +77,13 @@ def is_running():
return action_utils.service_is_running('mumble-server')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('mumble', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 django.utils.translation import ugettext_lazy as _
class MumbleForm(forms.Form):
"""Mumble configuration form."""
enabled = forms.BooleanField(
label=_('Enable Mumble daemon'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the Mumble module
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/mumble/$', views.index, name='index'),
url(r'^apps/mumble/$', ConfigurationView.as_view(module_name='mumble'),
name='index'),
]

View File

@ -1,76 +0,0 @@
#
# 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.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import MumbleForm
from plinth import actions
from plinth.modules import mumble
logger = logging.getLogger(__name__)
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': mumble.title,
'description': mumble.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings from server."""
return {'enabled': mumble.is_enabled(),
'is_running': mumble.is_running()}
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'))

View File

@ -116,7 +116,7 @@ def _collect_setup_result(request):
return_code = setup_process.poll()
# Setup process is not complete yet
if return_code == None:
if return_code is None:
return
if not return_code:

View File

@ -69,12 +69,27 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Return the current status"""
return {'enabled': is_enabled()}
def is_enabled():
"""Return whether the module is enabled."""
output = actions.run('owncloud-setup', ['status'])
return 'enable' in output.split()
def enable(should_enable):
"""Enable/disable the module."""
option = 'enable' if should_enable else 'noenable'
actions.superuser_run('owncloud-setup', [option])
# Send a signal to other modules that the service is
# enabled/disabled
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -21,9 +21,10 @@ URLs for the ownCloud module
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/owncloud/$', views.index, name='index'),
url(r'^apps/owncloud/$', ConfigurationView.as_view(module_name='owncloud'),
name='index'),
]

View File

@ -1,75 +0,0 @@
#
# 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 ownCloud.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext_lazy as _
from .forms import OwnCloudForm
from plinth import actions
from plinth.modules import owncloud
def index(request):
"""Serve the ownCloud configuration page"""
status = get_status()
form = None
if request.method == 'POST':
form = OwnCloudForm(request.POST, prefix='owncloud')
# pylint: disable-msg=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = OwnCloudForm(initial=status, prefix='owncloud')
else:
form = OwnCloudForm(initial=status, prefix='owncloud')
return TemplateResponse(request, 'owncloud.html',
{'title': owncloud.title,
'description': owncloud.description,
'form': form})
def get_status():
"""Return the current status"""
return {'enabled': owncloud.is_enabled()}
def _apply_changes(request, old_status, new_status):
"""Apply the changes"""
if old_status['enabled'] == new_status['enabled']:
messages.info(request, _('Setting unchanged'))
return
if new_status['enabled']:
messages.success(request, _('ownCloud enabled'))
option = 'enable'
else:
messages.success(request, _('ownCloud disabled'))
option = 'noenable'
actions.superuser_run('owncloud-setup', [option])
# Send a signal to other modules that the service is
# enabled/disabled
owncloud.service.notify_enabled(None, new_status['enabled'])

View File

@ -71,6 +71,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings from server."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('privoxy')
@ -81,6 +87,13 @@ def is_running():
return action_utils.service_is_running('privoxy')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('privoxy', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 Privoxy.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class PrivoxyForm(forms.Form):
"""Privoxy configuration form."""
enabled = forms.BooleanField(
label=_('Enable Privoxy'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the Privoxy module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/privoxy/$', views.index, name='index'),
url(r'^apps/privoxy/$', ConfigurationView.as_view(module_name='privoxy'),
name='index'),
]

View File

@ -1,78 +0,0 @@
#
# 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 Privoxy Server.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import PrivoxyForm
from plinth import actions
from plinth.modules import privoxy
logger = logging.getLogger(__name__)
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = PrivoxyForm(request.POST, prefix='privoxy')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = PrivoxyForm(initial=status, prefix='privoxy')
else:
form = PrivoxyForm(initial=status, prefix='privoxy')
return TemplateResponse(request, 'privoxy.html',
{'title': privoxy.title,
'description': privoxy.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings from server."""
status = {'enabled': privoxy.is_enabled(),
'is_running': privoxy.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('privoxy', [sub_command])
privoxy.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -21,6 +21,7 @@ Plinth module for Quassel.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@ -68,6 +69,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current service status."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('quasselcore')
@ -78,6 +85,13 @@ def is_running():
return action_utils.service_is_running('quasselcore')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('quassel', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 Quassel module.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class QuasselForm(forms.Form):
"""Quassel configuration form."""
enabled = forms.BooleanField(
label=_('Enable Quassel core service'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the quassel module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/quassel/$', views.index, name='index'),
url(r'^apps/quassel/$', ConfigurationView.as_view(module_name='quassel'),
name='index'),
]

View File

@ -1,72 +0,0 @@
#
# 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 Quassel module.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import QuasselForm
from plinth import actions
from plinth.modules import quassel
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = QuasselForm(request.POST, prefix='quassel')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = QuasselForm(initial=status, prefix='quassel')
else:
form = QuasselForm(initial=status, prefix='quassel')
return TemplateResponse(request, 'quassel.html',
{'title': quassel.title,
'description': quassel.description,
'status': status,
'form': form})
def get_status():
"""Get the current service status."""
return {'enabled': quassel.is_enabled(),
'is_running': quassel.is_running()}
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('quassel', [sub_command])
quassel.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -65,6 +65,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current service status."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('radicale')
@ -75,6 +81,13 @@ def is_running():
return action_utils.service_is_running('radicale')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('radicale', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 radicale module.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class RadicaleForm(forms.Form):
"""Radicale configuration form."""
enabled = forms.BooleanField(
label=_('Enable Radicale service'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the radicale module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/radicale/$', views.index, name='index'),
url(r'^apps/radicale/$', ConfigurationView.as_view(module_name='radicale'),
name='index'),
]

View File

@ -1,72 +0,0 @@
#
# 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 radicale module.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import RadicaleForm
from plinth import actions
from plinth.modules import radicale
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = RadicaleForm(request.POST, prefix='radicale')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = RadicaleForm(initial=status, prefix='radicale')
else:
form = RadicaleForm(initial=status, prefix='radicale')
return TemplateResponse(request, 'radicale.html',
{'title': radicale.title,
'description': radicale.description,
'status': status,
'form': form})
def get_status():
"""Get the current service status."""
return {'enabled': radicale.is_enabled(),
'is_running': radicale.is_running()}
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('radicale', [sub_command])
radicale.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -74,6 +74,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current service status."""
return {'enabled': is_enabled(),
'is_running': is_running()}
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('repro')
@ -84,6 +90,13 @@ def is_running():
return action_utils.service_is_running('repro')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('repro', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 repro module.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class ReproForm(forms.Form):
"""Configuration form."""
enabled = forms.BooleanField(
label=_('Enable repro service'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the repro module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/repro/$', views.index, name='index'),
url(r'^apps/repro/$', ConfigurationView.as_view(module_name='repro'),
name='index'),
]

View File

@ -1,72 +0,0 @@
#
# 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 repro module.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import ReproForm
from plinth import actions
from plinth.modules import repro
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = ReproForm(request.POST, prefix='repro')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ReproForm(initial=status, prefix='repro')
else:
form = ReproForm(initial=status, prefix='repro')
return TemplateResponse(request, 'repro.html',
{'title': repro.title,
'description': repro.description,
'status': status,
'form': form})
def get_status():
"""Get the current service status."""
return {'enabled': repro.is_enabled(),
'is_running': repro.is_running()}
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('repro', [sub_command])
repro.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -20,11 +20,12 @@ Plinth module to configure reStore.
"""
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils, cfg
from plinth import service as service_module
from plinth.utils import format_lazy
service = None
version = 1
@ -45,6 +46,8 @@ description = [
'<a href=\'/restore/\'>reStore web-interface</a>.')
]
service = None
def init():
"""Initialize the reStore module."""
@ -62,6 +65,18 @@ def setup(helper, old_version=None):
helper.install(['node-restore'])
def get_status():
"""Get the current settings."""
return {'enabled': is_enabled()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('node-restore')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('restore', [sub_command])
service.notify_enabled(None, should_enable)

View File

@ -1,30 +0,0 @@
#
# 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 reStore.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class ReStoreForm(forms.Form):
"""reStore configuration form."""
enabled = forms.BooleanField(
label=_('Enable reStore'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the reStore module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/restore/$', views.index, name='index'),
url(r'^apps/restore/$', ConfigurationView.as_view(module_name='restore'),
name='index'),
]

View File

@ -1,70 +0,0 @@
#
# 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 reStore.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import ReStoreForm
from plinth import actions
from plinth.modules import restore
def index(request):
"""Serve configuration page."""
status = get_status()
if request.method == 'POST':
form = ReStoreForm(request.POST, prefix='restore')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ReStoreForm(initial=status, prefix='restore')
else:
form = ReStoreForm(initial=status, prefix='restore')
return TemplateResponse(request, 'restore_index.html',
{'title': restore.title,
'description': restore.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings."""
status = {'enabled': restore.is_enabled()}
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('restore', [sub_command])
restore.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -68,11 +68,22 @@ def setup(helper, old_version=None):
helper.call('pre', actions.superuser_run, 'roundcube', ['setup'])
def get_status():
"""Get the current status."""
return {'enabled': is_enabled()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('roundcube')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('roundcube', [sub_command])
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -1,30 +0,0 @@
#
# 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 Roundcube.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class RoundcubeForm(forms.Form):
"""Roundcube configuration form."""
enabled = forms.BooleanField(
label=_('Enable Roundcube'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the Roundcube module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/roundcube/$', views.index, name='index'),
url(r'^apps/roundcube/$',
ConfigurationView.as_view(module_name='roundcube'), name='index'),
]

View File

@ -1,74 +0,0 @@
#
# 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 Roundcube.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import RoundcubeForm
from plinth import actions
from plinth.modules import roundcube
logger = logging.getLogger(__name__)
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = RoundcubeForm(request.POST, prefix='roundcube')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = RoundcubeForm(initial=status, prefix='roundcube')
else:
form = RoundcubeForm(initial=status, prefix='roundcube')
return TemplateResponse(request, 'roundcube.html',
{'title': roundcube.title,
'description': roundcube.description,
'status': status,
'form': form})
def get_status():
"""Get the current status."""
return {'enabled': roundcube.is_enabled()}
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('roundcube', [sub_command])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -21,6 +21,7 @@ Plinth module to configure Shaarli.
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@ -61,6 +62,18 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings."""
return {'enabled': is_enabled()}
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('shaarli')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('shaarli', [sub_command])
service.notify_enabled(None, should_enable)

View File

@ -1,30 +0,0 @@
#
# 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 Shaarli.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class ShaarliForm(forms.Form):
"""Shaarli configuration form."""
enabled = forms.BooleanField(
label=_('Enable Shaarli'),
required=False)

View File

@ -21,9 +21,10 @@ URLs for the Shaarli module.
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/shaarli/$', views.index, name='index'),
url(r'^apps/shaarli/$', ConfigurationView.as_view(module_name='shaarli'),
name='index'),
]

View File

@ -1,72 +0,0 @@
#
# 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 Shaarli.
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from .forms import ShaarliForm
from plinth import actions
from plinth.modules import shaarli
def index(request):
"""Serve configuration page."""
status = get_status()
form = None
if request.method == 'POST':
form = ShaarliForm(request.POST, prefix='shaarli')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ShaarliForm(initial=status, prefix='shaarli')
else:
form = ShaarliForm(initial=status, prefix='shaarli')
return TemplateResponse(request, 'shaarli.html',
{'title': shaarli.title,
'description': shaarli.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings."""
status = {'enabled': shaarli.is_enabled()}
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('shaarli', [sub_command])
shaarli.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -108,7 +108,7 @@ def _collect_config_result(request):
return_code = config_process.poll()
# Config process is not complete yet
if return_code == None:
if return_code is None:
return
status = tor.get_status()

View File

@ -21,6 +21,7 @@ Plinth module to configure Transmission server
from django.utils.translation import ugettext_lazy as _
import json
import socket
from plinth import actions
from plinth import action_utils
@ -42,6 +43,8 @@ description = [
service = None
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
def init():
"""Intialize the Transmission module."""
@ -67,6 +70,19 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings from Transmission server."""
configuration = open(TRANSMISSION_CONFIG, 'r').read()
status = json.loads(configuration)
status = {key.translate(str.maketrans({'-': '_'})): value
for key, value in status.items()}
status['enabled'] = is_enabled()
status['is_running'] = is_running()
status['hostname'] = socket.gethostname()
return status
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('transmission-daemon') and
@ -78,6 +94,13 @@ def is_running():
return action_utils.service_is_running('transmission-daemon')
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('transmission', [sub_command])
service.notify_enabled(None, should_enable)
def diagnose():
"""Run diagnostics and return the results."""
results = []

View File

@ -22,13 +22,11 @@ Plinth module for configuring Transmission.
from django import forms
from django.utils.translation import ugettext_lazy as _
from plinth.forms import ConfigurationForm
class TransmissionForm(forms.Form): # pylint: disable=W0232
class TransmissionForm(ConfigurationForm): # pylint: disable=W0232
"""Transmission configuration form"""
enabled = forms.BooleanField(
label=_('Enable Transmission daemon'),
required=False)
download_dir = forms.CharField(
label=_('Download directory'),
help_text=_('Directory where downloads are saved. If you change the \

View File

@ -21,9 +21,10 @@ URLs for the Transmission module.
from django.conf.urls import url
from . import views
from .views import ConfigurationView
urlpatterns = [
url(r'^apps/transmission/$', views.index, name='index'),
url(r'^apps/transmission/$',
ConfigurationView.as_view(module_name='transmission'), name='index'),
]

View File

@ -20,81 +20,37 @@ Plinth module for configuring Transmission Server
"""
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import json
import logging
import socket
from .forms import TransmissionForm
from plinth import actions
from plinth.modules import transmission
from plinth import views
logger = logging.getLogger(__name__)
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
def index(request):
class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
status = get_status()
form_class = TransmissionForm
form = None
def apply_changes(self, old_status, new_status):
"""Apply the changes submitted in the form."""
modified = super().apply_changes(old_status, new_status)
if request.method == 'POST':
form = TransmissionForm(request.POST, prefix='transmission')
# pylint: disable=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = TransmissionForm(initial=status, prefix='transmission')
else:
form = TransmissionForm(initial=status, prefix='transmission')
if old_status['download_dir'] != new_status['download_dir'] or \
old_status['rpc_username'] != new_status['rpc_username'] or \
old_status['rpc_password'] != new_status['rpc_password']:
new_configuration = {
'download-dir': new_status['download_dir'],
'rpc-username': new_status['rpc_username'],
'rpc-password': new_status['rpc_password'],
}
return TemplateResponse(request, 'transmission.html',
{'title': transmission.title,
'description': transmission.description,
'status': status,
'form': form})
actions.superuser_run('transmission', ['merge-configuration'],
input=json.dumps(new_configuration).encode())
messages.success(self.request, _('Configuration updated'))
return True
def get_status():
"""Get the current settings from Transmission server."""
configuration = open(TRANSMISSION_CONFIG, 'r').read()
status = json.loads(configuration)
status = {key.translate(str.maketrans({'-': '_'})): value
for key, value in status.items()}
status['enabled'] = transmission.is_enabled()
status['is_running'] = transmission.is_running()
status['hostname'] = socket.gethostname()
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('transmission', [sub_command])
transmission.service.notify_enabled(None, new_status['enabled'])
modified = True
if old_status['download_dir'] != new_status['download_dir'] or \
old_status['rpc_username'] != new_status['rpc_username'] or \
old_status['rpc_password'] != new_status['rpc_password']:
new_configuration = {
'download-dir': new_status['download_dir'],
'rpc-username': new_status['rpc_username'],
'rpc-password': new_status['rpc_password'],
}
actions.superuser_run('transmission', ['merge-configuration'],
input=json.dumps(new_configuration).encode())
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))
return modified

View File

@ -50,3 +50,20 @@ def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(['unattended-upgrades'])
helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto'])
def get_status():
"""Return the current status."""
return {'auto_upgrades_enabled': 'is_enabled'}
def is_enabled():
"""Return whether the module is enabled."""
output = actions.run('upgrades', ['check-auto'])
return 'True' in output.split()
def enable(should_enable):
"""Enable/disable the module."""
option = 'enable-auto' if should_enable else 'disable-auto'
actions.superuser_run('upgrades', [option])

View File

@ -25,6 +25,7 @@ from . import views
urlpatterns = [
url(r'^sys/upgrades/$', views.index, name='index'),
url(r'^sys/upgrades/$',
views.ConfigurationView.as_view(module_name='upgrades'), name='index'),
url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'),
]

View File

@ -27,6 +27,7 @@ import subprocess
from .forms import ConfigureForm
from plinth import actions
from plinth import views
from plinth.errors import ActionError
from plinth.modules import upgrades
@ -39,26 +40,43 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
LOCK_FILE = '/var/log/dpkg/lock'
def index(request):
"""Serve the configuration form."""
status = get_status()
class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
form_class = ConfigureForm
form = None
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
if 'subsubmenu' not in kwargs:
kwargs['subsubmenu'] = subsubmenu
if request.method == 'POST':
form = ConfigureForm(request.POST, prefix='upgrades')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ConfigureForm(initial=status, prefix='upgrades')
else:
form = ConfigureForm(initial=status, prefix='upgrades')
return super().get_context_data(**kwargs)
return TemplateResponse(request, 'upgrades_configure.html',
{'title': upgrades.title,
'description': upgrades.description,
'form': form,
'subsubmenu': subsubmenu})
def get_template_names(self):
"""Return the list of template names for the view."""
return ['upgrades_configure.html']
def apply_changes(self, old_status, new_status):
"""Apply the form changes."""
if old_status['auto_upgrades_enabled'] \
== new_status['auto_upgrades_enabled']:
return False
try:
upgrades.enable(new_status['auto_upgrades_enabled'])
except ActionError as exception:
error = exception.args[2]
messages.error(
self.request,
_('Error when configuring unattended-upgrades: {error}')
.format(error=error))
return True
if new_status['auto_upgrades_enabled']:
messages.success(self.request, _('Automatic upgrades enabled'))
else:
messages.success(self.request, _('Automatic upgrades disabled'))
return True
def is_package_manager_busy():
@ -97,36 +115,3 @@ def upgrade(request):
'subsubmenu': subsubmenu,
'is_busy': is_busy,
'log': get_log()})
def get_status():
"""Return the current status."""
output = actions.run('upgrades', ['check-auto'])
return {'auto_upgrades_enabled': 'True' in output.split()}
def _apply_changes(request, old_status, new_status):
"""Apply the form changes."""
if old_status['auto_upgrades_enabled'] \
== new_status['auto_upgrades_enabled']:
messages.info(request, _('Setting unchanged'))
return
if new_status['auto_upgrades_enabled']:
option = 'enable-auto'
else:
option = 'disable-auto'
try:
actions.superuser_run('upgrades', [option])
except ActionError as exception:
error = exception.args[2]
messages.error(
request, _('Error when configuring unattended-upgrades: {error}')
.format(error=error))
return
if option == 'enable-auto':
messages.success(request, _('Automatic upgrades enabled'))
else:
messages.success(request, _('Automatic upgrades disabled'))

View File

@ -67,5 +67,3 @@ def _diagnose_ldap_entry(search_item):
return [_('Check LDAP entry "{search_item}"')
.format(search_item=search_item), result]

View File

@ -79,6 +79,13 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
def get_status():
"""Get the current settings."""
return {'enabled': is_enabled(),
'is_running': is_running(),
'domainname': get_domainname()}
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('ejabberd') and
@ -96,6 +103,13 @@ def get_domainname():
return '.'.join(fqdn.split('.')[1:])
def enable(should_enable):
"""Enable/disable the module."""
sub_command = 'enable' if should_enable else 'disable'
actions.superuser_run('xmpp', [sub_command])
service.notify_enabled(None, should_enable)
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
"""
Backup ejabberd database before hostname is changed.

View File

@ -1,30 +0,0 @@
#
# 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 XMPP service.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class XmppForm(forms.Form): # pylint: disable=W0232
"""XMPP configuration form."""
enabled = forms.BooleanField(
label=_('Enable XMPP'),
required=False)

View File

@ -21,8 +21,10 @@ URLs for the XMPP module
from django.conf.urls import url
from . import views
from plinth.views import ConfigurationView
urlpatterns = [
url(r'^apps/xmpp/$', views.index, name='index'),
url(r'^apps/xmpp/$', ConfigurationView.as_view(module_name='xmpp'),
name='index'),
]

View File

@ -1,79 +0,0 @@
#
# 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.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import XmppForm
from plinth import actions
from plinth.modules import xmpp
logger = logging.getLogger(__name__)
def index(request):
"""Serve configuration page"""
status = get_status()
form = None
if request.method == 'POST':
form = XmppForm(request.POST, prefix='xmpp')
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = XmppForm(initial=status, prefix='xmpp')
else:
form = XmppForm(initial=status, prefix='xmpp')
return TemplateResponse(request, 'xmpp.html',
{'title': xmpp.title,
'description': xmpp.description,
'status': status,
'form': form})
def get_status():
"""Get the current settings."""
status = {'enabled': xmpp.is_enabled(),
'is_running': xmpp.is_running(),
'domainname': xmpp.get_domainname()}
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('xmpp', [sub_command])
xmpp.service.notify_enabled(None, new_status['enabled'])
modified = True
if modified:
messages.success(request, _('Configuration updated'))
else:
messages.info(request, _('Setting unchanged'))

View File

@ -19,17 +19,101 @@
Main Plinth views
"""
from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.http.response import HttpResponseRedirect
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from django.utils.translation import ugettext as _
import time
from . import forms
import plinth
def index(request):
"""Serve the main index page."""
return HttpResponseRedirect(reverse('apps:index'))
class ConfigurationView(FormView):
"""A generic view for configuring simple modules."""
form_class = forms.ConfigurationForm
module_name = None
def __init__(self, module_name=None, *args, **kwargs):
"""Set the module name on which this configuration view operates."""
self.instance_module_name = module_name
def get_module_name(self):
"""Return the name of the module associated with the view."""
if not self.instance_module_name and not self.module_name:
raise ImproperlyConfigured(
'Using ConfigurationView without the "module_name" class '
'attribute or intialization attribute is prohibited.')
else:
return self.instance_module_name or self.module_name
def get_module(self):
"""Return the module associated with the view."""
return plinth.module_loader.loaded_modules[self.get_module_name()]
def get_initial(self):
"""Return the status of the module to fill in the form."""
return self.get_module().get_status()
def get_prefix(self):
"""Return prefix for form used in the view."""
return self.get_module_name()
def get_template_names(self):
"""Return the list of template names for the view."""
return [self.get_module_name() + '.html']
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
if 'title' not in kwargs:
kwargs['title'] = getattr(self.get_module(), 'title', None)
if 'description' not in kwargs:
kwargs['description'] = \
getattr(self.get_module(), 'description', None)
context = super().get_context_data(**kwargs)
if 'status' not in context:
context['status'] = context['form'].initial
return context
def form_valid(self, form):
"""Perform operation when the form submission is valid."""
old_status = form.initial
new_status = form.cleaned_data
modified = self.apply_changes(old_status, new_status)
if not modified:
messages.info(self.request, _('Setting unchanged'))
context = self.get_context_data()
return self.render_to_response(context)
def apply_changes(self, old_status, new_status):
"""Apply the changes submitted in the form."""
if old_status['enabled'] == new_status['enabled']:
return False
should_enable = new_status['enabled']
self.get_module().enable(should_enable)
if should_enable:
messages.success(self.request, _('Application enabled'))
else:
messages.success(self.request, _('Application disabled'))
return True
class SetupView(TemplateView):
"""View to prompt and setup applications."""
template_name = 'setup.html'