64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* intent-opus4-scan_file.php
|
|
* AMBRE session · 2026-04-21
|
|
* Ferme gap autonomie : remplace LLM fallback hallucination quand on demande
|
|
* l'état d'un fichier (wtp_state, wepredict_state, etc.).
|
|
* Doctrine #4 ZERO FAKE DATA — retourne uniquement les faits stat+md5+version.
|
|
* Invocation : /api/opus-arch-generic.php?tool=scan_file&path=/var/www/html/xxx.html
|
|
*/
|
|
header('Content-Type: application/json');
|
|
|
|
$target = $_GET['path'] ?? '/var/www/html/wepredict.html';
|
|
|
|
// Whitelist sécurité : ne lit que sous /var/www/html ou /opt/wevads
|
|
$real = realpath($target);
|
|
$allowed = ['/var/www/html/', '/opt/wevads/', '/opt/weval-l99/'];
|
|
$ok_root = false;
|
|
foreach ($allowed as $root) {
|
|
if ($real && strpos($real, $root) === 0) { $ok_root = true; break; }
|
|
}
|
|
if (!$ok_root) {
|
|
echo json_encode(['ok'=>false, 'error'=>'path outside allowed roots', 'path'=>$target]);
|
|
exit;
|
|
}
|
|
if (!file_exists($real)) {
|
|
echo json_encode(['ok'=>false, 'error'=>'file not found', 'path'=>$target]);
|
|
exit;
|
|
}
|
|
|
|
$stat = stat($real);
|
|
$md5 = md5_file($real);
|
|
$content = file_get_contents($real);
|
|
|
|
// Version extraction patterns (HTML, PHP, JS)
|
|
$version = 'unknown';
|
|
foreach ([
|
|
'/data-version="([^"]+)"/',
|
|
'/"wevia-version"\s+content="([^"]+)"/',
|
|
'/@version\s+([^\s\*]+)/',
|
|
'/VERSION\s*=\s*[\'"]([^\'"]+)/',
|
|
] as $pat) {
|
|
if (preg_match($pat, $content, $m)) { $version = $m[1]; break; }
|
|
}
|
|
|
|
// Detect live URL if under /var/www/html
|
|
$url = null;
|
|
if (strpos($real, '/var/www/html/') === 0) {
|
|
$rel = substr($real, strlen('/var/www/html/'));
|
|
$url = 'https://weval-consulting.com/' . $rel;
|
|
}
|
|
|
|
echo json_encode([
|
|
'ok' => true,
|
|
'path' => $real,
|
|
'url' => $url,
|
|
'size' => $stat['size'],
|
|
'size_kb' => round($stat['size'] / 1024, 1),
|
|
'mtime' => date('c', $stat['mtime']),
|
|
'md5' => $md5,
|
|
'version' => $version,
|
|
'lines' => substr_count($content, "\n"),
|
|
'source' => 'intent-opus4-scan_file.php · ambre · doctrine#4 honest',
|
|
], JSON_PRETTY_PRINT);
|