From f1b94962e3a94dd6ee8bbe9b6bd563320c0cf075 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Mon, 13 Jul 2015 12:34:33 +0200 Subject: [PATCH] [fix] bad queue detection [fix] manual gen error --- bin/rasterize.js | 2 +- bin/thumb_server.sh | 21 ++++++++++------- inc/admin.php | 56 +++++++++++++++++++++++++++++++++------------ index.php | 14 ++++++------ 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/bin/rasterize.js b/bin/rasterize.js index eb7de8a..4ec6aba 100644 --- a/bin/rasterize.js +++ b/bin/rasterize.js @@ -12,7 +12,7 @@ if (phantom.args.length < 2) { page.open(address, function (status) { if (status !== 'success') { - //console.log('Unable to load the address!'); + console.log('Unable to load the address!'); page.close(); phantom.exit(); } else { diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh index 5c1f6f5..7b55524 100755 --- a/bin/thumb_server.sh +++ b/bin/thumb_server.sh @@ -9,6 +9,7 @@ thumbSize=$3 # size of thumb widthxheight ex : 190x90 sizeNameDir=$4 # name of size dir renderType=$5 # make only thumbshot / thumbshot + realSize / thumbshot + complete / thumbshot + complete + realSize waitForResult=$6 # if true we try to make soon as possible or add to queue +noErrorLog=$7 ########################################## ##### DON'T EDIT THIS PARAM USE ##### @@ -27,7 +28,7 @@ secondLevel=${hashUrl:2:2} startPath=$sizeNameDir/$firstLevel/$secondLevel/ getArch=$(getconf LONG_BIT) #echo $getArch -if [ "$site" -eq "manual" ] +if [ "$site" = "manual" ] then site=$(cat "../cache/tmp/manual.txt") echo '' > "../cache/tmp/manual.txt" @@ -42,6 +43,7 @@ fi if [ $currentProcess -gt $maxQueue ] then + rm "../cache/tmp/$hashUrl.lock" exit fi @@ -66,7 +68,6 @@ if [ ! -f "../cache/tmp/$hashUrl.png" ] then echo 0 errorCode=`echo $(curl -k -L --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` - echo $site if [ $site == 'manual' ] then errorCode='manual' @@ -76,13 +77,18 @@ then 000) cp "000.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "000.png" "../cache/img/$startPath""$hashUrl.png" && cp "000.png" "../cache/img/$startPath""$hashUrl""_complete.png";; 200) cp "error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "error.png" "../cache/img/$startPath""$hashUrl.png" && cp "error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; 404) cp "404.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "404.png" "../cache/img/$startPath""$hashUrl.png" && cp "404.png" "../cache/img/$startPath""$hashUrl""_complete.png";; + manual) rm "../cache/tmp/$hashUrl.lock" && exit;; *) cp "error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "error.png" "../cache/img/$startPath""$hashUrl.png" && cp "error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; esac rm "../cache/tmp/$hashUrl.lock" - if $log + if $log == true then end_time=`date +%s` logDate=`date +'[%a %d %b %Y] [%H:%M:%S]'` + if $noErrorLog + then + exit + fi if [ $errorCode == 200 ] then echo "none --- "$site" --- "$hashUrl" --- "$thumbSize" --- "$sizeNameDir" --- "$onlyThumb" --- true --- "$errorCode > "../cache/logs/retry/"$hashUrl".log" @@ -99,7 +105,7 @@ case $renderType in convert "../cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "../cache/tmp/$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" + eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" &>/dev/null fi mv "../cache/tmp/$hashUrl""_thumb.png" "../cache/img/$startPath""$hashUrl""_thumb.png" if [[ -f "../cache/img/$startPath""$hashUrl""_thumb.png" ]] @@ -116,7 +122,7 @@ case $renderType in convert "../cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "../cache/tmp/$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" + eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" &>/dev/null fi mv "../cache/tmp/$hashUrl.png" "../cache/img/$startPath""$hashUrl""_complete.png" mv "../cache/tmp/$hashUrl""_thumb.png" "../cache/img/$startPath""$hashUrl""_thumb.png" @@ -134,7 +140,7 @@ case $renderType in convert "../cache/tmp/$hashUrl.png" -filter Lanczos -thumbnail "$thumbSize" "../cache/tmp/$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" + eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" &>/dev/null fi mv "../cache/tmp/$hashUrl.png" "../cache/img/$startPath""$hashUrl.png" mv "../cache/tmp/$hashUrl""_thumb.png" "../cache/img/$startPath""$hashUrl""_thumb.png" @@ -153,7 +159,7 @@ case $renderType in convert "../cache/tmp/$hashUrl.png" -filter Lanczos -thumbnail "$thumbSize" "../cache/tmp/$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" "../cache/tmp/$hashUrl""_complete.png" + eval $optimizeTool "../cache/tmp/$hashUrl""_thumb.png" "../cache/tmp/$hashUrl.png" "../cache/tmp/$hashUrl""_complete.png" &>/dev/null fi mv "../cache/tmp/$hashUrl.png" "../cache/img/$startPath""$hashUrl.png" mv "../cache/tmp/$hashUrl""_thumb.png" "../cache/img/$startPath""$hashUrl""_thumb.png" @@ -164,7 +170,6 @@ case $renderType in else echo 0 fi - rm "../cache/tmp/$hashUrl.png" rm "../cache/tmp/$hashUrl.lock" ;; esac diff --git a/inc/admin.php b/inc/admin.php index b123ef2..824a741 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -85,8 +85,11 @@ function manualGen($hash, $log) { $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'] = 'Can\'t generate thumbshot manualy, try curl method.'; } + return $res; } function delAndRegen($hash, $size) { @@ -137,11 +140,22 @@ function tryWithCurl($hash, $log) { curl_setopt($ch, CURLOPT_USERAGENT, 'SoShot - perSOnal thumbSHOTer'); $resultat = curl_exec($ch); curl_close($ch); + $searchStr = array( + 'href="//', + 'src="//', + 'content="//' + ); + $replaceStr = array( + 'href="http://', + 'src="http://', + 'content="http://' + ); + $resultat = str_replace($searchStr, $replaceStr, $resultat); file_put_contents('cache/tmp/'.$line[2].'.html', $resultat); chdir('bin/'); - exec('bash thumb_server.sh ../cache/tmp/'.$hash.'.html '.escapeshellarg($line[2]).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' trc 1', $result); + 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'); + unlink('cache/tmp/'.$hash.'.html'); if ((int)$result[0] == 1) { $res['success'] = 1; $res['filePath'] = pathForFile($line[4], $hash).'.png'; @@ -229,7 +243,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') { $nbThumb = 0; $nbThumb = count($logs['genTime']); echo 'Total request : ', $nbThumb, '
'; - echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))
'; + echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))
'; } else { echo 'No result'; } @@ -239,30 +253,31 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || if (isset($ui['hash']) && !empty($ui['hash'])) { //$ui['hash'] = validHash($ui['hash']); if (isset($ui['root']) && (int)$ui['root'] === 1) { - $success = tryRootDomain($ui['hash'], $ui['log']); + $response = tryRootDomain($ui['hash'], $ui['log']); } if (isset($ui['cache']) && (int)$ui['cache'] === 1) { - $success['filePath'] = pathForFile($ui['s'], $ui['hash']).'.png'; - $success['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents($success['filePath'])); - if (!file_exists($success['filePath'])) { - $success['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents('bin/error.png')); + $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'])) { + $response['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents('bin/error.png')); } } if (isset($ui['keep']) && (int)$ui['keep'] === 1) { keepThisThumb($ui['hash'], $ui['log']); } if (isset($ui['mGen']) && (int)$ui['mGen'] === 1) { - $success = manualGen($ui['hash'], $ui['log']); + $response = manualGen($ui['hash'], $ui['log']); } if (isset($ui['tryCurl']) && (int)$ui['tryCurl'] === 1) { - $success = tryWithCurl($ui['hash'], $ui['log']); + $response = tryWithCurl($ui['hash'], $ui['log']); } } $logs = parseFailLog($ui['log']); if (!empty($logs)) { echo ''; } else { @@ -270,10 +285,21 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || } } echo ''; -if (!empty($success)) { +if (!empty($response) && $response['success'] === 1) { echo '
'; - echo ''; - echo '

'; + echo ''; + echo '

'; + echo 'Manuel launch / '; + if (extension_loaded("curl")) { + echo 'Try with curl / '; + } + echo 'Try with root domain / '; + echo 'Keep this thumbshot'; + echo '
'; +} +if (!empty($response) && $response['error'] === 1) { + echo '
'; + echo '

', $response['msg'], '

'; echo 'Manuel launch / '; if (extension_loaded("curl")) { echo 'Try with curl / '; diff --git a/index.php b/index.php index 13503f1..72d8d86 100644 --- a/index.php +++ b/index.php @@ -138,7 +138,7 @@ function testExistImg($file) { * @return */ function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) { - $oriUrl = $hashUrl; + $oriHash = $hashUrl; $hashUrl = escapeshellarg($hashUrl); $url = escapeshellarg($url); $width = escapeshellarg($width); @@ -152,8 +152,8 @@ function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) { $renderType = 't'; } if ($GLOBALS['config']['disableExec'] === false) { - if (!file_exists('cache/tmp/'.$hashUrl.'.lock')) { - touch('cache/tmp/'.$oriUrl.'.lock'); + if (!file_exists('cache/tmp/'.$oriHash.'.lock')) { + touch('cache/tmp/'.$oriHash.'.lock'); chdir('bin/'); if ($waitForResult === false) { exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' > /dev/null &', $result); @@ -577,7 +577,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && file_put_contents('cache/logs/suspect/'.$hashUrl.'.log', $_SERVER['REMOTE_ADDR'].' --- '.$ui['url'].' --- '.$hashUrl.' --- '.$width.' --- '.$ui['s'].' --- '.$renderType.' --- true'."\n"); } if ($ui['request'] === 'api') { - printThumbShot('bin/error'); + printThumbShot('bin/error', $ui['t']); } else { $success = array( 'normal' => 'bin/error.png', @@ -597,7 +597,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && if ($makeImg === true) { $GLOBALS['config']['disableExec'] = true; if ($ui['request'] === 'api') { - printThumbShot($file); + printThumbShot($file, $ui['t']); } else { $success = array( 'normal' => $file.'.png', @@ -616,7 +616,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && } if ($ui['request'] === 'api') { $file = 'bin/loadingGen'; - printThumbShot($file); + printThumbShot($file, $ui['t']); } else { if ($GLOBALS['config']['disableExec'] === true) { $file = 'bin/loadingGen'; @@ -641,7 +641,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && \ No newline at end of file