diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh index e2195a8..7584a76 100755 --- a/bin/thumb_server.sh +++ b/bin/thumb_server.sh @@ -4,19 +4,19 @@ # All info at http://forge.leslibres.org/projects/soshot site=$1 # url for thumbshot -md5Site=$2 # md5(url) is the name of final image +hashUrl=$2 # hash(url) is the name of final image thumbSize=$3 # size of thumb widthxheight ex : 190x90 onlyThumb=$4 # make only thumbshot no full size image waitForResult=$5 # if true we try to make soon as possible or add to queue -maxThread=3 # max parralle work for me the best is nb core - 1 +maxThread=3 # 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 log=false # log all generation success and error randomSleep=`echo $((RANDOM%20))` optimizeTool='' # external tool form optimize png maxQueue=50 # max process in queue currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l) -firstLevel=${md5Site:0:2} -secondLevel=${md5Site:2:2} +firstLevel=${hashUrl:0:2} +secondLevel=${hashUrl:2:2} startPath=$firstLevel/$secondLevel/ mkdir -p "cache/img/$startPath" @@ -40,15 +40,15 @@ then fi start_time=`date +%s` -timeout $timeOut ./bin/phantomjs --disk-cache=false --local-storage-path=/bin/ --ignore-ssl-errors=true /bin/rasterize.js "$site" "cache/tmp/$md5Site.png" -if [ ! -f "cache/tmp/$md5Site.png" ] +timeout $timeOut ./bin/phantomjs --disk-cache=false --local-storage-path=/bin/ --ignore-ssl-errors=true /bin/rasterize.js "$site" "cache/tmp/$hashUrl.png" +if [ ! -f "cache/tmp/$hashUrl.png" ] then echo 0 errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` case $errorCode in - 000) cp "bin/000.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$md5Site.png" ;; - 404) cp "bin/404.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$md5Site.png" ;; - *) cp "bin/error.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$md5Site.png" ;; + 000) cp "bin/000.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$hashUrl.png" ;; + 404) cp "bin/404.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$hashUrl.png" ;; + *) cp "bin/error.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$hashUrl.png" ;; esac if $log then @@ -60,31 +60,31 @@ then fi if [ $onlyThumb == 1 ] then - convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png" + convert "cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" + eval $optimizeTool "cache/img/$startPath""$hashUrl""_thumb.png" fi else - convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$startPath""$md5Site.png" - convert "cache/img/$startPath""$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png" + convert "cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 "cache/img/$startPath""$hashUrl.png" + convert "cache/img/$startPath""$hashUrl.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$hashUrl""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" "cache/img/$startPath""$md5Site.png" + eval $optimizeTool "cache/img/$startPath""$hashUrl""_thumb.png" "cache/img/$startPath""$hashUrl.png" fi fi -rm "cache/tmp/$md5Site.png" +rm "cache/tmp/$hashUrl.png" if [ $onlyThumb ] then - if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" ]] + if [[ -f "cache/img/$startPath""$hashUrl""_thumb.png" ]] then echo 1 else echo 0 fi else - if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" && -f "cache/img/$startPath""$md5Site.png" ]] + if [[ -f "cache/img/$startPath""$hashUrl""_thumb.png" && -f "cache/img/$startPath""$hashUrl.png" ]] then echo 1 else diff --git a/index.php b/index.php index cfb49ef..e2373b9 100644 --- a/index.php +++ b/index.php @@ -75,14 +75,14 @@ function testExistImg($file) { * @author Knah Tsaeb * @date 2013-02-12 * @param $url (string) url for thumbshot - * @param $md5Url (md5) md5($url) + * @param $hashUrl (md5) md5($url) * @param $width (string) size of thumbnail 190x90 * @param $onlyThumb (bool) * @param $waiForResult (bool) * @return */ -function launchScript($url, $md5Url, $width, $onlyThumb, $waitForResult = false) { - $md5Url = escapeshellarg($md5Url); +function launchScript($url, $hashUrl, $width, $onlyThumb, $waitForResult = false) { + $hashUrl = escapeshellarg($hashUrl); $url = escapeshellarg($url); $width = escapeshellarg($width); if ($GLOBALS['config']['onlyThumb'] === true) { @@ -92,9 +92,9 @@ function launchScript($url, $md5Url, $width, $onlyThumb, $waitForResult = false) } if ($waitForResult === false) { - exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . $onlyThumb . ' > /dev/null &', $result); + exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' > /dev/null &', $result); } else { - exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . $onlyThumb . ' 1', $result); + exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' 1', $result); } return $result; } @@ -239,17 +239,15 @@ if ($_GET) { $width = $GLOBALS['config']['defaultThumbSize']; } - $md5Url = md5($defUrl); - $startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/'; - $file = 'cache/img/'.$startPath.$md5Url; - - + $hashUrl = sha1($GLOBALS['config']['serverKey'] . $defUrl); + $startPath = substr($hashUrl, 0, 2) . '/' . substr($hashUrl, 2, 2) . '/'; + $file = 'cache/img/' . $startPath . $hashUrl; if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { if (isset($ui['iw']) && (int)$ui['iw'] === 1) { - launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true); + launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], true); } else { - $res = launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], false); + $res = launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], false); header("Content-type: image/png"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); echo file_get_contents('bin/loadingGen.png'); @@ -290,12 +288,12 @@ if ($_POST) { $width = $GLOBALS['config']['defaultThumbSize']; } - $md5Url = md5($defUrl); - $startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/'; - $file = 'cache/img/'.$startPath . $md5Url; + $hashUrl = sha1($GLOBALS['config']['serverKey'] . $defUrl); + $startPath = substr($hashUrl, 0, 2) . '/' . substr($hashUrl, 2, 2) . '/'; + $file = 'cache/img/' . $startPath . $hashUrl; if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { - launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true); + launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], true); } $success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png'); } @@ -349,7 +347,7 @@ if (empty($width)) { '; - echo ''; + echo ''; echo '

'; if ($GLOBALS['config']['onlyThumb'] === false) { echo '

';