From 62c3a2b2389b5593e05948d9c507485faf3769b5 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Mon, 17 Nov 2025 16:48:22 +0000 Subject: [PATCH] Update application to use environment variables and force IPv4 Modify syslog_parser.py to load environment variables from .env file and force IPv4 connection to the database. Update replit.md to reflect recent fixes and workflow changes. Increment version in version.json. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 727221f9-ad54-4498-b2e4-e87a951b4308 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/c9ITWqD --- .env.example | 3 ++- .replit | 4 ++++ python_ml/syslog_parser.py | 6 +++++- replit.md | 20 +++++++++++++++++++- version.json | 10 ++++++++-- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 1750ff7..e91b599 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ # Database PostgreSQL -PGHOST=localhost +# IMPORTANTE: Usa 127.0.0.1 invece di localhost per forzare IPv4 (evita problemi con ::1) +PGHOST=127.0.0.1 PGPORT=5432 PGDATABASE=ids_database PGUSER=ids_user diff --git a/.replit b/.replit index af7007c..aa82ec7 100644 --- a/.replit +++ b/.replit @@ -14,6 +14,10 @@ run = ["npm", "run", "start"] localPort = 5000 externalPort = 80 +[[ports]] +localPort = 42789 +externalPort = 3000 + [env] PORT = "5000" diff --git a/python_ml/syslog_parser.py b/python_ml/syslog_parser.py index ccf4e0c..8de6b15 100644 --- a/python_ml/syslog_parser.py +++ b/python_ml/syslog_parser.py @@ -183,9 +183,13 @@ class SyslogParser: def main(): """Main entry point""" + # Carica variabili d'ambiente da .env + load_dotenv("/opt/ids/.env") + # Configurazione database da environment + # IMPORTANTE: Usa 127.0.0.1 invece di localhost per forzare IPv4 db_config = { - 'host': os.getenv('PGHOST', 'localhost'), + 'host': os.getenv('PGHOST', '127.0.0.1'), 'port': os.getenv('PGPORT', '5432'), 'database': os.getenv('PGDATABASE', 'ids_database'), 'user': os.getenv('PGUSER', 'ids_user'), diff --git a/replit.md b/replit.md index 197488f..76ca838 100644 --- a/replit.md +++ b/replit.md @@ -36,11 +36,29 @@ Sistema di rilevamento intrusioni per router MikroTik basato su Machine Learning ## Workflow -1. **Log Collection**: Router → Syslog → PostgreSQL `network_logs` +1. **Log Collection**: Router → Syslog (UDP:514) → RSyslog → syslog_parser.py → PostgreSQL `network_logs` 2. **Training**: Python ML estrae 25 feature → Isolation Forest 3. **Detection**: Analisi real-time → Scoring 0-100 → Classificazione 4. **Auto-Block**: IP critico (>=80) → API REST → Tutti i router (parallelo) +## Fix Recenti (Novembre 2025) + +### PostgreSQL Authentication Fix +- **Problema**: Password authentication failed (SCRAM-SHA-256 vs MD5) +- **Soluzione**: `deployment/fix_postgresql_auth.sh` configura SCRAM-SHA-256 in pg_hba.conf +- **Password encryption**: ALTER SYSTEM SET password_encryption = 'scram-sha-256' +- **Utente ricreato**: DROP + CREATE con formato SCRAM corretto + +### IPv4 Force Fix +- **Problema**: syslog_parser si connetteva a ::1 (IPv6) invece di 127.0.0.1 (IPv4) +- **Soluzione**: PGHOST=127.0.0.1 in .env (NON usare localhost) +- **Parser**: load_dotenv() carica .env automaticamente + +### Git Ownership Fix +- **Problema**: dubious ownership error in /opt/ids +- **Soluzione**: `deployment/fix_git_ownership.sh` aggiunge safe.directory +- **Update script**: `deployment/update_from_git.sh` ora esegue git come utente ids + ## File Importanti ### Python ML Backend diff --git a/version.json b/version.json index 9dc8417..5142e26 100644 --- a/version.json +++ b/version.json @@ -1,7 +1,13 @@ { - "version": "1.0.4", - "lastUpdate": "2025-11-17T16:05:06.972Z", + "version": "1.0.5", + "lastUpdate": "2025-11-17T16:47:34.637Z", "changelog": [ + { + "version": "1.0.5", + "date": "2025-11-17", + "type": "patch", + "description": "Deployment automatico v1.0.5" + }, { "version": "1.0.4", "date": "2025-11-17",