| @ -0,0 +1,31 @@ | |||||
| import os | |||||
| from django.conf import settings | |||||
| from django.contrib.auth.decorators import user_passes_test | |||||
| from django.shortcuts import render | |||||
| from django.http import HttpResponseForbidden | |||||
| @user_passes_test(lambda u: u.is_staff) | |||||
| def ver_variables_entorno(request): | |||||
| if not settings.DEBUG: | |||||
| return HttpResponseForbidden("Acceso prohibido") | |||||
| # Variables a excluir por motivos de seguridad | |||||
| variables_excluidas = {'SECRET_KEY', 'DATABASES', 'EMAIL_HOST_PASSWORD', 'API_KEY'} | |||||
| # Obtiene todas las variables de entorno | |||||
| entorno = {key: os.getenv(key) for key in os.environ.keys() if key not in variables_excluidas} | |||||
| # Obtiene todas las variables de settings excluyendo las confidenciales | |||||
| configuracion = { | |||||
| key: getattr(settings, key) for key in dir(settings) | |||||
| if key.isupper() and key not in variables_excluidas | |||||
| } | |||||
| # Combina ambas en un solo diccionario | |||||
| contexto = { | |||||
| 'entorno': entorno, | |||||
| 'configuracion': configuracion | |||||
| } | |||||
| return render(request, 'ver_entorno.html', contexto) | |||||
| @ -0,0 +1,42 @@ | |||||
| {% extends 'base.html' %} | |||||
| {% block content %} | |||||
| <h2>Variables de Entorno y Configuración</h2> | |||||
| <p><strong>Nota:</strong> Asegúrate de que esta página solo esté accesible para administradores, ya que contiene información sensible.</p> | |||||
| <h3>Variables de Entorno</h3> | |||||
| <table class="table table-striped"> | |||||
| <thead> | |||||
| <tr> | |||||
| <th>Variable</th> | |||||
| <th>Valor</th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| {% for key, value in entorno.items %} | |||||
| <tr> | |||||
| <td>{{ key }}</td> | |||||
| <td>{{ value }}</td> | |||||
| </tr> | |||||
| {% endfor %} | |||||
| </tbody> | |||||
| </table> | |||||
| <h3>Variables de Configuración (settings.py)</h3> | |||||
| <table class="table table-striped"> | |||||
| <thead> | |||||
| <tr> | |||||
| <th>Variable</th> | |||||
| <th>Valor</th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| {% for key, value in configuracion.items %} | |||||
| <tr> | |||||
| <td>{{ key }}</td> | |||||
| <td>{{ value }}</td> | |||||
| </tr> | |||||
| {% endfor %} | |||||
| </tbody> | |||||
| </table> | |||||
| {% endblock %} | |||||