Просмотр исходного кода

feat: Enhance navbar with notification dropdown and update update scripts for proxy support

Manuel 1 год назад
Родитель
Сommit
d697fb46d6
4 измененных файлов с 128 добавлено и 25 удалено
  1. 5 5
      templates/base.html
  2. 84 3
      templates/components/navbar.html
  3. 29 14
      utils/updateSquid.py
  4. 10 3
      utils/updateSquidStats.py

+ 5 - 5
templates/base.html

@@ -17,11 +17,11 @@
 </head>
 <body class="overflow-x-hidden overflow-auto">
     <!-- Barra de navegación común -->
-    {% include 'components/navbar.html' %}
-
-    <main>
-        {% block content %}{% endblock %}  <!-- Contenido específico de cada página -->
-    </main>
+    <div class="relative">
+        {% include 'components/navbar.html' %}
+        <!-- Dropdown de notificaciones -->
+        <div class="absolute top-4 right-8 z-50">
+            <div class="relative inline-block text-left">
     
     <!-- Scripts de Flowbite (UI components) -->
     <script src="{{ url_for('static', filename='src/flowbite.min.js') }}"></script>

+ 84 - 3
templates/components/navbar.html

@@ -50,11 +50,92 @@
       </a>
     </div>
 
-    <!-- Action Buttons -->
+    <!-- Notificaciones y Action Buttons -->
     <div
-      class="navbar-actions"
-      x-data="{ showSquidModal: false, showWebModal: false }"
+      class="navbar-actions flex items-center gap-4"
+      x-data="{ showSquidModal: false, showWebModal: false, showNotif: false }"
     >
+      <!-- Dropdown Notificaciones -->
+      <div class="relative" x-data="{ open: false }">
+        <button
+          @click="open = !open"
+          class="relative inline-flex items-center justify-center w-12 h-12 rounded-xl bg-gradient-to-br from-slate-50 to-slate-100 border border-slate-200 shadow-sm hover:shadow-md hover:from-blue-50 hover:to-indigo-50 hover:border-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 transition-all duration-200 group"
+          aria-label="Notificaciones"
+        >
+          <i class="fas fa-bell text-slate-600 group-hover:text-blue-600 transition-colors duration-200"></i>
+          <span class="sr-only">Notificaciones</span>
+          <span class="absolute -top-2 -right-2 flex items-center justify-center w-5 h-5 bg-gradient-to-r from-red-500 to-red-600 text-white text-xs font-semibold rounded-full border-2 border-white shadow-lg">
+            3
+          </span>
+        </button>
+        <div
+          x-show="open"
+          @click.away="open = false"
+          @keydown.escape.window="open = false"
+          x-transition:enter="transition ease-out duration-200"
+          x-transition:enter-start="opacity-0 scale-95"
+          x-transition:enter-end="opacity-100 scale-100"
+          x-transition:leave="transition ease-in duration-150"
+          x-transition:leave-start="opacity-100 scale-100"
+          x-transition:leave-end="opacity-0 scale-95"
+          class="origin-top-right absolute right-0 mt-2 w-80 rounded-lg shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50"
+          style="display: none;"
+        >
+          <div class="py-2 px-4 border-b border-gray-200 flex items-center justify-between">
+            <span class="font-semibold text-gray-800">Notificaciones</span>
+            <button
+              @click="open = false"
+              class="text-gray-400 hover:text-gray-600 focus:outline-none"
+            >
+              <i class="fas fa-times"></i>
+            </button>
+          </div>
+          <ul class="max-h-72 overflow-y-auto divide-y divide-gray-100">
+            <li class="px-4 py-3 flex items-start hover:bg-gray-50 cursor-pointer">
+              <span class="inline-flex items-center justify-center h-8 w-8 rounded-full bg-blue-100 text-blue-600 mr-3">
+                <i class="fas fa-info-circle"></i>
+              </span>
+              <div class="flex-1">
+                <p class="text-sm text-gray-700">
+                  Actualización de Squid completada exitosamente.
+                </p>
+                <span class="text-xs text-gray-400">Hace 2 minutos</span>
+              </div>
+            </li>
+            <li class="px-4 py-3 flex items-start hover:bg-gray-50 cursor-pointer">
+              <span class="inline-flex items-center justify-center h-8 w-8 rounded-full bg-green-100 text-green-600 mr-3">
+                <i class="fas fa-check-circle"></i>
+              </span>
+              <div class="flex-1">
+                <p class="text-sm text-gray-700">
+                  Nuevo reporte generado y disponible en la sección de reportes.
+                </p>
+                <span class="text-xs text-gray-400">Hace 10 minutos</span>
+              </div>
+            </li>
+            <li class="px-4 py-3 flex items-start hover:bg-gray-50 cursor-pointer">
+              <span class="inline-flex items-center justify-center h-8 w-8 rounded-full bg-red-100 text-red-600 mr-3">
+                <i class="fas fa-exclamation-triangle"></i>
+              </span>
+              <div class="flex-1">
+                <p class="text-sm text-gray-700">
+                  Error al actualizar la lista de sitios bloqueados.
+                </p>
+                <span class="text-xs text-gray-400">Hace 1 hora</span>
+              </div>
+            </li>
+          </ul>
+          <div class="py-2 px-4 text-center border-t border-gray-200">
+            <a
+              href="#"
+              class="text-sm text-blue-600 hover:underline"
+              >Ver todas las notificaciones</a
+            >
+          </div>
+        </div>
+      </div>
+
+      <!-- Botones de Acción -->
       <button
         @click="showSquidModal = true"
         class="action-btn action-btn-primary"

