Files
html/api/opus5-fix-all-html.php
opus 10e581a01f
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync-1105
2026-04-17 11:05:01 +02:00

58 lines
1.7 KiB
PHP

<?php
header('Content-Type: application/json');
$R = ['ts' => date('c'), 'files' => [], 'total_replacements' => 0, 'ok' => true];
$TS = date('Ymd-Hi');
$files = [
'/var/www/html/cron-control.html',
'/var/www/html/enterprise-management.html',
'/var/www/html/enterprise-model.html',
'/var/www/html/ops-center.html',
'/var/www/html/wiki.html',
// faq déjà fixé
];
foreach ($files as $f) {
$info = ['path' => $f, 'exists' => file_exists($f)];
if (!$info['exists']) { $R['files'][] = $info+['skip'=>'missing']; continue; }
// Check chattr
exec('lsattr ' . escapeshellarg($f) . ' 2>&1', $lsa);
$immut = isset($lsa[0]) && strpos($lsa[0], '-i-') !== false;
$info['chattr_i'] = $immut;
if ($immut) {
$R['files'][] = $info + ['skip' => 'chattr_i_root_needed'];
continue;
}
$content = @file_get_contents($f);
$before = substr_count($content, '11435');
if ($before === 0) { $R['files'][] = $info+['skip'=>'no_11435']; continue; }
$GOLD = "/opt/wevads/vault/" . basename($f) . ".GOLD-pre-11434-{$TS}";
@copy($f, $GOLD);
$new = str_replace('11435', '11434', $content);
$temp = $f . '.tmp-opus5';
file_put_contents($temp, $new);
$renamed = @rename($temp, $f);
clearstatcache();
$after = substr_count(@file_get_contents($f), '11435');
$info += [
'before' => $before,
'after' => $after,
'renamed' => $renamed,
'gold' => $GOLD
];
$R['files'][] = $info;
if ($after === 0) $R['total_replacements'] += $before;
else $R['ok'] = false;
$lsa = []; // reset for next iter
}
echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);