Add support for fetch favicon

This commit is contained in:
Knah Tsaeb 2018-10-05 11:51:51 +02:00
parent 812b96302a
commit f8291f593d
4 changed files with 65 additions and 24 deletions

BIN
bin/error_fav.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -76,6 +76,32 @@ function parseFailLog($log)
return $res;
}
function parseFaviconLog($log)
{
if (empty($log) || ($log !== 'favicon')) {
die('Are you sure about this.');
}
$res = array();
$list = glob('cache/logs/' . $log . '/*.json');
if (!empty($list)) {
foreach ($list as $value) {
$res[] = json_decode(file_get_contents($value), true);
}
}
return $res;
}
function getInfoLog($hash)
{
$file = 'cache/logs/favicon/' . $hash . '.json';
if (file_exists($file)) {
$res = json_decode(file_get_contents($file), true);
} else {
$res = array();
}
return $res;
}
function manualGen($hash, $log)
{
$line = file_get_contents('cache/logs/' . $log . '/' . $hash . '.log');
@ -135,9 +161,13 @@ function tryRootDomain($hash, $log)
}
}
function keepThisThumb($hash, $log)
function keepThisThumb($hash, $log, $favicon = false)
{
if ($favicon === true) {
unlink('cache/logs/' . $log . '/' . $hash . '.json');
} else {
unlink('cache/logs/' . $log . '/' . $hash . '.log');
}
}
function tryWithCurl($hash, $log)
@ -170,14 +200,14 @@ function tryWithCurl($hash, $log)
exec('bash thumb_server.sh ../cache/tmp/' . $hash . '.html ' . escapeshellarg($line[2]) . ' ' . escapeshellarg($line[3]) . ' ' . escapeshellarg($line[4]) . ' trc 1 noErrorLog', $result);
chdir('../');
unlink('cache/tmp/' . $hash . '.html');
if ((int) $result[0] == 1) {
if (file_exists(pathForFile($line[4], $hash) . '.png')) {
$res['success'] = 1;
$res['filePath'] = pathForFile($line[4], $hash) . '.png';
$res['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents($res['filePath']));
return $res;
} else {
$res['error'] = 1;
$res['msg'] = 'Error with curl'.n_print($result);
$res['msg'] = 'Error with curl' . n_print($result);
return $res;
}
}
@ -210,6 +240,7 @@ function tryWithOpenGraph($hash, $log)
} else {
$res['error'] = 1;
$res['msg'] = 'Error with OpenGraph data';
$res['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents('bin/error.png'));
return $res;
}
@ -310,7 +341,13 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' ||
if (isset($ui['cache']) && (int) $ui['cache'] === 1) {
$response['success'] = 1;
$response['filePath'] = pathForFile($ui['s'], $ui['hash']) . '.png';
$response['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents($response['filePath']));
if(file_exists($response['filePath'])){
$file = file_get_contents($response['filePath']);
} else {
$file = file_get_contents('bin/error.png');
}
$response['base64'] = 'data:image/png;base64,' . base64_encode($file);
if (!file_exists($response['filePath'])) {
$response['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents('bin/error.png'));
}
@ -339,29 +376,30 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' ||
echo 'No result';
}
}
echo '</div>';
if (!empty($response) && !empty($response['success']) && $response['success'] === 1) {
echo '<div id="result">';
echo '<img src="', $response['base64'], '" style="width:100%;"/>';
echo '<img src="', $response['base64'], '" style="max-width:100%;"/>';
echo '<p><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $response['filePath'], '" onclick="this.select()"/></p>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&mGen=1">Manuel launch</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&mGen=1#result">Manuel launch</a> / ';
if (extension_loaded("curl")) {
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&tryCurl=1">Try with curl</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&tryCurl=1#result">Try with curl</a> / ';
}
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&root=1">Try with root domain</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&openGraph=1">Try with OpenGraph</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&keep=1">Keep this thumbshot</a>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&root=1#result">Try with root domain</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&openGraph=1#result">Try with OpenGraph</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&keep=1#result">Keep this thumbshot</a>';
echo '</div>';
}
if (!empty($response) && !empty($response['error']) && $response['error'] === 1) {
} elseif (!empty($response) && !empty($response['error']) && $response['error'] === 1) {
echo '<div id="result">';
echo '<p>', $response['msg'], '</p>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&mGen=1">Manuel launch</a> / ';
echo '<p><img src="', $response['base64'], '" style="max-width:100%;"/></p>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&mGen=1#result">Manuel launch</a> / ';
if (extension_loaded("curl")) {
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&tryCurl=1">Try with curl</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&tryCurl=1#result">Try with curl</a> / ';
}
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&root=1">Try with root domain</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&openGraph=1">Try with OpenGraph</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&keep=1">Keep this thumbshot</a>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&root=1#result">Try with root domain</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&openGraph=1#result">Try with OpenGraph</a> / ';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&keep=1#result">Keep this thumbshot</a>';
echo '</div>';
}

View file

@ -618,7 +618,7 @@ function makeFavicon($hash, $url, $filePath)
if (!is_dir($hashPath)) {
mkdir($hashPath, 0700, true);
}
exec('convert -background transparent ' . escapeshellarg($tmpFile[' . $key . ']) . ' -resize x32 ' . $file, $resResize);
exec('convert -background transparent ' . escapeshellarg($tmpFile . '[' . $key . ']') . ' -resize x32 ' . $file, $resResize);
unlink('cache/tmp/' . $hash . '.' . $data['ext']);
}
} else {
@ -629,9 +629,11 @@ function makeFavicon($hash, $url, $filePath)
unlink('cache/tmp/' . $hash . '.' . $data['ext']);
}
//n_print($data);
if (file_exists($file)) {
return $file;
} else {
file_put_contents($file, file_get_contents('bin/error_fav.png'));
return $file;
}
}
@ -721,7 +723,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' &&
'normal' => 'bin/error.png',
'thumb' => 'bin/error_thumb.png',
'complete' => 'bin/error.png',
'favicon' => 'bin/error.png',
'favicon' => 'bin/error_fav.png',
);
}
} else {

View file

@ -8,6 +8,7 @@ All info in the homepage http://forge.leslibres.org/projects/soshot
**Thanks**
* Icon by http://www.iconfinder.com/icondetails/7917/128/camera_file_image_icon
* Icon by https://www.iconfinder.com/icons/34267/browser_earth_global_globe_international_internet_map_planet_world_icon
* Bash script idea by http://www.cambus.net/blog/page/3/
* Httpstatus in bash by https://gist.github.com/rsvp/1171304
* The engine phantomjs by http://phantomjs.org/