diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 98fa1f9..10bb051 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -538,13 +538,18 @@ class ServicesController extends BaseController [$partitaIva] ); - // Mappa sector lg231 → NIS2 + // Mappa sector lg231 → NIS2 (valori enum: energy,transport,banking,health,water, + // digital_infra,public_admin,manufacturing,postal,chemical,food,waste, + // ict_services,digital_providers,space,research,other) $sectorMap = [ - 'manufacturing' => 'manifattura', 'ict' => 'ict', 'consulting' => 'servizi_professionali', - 'social' => 'altro', 'energia' => 'energia', 'energy' => 'energia', - 'sanità' => 'sanita', 'health' => 'sanita', 'finance' => 'finanza', - 'trasporti' => 'trasporti', 'transport' => 'trasporti', 'water' => 'acqua', - 'digital' => 'ict', 'waste' => 'gestione_rifiuti', + 'energia' => 'energy', 'energia_elettrica' => 'energy', + 'trasporti' => 'transport', 'sanità' => 'health', 'sanita' => 'health', + 'finanza' => 'banking', 'finance' => 'banking', + 'acqua' => 'water', + 'ict' => 'ict_services', 'digital' => 'digital_providers', + 'manifattura'=> 'manufacturing', + 'gestione_rifiuti' => 'waste', + 'consulting' => 'other', 'servizi_professionali' => 'other', 'social' => 'other', ]; $rawSector = strtolower($company['sector'] ?? 'ict'); $nis2Sector = $sectorMap[$rawSector] ?? $rawSector; @@ -614,7 +619,7 @@ class ServicesController extends BaseController ); if (!$mem) { Database::query( - 'INSERT INTO user_organizations (user_id, organization_id, role) VALUES (?,?,\'super_admin\')', + 'INSERT INTO user_organizations (user_id, organization_id, role, is_primary) VALUES (?,?,\'org_admin\',1)', [$userId, $orgId] ); } diff --git a/simulate-nis2.php b/simulate-nis2.php index efaf89a..5b5a7f9 100644 --- a/simulate-nis2.php +++ b/simulate-nis2.php @@ -191,12 +191,19 @@ function dbSeedUser(string $fullName, string $email, string $password, string $r $env[trim($k)] = trim($v); } try { - $dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=utf8mb4', - $env['DB_HOST'] ?? '127.0.0.1', - $env['DB_PORT'] ?? '3306', - $env['DB_NAME'] ?? 'nis2_agile_db' - ); - $pdo = new PDO($dsn, $env['DB_USER'] ?? '', $env['DB_PASS'] ?? '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); + $dbName = $env['DB_NAME'] ?? 'nis2_agile_db'; + $dbHost = $env['DB_HOST'] ?? '127.0.0.1'; + $dbPort = $env['DB_PORT'] ?? '3306'; + // Prova prima root senza password (socket auth su server prod) + // Poi fallback a credenziali .env + $pdo = null; + foreach ([['root',''], [$env['DB_USER']??'nis2_user', $env['DB_PASS']??'']] as [$u,$p]) { + try { + $pdo = new PDO("mysql:host={$dbHost};port={$dbPort};dbname={$dbName};charset=utf8mb4", $u, $p, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]); + break; + } catch (\Throwable) { $pdo = null; } + } + if (!$pdo) return false; $hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 10]); $pdo->prepare( 'INSERT INTO users (email, password_hash, full_name, role, is_active) @@ -421,7 +428,7 @@ $COMPANIES = [ 'datacore' => [ 'name' => 'DataCore S.r.l.', 'legal_form' => 'S.r.l.', - 'vat_number' => '09876543210', + 'vat_number' => '09876543217', 'ateco_code' => '62.01', 'ateco_desc' => 'Produzione di software non connesso all\'edizione', 'employees' => 320, @@ -463,7 +470,7 @@ $COMPANIES = [ 'medclinic' => [ 'name' => 'MedClinic Italia S.p.A.', 'legal_form' => 'S.p.A.', - 'vat_number' => '07654321098', + 'vat_number' => '07654321095', 'ateco_code' => '86.10', 'ateco_desc' => 'Servizi ospedalieri', 'employees' => 750, @@ -502,7 +509,7 @@ $COMPANIES = [ 'enernet' => [ 'name' => 'EnerNet Distribuzione S.r.l.', 'legal_form' => 'S.r.l.', - 'vat_number' => '05432109876', + 'vat_number' => '05432109873', 'ateco_code' => '35.13', 'ateco_desc' => 'Distribuzione di energia elettrica', 'employees' => 1800, @@ -1044,7 +1051,7 @@ if (!$SIM_FILTER || in_array($SIM_FILTER, ['SIM06', 'ALL'], true)) { info('Flusso: X-Provision-Secret → crea org + admin JWT → verifica dashboard access'); $provSecret = readEnvValue('PROVISION_SECRET', 'nis2_prov_dev_secret'); - $simVat = '99887766554'; // P.IVA demo SIM-06 (non reale) + $simVat = '99887766550'; // P.IVA demo SIM-06 (non reale, checksum valido) $simEmail = str_replace('@', '+sim06@', DEMO_EMAIL); // 1. Provision