84 lines
2.5 KiB
PHP
84 lines
2.5 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
$R = ['ts'=>date('c'), 'files'=>[], 'ok'=>true, 'total_replacements'=>0];
|
|
|
|
// 9 HTML files + 8 PHP brain files that reference 11435
|
|
$files = [
|
|
'/var/www/html/admin-saas.html',
|
|
'/var/www/html/admin-v2.html',
|
|
'/var/www/html/ai-hub.html',
|
|
'/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/tools-hub.html',
|
|
'/var/www/html/wiki.html',
|
|
];
|
|
|
|
$TS = date('Ymd-Hi');
|
|
|
|
foreach ($files as $f) {
|
|
$info = ['path' => $f, 'exists' => file_exists($f), 'writable' => is_writable($f)];
|
|
if (!$info['exists']) {
|
|
$R['files'][] = $info + ['skip' => 'not_exists'];
|
|
continue;
|
|
}
|
|
|
|
$content = @file_get_contents($f);
|
|
$size_before = strlen($content);
|
|
$count = substr_count($content, '11435');
|
|
|
|
if ($count === 0) {
|
|
$R['files'][] = $info + ['skip' => 'no_11435', 'size' => $size_before];
|
|
continue;
|
|
}
|
|
|
|
// GOLD
|
|
$gold_name = basename($f).".GOLD-pre-11434-{$TS}";
|
|
$gold_path = "/opt/wevads/vault/$gold_name";
|
|
@copy($f, $gold_path);
|
|
|
|
// Replace 11435 → 11434
|
|
$new = str_replace('11435', '11434', $content);
|
|
$size_after = strlen($new);
|
|
|
|
// chattr check
|
|
exec("lsattr ".escapeshellarg($f)." 2>&1", $lsa);
|
|
$immutable = (strpos(($lsa[0] ?? ''), '-i-') !== false);
|
|
|
|
if ($immutable) {
|
|
exec("chattr -i ".escapeshellarg($f)." 2>&1", $c1, $rc1);
|
|
$info['chattr_removed'] = ($rc1 === 0);
|
|
}
|
|
|
|
$written = @file_put_contents($f, $new);
|
|
|
|
if ($immutable) {
|
|
exec("chattr +i ".escapeshellarg($f)." 2>&1", $c2, $rc2);
|
|
$info['chattr_restored'] = ($rc2 === 0);
|
|
}
|
|
|
|
$info += [
|
|
'size_before' => $size_before,
|
|
'size_after' => $size_after,
|
|
'count_11435' => $count,
|
|
'written_bytes' => $written !== false ? $written : 'FAILED',
|
|
'gold' => $gold_path,
|
|
'immutable_initial' => $immutable,
|
|
];
|
|
|
|
if ($written > 0) $R['total_replacements'] += $count;
|
|
else $R['ok'] = false;
|
|
|
|
$R['files'][] = $info;
|
|
}
|
|
|
|
// Validation: recount 11435 after
|
|
foreach ($files as $f) {
|
|
if (!file_exists($f)) continue;
|
|
$remaining = substr_count(@file_get_contents($f), '11435');
|
|
if ($remaining > 0) $R['files_still_have_11435'][] = ['file'=>$f, 'remaining'=>$remaining];
|
|
}
|
|
|
|
echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|