47 lines
1.7 KiB
PHP
47 lines
1.7 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
$path = "/var/www/html/wevia.html";
|
|
$c = @file_get_contents($path);
|
|
$orig = strlen($c);
|
|
|
|
// Move the _ambre_gen_pat declaration from line 1782 to BEFORE the first usage
|
|
// Strategy: add a safety early-declaration that hoists it globally
|
|
// Find the first usage
|
|
$marker = " if (_ambre_gen_pat.test(text)) {";
|
|
$pos = strpos($c, $marker);
|
|
if ($pos === false) {
|
|
echo json_encode(["error"=>"first usage marker not found"]);
|
|
exit;
|
|
}
|
|
|
|
// Find the exact regex definition line
|
|
$regex_def_start = strpos($c, "var _ambre_gen_pat = ");
|
|
if ($regex_def_start === false) {
|
|
echo json_encode(["error"=>"regex def not found"]);
|
|
exit;
|
|
}
|
|
$regex_def_end = strpos($c, ";\n", $regex_def_start);
|
|
$regex_def = substr($c, $regex_def_start, $regex_def_end - $regex_def_start + 1);
|
|
|
|
// Prepend declaration using window. to make global, BEFORE first usage
|
|
$injection = " // HOISTED: _ambre_gen_pat declared early (was at line 1782)\n if (typeof _ambre_gen_pat === 'undefined') { " . str_replace("var ", "var ", $regex_def) . " }\n";
|
|
|
|
// Insert BEFORE the first usage
|
|
$new_c = substr($c, 0, $pos) . $injection . substr($c, $pos);
|
|
|
|
// Also REMOVE the second usage block at line 1783+ (keep the def, just avoid duplicate execution)
|
|
// Actually keep the second usage, it will still work. Just don't remove.
|
|
|
|
$backup = "/opt/wevads/vault/wevia.html.GOLD-" . date("Ymd-His") . "-hoist-gen-pat";
|
|
@copy($path, $backup);
|
|
$wrote = @file_put_contents($path, $new_c);
|
|
|
|
echo json_encode([
|
|
"orig" => $orig,
|
|
"new" => strlen($new_c),
|
|
"delta" => strlen($new_c) - $orig,
|
|
"wrote" => $wrote,
|
|
"backup" => basename($backup),
|
|
"injection_size" => strlen($injection),
|
|
]);
|