secubox-openwrt/package/secubox/secubox-app-mitmproxy/files/usr/sbin/waf-stats-update
CyberMind-FR 1bbd345cee refactor(luci): Mass KissTheme UI rework across all LuCI apps
Convert 90+ LuCI view files from legacy cbi-button-* classes to
KissTheme kiss-btn-* classes for consistent dark theme styling.

Pattern conversions applied:
- cbi-button-positive → kiss-btn-green
- cbi-button-negative/remove → kiss-btn-red
- cbi-button-apply → kiss-btn-cyan
- cbi-button-action → kiss-btn-blue
- cbi-button (plain) → kiss-btn

Also replaced hardcoded colors (#080, #c00, #888, etc.) with
CSS variables (--kiss-green, --kiss-red, --kiss-muted, etc.)
for proper dark theme compatibility.

Apps updated include: ai-gateway, auth-guardian, bandwidth-manager,
cloner, config-advisor, crowdsec-dashboard, dns-provider, exposure,
glances, haproxy, hexojs, iot-guard, jellyfin, ksm-manager,
mac-guardian, magicmirror2, master-link, meshname-dns, metablogizer,
metabolizer, mqtt-bridge, netdata-dashboard, picobrew, routes-status,
secubox-admin, secubox-mirror, secubox-p2p, secubox-security-threats,
service-registry, simplex, streamlit, system-hub, tor-shield,
traffic-shaper, vhost-manager, vortex-dns, vortex-firewall,
webradio, wireguard-dashboard, zigbee2mqtt, zkp, and more.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-12 11:09:34 +01:00

61 lines
2.1 KiB
Bash

#!/bin/sh
# WAF Stats Updater - writes to /tmp/secubox/waf-stats.json
# Run via cron every minute: * * * * * /usr/sbin/waf-stats-update
CACHE_DIR="/tmp/secubox"
CACHE_FILE="$CACHE_DIR/waf-stats.json"
WAF_DATA="/srv/mitmproxy-in"
mkdir -p "$CACHE_DIR"
# Check if mitmproxy containers are running
running=0
(lxc-info -n mitmproxy-in -s 2>/dev/null | grep -q "RUNNING") && running=1
# Count threats today
threats_today=0
today=$(date -u +%Y-%m-%d)
if [ -f "$WAF_DATA/threats.log" ]; then
threats_today=$(grep -c "\"timestamp\": \"$today" "$WAF_DATA/threats.log" 2>/dev/null)
[ -z "$threats_today" ] && threats_today=0
fi
# Count autobans
autobans_total=0
autobans_today=0
if [ -f "$WAF_DATA/autoban-processed.log" ]; then
autobans_total=$(wc -l < "$WAF_DATA/autoban-processed.log" 2>/dev/null | tr -d ' ')
[ -z "$autobans_total" ] && autobans_total=0
autobans_today=$(grep -c "^$(date +%Y-%m-%d)" "$WAF_DATA/autoban-processed.log" 2>/dev/null)
[ -z "$autobans_today" ] && autobans_today=0
fi
# Pending
autobans_pending=0
if [ -f "$WAF_DATA/autoban-requests.log" ] && [ -s "$WAF_DATA/autoban-requests.log" ]; then
autobans_pending=$(wc -l < "$WAF_DATA/autoban-requests.log" 2>/dev/null | tr -d ' ')
[ -z "$autobans_pending" ] && autobans_pending=0
fi
# UCI settings
autoban_enabled=$(uci -q get mitmproxy.autoban.enabled || echo 0)
autoban_sensitivity=$(uci -q get mitmproxy.autoban.sensitivity || echo moderate)
autoban_duration=$(uci -q get mitmproxy.autoban.ban_duration || echo 4h)
mode=$(uci -q get mitmproxy.main.mode || echo upstream)
# Write cache with compact JSON (no newlines in values)
cat > "$CACHE_FILE" << EOF
{
"running": $([ "$running" = "1" ] && echo "true" || echo "false"),
"threats_today": $threats_today,
"autobans_today": $autobans_today,
"autobans_total": $autobans_total,
"autobans_pending": $autobans_pending,
"autoban_enabled": $([ "$autoban_enabled" = "1" ] && echo "true" || echo "false"),
"autoban_sensitivity": "$autoban_sensitivity",
"autoban_duration": "$autoban_duration",
"mode": "$mode",
"updated": "$(date -Iseconds)"
}
EOF