{% extends "base.html" %} {% block title %}Panel bezpieczeństwa - Admin{% endblock %} {% block extra_css %} {% endblock %} {% block content %}

🛡️ Panel bezpieczeństwa

Monitoring alertów, audit log i zarządzanie bezpieczeństwem

{{ stats.new_alerts }}
Nowe alerty
{{ stats.locked_accounts }}
Zablokowane konta
{{ stats.users_with_2fa }}/{{ stats.total_admins }}
Admini z 2FA
{{ stats.alert_breakdown.values()|sum if stats.alert_breakdown else 0 }}
Wszystkie alerty

🔐 Mechanizmy bezpieczeństwa

Lista wszystkich aktywnych mechanizmów ochrony systemu, posortowana według ważności (5★ = krytyczne).

★★★★★ Uwierzytelnianie dwuskładnikowe (2FA) TOTP przez aplikacje mobilne (Google/Microsoft Authenticator) Aktywne
★★★★★ Ochrona przed CSRF Tokeny CSRF w formularzach (Flask-WTF) Aktywne
★★★★★ Szyfrowanie połączeń (HTTPS/TLS) Let's Encrypt SSL z automatycznym odnowieniem Aktywne
★★★★★ Hashowanie haseł Bezpieczne przechowywanie z Werkzeug (bcrypt) Aktywne
★★★★★ Ochrona przed SQL Injection Parametryzowane zapytania przez SQLAlchemy ORM Aktywne
★★★★★ Ochrona przed XSS Automatyczne escapowanie w szablonach Jinja2 Aktywne
★★★★☆ Blokowanie geograficzne (GeoIP) Blokada krajów wysokiego ryzyka: RU, CN, KP, IR, BY, SY, VE, CU {{ 'Aktywne' if geoip_enabled else 'Nieaktywne' }}
★★★★☆ Rate Limiting Ograniczenie żądań przez Flask-Limiter z Redis Aktywne
★★★★☆ Blokada konta Automatyczna blokada po 5 nieudanych logowaniach Aktywne
★★★★☆ Audit Log Śledzenie wszystkich działań administracyjnych Aktywne
★★★★☆ Bezpieczne sesje Zarządzanie sesjami przez Flask-Login Aktywne
★★★☆☆ Honeypot endpoints Wykrywanie skanerów i botów (/.env, /wp-admin, /phpmyadmin) Aktywne
★★★☆☆ Security Alerting Powiadomienia email o krytycznych zdarzeniach Aktywne
★★★☆☆ Security Logging Centralne logowanie zdarzeń bezpieczeństwa Aktywne

🌍 Statystyki GeoIP Blocking

Ostatnia aktualizacja: {{ generated_at|local_time('%H:%M:%S') }}
Auto-refresh: 5:00
{% if geoip_enabled %}
{{ geoip_stats.today }}
Zablokowanych dziś
{{ geoip_stats.this_month }}
W tym miesiącu
{{ geoip_stats.this_year }}
W tym roku
{{ geoip_stats.total }}
Od początku

Zablokowane kraje

Blokowane: 🇷🇺 Rosja, 🇨🇳 Chiny, 🇰🇵 Korea Północna, 🇮🇷 Iran, 🇧🇾 Białoruś, 🇸🇾 Syria, 🇻🇪 Wenezuela, 🇨🇺 Kuba

{% if geoip_stats.by_country %} {% for country in geoip_stats.by_country %}
{{ country.flag }} {{ country.name }} {{ country.count }}
{% endfor %} {% else %}

Brak zablokowanych połączeń

{% endif %}
{% if top_paths %}

🎯 Najczęściej atakowane ścieżki

{% for path, count in top_paths %}
{{ path }} {{ count }}
{% endfor %}
{% endif %} {% if recent_geo_blocks %}

📋 Ostatnie zablokowane próby

{% for block in recent_geo_blocks %} {% endfor %}
Data i godzina IP Kraj Ścieżka
{{ block.created_at.strftime('%d.%m.%Y %H:%M:%S') }} {{ block.ip }} {{ block.country_flag }} {{ block.country_name }} {{ block.path }}
{% endif %} {% else %}

