From b8fff6c752bcc872bb22ae4dbdb44eb17531aba3 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 16 May 2019 17:43:44 +0200 Subject: [PATCH 2/2] debian: add InternalIpMiddleware (#29149) It sets DEBUG=True when current request IP is in settings.INTERNAL_IPS. --- debian/debian_config_common.py | 1 + hobo/middleware/debug.py | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 hobo/middleware/debug.py diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index 60e437e..304c106 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -364,6 +364,7 @@ if 'authentic2' not in INSTALLED_APPS: MIDDLEWARE_CLASSES = ( 'hobo.middleware.utils.StoreRequestMiddleware', 'hobo.middleware.xforwardedfor.XForwardedForMiddleware', + 'hobo.middleware.debug.InternalIPMiddleware', ) + MIDDLEWARE_CLASSES MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ( diff --git a/hobo/middleware/debug.py b/hobo/middleware/debug.py new file mode 100644 index 0000000..c23a601 --- /dev/null +++ b/hobo/middleware/debug.py @@ -0,0 +1,35 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2019 Entr'ouvert +# +# 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 . + +from django.conf import settings + + +class InternalIPMiddleware(object): + def process_request(self, request): + internal_ips = getattr(settings, 'INTERNAL_IPS', []) + try: + if request.META['REMOTE_ADDR'] in internal_ips: + self.old_value = settings.DEBUG + settings.DEBUG = True + except TypeError: + pass + return None + + def process_response(self, request, response): + if hasattr(self, 'old_value'): + settings.DEBUG = self.old_value + del self.old_value + return response -- 2.20.1