+ 29 - 14
utils/updateSquid.py

@@ -13,45 +13,60 @@ def update_squid():
             print('Sistema operativo no compatible', 'error')
             return False
 
-        version_response = subprocess.run(
-            ['curl', '-s', 'https://api.github.com/repos/cuza/squid/releases/latest'],
-            capture_output=True, text=True
+        proxy_url = os.getenv("HTTP_PROXY", "")
+        env = os.environ.copy()
+        if proxy_url:
+            env["http_proxy"] = proxy_url
+            env["https_proxy"] = proxy_url
+
+        version_info = subprocess.run(
+            ['wget', '-qO-', 'https://api.github.com/repos/cuza/squid/releases/latest'],
+            capture_output=True, text=True, env=env
         )
-
-        if version_response.returncode != 0:
-            print('Error obteniendo última versión', 'error')
+        if version_info.returncode != 0:
+            print('Error obteniendo información de versión', 'error')
             return False
 
         try:
-            latest_version = json.loads(version_response.stdout)['tag_name']
+            latest_version = json.loads(version_info.stdout)['tag_name']
         except (json.JSONDecodeError, KeyError):
             print('Error procesando versión', 'error')
             return False
 
-        # Create name package
         package_name = f"squid_{latest_version}-{os_id}-{codename}_amd64.deb"
         download_url = f"https://github.com/cuza/squid/releases/download/{latest_version}/{package_name}"
 
+        # Verificar y descargar el paquete
         check_package = subprocess.run(
             ['wget', '--spider', download_url],
-            capture_output=True, text=True
+            capture_output=True, text=True, env=env
         )
-
         if check_package.returncode != 0:
             print(f'Paquete no disponible para {os_id.capitalize()} {codename.capitalize()}', 'error')
             return False
 
-        download = subprocess.run(['wget', download_url, '-O', f'/tmp/{package_name}'])
-        subprocess.run(['apt', 'update'])
-
+        download = subprocess.run(
+            ['wget', download_url, '-O', f'/tmp/{package_name}'],
+            capture_output=True, text=True, env=env
+        )
         if download.returncode != 0:
             print('Error descargando el paquete', 'error')
             return False
 
+        # Configurar proxy para apt si es necesario
+        apt_env = env.copy()
+        if proxy_url:
+            apt_conf = '/etc/apt/apt.conf.d/95proxies'
+            with open(apt_conf, 'w') as f:
+                f.write(f'Acquire::http::Proxy "{proxy_url}";\n')
+                f.write(f'Acquire::https::Proxy "{proxy_url}";\n')
+
+        subprocess.run(['apt', 'update'], env=apt_env)
+
         install = subprocess.run(['dpkg', '-i', '--force-overwrite', f'/tmp/{package_name}'])
         if install.returncode != 0:
             print('Error instalando el paquete', 'error')
-            subprocess.run(['apt', 'install', '-f', '-y'])
+            subprocess.run(['apt', 'install', '-f', '-y'], env=apt_env)
 
         subprocess.run(['cp', f'{os.getcwd()}/./utils/squid', '/etc/init.d/'])
         subprocess.run(['chmod', '+x', '/etc/init.d/squid'])

+ 10 - 3
utils/updateSquidStats.py

@@ -1,10 +1,17 @@
 import subprocess
+import os
 
 def updateSquidStats():
     try:
+        proxy_url = os.getenv("HTTP_PROXY", "")
+        env = os.environ.copy()
+        if proxy_url:
+            env["http_proxy"] = proxy_url
+            env["https_proxy"] = proxy_url
+
         script_install = subprocess.run(
-            ['wget', '-O' , '/tmp/install.sh', 'https://github.com/kaelthasmanu/SquidStats/releases/download/0.2/install.sh'],
-            capture_output=True, text=True
+            ['wget', '-O' , '/tmp/install.sh', 'https://github.com/kaelthasmanu/SquidStats/releases/download/0.2/install.sh'] + (['-e', f'http_proxy={proxy_url}'] if proxy_url else []),
+            capture_output=True, text=True, env=env
         )
 
         if script_install.returncode != 0:
@@ -14,7 +21,7 @@ def updateSquidStats():
         subprocess.run(
             ['chmod', '+x', '/tmp/install.sh']
         )
-        subprocess.run(['bash' , '/tmp/install.sh', '--update'])
+        subprocess.run(['bash' , '/tmp/install.sh', '--update'], env=env)
         return True
 
     except Exception as e: