[add] another method for manualy generate thumb on error

This commit is contained in:
Knah Tsaeb 2015-07-10 17:19:53 +02:00
parent 840de1ac0e
commit 57d88558cc
3 changed files with 48 additions and 18 deletions

View file

@ -8,7 +8,7 @@ if (phantom.args.length < 2) {
address = phantom.args[0]; address = phantom.args[0];
output = phantom.args[1]; output = phantom.args[1];
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0'; page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0';
page.viewportSize = { width: 1280, height:1024}; page.viewportSize = { width: 1280, height:1024};
page.open(address, function (status) { page.open(address, function (status) {
if (status !== 'success') { if (status !== 'success') {
@ -20,7 +20,7 @@ if (phantom.args.length < 2) {
page.render(output); page.render(output);
page.close(); page.close();
phantom.exit(); phantom.exit();
}, 300); }, 1000);
} }
}); });
} }

View file

@ -16,7 +16,7 @@ waitForResult=$6 # if true we try to make soon as possible or add to queue
##### for overwrite options ##### ##### for overwrite options #####
########################################## ##########################################
maxThread=1 # max parralle work. For me the best is nb core - 1 maxThread=1 # max parralle work. For me the best is nb core - 1
timeOut=60 # default time out, after this time the site are declared in error timeOut=190 # default time out, after this time the site are declared in error
log=false # log all generation success and error log=false # log all generation success and error
randomSleep=`echo $((RANDOM%20))` randomSleep=`echo $((RANDOM%20))`
optimizeTool='' # external tool form optimize png optimizeTool='' # external tool form optimize png
@ -27,7 +27,7 @@ secondLevel=${hashUrl:2:2}
startPath=$sizeNameDir/$firstLevel/$secondLevel/ startPath=$sizeNameDir/$firstLevel/$secondLevel/
getArch=$(getconf LONG_BIT) getArch=$(getconf LONG_BIT)
#echo $getArch #echo $getArch
if [ $site == "manual" ] if [ "$site" -eq "manual" ]
then then
site=$(cat "../cache/tmp/manual.txt") site=$(cat "../cache/tmp/manual.txt")
echo '' > "../cache/tmp/manual.txt" echo '' > "../cache/tmp/manual.txt"
@ -57,26 +57,26 @@ fi
start_time=`date +%s` start_time=`date +%s`
if [ $getArch -eq 64 ] if [ $getArch -eq 64 ]
then then
timeout $timeOut ./phantomjs_x64 --disk-cache=false --local-storage-path=bin/ --ignore-ssl-errors=true rasterize.js "$site" "../cache/tmp/$hashUrl.png" phanTom=$(./phantomjs_x64 --disk-cache=false --local-storage-path=../cache/tmp --ignore-ssl-errors=true --web-security=false rasterize.js "$site" "../cache/tmp/$hashUrl.png")
else else
timeout $timeOut ./phantomjs_x86 --disk-cache=false --local-storage-path=bin/ --ignore-ssl-errors=true rasterize.js "$site" "../cache/tmp/$hashUrl.png" phanTom=$(./phantomjs_x86 --disk-cache=false --local-storage-path=../cache/tmp --ignore-ssl-errors=true --web-security=false rasterize.js "$site" "../cache/tmp/$hashUrl.png")
fi fi
sleep 5
if [ ! -f "../cache/tmp/$hashUrl.png" ] if [ ! -f "../cache/tmp/$hashUrl.png" ]
then then
echo 0 echo 0
errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` 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' ] if [ $site == 'manual' ]
then then
errorCode='manual' errorCode='manual'
fi fi
echo $errorCode
case $errorCode in case $errorCode in
000) cp "../bin/000.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/000.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/000.png" "../cache/img/$startPath""$hashUrl""_complete.png";; 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 "../bin/error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/error.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 "../bin/404.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/404.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/404.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";;
*) cp "..bin/error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; *) 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 esac
rm "../cache/tmp/$hashUrl.lock" rm "../cache/tmp/$hashUrl.lock"
if $log if $log
@ -93,7 +93,6 @@ then
exit exit
fi fi
case $renderType in case $renderType in
# thumbnail only # thumbnail only
t) t)

View file

@ -125,6 +125,31 @@ function keepThisThumb($hash, $log) {
unlink('cache/logs/'.$log.'/'.$hash.'.log'); unlink('cache/logs/'.$log.'/'.$hash.'.log');
} }
function tryWithCurl($hash, $log) {
$line = file_get_contents('cache/logs/'.$log.'/'.$hash.'.log');
$line = trim($line);
$line = explode(' --- ', $line);
//$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1]));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $line[1]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'SoShot - perSOnal thumbSHOTer');
$resultat = curl_exec($ch);
curl_close($ch);
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);
chdir('../');
//unlink('../cache/tmp/'.$hash.'.html');
if ((int)$result[0] == 1) {
$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;
}
}
if (isset($ui['clear']) && (int)$ui['clear'] === 1) { if (isset($ui['clear']) && (int)$ui['clear'] === 1) {
clearLog($ui['log']); clearLog($ui['log']);
} }
@ -204,7 +229,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') {
$nbThumb = 0; $nbThumb = 0;
$nbThumb = count($logs['genTime']); $nbThumb = count($logs['genTime']);
echo 'Total request : ', $nbThumb, '</br>'; echo 'Total request : ', $nbThumb, '</br>';
echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))</br>'; echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))</br>';
} else { } else {
echo 'No result'; echo 'No result';
} }
@ -212,7 +237,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') {
} }
if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || $ui['log'] === 'other')) { if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || $ui['log'] === 'other')) {
if (isset($ui['hash']) && !empty($ui['hash'])) { if (isset($ui['hash']) && !empty($ui['hash'])) {
$ui['hash'] = validHash($ui['hash']); //$ui['hash'] = validHash($ui['hash']);
if (isset($ui['root']) && (int)$ui['root'] === 1) { if (isset($ui['root']) && (int)$ui['root'] === 1) {
$success = tryRootDomain($ui['hash'], $ui['log']); $success = tryRootDomain($ui['hash'], $ui['log']);
} }
@ -229,12 +254,15 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' ||
if (isset($ui['mGen']) && (int)$ui['mGen'] === 1) { if (isset($ui['mGen']) && (int)$ui['mGen'] === 1) {
$success = manualGen($ui['hash'], $ui['log']); $success = manualGen($ui['hash'], $ui['log']);
} }
if (isset($ui['tryCurl']) && (int)$ui['tryCurl'] === 1) {
$success = tryWithCurl($ui['hash'], $ui['log']);
}
} }
$logs = parseFailLog($ui['log']); $logs = parseFailLog($ui['log']);
if (!empty($logs)) { if (!empty($logs)) {
echo '<ul>'; echo '<ul>';
foreach ($logs as $value) { foreach ($logs as $value) {
echo '<li>', htmlentities(strip_tags($value['3'])), htmlentities(strip_tags($value['0'])), '</br><a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&mGen=1#result">manuel launch</a> <a href="', htmlentities(strip_tags($value['0'])), '">view site</a> <a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&cache=1&s=', $value['2'], '#result">view image in cache</a></li>'; echo '<li>', htmlentities(strip_tags($value['3'])), htmlentities(strip_tags($value['0'])), '</br><a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&mGen=1#result">manuel launch</a> <a href="', htmlentities(strip_tags($value['0'])), '">view site</a> <a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&cache=1&s=', $value['2'], '#result">view image in cache</a></li>';
} }
echo '</ul>'; echo '</ul>';
} else { } else {
@ -246,7 +274,10 @@ if (!empty($success)) {
echo '<div id="result">'; echo '<div id="result">';
echo '<img src="', $success['base64'], '" style="width:100%;"/>'; echo '<img src="', $success['base64'], '" style="width:100%;"/>';
echo '<p><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['filePath'], '" onclick="this.select()"/></p>'; echo '<p><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['filePath'], '" onclick="this.select()"/></p>';
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&mGen=1">manuel launch</a> / '; echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&mGen=1">Manuel launch</a> / ';
if (extension_loaded("curl")) {
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&tryCurl=1">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'], '&root=1">Try with root domain</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'], '&keep=1">Keep this thumbshot</a>';
echo '</div>'; echo '</div>';