4c61b7f276
- Add missing MovieController::remove/markWatched (routes called undefined methods) - Fix linkPartner(): commit() was unreachable after an early return, so partner linking was never actually persisted in the DB - Add missing removeMovie/markWatched functions in app.js - webhook.php now verifies a GitHub HMAC signature before running git reset --hard - Move TMDB API key server-side via a new TmdbController proxy (tmdb-search/tmdb-details) instead of exposing it in client-side JS Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
1.2 KiB
PHP
Executable File
34 lines
1.2 KiB
PHP
Executable File
<?php
|
|
// webhook.php
|
|
// Déclenché par un webhook GitHub (push sur main) pour resynchroniser le serveur.
|
|
|
|
chdir(__DIR__);
|
|
require_once __DIR__ . '/config/database.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
http_response_code(405);
|
|
exit('Method not allowed');
|
|
}
|
|
|
|
$database = new Database();
|
|
$secret = $database->webhook_secret;
|
|
|
|
$payload = file_get_contents('php://input');
|
|
$signatureHeader = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '';
|
|
$expectedSignature = 'sha256=' . hash_hmac('sha256', $payload, $secret);
|
|
|
|
// Comparaison en temps constant pour éviter les attaques par timing
|
|
if (!$signatureHeader || !hash_equals($expectedSignature, $signatureHeader)) {
|
|
http_response_code(403);
|
|
file_put_contents('webhook.log', date('Y-m-d H:i:s') . " - Tentative refusée (signature invalide)\n", FILE_APPEND);
|
|
exit('Forbidden');
|
|
}
|
|
|
|
// On récupère les modifs et on force l'écrasement pour éviter les conflits
|
|
$output = shell_exec('git fetch origin && git reset --hard origin/main 2>&1');
|
|
|
|
// On logue ça pour vérifier si ça marche (tu pourras voir le contenu dans webhook.log)
|
|
file_put_contents('webhook.log', date('Y-m-d H:i:s') . "\n" . $output . "\n---\n", FILE_APPEND);
|
|
|
|
echo "Sync done.";
|