Implement automated detection cleanup after 48 hours and IP unblocking after 2 hours using systemd timers and Python scripts. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 3809a8a0-8dd5-4b5a-9e32-9e075dab335e Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/L6QSDnx
65 lines
1.9 KiB
Bash
65 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# =========================================================
|
|
# IDS - Setup Cleanup Timer
|
|
# =========================================================
|
|
# Installa e avvia il timer systemd per cleanup automatico
|
|
#
|
|
# Uso: sudo ./deployment/setup_cleanup_timer.sh
|
|
# =========================================================
|
|
|
|
set -e
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "❌ Questo script deve essere eseguito come root (sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo "🔧 Setup IDS Cleanup Timer..."
|
|
echo ""
|
|
|
|
# 1. Crea directory log
|
|
echo "[1/6] Creazione directory log..."
|
|
mkdir -p /var/log/ids
|
|
chmod 755 /var/log/ids
|
|
|
|
# 2. Rendi eseguibili gli script
|
|
echo "[2/6] Permessi esecuzione script..."
|
|
chmod +x "$SCRIPT_DIR/run_cleanup.sh"
|
|
chmod +x "$SCRIPT_DIR/../python_ml/cleanup_detections.py"
|
|
|
|
# 3. Copia service file
|
|
echo "[3/6] Installazione service file..."
|
|
cp "$SCRIPT_DIR/systemd/ids-cleanup.service" /etc/systemd/system/
|
|
cp "$SCRIPT_DIR/systemd/ids-cleanup.timer" /etc/systemd/system/
|
|
|
|
# 4. Reload systemd
|
|
echo "[4/6] Reload systemd daemon..."
|
|
systemctl daemon-reload
|
|
|
|
# 5. Abilita timer
|
|
echo "[5/6] Abilitazione timer..."
|
|
systemctl enable ids-cleanup.timer
|
|
|
|
# 6. Avvia timer
|
|
echo "[6/6] Avvio timer..."
|
|
systemctl start ids-cleanup.timer
|
|
|
|
echo ""
|
|
echo "✅ Cleanup timer installato e avviato con successo!"
|
|
echo ""
|
|
echo "📊 Status:"
|
|
systemctl status ids-cleanup.timer --no-pager -l
|
|
echo ""
|
|
echo "📅 Prossima esecuzione:"
|
|
systemctl list-timers ids-cleanup.timer --no-pager
|
|
echo ""
|
|
echo "💡 Comandi utili:"
|
|
echo " - Test manuale: sudo ./deployment/run_cleanup.sh"
|
|
echo " - Esegui ora: sudo systemctl start ids-cleanup.service"
|
|
echo " - Stato timer: sudo systemctl status ids-cleanup.timer"
|
|
echo " - Log cleanup: tail -f /var/log/ids/cleanup.log"
|
|
echo " - Disabilita timer: sudo systemctl stop ids-cleanup.timer && sudo systemctl disable ids-cleanup.timer"
|
|
echo ""
|