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']]);