mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Merge branch 'common-view'
This commit is contained in:
commit
b38859b0d3
@ -16,15 +16,15 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Forms for configuring ownCloud.
|
Common forms for use by modules.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class OwnCloudForm(forms.Form): # pylint: disable-msg=W0232
|
class ConfigurationForm(forms.Form):
|
||||||
"""ownCloud configuration form"""
|
"""Generic configuration form for simple modules."""
|
||||||
enabled = forms.BooleanField(
|
enabled = forms.BooleanField(
|
||||||
label=_('Enable ownCloud'),
|
label=_('Enable application'),
|
||||||
required=False)
|
required=False)
|
||||||
@ -23,8 +23,8 @@ from plinth import cfg
|
|||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initailize the apps module"""
|
"""Initailize the apps module"""
|
||||||
cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt', 'apps:index',
|
cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt',
|
||||||
80)
|
'apps:index', 80)
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
|||||||
@ -21,6 +21,7 @@ Plinth module for service discovery.
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
from plinth import service as service_module
|
||||||
@ -65,6 +66,12 @@ def setup(helper, old_version=False):
|
|||||||
helper.install(['avahi-daemon'])
|
helper.install(['avahi-daemon'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current settings from server."""
|
||||||
|
return {'enabled': is_enabled(),
|
||||||
|
'is_running': is_running()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('avahi-daemon')
|
return action_utils.service_is_enabled('avahi-daemon')
|
||||||
@ -73,3 +80,10 @@ def is_enabled():
|
|||||||
def is_running():
|
def is_running():
|
||||||
"""Return whether the service is running."""
|
"""Return whether the service is running."""
|
||||||
return action_utils.service_is_running('avahi-daemon')
|
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)
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the service discovery module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^sys/avahi/$', views.index, name='index'),
|
url(r'^sys/avahi/$', ConfigurationView.as_view(module_name='avahi'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -226,7 +226,7 @@ def _apply_changes(request, old_status, new_status):
|
|||||||
request.session[translation.LANGUAGE_SESSION_KEY] = language
|
request.session[translation.LANGUAGE_SESSION_KEY] = language
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
messages.error(request, _('Error setting language: {exception}')
|
messages.error(request, _('Error setting language: {exception}')
|
||||||
.format(exception=exception))
|
.format(exception=exception))
|
||||||
else:
|
else:
|
||||||
messages.success(request, _('Language changed'))
|
messages.success(request, _('Language changed'))
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,19 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('ntp')
|
return action_utils.service_is_enabled('ntp')
|
||||||
|
|||||||
@ -21,8 +21,10 @@ URLs for the date and time module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from .views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^sys/datetime/$', views.index, name='index'),
|
url(r'^sys/datetime/$', ConfigurationView.as_view(module_name='datetime'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -20,74 +20,43 @@ Plinth module for configuring date and time
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.template.response import TemplateResponse
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .forms import DateTimeForm
|
from .forms import DateTimeForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
from plinth import views
|
||||||
from plinth.modules import datetime
|
from plinth.modules import datetime
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class ConfigurationView(views.ConfigurationView):
|
||||||
"""Serve configuration page."""
|
"""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':
|
if old_status['enabled'] != new_status['enabled']:
|
||||||
form = DateTimeForm(request.POST, prefix='datetime')
|
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
||||||
# pylint: disable=E1101
|
modified = True
|
||||||
if form.is_valid():
|
actions.superuser_run('datetime', [sub_command])
|
||||||
_apply_changes(request, status, form.cleaned_data)
|
datetime.service.notify_enabled(None, new_status['enabled'])
|
||||||
status = get_status()
|
messages.success(self.request, _('Configuration updated'))
|
||||||
form = DateTimeForm(initial=status, prefix='datetime')
|
|
||||||
else:
|
|
||||||
form = DateTimeForm(initial=status, prefix='datetime')
|
|
||||||
|
|
||||||
return TemplateResponse(request, 'datetime.html',
|
if old_status['time_zone'] != new_status['time_zone'] and \
|
||||||
{'title': datetime.title,
|
new_status['time_zone'] != 'none':
|
||||||
'description': datetime.description,
|
modified = True
|
||||||
'status': status,
|
try:
|
||||||
'form': form})
|
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'))
|
||||||
|
|
||||||
|
return modified
|
||||||
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'))
|
|
||||||
|
|||||||
@ -63,6 +63,12 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return (action_utils.webserver_is_enabled('deluge-plinth') and
|
return (action_utils.webserver_is_enabled('deluge-plinth') and
|
||||||
@ -74,6 +80,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('deluge-web')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the Deluge module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/deluge/$', views.index, name='index'),
|
url(r'^apps/deluge/$', ConfigurationView.as_view(module_name='deluge'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -26,7 +26,7 @@ import plinth.service as service_module
|
|||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Serve introcution page"""
|
"""Serve introduction page"""
|
||||||
if not firewall.get_enabled_status():
|
if not firewall.get_enabled_status():
|
||||||
return TemplateResponse(request, 'firewall.html',
|
return TemplateResponse(request, 'firewall.html',
|
||||||
{'title': firewall.title,
|
{'title': firewall.title,
|
||||||
|
|||||||
@ -20,7 +20,6 @@ Help module for Plinth.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gettext import gettext as _
|
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
|
|||||||
@ -65,11 +65,23 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
helper.call('post', service.notify_enabled, None, True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current setting."""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.webserver_is_enabled('ikiwiki-plinth')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -23,13 +23,6 @@ from django import forms
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
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):
|
class IkiwikiCreateForm(forms.Form):
|
||||||
"""Form to create a wiki or blog."""
|
"""Form to create a wiki or blog."""
|
||||||
site_type = forms.ChoiceField(
|
site_type = forms.ChoiceField(
|
||||||
|
|||||||
@ -25,7 +25,8 @@ from . import views
|
|||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
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/manage/$', views.manage, name='manage'),
|
||||||
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', views.delete,
|
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', views.delete,
|
||||||
name='delete'),
|
name='delete'),
|
||||||
|
|||||||
@ -25,9 +25,9 @@ from django.shortcuts import redirect
|
|||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
|
|
||||||
from .forms import IkiwikiForm, IkiwikiCreateForm
|
from .forms import IkiwikiCreateForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.modules import ikiwiki
|
from plinth import views
|
||||||
|
|
||||||
|
|
||||||
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
||||||
@ -38,48 +38,14 @@ subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
|||||||
'text': ugettext_lazy('Create')}]
|
'text': ugettext_lazy('Create')}]
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class ConfigurationView(views.ConfigurationView):
|
||||||
"""Serve configuration page."""
|
"""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
|
return super().get_context_data(**kwargs)
|
||||||
|
|
||||||
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'))
|
|
||||||
|
|
||||||
|
|
||||||
def manage(request):
|
def manage(request):
|
||||||
|
|||||||
@ -21,6 +21,7 @@ Plinth module for minetest.
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
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)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the service is enabled."""
|
"""Return whether the service is enabled."""
|
||||||
return action_utils.service_is_enabled('minetest-server')
|
return action_utils.service_is_enabled('minetest-server')
|
||||||
@ -71,6 +78,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('minetest-server')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the minetest module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/minetest/$', views.index, name='index'),
|
url(r'^apps/minetest/$', ConfigurationView.as_view(module_name='minetest'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -21,6 +21,7 @@ Plinth module to configure Mumble server
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
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)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('mumble-server')
|
return action_utils.service_is_enabled('mumble-server')
|
||||||
@ -70,6 +77,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('mumble-server')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the Mumble module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/mumble/$', views.index, name='index'),
|
url(r'^apps/mumble/$', ConfigurationView.as_view(module_name='mumble'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -116,7 +116,7 @@ def _collect_setup_result(request):
|
|||||||
return_code = setup_process.poll()
|
return_code = setup_process.poll()
|
||||||
|
|
||||||
# Setup process is not complete yet
|
# Setup process is not complete yet
|
||||||
if return_code == None:
|
if return_code is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not return_code:
|
if not return_code:
|
||||||
|
|||||||
@ -69,12 +69,27 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
helper.call('post', service.notify_enabled, None, True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Return the current status"""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
output = actions.run('owncloud-setup', ['status'])
|
output = actions.run('owncloud-setup', ['status'])
|
||||||
return 'enable' in output.split()
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -21,9 +21,10 @@ URLs for the ownCloud module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/owncloud/$', views.index, name='index'),
|
url(r'^apps/owncloud/$', ConfigurationView.as_view(module_name='owncloud'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'])
|
|
||||||
@ -71,6 +71,12 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('privoxy')
|
return action_utils.service_is_enabled('privoxy')
|
||||||
@ -81,6 +87,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('privoxy')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the Privoxy module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/privoxy/$', views.index, name='index'),
|
url(r'^apps/privoxy/$', ConfigurationView.as_view(module_name='privoxy'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -21,6 +21,7 @@ Plinth module for Quassel.
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
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)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the service is enabled."""
|
"""Return whether the service is enabled."""
|
||||||
return action_utils.service_is_enabled('quasselcore')
|
return action_utils.service_is_enabled('quasselcore')
|
||||||
@ -78,6 +85,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('quasselcore')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the quassel module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/quassel/$', views.index, name='index'),
|
url(r'^apps/quassel/$', ConfigurationView.as_view(module_name='quassel'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -65,6 +65,12 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the service is enabled."""
|
"""Return whether the service is enabled."""
|
||||||
return action_utils.service_is_enabled('radicale')
|
return action_utils.service_is_enabled('radicale')
|
||||||
@ -75,6 +81,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('radicale')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the radicale module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/radicale/$', views.index, name='index'),
|
url(r'^apps/radicale/$', ConfigurationView.as_view(module_name='radicale'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -74,6 +74,12 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the service is enabled."""
|
"""Return whether the service is enabled."""
|
||||||
return action_utils.service_is_enabled('repro')
|
return action_utils.service_is_enabled('repro')
|
||||||
@ -84,6 +90,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('repro')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the repro module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/repro/$', views.index, name='index'),
|
url(r'^apps/repro/$', ConfigurationView.as_view(module_name='repro'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -20,11 +20,12 @@ Plinth module to configure reStore.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils, cfg
|
from plinth import action_utils, cfg
|
||||||
from plinth import service as service_module
|
from plinth import service as service_module
|
||||||
from plinth.utils import format_lazy
|
from plinth.utils import format_lazy
|
||||||
|
|
||||||
service = None
|
|
||||||
|
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
@ -45,6 +46,8 @@ description = [
|
|||||||
'<a href=\'/restore/\'>reStore web-interface</a>.')
|
'<a href=\'/restore/\'>reStore web-interface</a>.')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
service = None
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initialize the reStore module."""
|
"""Initialize the reStore module."""
|
||||||
@ -62,6 +65,18 @@ def setup(helper, old_version=None):
|
|||||||
helper.install(['node-restore'])
|
helper.install(['node-restore'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current settings."""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('node-restore')
|
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)
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the reStore module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/restore/$', views.index, name='index'),
|
url(r'^apps/restore/$', ConfigurationView.as_view(module_name='restore'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -68,11 +68,22 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('pre', actions.superuser_run, 'roundcube', ['setup'])
|
helper.call('pre', actions.superuser_run, 'roundcube', ['setup'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current status."""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.webserver_is_enabled('roundcube')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the Roundcube module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/roundcube/$', views.index, name='index'),
|
url(r'^apps/roundcube/$',
|
||||||
|
ConfigurationView.as_view(module_name='roundcube'), name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -21,6 +21,7 @@ Plinth module to configure Shaarli.
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
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)
|
helper.call('post', service.notify_enabled, None, True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current settings."""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.webserver_is_enabled('shaarli')
|
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)
|
||||||
|
|||||||
@ -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)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the Shaarli module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/shaarli/$', views.index, name='index'),
|
url(r'^apps/shaarli/$', ConfigurationView.as_view(module_name='shaarli'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -108,7 +108,7 @@ def _collect_config_result(request):
|
|||||||
return_code = config_process.poll()
|
return_code = config_process.poll()
|
||||||
|
|
||||||
# Config process is not complete yet
|
# Config process is not complete yet
|
||||||
if return_code == None:
|
if return_code is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
status = tor.get_status()
|
status = tor.get_status()
|
||||||
|
|||||||
@ -21,6 +21,7 @@ Plinth module to configure Transmission server
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
@ -42,6 +43,8 @@ description = [
|
|||||||
|
|
||||||
service = None
|
service = None
|
||||||
|
|
||||||
|
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Intialize the Transmission module."""
|
"""Intialize the Transmission module."""
|
||||||
@ -67,6 +70,19 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return (action_utils.service_is_enabled('transmission-daemon') and
|
return (action_utils.service_is_enabled('transmission-daemon') and
|
||||||
@ -78,6 +94,13 @@ def is_running():
|
|||||||
return action_utils.service_is_running('transmission-daemon')
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@ -22,13 +22,11 @@ Plinth module for configuring Transmission.
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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"""
|
"""Transmission configuration form"""
|
||||||
enabled = forms.BooleanField(
|
|
||||||
label=_('Enable Transmission daemon'),
|
|
||||||
required=False)
|
|
||||||
|
|
||||||
download_dir = forms.CharField(
|
download_dir = forms.CharField(
|
||||||
label=_('Download directory'),
|
label=_('Download directory'),
|
||||||
help_text=_('Directory where downloads are saved. If you change the \
|
help_text=_('Directory where downloads are saved. If you change the \
|
||||||
|
|||||||
@ -21,9 +21,10 @@ URLs for the Transmission module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from .views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/transmission/$', views.index, name='index'),
|
url(r'^apps/transmission/$',
|
||||||
|
ConfigurationView.as_view(module_name='transmission'), name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -20,81 +20,37 @@ Plinth module for configuring Transmission Server
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.template.response import TemplateResponse
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
|
|
||||||
from .forms import TransmissionForm
|
from .forms import TransmissionForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.modules import transmission
|
from plinth import views
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
|
|
||||||
|
|
||||||
|
class ConfigurationView(views.ConfigurationView):
|
||||||
def index(request):
|
|
||||||
"""Serve configuration page."""
|
"""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':
|
if old_status['download_dir'] != new_status['download_dir'] or \
|
||||||
form = TransmissionForm(request.POST, prefix='transmission')
|
old_status['rpc_username'] != new_status['rpc_username'] or \
|
||||||
# pylint: disable=E1101
|
old_status['rpc_password'] != new_status['rpc_password']:
|
||||||
if form.is_valid():
|
new_configuration = {
|
||||||
_apply_changes(request, status, form.cleaned_data)
|
'download-dir': new_status['download_dir'],
|
||||||
status = get_status()
|
'rpc-username': new_status['rpc_username'],
|
||||||
form = TransmissionForm(initial=status, prefix='transmission')
|
'rpc-password': new_status['rpc_password'],
|
||||||
else:
|
}
|
||||||
form = TransmissionForm(initial=status, prefix='transmission')
|
|
||||||
|
|
||||||
return TemplateResponse(request, 'transmission.html',
|
actions.superuser_run('transmission', ['merge-configuration'],
|
||||||
{'title': transmission.title,
|
input=json.dumps(new_configuration).encode())
|
||||||
'description': transmission.description,
|
messages.success(self.request, _('Configuration updated'))
|
||||||
'status': status,
|
return True
|
||||||
'form': form})
|
|
||||||
|
|
||||||
|
return modified
|
||||||
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'))
|
|
||||||
|
|||||||
@ -50,3 +50,20 @@ def setup(helper, old_version=None):
|
|||||||
"""Install and configure the module."""
|
"""Install and configure the module."""
|
||||||
helper.install(['unattended-upgrades'])
|
helper.install(['unattended-upgrades'])
|
||||||
helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto'])
|
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])
|
||||||
|
|||||||
@ -25,6 +25,7 @@ from . import views
|
|||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
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'),
|
url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import subprocess
|
|||||||
|
|
||||||
from .forms import ConfigureForm
|
from .forms import ConfigureForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
from plinth import views
|
||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
from plinth.modules import upgrades
|
from plinth.modules import upgrades
|
||||||
|
|
||||||
@ -39,26 +40,43 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
|||||||
LOCK_FILE = '/var/log/dpkg/lock'
|
LOCK_FILE = '/var/log/dpkg/lock'
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class ConfigurationView(views.ConfigurationView):
|
||||||
"""Serve the configuration form."""
|
"""Serve configuration page."""
|
||||||
status = get_status()
|
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':
|
return super().get_context_data(**kwargs)
|
||||||
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 TemplateResponse(request, 'upgrades_configure.html',
|
def get_template_names(self):
|
||||||
{'title': upgrades.title,
|
"""Return the list of template names for the view."""
|
||||||
'description': upgrades.description,
|
return ['upgrades_configure.html']
|
||||||
'form': form,
|
|
||||||
'subsubmenu': subsubmenu})
|
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():
|
def is_package_manager_busy():
|
||||||
@ -97,36 +115,3 @@ def upgrade(request):
|
|||||||
'subsubmenu': subsubmenu,
|
'subsubmenu': subsubmenu,
|
||||||
'is_busy': is_busy,
|
'is_busy': is_busy,
|
||||||
'log': get_log()})
|
'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'))
|
|
||||||
|
|||||||
@ -67,5 +67,3 @@ def _diagnose_ldap_entry(search_item):
|
|||||||
|
|
||||||
return [_('Check LDAP entry "{search_item}"')
|
return [_('Check LDAP entry "{search_item}"')
|
||||||
.format(search_item=search_item), result]
|
.format(search_item=search_item), result]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -79,6 +79,13 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', service.notify_enabled, None, True)
|
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():
|
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
|
||||||
@ -96,6 +103,13 @@ def get_domainname():
|
|||||||
return '.'.join(fqdn.split('.')[1:])
|
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):
|
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,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)
|
|
||||||
@ -21,8 +21,10 @@ URLs for the XMPP module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/xmpp/$', views.index, name='index'),
|
url(r'^apps/xmpp/$', ConfigurationView.as_view(module_name='xmpp'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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'))
|
|
||||||
@ -19,17 +19,101 @@
|
|||||||
Main Plinth views
|
Main Plinth views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http.response import HttpResponseRedirect
|
from django.http.response import HttpResponseRedirect
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
from django.views.generic.edit import FormView
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from . import forms
|
||||||
|
import plinth
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Serve the main index page."""
|
"""Serve the main index page."""
|
||||||
return HttpResponseRedirect(reverse('apps:index'))
|
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):
|
class SetupView(TemplateView):
|
||||||
"""View to prompt and setup applications."""
|
"""View to prompt and setup applications."""
|
||||||
template_name = 'setup.html'
|
template_name = 'setup.html'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user