diff --git a/ReyMotaAppsDj/K8S/Makefile.local b/ReyMotaAppsDj/K8S/Makefile.local index 2d871cd..248504c 100644 --- a/ReyMotaAppsDj/K8S/Makefile.local +++ b/ReyMotaAppsDj/K8S/Makefile.local @@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export REGISTRY=localhost:30500 #export REGISTRY=registry.reymota.es -export IMG_VERSION = 0.63 +export IMG_VERSION = 0.64 export IMG_NGINX_VERSION = 1.0 # limpia todo diff --git a/ReyMotaAppsDj/reymota/reymota/urls.py b/ReyMotaAppsDj/reymota/reymota/urls.py index eff3e50..3fcc446 100644 --- a/ReyMotaAppsDj/reymota/reymota/urls.py +++ b/ReyMotaAppsDj/reymota/reymota/urls.py @@ -20,6 +20,8 @@ from django.conf.urls.static import static from django.conf import settings from django.views.generic.base import TemplateView # new +from . import views + urlpatterns = [ path('obreros/', admin.site.urls), @@ -35,4 +37,7 @@ urlpatterns = [ path("", TemplateView.as_view(template_name="index.html"), name="principal"), # new + + path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'), + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/ReyMotaAppsDj/reymota/reymota/views.py b/ReyMotaAppsDj/reymota/reymota/views.py new file mode 100644 index 0000000..621798e --- /dev/null +++ b/ReyMotaAppsDj/reymota/reymota/views.py @@ -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) diff --git a/ReyMotaAppsDj/reymota/templates/ver_entorno.html b/ReyMotaAppsDj/reymota/templates/ver_entorno.html new file mode 100644 index 0000000..aad6bdc --- /dev/null +++ b/ReyMotaAppsDj/reymota/templates/ver_entorno.html @@ -0,0 +1,42 @@ +{% extends 'base.html' %} + +{% block content %} +

Variables de Entorno y Configuración

+

Nota: Asegúrate de que esta página solo esté accesible para administradores, ya que contiene información sensible.

+ +

Variables de Entorno

+ + + + + + + + + {% for key, value in entorno.items %} + + + + + {% endfor %} + +
VariableValor
{{ key }}{{ value }}
+ +

Variables de Configuración (settings.py)

+ + + + + + + + + {% for key, value in configuracion.items %} + + + + + {% endfor %} + +
VariableValor
{{ key }}{{ value }}
+{% endblock %}