Files
html/api/file_dump.php
opus 649ed5bcd3
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
wave(204): global sanitizer ob_start + 7 handlers moved to /api/ root
2026-04-21 14:53:21 +02:00

39 lines
1.1 KiB
PHP

<?php
/**
* intent-opus4-file_dump.php
* AMBRE session · chunked file reader · offset + length
* Invocation: /api/opus-arch-generic.php?tool=file_dump&path=X&offset=0&length=10000
*/
header("Content-Type: application/json");
$target = $_GET["path"] ?? "";
$offset = (int)($_GET["offset"] ?? 0);
$length = min((int)($_GET["length"] ?? 8000), 50000);
$real = realpath($target);
$allowed = ["/var/www/html/", "/opt/wevads/", "/opt/weval-l99/"];
$ok = false;
foreach ($allowed as $root) {
if ($real && strpos($real, $root) === 0) { $ok = true; break; }
}
if (!$ok || !file_exists($real)) {
echo json_encode(["ok"=>false, "error"=>"path denied or not found", "path"=>$target]);
exit;
}
$fh = fopen($real, "r");
fseek($fh, $offset);
$chunk = fread($fh, $length);
fclose($fh);
echo json_encode([
"ok" => true,
"path" => $real,
"offset" => $offset,
"length" => strlen($chunk),
"total" => filesize($real),
"eof" => ($offset + strlen($chunk)) >= filesize($real),
"content" => $chunk,
"source" => "intent-opus4-file_dump.php · ambre · honest chunked read",
]);