⚠️ GeoIP Blocking jest wyłączone

Ustaw GEOIP_ENABLED=true w .env aby włączyć

{% endif %}

🚨 Alerty bezpieczeństwa

{% if alerts %} {% for alert in alerts %} {% endfor %}
Typ Ważność IP Użytkownik Status Data Akcje
{{ alert.alert_type }} {{ alert.severity }} {{ alert.ip_address or '-' }} {{ alert.user_email or '-' }} {{ alert.status }} {{ alert.created_at|local_time('%Y-%m-%d %H:%M') }} {% if alert.status == 'new' %}
{{ csrf_token() }}
{{ csrf_token() }}
{% elif alert.status == 'acknowledged' %}
{{ csrf_token() }}
{% else %} Rozwiązany {% endif %}
{% else %}

✅ Brak alertów bezpieczeństwa

{% endif %}

📋 Audit log

{% if audit_logs %} {% for log in audit_logs %} {% endfor %}
Użytkownik Akcja Encja IP Data
{{ log.user_email }} {{ log.action }} {{ log.entity_type }} {% if log.entity_id %}:{{ log.entity_id }}{% endif %} {% if log.entity_name %}
{{ log.entity_name }}{% endif %}
{{ log.ip_address or '-' }} {{ log.created_at|local_time('%Y-%m-%d %H:%M') }}
{% else %}

Brak wpisów w audit log

{% endif %}

🔒 Zablokowane konta

{% if locked_accounts %} {% for user in locked_accounts %} {% endfor %}
Email Nieudane próby Zablokowane do Akcje
{{ user.email }} {{ user.failed_login_attempts }} {{ user.locked_until|local_time('%Y-%m-%d %H:%M') }}
{{ csrf_token() }}
{% else %}

✅ Brak zablokowanych kont

{% endif %}
{% endblock %} {% block extra_js %} function showTab(tabName) { // Hide all tabs document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active')); document.querySelectorAll('.tab').forEach(el => el.classList.remove('active')); // Show selected tab document.getElementById('tab-' + tabName).classList.add('active'); event.target.classList.add('active'); } // GeoIP auto-refresh every 5 minutes let geoipCountdown = 300; function updateGeoipCountdown() { const minutes = Math.floor(geoipCountdown / 60); const seconds = geoipCountdown % 60; const countdownEl = document.getElementById('geoip-countdown'); if (countdownEl) { countdownEl.textContent = `${minutes}:${seconds.toString().padStart(2, '0')}`; } if (geoipCountdown <= 0) { refreshGeoipStats(); geoipCountdown = 300; } else { geoipCountdown--; } } async function refreshGeoipStats() { try { const response = await fetch('/api/admin/security/geoip-stats'); if (response.ok) { const data = await response.json(); // Update timestamp const timestamp = new Date(data.timestamp); const timestampEl = document.getElementById('geoip-timestamp'); if (timestampEl) { timestampEl.textContent = timestamp.toLocaleTimeString('pl-PL'); } if (data.enabled) { // Update stats const todayEl = document.getElementById('geoip-today'); const monthEl = document.getElementById('geoip-month'); const yearEl = document.getElementById('geoip-year'); const totalEl = document.getElementById('geoip-total'); if (todayEl) todayEl.textContent = data.today; if (monthEl) monthEl.textContent = data.this_month; if (yearEl) yearEl.textContent = data.this_year; if (totalEl) totalEl.textContent = data.total; // Update country breakdown const breakdownEl = document.getElementById('country-breakdown'); if (breakdownEl && data.by_country) { if (data.by_country.length > 0) { breakdownEl.innerHTML = data.by_country.map(c => `
${c.flag} ${c.name} ${c.count}
` ).join(''); } else { breakdownEl.innerHTML = '

Brak zablokowanych połączeń

'; } } } } } catch (error) { console.error('Failed to refresh GeoIP stats:', error); } } // Start countdown setInterval(updateGeoipCountdown, 1000); // Refresh when page becomes visible document.addEventListener('visibilitychange', function() { if (!document.hidden) { refreshGeoipStats(); geoipCountdown = 300; } }); {% endblock %}