Files
html/api/opus-arch-browser-use.php
opus 43054e91f0
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
V37 caps wire + browser/voice/graphrag + doctrines 90-93
2026-04-17 19:19:22 +02:00

22 lines
1.4 KiB
PHP

<?php
// opus-arch-browser-use.php - Cap 2
header('Content-Type: application/json');
$action = $_POST['action'] ?? $_GET['action'] ?? 'browse';
$whitelist = ['github.com','console.groq.com','cloud.cerebras.ai','openrouter.ai','aistudio.google.com','docs.anthropic.com'];
if ($action === 'whitelist') { echo json_encode(['ok'=>true,'whitelist'=>$whitelist]); exit; }
if ($action === 'browse') {
$url = $_POST['url'] ?? $_GET['url'] ?? '';
$host = parse_url($url, PHP_URL_HOST) ?: '';
$allowed = false;
foreach ($whitelist as $w) if (strpos($host,$w) !== false) { $allowed=true; break; }
if (!$allowed) { echo json_encode(['ok'=>false,'error'=>'not whitelisted','whitelist'=>$whitelist]); exit; }
$script = "from playwright.sync_api import sync_playwright\nimport sys,json\nwith sync_playwright() as p:\n b=p.chromium.launch(headless=True,args=['--no-sandbox'])\n pg=b.new_page()\n try:\n pg.goto(sys.argv[1],timeout=15000)\n print(json.dumps({'ok':True,'title':pg.title(),'text':pg.inner_text('body')[:2000]}))\n except Exception as e: print(json.dumps({'ok':False,'error':str(e)}))\n finally: b.close()";
$tmp = tempnam('/tmp','br_').'.py';
file_put_contents($tmp, $script);
$out = shell_exec('timeout 30 python3 '.escapeshellarg($tmp).' '.escapeshellarg($url).' 2>&1');
@unlink($tmp);
echo $out ?: json_encode(['ok'=>false,'error'=>'empty']);
exit;
}
echo json_encode(['ok'=>false,'actions'=>['browse','whitelist']]);