false, 'error' => 'Méthode non autorisée. Utilisez POST.'], JSON_UNESCAPED_UNICODE); exit; } /* Anti-spam : champ piège « website » rempli par les robots → on ignore sans le dire */ $honeypot = trim((string) ($_POST['website'] ?? '')); if ($honeypot !== '') { http_response_code(201); echo json_encode(['ok' => true, 'id' => null, 'message' => 'Merci.'], JSON_UNESCAPED_UNICODE); exit; } /* Lecture du corps : JSON ou formulaire classique */ $rawBody = file_get_contents('php://input'); $ct = $_SERVER['CONTENT_TYPE'] ?? ''; $data = $_POST; if (stripos($ct, 'application/json') !== false) { $decoded = json_decode($rawBody === false ? '' : $rawBody, true); if (!is_array($decoded)) { http_response_code(400); echo json_encode(['ok' => false, 'error' => 'JSON invalide.'], JSON_UNESCAPED_UNICODE); exit; } $data = $decoded; } /* Champs acceptés, avec des alias tolérés */ $fields = [ 'app' => strval($data['app'] ?? $data['application'] ?? ''), 'version' => strval($data['version'] ?? ''), 'type' => strval($data['type'] ?? $data['category'] ?? 'bug'), 'title' => strval($data['title'] ?? $data['subject'] ?? ''), 'description' => strval($data['description'] ?? $data['message'] ?? $data['details'] ?? ''), 'email' => strval($data['email'] ?? $data['contact'] ?? ''), 'system_info' => strval($data['system_info'] ?? $data['system'] ?? $data['hardware'] ?? ''), 'logs' => strval($data['logs'] ?? $data['log'] ?? $data['journal'] ?? ''), ]; $title = mb_substr(trim($fields['title']), 0, 200); $description = mb_substr(trim($fields['description']), 0, 20000); $logs = mb_substr(trim($fields['logs']), 0, 150000); $app = mb_substr(trim($fields['app']), 0, 100); $version = mb_substr(trim($fields['version']), 0, 100); $email = mb_substr(trim($fields['email']), 0, 200); $systemInfo = mb_substr(trim($fields['system_info']), 0, 4000); $type = mb_substr(trim($fields['type']), 0, 50); /* Un signalement doit contenir au moins un peu de contenu utile */ if ($title === '' && $description === '' && $logs === '') { http_response_code(400); echo json_encode([ 'ok' => false, 'error' => 'Contenu vide : envoyez au moins un titre, une description ou des logs.', ], JSON_UNESCAPED_UNICODE); exit; } /* Anti-flood léger : 25 signalements / heure / IP */ try { $pdo = fws_bugs_db(); } catch (Throwable $e) { error_log('[fws-bugs] ' . $e->getMessage()); http_response_code(500); echo json_encode(['ok' => false, 'error' => 'Erreur interne de la base de données.'], JSON_UNESCAPED_UNICODE); exit; } $ip = fws_bugs_client_ip(); if (fws_bugs_count_recent_for_ip($pdo, $ip) >= 25) { http_response_code(429); echo json_encode(['ok' => false, 'error' => 'Trop de signalements depuis cette adresse, réessayez plus tard.'], JSON_UNESCAPED_UNICODE); exit; } /* Insertion — l'id repart de 1 et saute ceux déjà pris */ try { $bugId = fws_bugs_next_id($pdo, 'bug_reports'); $stmt = $pdo->prepare( 'INSERT INTO bug_reports (id, app, version, type, title, description, email, system_info, logs, ip, user_agent) VALUES (:id, :app, :version, :type, :title, :description, :email, :system_info, :logs, :ip, :ua)' ); $stmt->execute([ ':id' => $bugId, ':app' => $app, ':version' => $version, ':type' => $type !== '' ? $type : 'bug', ':title' => $title, ':description' => $description, ':email' => $email, ':system_info' => $systemInfo, ':logs' => $logs, ':ip' => $ip, ':ua' => mb_substr((string) ($_SERVER['HTTP_USER_AGENT'] ?? ''), 0, 300), ]); } catch (Throwable $e) { error_log('[fws-bugs] insertion : ' . $e->getMessage()); http_response_code(500); echo json_encode(['ok' => false, 'error' => 'Erreur interne lors de l\'enregistrement.'], JSON_UNESCAPED_UNICODE); exit; } http_response_code(201); echo json_encode([ 'ok' => true, 'id' => $bugId, 'message' => 'Signalement enregistré. Merci !', ], JSON_UNESCAPED_UNICODE); /* Envoie la réponse au client tout de suite ; la notif Discord suit en arrière-plan. */ if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } else { flush(); } /* Notification Discord (best-effort : n'affecte jamais la réponse de l'API) */ try { $discord = fws_bugs_discord_notify([ 'id' => $bugId, 'app' => $app, 'version' => $version, 'type' => $type !== '' ? $type : 'bug', 'title' => $title, 'description' => $description, 'email' => $email, 'system_info' => $systemInfo, 'logs' => $logs, 'status' => 'nouveau', ]); if (is_array($discord) && !empty($discord['thread_id'])) { fws_bugs_save_discord_info($pdo, $bugId, (string) $discord['thread_id'], (string) ($discord['post_url'] ?? '')); } } catch (Throwable $e) { error_log('[fws-bugs] discord : ' . $e->getMessage()); } exit; /* ──────────────────────────────────────────── */ function render_test_page(): void { $base = htmlspecialchars(strtok($_SERVER['REQUEST_URI'] ?? '/api/bugs.php', '?'), ENT_QUOTES, 'UTF-8'); ?> Envoyer un signalement — FWS Linux

🐞 Envoyer un signalement

Page de test — le vrai envoi est fait par l'application (curl / script) sur POST .