39 lines
1.1 KiB
PHP
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",
|
|
]);
|