diff --git a/bin/error_fav.png b/bin/error_fav.png new file mode 100644 index 0000000..069194d Binary files /dev/null and b/bin/error_fav.png differ diff --git a/inc/admin.php b/inc/admin.php index 34a261b..ecb060d 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -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) { - unlink('cache/logs/' . $log . '/' . $hash . '.log'); + if ($favicon === true) { + unlink('cache/logs/' . $log . '/' . $hash . '.json'); + } else { + unlink('cache/logs/' . $log . '/' . $hash . '.log'); + } } function tryWithCurl($hash, $log) @@ -147,7 +177,7 @@ function tryWithCurl($hash, $log) $line = explode(' --- ', $line); //$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1])); $line[1] = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $line[1]); - $ch = curl_init(); + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $line[1]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @@ -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; } } @@ -190,7 +220,7 @@ function tryWithOpenGraph($hash, $log) $line = explode(' --- ', $line); $url = $line[1]; $startPath = ''; - $url = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $url); + $url = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $url); $info = Embed::create($url); $ext = testIfImg($info->image); @@ -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 ''; if (!empty($response) && !empty($response['success']) && $response['success'] === 1) { echo '
', $response['msg'], '
'; - echo 'Manuel launch / '; + echo ''; + echo 'Manuel launch / '; if (extension_loaded("curl")) { - echo 'Try with curl / '; + echo 'Try with curl / '; } - echo 'Try with root domain / '; - echo 'Try with OpenGraph / '; - echo 'Keep this thumbshot'; + echo 'Try with root domain / '; + echo 'Try with OpenGraph / '; + echo 'Keep this thumbshot'; echo '