fix: enhance error handling and improve URL decoding in http2pic class and index.php

This commit is contained in:
2026-04-20 07:59:06 +02:00
parent 7616dee994
commit 7323eed789
2 changed files with 19 additions and 14 deletions

View File

@@ -104,7 +104,7 @@ class http2pic
//validate URL and check if exists
if ($this->isBase64($this->params['url']))
$this->params['url'] = base64_decode($url);
$this->params['url'] = base64_decode($this->params['url']);
else
$this->params['url'] = rawurldecode($_GET['url']);
@@ -171,22 +171,25 @@ class http2pic
$cmd.=' -f png';
//add url to cmd
$cmd.=' \''.addslashes($this->params['url']).'\'';
$cmd.=' '.escapeshellarg($this->params['url']);
//add storage path to cmd
$cmd.=' '.escapeshellarg($this->params['file']);
$cmd.=' --wait-for-network-idle';
$cmd = escapeshellcmd($cmd);
$output = [];
$rc = 0;
exec($cmd . ' 2>&1', $output, $rc);
$this->params['cmd'] = $cmd;
if ($rc !== 0) {
$this->params['render_error'] = implode("\n", $output);
header('Content-Type: image/jpeg');
$result = imagecreatefromjpeg($this->params['onfail']);
imagejpeg($result, NULL, 100);
return $cmd;
}
$this->postRender();
if(DEBUG)
@@ -274,8 +277,10 @@ class http2pic
*/
function isURLReachable($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if(curl_exec($ch) != false){
//We were able to connect to a webserver, what did it return?
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

View File

@@ -55,15 +55,13 @@ switch ($url[0]) {
$driver = null;
$error = null;
try {
$driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60);
$driver->get($target);
//hide scroll bars
$driver->executeScript('document.body.style.overflow = "hidden";');
//set screenshot size to 1920x1080
//$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
//if $viewport is set, set window size
if ($viewport) {
$viewport = explode('x', $viewport);
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
@@ -80,15 +78,17 @@ switch ($url[0]) {
header('Content-Length: ' . strlen($screenshot));
echo $screenshot;
} catch (Exception $e) {
header('HTTP/1.0 500 Internal Server Error');
addToLog("$ip\tRequested $target but resulted in error:\t" . $e->getMessage());
echo 'Error: ' . $e->getMessage();
exit;
$error = $e->getMessage();
addToLog("$ip\tRequested $target but resulted in error:\t" . $error);
} finally {
if ($driver instanceof \Facebook\WebDriver\Remote\RemoteWebDriver) {
try { $driver->quit(); } catch (Exception $q) {}
}
}
if ($error !== null) {
header('HTTP/1.0 500 Internal Server Error');
echo 'Error: ' . $error;
}
break;
default: