Files
watchgether-api/webhook-web.php
T
Whykioh c668629268 Add webhook to auto-deploy watchgether-web
watchgether-web has no PHP runtime of its own (static files served by
a plain nginx container), so it reuses this repo's PHP/nginx to receive
its Gitea webhook and git-pull the separate watchgether-web checkout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 20:36:13 +02:00

33 lines
1.2 KiB
PHP

<?php
// webhook-web.php
// Déclenché par le webhook Gitea du dépôt watchgether-web (séparé de l'API).
// Vit ici parce que c'est le seul endroit du serveur avec un runtime PHP ;
// le front est servi par un simple conteneur nginx statique sans exécution possible.
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_GITEA_SIGNATURE'] ?? '';
$expectedSignature = hash_hmac('sha256', $payload, $secret);
if (!$signatureHeader || !hash_equals($expectedSignature, $signatureHeader)) {
http_response_code(403);
file_put_contents(__DIR__ . '/webhook-web.log', date('Y-m-d H:i:s') . " - Tentative refusée (signature invalide)\n", FILE_APPEND);
exit('Forbidden');
}
$webSiteDir = '/home/admin2root/watchgether-web/site';
$output = shell_exec("cd {$webSiteDir} && git fetch origin && git reset --hard origin/main 2>&1");
file_put_contents(__DIR__ . '/webhook-web.log', date('Y-m-d H:i:s') . "\n" . $output . "\n---\n", FILE_APPEND);
echo "Web sync done.";