From c6686292687e59550a85b4ea6422cf2394172ba7 Mon Sep 17 00:00:00 2001 From: Whykioh Date: Sun, 12 Jul 2026 20:36:13 +0200 Subject: [PATCH] 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 --- .gitignore | 3 ++- webhook-web.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 webhook-web.php diff --git a/.gitignore b/.gitignore index 0b74843..9ffd12c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config/database.php -webhook.log \ No newline at end of file +webhook.log +webhook-web.log \ No newline at end of file diff --git a/webhook-web.php b/webhook-web.php new file mode 100644 index 0000000..a6dc85d --- /dev/null +++ b/webhook-web.php @@ -0,0 +1,32 @@ +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.";