From 2f075a4e3d5044e0e3f08c68e42715d485036566 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 4 Nov 2024 08:54:02 +0000 Subject: [PATCH] Ver variables de entorno. --- JugarAlPadel/K8S/Makefile.local | 2 +- .../K8S/env-prod-configmap-local.yaml | 2 +- JugarAlPadel/gestion_reservas/eventos/urls.py | 3 ++ .../gestion_reservas/eventos/views.py | 19 ++++++++- .../gestion_reservas/settings.py | 3 +- .../templates/ver_entorno.html | 42 +++++++++++++++++++ 6 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 JugarAlPadel/gestion_reservas/templates/ver_entorno.html diff --git a/JugarAlPadel/K8S/Makefile.local b/JugarAlPadel/K8S/Makefile.local index 8850122..4d095a7 100644 --- a/JugarAlPadel/K8S/Makefile.local +++ b/JugarAlPadel/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.92 +export IMG_VERSION = 0.95 export IMG_NGINX_VERSION = 2.4 # limpia todo diff --git a/JugarAlPadel/K8S/env-prod-configmap-local.yaml b/JugarAlPadel/K8S/env-prod-configmap-local.yaml index 065ab18..bda857f 100644 --- a/JugarAlPadel/K8S/env-prod-configmap-local.yaml +++ b/JugarAlPadel/K8S/env-prod-configmap-local.yaml @@ -1,6 +1,6 @@ apiVersion: v1 data: - DEBUG: "True" + DEBUG: "False" ENTORNO: "Pruebas" DJANGO_ALLOWED_HOSTS: "jugaralpadel.ddns.net vmcluster reymota.es k8s-server localhost 127.0.0.1 [::1]" CSRF_TRUSTED_ORIGINS: "https://jugaralpadel.ddns.net http://vmcluster" diff --git a/JugarAlPadel/gestion_reservas/eventos/urls.py b/JugarAlPadel/gestion_reservas/eventos/urls.py index 0d6fa22..bccf950 100644 --- a/JugarAlPadel/gestion_reservas/eventos/urls.py +++ b/JugarAlPadel/gestion_reservas/eventos/urls.py @@ -15,4 +15,7 @@ urlpatterns = [ path('reservar//', views.reservar_evento, name='reservar_evento'), + + path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'), + ] diff --git a/JugarAlPadel/gestion_reservas/eventos/views.py b/JugarAlPadel/gestion_reservas/eventos/views.py index 3d485f7..932c578 100644 --- a/JugarAlPadel/gestion_reservas/eventos/views.py +++ b/JugarAlPadel/gestion_reservas/eventos/views.py @@ -1,14 +1,31 @@ +import os from django.shortcuts import render, get_object_or_404, redirect from django.contrib.auth.decorators import login_required, user_passes_test from django.contrib import messages from django.core.mail import EmailMultiAlternatives from django.conf import settings from django.template.loader import render_to_string +from django.http import HttpResponseForbidden from .models import Evento, Reserva, ListaEspera, ReyMotaUser from .forms import ListaEsperaForm, EventoForm -# import random + +@user_passes_test(lambda u: u.is_staff) +def ver_variables_entorno(request): + # Obtiene todas las variables de entorno + entorno = {key: os.getenv(key) for key in os.environ.keys()} + + # Obtiene todas las variables de settings que no son métodos + configuracion = {key: getattr(settings, key) for key in dir(settings) if key.isupper()} + + # Combina ambas en un solo diccionario + contexto = { + 'entorno': entorno, + 'configuracion': configuracion + } + + return render(request, 'ver_entorno.html', contexto) @login_required diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py index 09a66bd..d5eba7d 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py @@ -167,7 +167,8 @@ EMAIL_HOST_PASSWORD = 'oxdkclbtggewxhqc' # Es mejor usar una contraseña de apl DEFAULT_FROM_EMAIL = 'jugaralpadelentreamigos@gmail.com' # Dirección del administrador -ADMIN_EMAIL = 'king.bernard.b@gmail.com' +# ADMIN_EMAIL = 'king.bernard.b@gmail.com' +ADMIN_EMAIL = '' # El tiempo de validez del enlace para resetear la contraseña (por defecto es de 3 días) PASSWORD_RESET_TIMEOUT = 86400 # 1 día en segundos diff --git a/JugarAlPadel/gestion_reservas/templates/ver_entorno.html b/JugarAlPadel/gestion_reservas/templates/ver_entorno.html new file mode 100644 index 0000000..aad6bdc --- /dev/null +++ b/JugarAlPadel/gestion_reservas/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 %}