Änderungen am Email Report + Aufbewahrungsdauer implementiert
This commit is contained in:
@@ -70,6 +70,11 @@ LOG_MAX_SIZE_MB=50
|
|||||||
# Ban-History Datei (protokolliert alle Sperren & Entsperrungen dauerhaft)
|
# Ban-History Datei (protokolliert alle Sperren & Entsperrungen dauerhaft)
|
||||||
BAN_HISTORY_FILE="/var/log/adguard-shield-bans.log"
|
BAN_HISTORY_FILE="/var/log/adguard-shield-bans.log"
|
||||||
|
|
||||||
|
# Maximale Aufbewahrungsdauer der Ban-History in Tagen
|
||||||
|
# 0 = unbegrenzt (niemals automatisch löschen)
|
||||||
|
# Beispiel: 90 = Einträge älter als 90 Tage werden beim nächsten Report entfernt
|
||||||
|
BAN_HISTORY_RETENTION_DAYS=0
|
||||||
|
|
||||||
# --- Benachrichtigungen (optional) ---
|
# --- Benachrichtigungen (optional) ---
|
||||||
# Aktiviert Benachrichtigungen bei Sperren/Entsperrungen
|
# Aktiviert Benachrichtigungen bei Sperren/Entsperrungen
|
||||||
NOTIFY_ENABLED=false
|
NOTIFY_ENABLED=false
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ Wiederholungstäter werden wie bei fail2ban stufenweise länger gesperrt. Wird e
|
|||||||
| `LOG_LEVEL` | `INFO` | Log-Level: `DEBUG`, `INFO`, `WARN`, `ERROR` |
|
| `LOG_LEVEL` | `INFO` | Log-Level: `DEBUG`, `INFO`, `WARN`, `ERROR` |
|
||||||
| `LOG_MAX_SIZE_MB` | `50` | Max. Log-Größe bevor rotiert wird |
|
| `LOG_MAX_SIZE_MB` | `50` | Max. Log-Größe bevor rotiert wird |
|
||||||
| `BAN_HISTORY_FILE` | `/var/log/adguard-shield-bans.log` | Datei für die Ban-History (alle Sperren/Entsperrungen) |
|
| `BAN_HISTORY_FILE` | `/var/log/adguard-shield-bans.log` | Datei für die Ban-History (alle Sperren/Entsperrungen) |
|
||||||
|
| `BAN_HISTORY_RETENTION_DAYS` | `0` | Aufbewahrungsdauer der Ban-History in Tagen. `0` = unbegrenzt (niemals löschen). Alte Einträge werden beim nächsten Report automatisch entfernt. |
|
||||||
|
|
||||||
### Benachrichtigungen
|
### Benachrichtigungen
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ REPORT_EMAIL_FROM="${REPORT_EMAIL_FROM:-adguard-shield@$(hostname -f 2>/dev/null
|
|||||||
REPORT_FORMAT="${REPORT_FORMAT:-html}"
|
REPORT_FORMAT="${REPORT_FORMAT:-html}"
|
||||||
REPORT_MAIL_CMD="${REPORT_MAIL_CMD:-msmtp}"
|
REPORT_MAIL_CMD="${REPORT_MAIL_CMD:-msmtp}"
|
||||||
BAN_HISTORY_FILE="${BAN_HISTORY_FILE:-/var/log/adguard-shield-bans.log}"
|
BAN_HISTORY_FILE="${BAN_HISTORY_FILE:-/var/log/adguard-shield-bans.log}"
|
||||||
|
BAN_HISTORY_RETENTION_DAYS="${BAN_HISTORY_RETENTION_DAYS:-0}"
|
||||||
STATE_DIR="${STATE_DIR:-/var/lib/adguard-shield}"
|
STATE_DIR="${STATE_DIR:-/var/lib/adguard-shield}"
|
||||||
TEMPLATE_DIR="${SCRIPT_DIR}/templates"
|
TEMPLATE_DIR="${SCRIPT_DIR}/templates"
|
||||||
|
|
||||||
@@ -146,8 +147,51 @@ filter_history_by_period() {
|
|||||||
done < "$BAN_HISTORY_FILE"
|
done < "$BAN_HISTORY_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ─── Ban-History bereinigen ────────────────────────────────────────────────────
|
||||||
|
# Entfernt Einträge älter als BAN_HISTORY_RETENTION_DAYS (0 = deaktiviert)
|
||||||
|
cleanup_ban_history() {
|
||||||
|
[[ ! -f "$BAN_HISTORY_FILE" ]] && return
|
||||||
|
[[ "$BAN_HISTORY_RETENTION_DAYS" == "0" || -z "$BAN_HISTORY_RETENTION_DAYS" ]] && return
|
||||||
|
|
||||||
|
local cutoff_epoch
|
||||||
|
cutoff_epoch=$(date -d "-${BAN_HISTORY_RETENTION_DAYS} days" '+%s' 2>/dev/null)
|
||||||
|
[[ -z "$cutoff_epoch" ]] && return
|
||||||
|
|
||||||
|
local tmp_file="${BAN_HISTORY_FILE}.tmp"
|
||||||
|
local removed=0
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
# Header-Zeilen immer beibehalten
|
||||||
|
if [[ "$line" =~ ^#.*$ || -z "$line" ]]; then
|
||||||
|
echo "$line"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
local timestamp
|
||||||
|
timestamp=$(echo "$line" | awk -F'|' '{print $1}' | xargs)
|
||||||
|
local line_epoch
|
||||||
|
line_epoch=$(date -d "$timestamp" '+%s' 2>/dev/null || echo "0")
|
||||||
|
|
||||||
|
if [[ "$line_epoch" -ge "$cutoff_epoch" ]]; then
|
||||||
|
echo "$line"
|
||||||
|
else
|
||||||
|
((removed++)) || true
|
||||||
|
fi
|
||||||
|
done < "$BAN_HISTORY_FILE" > "$tmp_file"
|
||||||
|
|
||||||
|
if [[ $removed -gt 0 ]]; then
|
||||||
|
mv "$tmp_file" "$BAN_HISTORY_FILE"
|
||||||
|
log "INFO" "Ban-History bereinigt: $removed Einträge älter als ${BAN_HISTORY_RETENTION_DAYS} Tage entfernt"
|
||||||
|
else
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ─── Statistiken berechnen ────────────────────────────────────────────────────
|
# ─── Statistiken berechnen ────────────────────────────────────────────────────
|
||||||
calculate_stats() {
|
calculate_stats() {
|
||||||
|
# Ban-History bereinigen (falls Retention konfiguriert)
|
||||||
|
cleanup_ban_history
|
||||||
|
|
||||||
local start_epoch
|
local start_epoch
|
||||||
start_epoch=$(get_period_start_epoch)
|
start_epoch=$(get_period_start_epoch)
|
||||||
|
|
||||||
@@ -794,9 +838,11 @@ send_test_email() {
|
|||||||
<p style="color:#6c757d;font-size:13px;">Ab jetzt kannst du den automatischen Versand aktivieren mit:<br><code>sudo $(basename "$0") install</code></p>
|
<p style="color:#6c757d;font-size:13px;">Ab jetzt kannst du den automatischen Versand aktivieren mit:<br><code>sudo $(basename "$0") install</code></p>
|
||||||
</div>
|
</div>
|
||||||
<div style="background:#f8f9fc;padding:20px;text-align:center;font-size:12px;color:#6c757d;border-top:1px solid #e8ecf1;">
|
<div style="background:#f8f9fc;padding:20px;text-align:center;font-size:12px;color:#6c757d;border-top:1px solid #e8ecf1;">
|
||||||
<a href="https://www.patrick-asmus.de" style="color:#0f3460;text-decoration:none;font-weight:600;">patrick-asmus.de</a>
|
<a href="https://www.patrick-asmus.de" style="color:#0f3460;text-decoration:none;font-weight:600;">Patrick-Asmus.DE</a>
|
||||||
<span style="margin:0 8px;color:#ced4da;">|</span>
|
<span style="margin:0 8px;color:#ced4da;">|</span>
|
||||||
<a href="https://git.techniverse.net/scriptos/adguard-shield.git" style="color:#0f3460;text-decoration:none;font-weight:600;">Git Repository</a>
|
<a href="https://www.cleveradmin.de" style="color:#0f3460;text-decoration:none;font-weight:600;">CleverAdmin.DE</a>
|
||||||
|
<span style="margin:0 8px;color:#ced4da;">|</span>
|
||||||
|
<a href="https://git.techniverse.net/scriptos/adguard-shield.git" style="color:#0f3460;text-decoration:none;font-weight:600;">AdGuard Shield auf Gitea</a>
|
||||||
<div style="margin-top:8px;font-size:11px;color:#adb5bd;">AdGuard Shield v${VERSION} · ${hostname}</div>
|
<div style="margin-top:8px;font-size:11px;color:#adb5bd;">AdGuard Shield v${VERSION} · ${hostname}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -829,6 +875,7 @@ TESTHTML
|
|||||||
AdGuard Shield v${VERSION} · ${hostname}
|
AdGuard Shield v${VERSION} · ${hostname}
|
||||||
|
|
||||||
Web: https://www.patrick-asmus.de
|
Web: https://www.patrick-asmus.de
|
||||||
|
Blog: https://www.cleveradmin.de
|
||||||
Repo: https://git.techniverse.net/scriptos/adguard-shield.git
|
Repo: https://git.techniverse.net/scriptos/adguard-shield.git
|
||||||
═══════════════════════════════════════════════════════════════
|
═══════════════════════════════════════════════════════════════
|
||||||
TESTTXT
|
TESTTXT
|
||||||
|
|||||||
@@ -305,9 +305,11 @@
|
|||||||
Dieser Report wurde automatisch von <strong>AdGuard Shield</strong> generiert.<br>
|
Dieser Report wurde automatisch von <strong>AdGuard Shield</strong> generiert.<br>
|
||||||
Generiert am: {{REPORT_DATE}}
|
Generiert am: {{REPORT_DATE}}
|
||||||
<div class="links">
|
<div class="links">
|
||||||
<a href="https://www.patrick-asmus.de">patrick-asmus.de</a>
|
<a href="https://www.patrick-asmus.de">Patrick-Asmus.DE</a>
|
||||||
<span class="separator">|</span>
|
<span class="separator">|</span>
|
||||||
<a href="https://git.techniverse.net/scriptos/adguard-shield.git">Git Repository</a>
|
<a href="https://www.cleveradmin.de">CleverAdmin.DE</a>
|
||||||
|
<span class="separator">|</span>
|
||||||
|
<a href="https://git.techniverse.net/scriptos/adguard-shield.git">AdGuard Shield auf Gitea</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="version-tag">AdGuard Shield v{{VERSION}} · {{HOSTNAME}}</div>
|
<div class="version-tag">AdGuard Shield v{{VERSION}} · {{HOSTNAME}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -55,5 +55,6 @@
|
|||||||
AdGuard Shield v{{VERSION}}
|
AdGuard Shield v{{VERSION}}
|
||||||
|
|
||||||
Web: https://www.patrick-asmus.de
|
Web: https://www.patrick-asmus.de
|
||||||
|
Blog: https://www.cleveradmin.de
|
||||||
Repo: https://git.techniverse.net/scriptos/adguard-shield.git
|
Repo: https://git.techniverse.net/scriptos/adguard-shield.git
|
||||||
═══════════════════════════════════════════════════════════════
|
═══════════════════════════════════════════════════════════════
|
||||||
|
|||||||
Reference in New Issue
Block a user