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
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user