Files
html/api/ambre-parse-all.php
2026-04-22 01:55:03 +02:00

32 lines
1.1 KiB
PHP

<?php
header("Content-Type: text/plain");
$wevia = @file_get_contents("/var/www/html/wevia.html");
// Extract all <script> contents and try each with node
$pos = 0; $n = 0;
while (($m = strpos($wevia, "<script", $pos)) !== false) {
$tag_end = strpos($wevia, ">", $m);
if ($tag_end === false) break;
$tag = substr($wevia, $m, $tag_end - $m + 1);
// Skip if has src=
if (strpos($tag, "src=") !== false) { $pos = $tag_end + 1; continue; }
$end = strpos($wevia, "</script>", $tag_end);
if ($end === false) break;
$content = substr($wevia, $tag_end + 1, $end - $tag_end - 1);
if (strlen($content) < 50) { $pos = $end + 9; continue; }
$n++;
$abs_line = substr_count(substr($wevia, 0, $tag_end + 1), "\n") + 1;
$tmp = "/tmp/wscript-$n.js";
file_put_contents($tmp, $content);
$parse = @shell_exec("node --check $tmp 2>&1");
if (trim($parse)) {
echo "=== Script #$n (starts abs line $abs_line, " . strlen($content) . "B) ===\n";
echo "$parse\n\n";
} else {
echo "Script #$n (line $abs_line, " . strlen($content) . "B): OK\n";
}
$pos = $end + 9;
}