From b8818a78de211b519630fc9f8387166cbfa86c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauricio=20L=C3=B3pez=20Coria?= Date: Wed, 5 Aug 2026 13:00:47 -0300 Subject: [PATCH] fix: deshabilitado deploy-webhook.php (borraba el docroot en cada push) --- scripts/deploy.sh | 5 +- src/forms/deploy-webhook.php | 95 ++++++++---------------------------- 2 files changed, 24 insertions(+), 76 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index a1f100b..596d64a 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -22,8 +22,11 @@ fi # Copy PHP endpoints into dist (they don't go through Astro) mkdir -p "$DIST/api" cp "$REPO/src/forms/contact.php" "$DIST/api/contact.php" -cp "$REPO/src/forms/deploy-webhook.php" "$DIST/api/deploy-webhook.php" cp "$REPO/src/forms/api-htaccess" "$DIST/api/.htaccess" +# deploy-webhook.php NO se deploya (deshabilitado 2026-08-05). +# Hacia `rm -rf` del docroot en cada push y borro mee/ cuatro veces. +# Ver src/forms/deploy-webhook.php para el detalle. +rm -f "$DIST/api/deploy-webhook.php" # Copy root .htaccess (HTTPS forzado, security headers) cp "$REPO/scripts/htaccess.conf" "$DIST/.htaccess" diff --git a/src/forms/deploy-webhook.php b/src/forms/deploy-webhook.php index b537eb3..395e919 100644 --- a/src/forms/deploy-webhook.php +++ b/src/forms/deploy-webhook.php @@ -1,83 +1,28 @@ false, 'error' => 'Invalid signature']); - exit; -} - -$body = json_decode($payload, true); -$ref = $body['ref'] ?? ''; -$repoName = $body['repository']['name'] ?? ''; - -if ($ref !== 'refs/heads/main' || $repoName !== 'hostingdelsur.net') { - http_response_code(200); - echo json_encode(['ok' => true, 'message' => 'Ignored (not main or wrong repo)']); - exit; -} - -$logFile = '/home/hostingd/deploy.log'; -$timestamp = date('Y-m-d H:i:s'); -$logLine = "[{$timestamp}] Deploy started for {$repoName} @ {$ref}\n"; - -$projectDir = '/home/hostingd/hostingdelsur.net'; -$distDir = $projectDir . '/dist'; -$publicHtml = '/home/hostingd/public_html'; -$projectSrc = '/root/opencode/development/hostingdelsur.net'; -$srcForms = $projectSrc . '/src/forms'; - -// Directorios/archivos que NO pertenecen al build de Astro y deben -// sobrevivir el wipe (mismo criterio que scripts/deploy.sh --exclude). -// Se mueven a un staging dir antes del rm -rf y se restauran después. -$preserve = ['mwp', 'mee', 'blog', 'design-system', '.well-known', '.smtp-credentials.json']; -$stagingDir = '/home/hostingd/.deploy-preserve-tmp'; - -$preserveOut = "rm -rf {$stagingDir} && mkdir -p {$stagingDir}"; -foreach ($preserve as $item) { - $preserveOut .= " && [ -e {$publicHtml}/{$item} ] && mv {$publicHtml}/{$item} {$stagingDir}/{$item} || true"; -} - -$restoreOut = ""; -foreach ($preserve as $item) { - $restoreOut .= "[ -e {$stagingDir}/{$item} ] && mv {$stagingDir}/{$item} {$publicHtml}/{$item} || true; "; -} -$restoreOut .= "rm -rf {$stagingDir}"; - -$commands = [ - "cd {$projectDir} && git pull origin main 2>&1", - "cd {$projectDir} && npm install --production=false 2>&1", - "cd {$projectDir} && npm run build 2>&1", - "cp {$srcForms}/contact.php {$distDir}/api/contact.php 2>&1", - "cp {$srcForms}/deploy-webhook.php {$distDir}/api/deploy-webhook.php 2>&1", - "cp {$srcForms}/api-htaccess {$distDir}/api/.htaccess 2>&1", - "{$preserveOut} 2>&1", - "rm -rf {$publicHtml}/* {$publicHtml}/.[!.]* 2>&1; mkdir -p {$publicHtml}", - "cp -r {$distDir}/* {$distDir}/.[!.]* {$publicHtml}/ 2>&1", - "{$restoreOut} 2>&1", -]; - -foreach ($commands as $cmd) { - $output = shell_exec($cmd . ' 2>&1'); - $logLine .= "$ {$cmd}\n{$output}\n"; -} - -$logLine .= "[{$timestamp}] Deploy completed\n\n"; -file_put_contents($logFile, $logLine, FILE_APPEND); - -http_response_code(200); -echo json_encode(['ok' => true, 'message' => 'Deploy triggered', 'log' => basename($logFile)]); +http_response_code(410); +header('Content-Type: application/json'); +echo json_encode([ + 'ok' => false, + 'error' => 'Deploy webhook disabled. Use scripts/deploy.sh (rsync).', +]);