email = new EmailService(); } /** * POST /api/contact/request-invite * Raccoglie i dati del lead e invia notifica a info@agile.software */ public function requestInvite(): void { // Rate limit: max 3 richieste / 10 min per IP $ip = $this->getClientIP(); $key = 'contact_' . md5($ip); $cacheFile = sys_get_temp_dir() . '/nis2_contact_' . $key; $now = time(); if (file_exists($cacheFile)) { $data = json_decode(file_get_contents($cacheFile), true); $data['requests'] = array_filter($data['requests'] ?? [], fn($t) => $t > ($now - 600)); if (count($data['requests']) >= 3) { $this->jsonError('Troppe richieste. Riprova tra qualche minuto.', 429); return; } } else { $data = ['requests' => []]; } $data['requests'][] = $now; file_put_contents($cacheFile, json_encode($data)); // Validazione input $body = $this->getRequestBody(); $nome = trim($body['nome'] ?? ''); $email = trim($body['email'] ?? ''); $azienda = trim($body['azienda'] ?? ''); $ruolo = trim($body['ruolo'] ?? ''); $dimensioni = trim($body['dimensioni'] ?? ''); $messaggio = trim($body['messaggio'] ?? ''); if (!$nome || !$email || !$azienda || !$ruolo) { $this->jsonError('Compila tutti i campi obbligatori (nome, email, azienda, ruolo).', 422); return; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->jsonError('Indirizzo email non valido.', 422); return; } // Sanitize $nome = htmlspecialchars($nome, ENT_QUOTES, 'UTF-8'); $email = htmlspecialchars($email, ENT_QUOTES, 'UTF-8'); $azienda = htmlspecialchars($azienda, ENT_QUOTES, 'UTF-8'); $ruolo = htmlspecialchars($ruolo, ENT_QUOTES, 'UTF-8'); $dimensioni = htmlspecialchars($dimensioni, ENT_QUOTES, 'UTF-8'); $messaggio = htmlspecialchars($messaggio, ENT_QUOTES, 'UTF-8'); $date = date('d/m/Y H:i'); $html = "

🛡️ Nuova richiesta codice invito — NIS2 Agile

Ricevuta il {$date}

" . ($dimensioni ? " " : "") . " " . ($messaggio ? " " : "") . "
Nome {$nome}
Email {$email}
Azienda/Studio {$azienda}
Ruolo {$ruolo}
Dimensioni {$dimensioni}
Messaggio {$messaggio}
IP {$ip}

Rispondi a questo lead generando un codice invito da: licenseExt.html

"; $sent = $this->email->send( 'info@agile.software', "🛡️ Richiesta accesso NIS2 Agile — {$nome} ({$azienda})", $html, 'noreply@agile.software' ); if (!$sent) { $this->jsonError('Errore nell\'invio della richiesta. Prova a contattarci direttamente a info@agile.software.', 500); return; } $this->jsonSuccess(null, 'Richiesta inviata! Ti contatteremo entro 24 ore con il tuo codice di accesso.'); } private function getClientIP(): string { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return trim($ips[0]); } return $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'; } }