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->getJsonBody(); $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 = "
Ricevuta il {$date}
| Nome | {$nome} |
| {$email} | |
| Azienda/Studio | {$azienda} |
| Ruolo | {$ruolo} |
| Dimensioni | {$dimensioni} |
| Messaggio | {$messaggio} |
| IP | {$ip} |
Rispondi a questo lead generando un codice invito da: licenseExt.html