From 824a9091c1ec0ac9f592b627285aff95ea7d3fde Mon Sep 17 00:00:00 2001 From: fonfon Date: Tue, 11 Nov 2014 15:32:40 +0100 Subject: [PATCH] use django-stronghold for authentication handling (instead of @login_required) --- plinth/__main__.py | 3 +++ plinth/modules/config/config.py | 2 -- plinth/modules/deluge/views.py | 2 -- plinth/modules/diagnostics/diagnostics.py | 3 --- plinth/modules/dynamicdns/dynamicdns.py | 4 ---- plinth/modules/firewall/firewall.py | 2 -- plinth/modules/help/help.py | 4 ++++ plinth/modules/ikiwiki/views.py | 5 ----- plinth/modules/mumble/views.py | 2 -- plinth/modules/networks/networks.py | 10 ---------- plinth/modules/owncloud/owncloud.py | 2 -- plinth/modules/packages/packages.py | 2 -- plinth/modules/pagekite/urls.py | 17 +++++++---------- plinth/modules/privoxy/views.py | 2 -- plinth/modules/roundcube/views.py | 2 -- plinth/modules/tor/tor.py | 2 -- plinth/modules/transmission/views.py | 2 -- plinth/modules/upgrades/upgrades.py | 4 ---- plinth/modules/users/urls.py | 18 +++++++----------- plinth/modules/xmpp/xmpp.py | 4 ---- 20 files changed, 21 insertions(+), 71 deletions(-) diff --git a/plinth/__main__.py b/plinth/__main__.py index 9df3a10b6..03eb4f890 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -188,6 +188,7 @@ def configure_django(): 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.messages', + 'stronghold', 'plinth'] applications += module_loader.get_modules_to_load() sessions_directory = os.path.join(cfg.data_dir, 'sessions') @@ -217,6 +218,7 @@ def configure_django(): 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'stronghold.middleware.LoginRequiredMiddleware', 'plinth.modules.first_boot.middleware.FirstBootMiddleware', ), ROOT_URLCONF='plinth.urls', @@ -224,6 +226,7 @@ def configure_django(): SESSION_ENGINE='django.contrib.sessions.backends.file', SESSION_FILE_PATH=sessions_directory, STATIC_URL='/'.join([cfg.server_dir, 'static/']).replace('//', '/'), + STRONGHOLD_PUBLIC_NAMED_URLS=('lib:login',), TEMPLATE_CONTEXT_PROCESSORS=context_processors, USE_X_FORWARDED_HOST=bool(cfg.use_x_forwarded_host)) django.setup() diff --git a/plinth/modules/config/config.py b/plinth/modules/config/config.py index 9892f8db9..5ea97bbe2 100644 --- a/plinth/modules/config/config.py +++ b/plinth/modules/config/config.py @@ -21,7 +21,6 @@ Plinth module for configuring timezone, hostname etc. from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core import validators from django.template.response import TemplateResponse from gettext import gettext as _ @@ -116,7 +115,6 @@ def init(): menu.add_urlname(_('Configure'), 'glyphicon-cog', 'config:index', 10) -@login_required def index(request): """Serve the configuration form""" status = get_status() diff --git a/plinth/modules/deluge/views.py b/plinth/modules/deluge/views.py index 6ef151d08..c73818c06 100644 --- a/plinth/modules/deluge/views.py +++ b/plinth/modules/deluge/views.py @@ -20,7 +20,6 @@ Plinth module to configure a Deluge web client. """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ @@ -30,7 +29,6 @@ from plinth import package from plinth.modules import deluge -@login_required @package.required(['deluged', 'deluge-web']) def index(request): """Serve configuration page.""" diff --git a/plinth/modules/diagnostics/diagnostics.py b/plinth/modules/diagnostics/diagnostics.py index 808a51404..01d487d0f 100644 --- a/plinth/modules/diagnostics/diagnostics.py +++ b/plinth/modules/diagnostics/diagnostics.py @@ -19,7 +19,6 @@ Plinth module for running diagnostics """ -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ @@ -35,14 +34,12 @@ def init(): "diagnostics:index", 30) -@login_required def index(request): """Serve the index page""" return TemplateResponse(request, 'diagnostics.html', {'title': _('System Diagnostics')}) -@login_required def test(request): """Run diagnostics and the output page""" output = '' diff --git a/plinth/modules/dynamicdns/dynamicdns.py b/plinth/modules/dynamicdns/dynamicdns.py index 86443ac6c..88c3b3841 100644 --- a/plinth/modules/dynamicdns/dynamicdns.py +++ b/plinth/modules/dynamicdns/dynamicdns.py @@ -17,7 +17,6 @@ from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core import validators from django.core.urlresolvers import reverse_lazy from django.template.response import TemplateResponse @@ -47,7 +46,6 @@ def init(): 'dynamicdns:index', 40) -@login_required @package.required(['ez-ipupdate']) def index(request): """Serve dynamic DNS page""" @@ -205,7 +203,6 @@ class ConfigureForm(forms.Form): LOGGER.info('no password given') -@login_required @package.required(['ez-ipupdate']) def configure(request): """Serve the configuration form""" @@ -227,7 +224,6 @@ def configure(request): 'subsubmenu': subsubmenu}) -@login_required @package.required(['ez-ipupdate']) def statuspage(request): """Serve the status page """ diff --git a/plinth/modules/firewall/firewall.py b/plinth/modules/firewall/firewall.py index b7a5d0dc6..7e1d7f3a2 100644 --- a/plinth/modules/firewall/firewall.py +++ b/plinth/modules/firewall/firewall.py @@ -19,7 +19,6 @@ Plinth module to configure a firewall """ -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import logging @@ -42,7 +41,6 @@ def init(): service_enabled.connect(on_service_enabled) -@login_required @package.required(['firewalld']) def index(request): """Serve introcution page""" diff --git a/plinth/modules/help/help.py b/plinth/modules/help/help.py index 8d843a050..3d0fa1b66 100644 --- a/plinth/modules/help/help.py +++ b/plinth/modules/help/help.py @@ -19,6 +19,7 @@ import os from gettext import gettext as _ from django.http import Http404 from django.template.response import TemplateResponse +from stronghold.decorators import public from plinth import cfg, __version__ @@ -38,12 +39,14 @@ def init(): menu.add_urlname(_('About'), 'glyphicon-star', 'help:about', 100) +@public def index(request): """Serve the index page""" return TemplateResponse(request, 'help_index.html', {'title': _('Documentation and FAQ')}) +@public def about(request): """Serve the about page""" context = { @@ -53,6 +56,7 @@ def about(request): return TemplateResponse(request, 'help_about.html', context) +@public def helppage(request, page): """Serve a help page from the 'doc' directory""" try: diff --git a/plinth/modules/ikiwiki/views.py b/plinth/modules/ikiwiki/views.py index 66e5cd8c3..4e4cc9cf4 100644 --- a/plinth/modules/ikiwiki/views.py +++ b/plinth/modules/ikiwiki/views.py @@ -20,7 +20,6 @@ Plinth module for configuring ikiwiki """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.template.response import TemplateResponse @@ -45,7 +44,6 @@ def on_install(): actions.superuser_run('ikiwiki', ['setup']) -@login_required @package.required(['ikiwiki', 'gcc', 'libc6-dev', @@ -98,7 +96,6 @@ def _apply_changes(request, old_status, new_status): messages.info(request, _('Setting unchanged')) -@login_required def manage(request): """Manage existing wikis and blogs.""" sites = actions.run('ikiwiki', ['get-sites']).split('\n') @@ -110,7 +107,6 @@ def manage(request): 'sites': sites}) -@login_required def create(request): """Form to create a wiki or blog.""" form = None @@ -161,7 +157,6 @@ def _create_blog(request, name, admin_name, admin_password): messages.error(request, _('Could not create blog: %s') % err) -@login_required def delete(request, name): """Handle deleting wikis/blogs, showing a confirmation dialog first. diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py index afddb4262..fbb5e57f3 100644 --- a/plinth/modules/mumble/views.py +++ b/plinth/modules/mumble/views.py @@ -20,7 +20,6 @@ Plinth module for configuring Mumble Server """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import logging @@ -38,7 +37,6 @@ def on_install(): mumble.service.notify_enabled(None, True) -@login_required @package.required(['mumble-server'], on_install=on_install) def index(request): """Serve configuration page.""" diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index 96d92ccee..f18eb7c56 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -16,7 +16,6 @@ # from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.template.response import TemplateResponse @@ -45,7 +44,6 @@ def init(): menu.add_urlname(_('Networks'), 'glyphicon-signal', 'networks:index', 18) -@login_required @package.required(['network-manager']) def index(request): """Show connection list.""" @@ -57,7 +55,6 @@ def index(request): 'connections': connections}) -@login_required def edit(request, uuid): """Serve connection editing form.""" try: @@ -148,7 +145,6 @@ def edit(request, uuid): 'form': form}) -@login_required def activate(request, uuid): """Activate the connection.""" try: @@ -166,7 +162,6 @@ def activate(request, uuid): return redirect(reverse_lazy('networks:index')) -@login_required def deactivate(request, uuid): """Deactivate the connection.""" try: @@ -180,7 +175,6 @@ def deactivate(request, uuid): return redirect(reverse_lazy('networks:index')) -@login_required def scan(request): """Show a list of nearby visible Wi-Fi access points.""" access_points = network.wifi_scan() @@ -190,7 +184,6 @@ def scan(request): 'access_points': access_points}) -@login_required def add(request): """Serve the connection type selection form.""" form = None @@ -211,7 +204,6 @@ def add(request): 'form': form}) -@login_required def add_ethernet(request): """Serve ethernet connection create form.""" form = None @@ -237,7 +229,6 @@ def add_ethernet(request): 'form': form}) -@login_required def add_wifi(request, ssid=None): """Serve wifi connection create form.""" form = None @@ -280,7 +271,6 @@ def add_wifi(request, ssid=None): 'form': form}) -@login_required def delete(request, uuid): """Handle deleting connections, showing a confirmation dialog first. diff --git a/plinth/modules/owncloud/owncloud.py b/plinth/modules/owncloud/owncloud.py index 3f378c96b..d62770616 100644 --- a/plinth/modules/owncloud/owncloud.py +++ b/plinth/modules/owncloud/owncloud.py @@ -17,7 +17,6 @@ from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ @@ -47,7 +46,6 @@ def init(): is_external=True, enabled=status['enabled']) -@login_required @package.required(['postgresql', 'php5-pgsql', 'owncloud']) def index(request): """Serve the ownCloud configuration page""" diff --git a/plinth/modules/packages/packages.py b/plinth/modules/packages/packages.py index 9368b66f1..ce92dff64 100644 --- a/plinth/modules/packages/packages.py +++ b/plinth/modules/packages/packages.py @@ -17,7 +17,6 @@ from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import os @@ -60,7 +59,6 @@ def init(): menu.add_urlname('Package Manager', 'glyphicon-gift', 'packages:index', 20) -@login_required def index(request): """Serve the form""" status = get_status() diff --git a/plinth/modules/pagekite/urls.py b/plinth/modules/pagekite/urls.py index 32c13548d..e88cd839f 100644 --- a/plinth/modules/pagekite/urls.py +++ b/plinth/modules/pagekite/urls.py @@ -20,7 +20,6 @@ URLs for the PageKite module """ from django.conf.urls import patterns, url -from django.contrib.auth.decorators import login_required from .views import StandardServiceView, CustomServiceView, ConfigurationView, \ DeleteServiceView, index @@ -28,15 +27,13 @@ from .views import StandardServiceView, CustomServiceView, ConfigurationView, \ urlpatterns = patterns( # pylint: disable-msg=C0103 'plinth.modules.pagekite.views', - url(r'^apps/pagekite/$', login_required(index), name='index'), - url(r'^apps/pagekite/configure/$', - login_required(ConfigurationView.as_view()), name='configure'), - url(r'^apps/pagekite/services/standard$', - login_required(StandardServiceView.as_view()), + url(r'^apps/pagekite/$', index, name='index'), + url(r'^apps/pagekite/configure/$', ConfigurationView.as_view(), + name='configure'), + url(r'^apps/pagekite/services/standard$', StandardServiceView.as_view(), name='standard-services'), - url(r'^apps/pagekite/services/custom$', - login_required(CustomServiceView.as_view()), name='custom-services'), - url(r'^apps/pagekite/services/custom/delete$', - login_required(DeleteServiceView.as_view()), + url(r'^apps/pagekite/services/custom$', CustomServiceView.as_view(), + name='custom-services'), + url(r'^apps/pagekite/services/custom/delete$', DeleteServiceView.as_view(), name='delete-custom-service'), ) diff --git a/plinth/modules/privoxy/views.py b/plinth/modules/privoxy/views.py index ae5198a00..27e948136 100644 --- a/plinth/modules/privoxy/views.py +++ b/plinth/modules/privoxy/views.py @@ -20,7 +20,6 @@ Plinth module for configuring Privoxy Server. """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import logging @@ -38,7 +37,6 @@ def on_install(): actions.superuser_run('privoxy', ['setup']) -@login_required @package.required(['privoxy'], on_install=on_install) def index(request): """Serve configuration page.""" diff --git a/plinth/modules/roundcube/views.py b/plinth/modules/roundcube/views.py index eca875e98..9a7d8a162 100644 --- a/plinth/modules/roundcube/views.py +++ b/plinth/modules/roundcube/views.py @@ -20,7 +20,6 @@ Plinth module for configuring Roundcube. """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import logging @@ -42,7 +41,6 @@ def on_install(): actions.superuser_run('roundcube', ['setup']) -@login_required @package.required(['sqlite3', 'roundcube', 'roundcube-sqlite3'], before_install=before_install, on_install=on_install) def index(request): diff --git a/plinth/modules/tor/tor.py b/plinth/modules/tor/tor.py index 37089fb0b..1ee106c21 100644 --- a/plinth/modules/tor/tor.py +++ b/plinth/modules/tor/tor.py @@ -21,7 +21,6 @@ Plinth module for configuring Tor from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ @@ -43,7 +42,6 @@ def init(): menu.add_urlname('Tor', 'glyphicon-eye-close', 'tor:index', 30) -@login_required @package.required(['tor']) def index(request): """Service the index page""" diff --git a/plinth/modules/transmission/views.py b/plinth/modules/transmission/views.py index 5111d900d..ab3fbd529 100644 --- a/plinth/modules/transmission/views.py +++ b/plinth/modules/transmission/views.py @@ -20,7 +20,6 @@ Plinth module for configuring Transmission Server """ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from gettext import gettext as _ import json @@ -42,7 +41,6 @@ def on_install(): actions.superuser_run('transmission', ['enable']) -@login_required @package.required(['transmission-daemon'], on_install=on_install) def index(request): """Serve configuration page.""" diff --git a/plinth/modules/upgrades/upgrades.py b/plinth/modules/upgrades/upgrades.py index 7a67759ac..6a3b3e6b3 100644 --- a/plinth/modules/upgrades/upgrades.py +++ b/plinth/modules/upgrades/upgrades.py @@ -21,7 +21,6 @@ Plinth module for upgrades from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse_lazy from django.template.response import TemplateResponse from django.views.decorators.http import require_POST @@ -45,7 +44,6 @@ def init(): 'upgrades:index', 21) -@login_required @package.required(['unattended-upgrades']) def index(request): """Serve the index page.""" @@ -54,7 +52,6 @@ def index(request): 'subsubmenu': subsubmenu}) -@login_required @require_POST @package.required(['unattended-upgrades']) def run(request): @@ -84,7 +81,6 @@ run once per day. It will attempt to perform any package upgrades that are \ available.')) -@login_required @package.required(['unattended-upgrades']) def configure(request): """Serve the configuration form.""" diff --git a/plinth/modules/users/urls.py b/plinth/modules/users/urls.py index 7f7c38246..a305ad129 100644 --- a/plinth/modules/users/urls.py +++ b/plinth/modules/users/urls.py @@ -20,7 +20,6 @@ URLs for the Users module """ from django.conf.urls import patterns, url -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse_lazy from . import views @@ -28,17 +27,14 @@ from . import views urlpatterns = patterns( '', - url(r'^sys/users/$', login_required(views.UserList.as_view()), - name='index'), - url(r'^sys/users/create/$', login_required(views.UserCreate.as_view()), - name='create'), - url(r'^sys/users/(?P[\w.@+-]+)/edit/$', - login_required(views.UserUpdate.as_view()), name='edit'), - url(r'^sys/users/(?P[\w.@+-]+)/delete/$', - login_required(views.UserDelete.as_view()), name='delete'), + url(r'^sys/users/$', views.UserList.as_view(), name='index'), + url(r'^sys/users/create/$', views.UserCreate.as_view(), name='create'), + url(r'^sys/users/(?P[\w.@+-]+)/edit/$', views.UserUpdate.as_view(), + name='edit'), + url(r'^sys/users/(?P[\w.@+-]+)/delete/$', views.UserDelete.as_view(), + name='delete'), url(r'^sys/users/(?P[\w.@+-]+)/change_password/$', - login_required(views.UserChangePassword.as_view()), - name='change_password'), + views.UserChangePassword.as_view(), name='change_password'), # Add Django's login/logout urls url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'), diff --git a/plinth/modules/xmpp/xmpp.py b/plinth/modules/xmpp/xmpp.py index f44104299..121551469 100644 --- a/plinth/modules/xmpp/xmpp.py +++ b/plinth/modules/xmpp/xmpp.py @@ -17,7 +17,6 @@ from django import forms from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse_lazy from django.template.response import TemplateResponse from gettext import gettext as _ @@ -75,7 +74,6 @@ def on_install(): actions.superuser_run('xmpp', ['setup']) -@login_required @package.required(['jwchat', 'ejabberd'], before_install=before_install, on_install=on_install) @@ -98,7 +96,6 @@ the XMPP service')) allowed to register an account through an XMPP client')) -@login_required def configure(request): """Serve the configuration form""" status = get_status() @@ -196,7 +193,6 @@ class RegisterForm(forms.Form): # pylint: disable-msg=W0232 for vhost in vhosts) -@login_required def register(request): """Serve the registration form.""" form = None