61 lines
1.8 KiB
PHP
Executable File
61 lines
1.8 KiB
PHP
Executable File
<?php
|
|
// Fix paperclip-status.php : port 3100 -> 3002 (vrai paperclipai Next.js)
|
|
// Cause racine: loki écoute :3100, paperclipai écoute :3002
|
|
// Doctrine: zéro écrasement, backup GOLD, PHP lint
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$target = '/var/www/html/api/paperclip-status.php';
|
|
$backup = '/var/www/html/vault-gold/opus/paperclip-status-' . date('Ymd-His') . '.bak';
|
|
|
|
if (!file_exists($target)) {
|
|
echo json_encode(['ok'=>false,'err'=>'target not found']);
|
|
exit;
|
|
}
|
|
|
|
@mkdir(dirname($backup), 0755, true);
|
|
copy($target, $backup);
|
|
|
|
$content = file_get_contents($target);
|
|
|
|
// Remplacer ['port'=>3100,'src'=>'pnpm dev'] par ['port'=>3002,'src'=>'pnpm dev next']
|
|
$old = "['port'=>3100,'src'=>'pnpm dev']";
|
|
$new = "['port'=>3002,'src'=>'pnpm dev next']";
|
|
|
|
if (strpos($content, $old) === false) {
|
|
echo json_encode(['ok'=>false, 'err'=>'pattern not found (deja fixe?)', 'search'=>$old]);
|
|
exit;
|
|
}
|
|
|
|
$new_content = str_replace($old, $new, $content);
|
|
|
|
// Lint
|
|
$tmp = tempnam('/tmp', 'pap-fix-');
|
|
file_put_contents($tmp, $new_content);
|
|
$lint = shell_exec("php -l $tmp 2>&1");
|
|
if (strpos($lint, 'No syntax errors') === false) {
|
|
unlink($tmp);
|
|
echo json_encode(['ok'=>false, 'err'=>'php lint fail', 'lint'=>$lint]);
|
|
exit;
|
|
}
|
|
|
|
// chattr -i, write, +i
|
|
shell_exec("sudo chattr -i $target 2>/dev/null");
|
|
file_put_contents($target, $new_content);
|
|
shell_exec("sudo chown www-data:www-data $target");
|
|
shell_exec("sudo chattr +i $target 2>/dev/null");
|
|
unlink($tmp);
|
|
|
|
@opcache_reset();
|
|
|
|
// Test the fix
|
|
$test = shell_exec("curl -sk -m 5 'http://localhost/api/paperclip-status.php' 2>&1 | head -c 800");
|
|
|
|
echo json_encode([
|
|
'ok' => true,
|
|
'backup' => $backup,
|
|
'fix' => 'port 3100 (loki) -> 3002 (paperclipai Next.js)',
|
|
'test_response' => substr($test, 0, 500),
|
|
'ts' => date('c')
|
|
]);
|