fix: enhance error handling and improve URL decoding in http2pic class and index.php
This commit is contained in:
@@ -104,7 +104,7 @@ class http2pic
|
|||||||
|
|
||||||
//validate URL and check if exists
|
//validate URL and check if exists
|
||||||
if ($this->isBase64($this->params['url']))
|
if ($this->isBase64($this->params['url']))
|
||||||
$this->params['url'] = base64_decode($url);
|
$this->params['url'] = base64_decode($this->params['url']);
|
||||||
else
|
else
|
||||||
$this->params['url'] = rawurldecode($_GET['url']);
|
$this->params['url'] = rawurldecode($_GET['url']);
|
||||||
|
|
||||||
@@ -171,20 +171,23 @@ class http2pic
|
|||||||
$cmd.=' -f png';
|
$cmd.=' -f png';
|
||||||
|
|
||||||
//add url to cmd
|
//add url to cmd
|
||||||
$cmd.=' \''.addslashes($this->params['url']).'\'';
|
$cmd.=' '.escapeshellarg($this->params['url']);
|
||||||
|
|
||||||
//add storage path to cmd
|
//add storage path to cmd
|
||||||
$cmd.=' '.escapeshellarg($this->params['file']);
|
$cmd.=' '.escapeshellarg($this->params['file']);
|
||||||
|
|
||||||
$cmd.=' --wait-for-network-idle';
|
$cmd.=' --wait-for-network-idle';
|
||||||
|
|
||||||
$cmd = escapeshellcmd($cmd);
|
|
||||||
$output = [];
|
$output = [];
|
||||||
$rc = 0;
|
$rc = 0;
|
||||||
exec($cmd . ' 2>&1', $output, $rc);
|
exec($cmd . ' 2>&1', $output, $rc);
|
||||||
$this->params['cmd'] = $cmd;
|
$this->params['cmd'] = $cmd;
|
||||||
if ($rc !== 0) {
|
if ($rc !== 0) {
|
||||||
$this->params['render_error'] = implode("\n", $output);
|
$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();
|
$this->postRender();
|
||||||
@@ -276,6 +279,8 @@ class http2pic
|
|||||||
{
|
{
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||||
if(curl_exec($ch) != false){
|
if(curl_exec($ch) != false){
|
||||||
//We were able to connect to a webserver, what did it return?
|
//We were able to connect to a webserver, what did it return?
|
||||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
|||||||
@@ -55,15 +55,13 @@ switch ($url[0]) {
|
|||||||
|
|
||||||
|
|
||||||
$driver = null;
|
$driver = null;
|
||||||
|
$error = null;
|
||||||
try {
|
try {
|
||||||
$driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60);
|
$driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60);
|
||||||
$driver->get($target);
|
$driver->get($target);
|
||||||
//hide scroll bars
|
//hide scroll bars
|
||||||
$driver->executeScript('document.body.style.overflow = "hidden";');
|
$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) {
|
if ($viewport) {
|
||||||
$viewport = explode('x', $viewport);
|
$viewport = explode('x', $viewport);
|
||||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
|
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
|
||||||
@@ -80,15 +78,17 @@ switch ($url[0]) {
|
|||||||
header('Content-Length: ' . strlen($screenshot));
|
header('Content-Length: ' . strlen($screenshot));
|
||||||
echo $screenshot;
|
echo $screenshot;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
header('HTTP/1.0 500 Internal Server Error');
|
$error = $e->getMessage();
|
||||||
addToLog("$ip\tRequested $target but resulted in error:\t" . $e->getMessage());
|
addToLog("$ip\tRequested $target but resulted in error:\t" . $error);
|
||||||
echo 'Error: ' . $e->getMessage();
|
|
||||||
exit;
|
|
||||||
} finally {
|
} finally {
|
||||||
if ($driver instanceof \Facebook\WebDriver\Remote\RemoteWebDriver) {
|
if ($driver instanceof \Facebook\WebDriver\Remote\RemoteWebDriver) {
|
||||||
try { $driver->quit(); } catch (Exception $q) {}
|
try { $driver->quit(); } catch (Exception $q) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($error !== null) {
|
||||||
|
header('HTTP/1.0 500 Internal Server Error');
|
||||||
|
echo 'Error: ' . $error;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user