3840 || $vpParts[1] > 2160) { header('HTTP/1.0 400 Bad Request'); echo 'Viewport exceeds maximum (3840x2160)'; exit; } $js = $_REQUEST['js'] == 'false' ? false : true; if (defined('BLOCK_PRIVATE_IPS') && BLOCK_PRIVATE_IPS) { $host = parse_url($target, PHP_URL_HOST); if (filter_var($host, FILTER_VALIDATE_IP)) { $resolvedIp = $host; } else { $resolvedIp = gethostbyname($host); if ($resolvedIp === $host) { header('HTTP/1.0 403 Forbidden'); echo 'URL not allowed'; exit; } } if (isPrivateIP($resolvedIp)) { header('HTTP/1.0 403 Forbidden'); echo 'URL not allowed'; exit; } } $serverUrl = 'http://localhost:4444'; $options = new \Facebook\WebDriver\Chrome\ChromeOptions(); $options->addArguments(['--headless', '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage']); $capabilities = DesiredCapabilities::chrome(); $capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options); if (!$js) $capabilities->setCapability('javascriptEnabled', false); $driver = null; $error = null; try { $driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60000); $driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($vpParts[0], $vpParts[1])); $driver->get($target); $driver->executeScript('document.body.style.overflow = "hidden";'); addToLog($ip . ' Requested ' . $target . ' viewport=' . $viewport . ' js=' . ($js ? 'enabled' : 'disabled')); $screenshot = $driver->takeScreenshot(); header('Content-Type: image/png'); header('Content-Length: ' . strlen($screenshot)); echo $screenshot; } catch (Exception $e) { $error = $e->getMessage(); addToLog($ip . ' Error requesting ' . $target . ': ' . $error); } finally { if ($driver instanceof RemoteWebDriver) { try { $driver->quit(); } catch (Exception $q) {} } } if ($error !== null) { header('HTTP/1.0 500 Internal Server Error'); echo 'Screenshot failed'; } break; default: echo renderTemplate('index.html.php'); break; }