Browse Source

Ver entorno y settings

politica
Celestino Rey 1 year ago
parent
commit
447c09b3b8
4 changed files with 79 additions and 1 deletions
  1. +1
    -1
      ReyMotaAppsDj/K8S/Makefile.local
  2. +5
    -0
      ReyMotaAppsDj/reymota/reymota/urls.py
  3. +31
    -0
      ReyMotaAppsDj/reymota/reymota/views.py
  4. +42
    -0
      ReyMotaAppsDj/reymota/templates/ver_entorno.html

+ 1
- 1
ReyMotaAppsDj/K8S/Makefile.local View File

@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
export REGISTRY=localhost:30500 export REGISTRY=localhost:30500
#export REGISTRY=registry.reymota.es #export REGISTRY=registry.reymota.es
export IMG_VERSION = 0.63
export IMG_VERSION = 0.64
export IMG_NGINX_VERSION = 1.0 export IMG_NGINX_VERSION = 1.0
# limpia todo # limpia todo


+ 5
- 0
ReyMotaAppsDj/reymota/reymota/urls.py View File

@ -20,6 +20,8 @@ from django.conf.urls.static import static
from django.conf import settings from django.conf import settings
from django.views.generic.base import TemplateView # new from django.views.generic.base import TemplateView # new
from . import views
urlpatterns = [ urlpatterns = [
path('obreros/', admin.site.urls), path('obreros/', admin.site.urls),
@ -35,4 +37,7 @@ urlpatterns = [
path("", TemplateView.as_view(template_name="index.html"), path("", TemplateView.as_view(template_name="index.html"),
name="principal"), # new name="principal"), # new
path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

+ 31
- 0
ReyMotaAppsDj/reymota/reymota/views.py View File

@ -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)

+ 42
- 0
ReyMotaAppsDj/reymota/templates/ver_entorno.html View File

@ -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 %}

Loading…
Cancel
Save