From 0ab5e45413bc72da5cbb48cd1c9b304492ae3a92 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Mon, 17 Nov 2025 18:03:30 +0000 Subject: [PATCH] Add database tables for storing detection, training, and whitelist information Create SQL schemas for `detections`, `training_history`, and `whitelist` tables to manage IDS data, model training logs, and trusted IPs. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: f93295bb-74e9-4b67-b3d7-05437cb8c23f Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/MkBJZ0L --- .replit | 4 +++ database-schema/create_detections.sql | 35 +++++++++++++++++++++ database-schema/create_training_history.sql | 30 ++++++++++++++++++ database-schema/create_whitelist.sql | 29 +++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 database-schema/create_detections.sql create mode 100644 database-schema/create_training_history.sql create mode 100644 database-schema/create_whitelist.sql diff --git a/.replit b/.replit index af7007c..e303f0e 100644 --- a/.replit +++ b/.replit @@ -14,6 +14,10 @@ run = ["npm", "run", "start"] localPort = 5000 externalPort = 80 +[[ports]] +localPort = 45045 +externalPort = 3000 + [env] PORT = "5000" diff --git a/database-schema/create_detections.sql b/database-schema/create_detections.sql new file mode 100644 index 0000000..6bfcc03 --- /dev/null +++ b/database-schema/create_detections.sql @@ -0,0 +1,35 @@ +-- ========================================================= +-- SCHEMA: Tabella detections per IDS anomalie +-- ========================================================= +-- Memorizza IP rilevati come pericolosi dal ML +-- ========================================================= + +-- Drop tabella se esiste (solo per ambiente di sviluppo) +DROP TABLE IF EXISTS detections CASCADE; + +-- Crea tabella detections +CREATE TABLE detections ( + id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(), + source_ip TEXT NOT NULL, + risk_score DECIMAL(5, 2) NOT NULL, + confidence DECIMAL(5, 2) NOT NULL, + anomaly_type TEXT NOT NULL, + reason TEXT, + log_count INTEGER NOT NULL, + first_seen TIMESTAMP NOT NULL, + last_seen TIMESTAMP NOT NULL, + blocked BOOLEAN NOT NULL DEFAULT FALSE, + blocked_at TIMESTAMP, + detected_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +-- Indici per performance +CREATE INDEX IF NOT EXISTS detection_source_ip_idx ON detections(source_ip); +CREATE INDEX IF NOT EXISTS risk_score_idx ON detections(risk_score); +CREATE INDEX IF NOT EXISTS detected_at_idx ON detections(detected_at); + +-- Commento tabella +COMMENT ON TABLE detections IS 'IP pericolosi rilevati dal sistema ML (Isolation Forest)'; + +-- Verifica +SELECT 'Tabella detections creata con successo!' AS status; diff --git a/database-schema/create_training_history.sql b/database-schema/create_training_history.sql new file mode 100644 index 0000000..1725500 --- /dev/null +++ b/database-schema/create_training_history.sql @@ -0,0 +1,30 @@ +-- ========================================================= +-- SCHEMA: Tabella training_history per storico ML +-- ========================================================= +-- Memorizza storia training modelli ML +-- ========================================================= + +-- Drop tabella se esiste (solo per ambiente di sviluppo) +DROP TABLE IF EXISTS training_history CASCADE; + +-- Crea tabella training_history +CREATE TABLE training_history ( + id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(), + model_version TEXT NOT NULL, + records_processed INTEGER NOT NULL, + features_count INTEGER NOT NULL, + accuracy DECIMAL(5, 2), + training_duration INTEGER, + status TEXT NOT NULL, + notes TEXT, + trained_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +-- Indici per performance +CREATE INDEX IF NOT EXISTS trained_at_idx ON training_history(trained_at); + +-- Commento tabella +COMMENT ON TABLE training_history IS 'Storico training modelli ML per IDS'; + +-- Verifica +SELECT 'Tabella training_history creata con successo!' AS status; diff --git a/database-schema/create_whitelist.sql b/database-schema/create_whitelist.sql new file mode 100644 index 0000000..9ee8509 --- /dev/null +++ b/database-schema/create_whitelist.sql @@ -0,0 +1,29 @@ +-- ========================================================= +-- SCHEMA: Tabella whitelist per IP fidati +-- ========================================================= +-- IP che non devono mai essere bloccati +-- ========================================================= + +-- Drop tabella se esiste (solo per ambiente di sviluppo) +DROP TABLE IF EXISTS whitelist CASCADE; + +-- Crea tabella whitelist +CREATE TABLE whitelist ( + id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(), + ip_address TEXT NOT NULL UNIQUE, + comment TEXT, + reason TEXT, + created_by TEXT, + active BOOLEAN NOT NULL DEFAULT TRUE, + created_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +-- Indici per performance +CREATE INDEX IF NOT EXISTS whitelist_ip_idx ON whitelist(ip_address); +CREATE INDEX IF NOT EXISTS whitelist_active_idx ON whitelist(active); + +-- Commento tabella +COMMENT ON TABLE whitelist IS 'IP fidati che non devono mai essere bloccati dal sistema'; + +-- Verifica +SELECT 'Tabella whitelist creata con successo!' AS status;