diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh index 6d76c82..fb5f5f9 100755 --- a/bin/thumb_server.sh +++ b/bin/thumb_server.sh @@ -6,10 +6,11 @@ site=$1 # url for thumbshot 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 +sizeNameDir=$4 # name of size dir +onlyThumb=$5 # make only thumbshot no full size image +waitForResult=$6 # if true we try to make soon as possible or add to queue 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=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 @@ -17,7 +18,8 @@ maxQueue=50 # max process in queue currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l) firstLevel=${hashUrl:0:2} secondLevel=${hashUrl:2:2} -startPath=$firstLevel/$secondLevel/ +startPath=$sizeNameDir/$firstLevel/$secondLevel/ + mkdir -p "cache/img/$startPath" if [ -f "cache/config/serverOptions.php" ] diff --git a/inc/style.css b/inc/style.css index 0db9793..024e378 100644 --- a/inc/style.css +++ b/inc/style.css @@ -6,7 +6,7 @@ html { background-color: #dedede; } -form, #result{ +form, #result, #header{ padding: 1em; text-align: center; width: 50%; @@ -43,7 +43,7 @@ form .info { font-size : 0.8em; } -#result { +#result, #header { text-align: center; padding: 1em; margin: 1em auto; diff --git a/index.php b/index.php index bb66679..bce7ebf 100644 --- a/index.php +++ b/index.php @@ -2,24 +2,32 @@ if (empty($_SESSION)) { session_start(); } -date_default_timezone_set('Europe/Paris'); // change if you want no inpact -$GLOBALS['config']['onlyLocalServer'] = false; +date_default_timezone_set('Europe/Paris'); // soshot only accept request by 127.0.0.1 -$GLOBALS['config']['NoWebPage'] = false; +$GLOBALS['config']['onlyLocalServer'] = false; // No form for post url only acces by GET method -$GLOBALS['config']['maxErrorBeforeBan'] = 3; +$GLOBALS['config']['NoWebPage'] = false; // After 3 criticla error ban user -$GLOBALS['config']['banTime'] = 60; +$GLOBALS['config']['maxErrorBeforeBan'] = 3; // Ban for 60 minutes -$GLOBALS['config']['defaultUrl'] = 'https://google.com'; +$GLOBALS['config']['banTime'] = 60; // default url for form -$GLOBALS['config']['defaultThumbSize'] = '120x90'; +$GLOBALS['config']['defaultUrl'] = 'https://google.com'; // default size for thumbnail -$GLOBALS['config']['onlyThumb'] = TRUE; +$GLOBALS['config']['defaultThumbSize'] = '120x90'; // generate only thumbnail or generate thumbnail + 1280x1024 image -$GLOBALS['config']['thumbSize'] = array('s' => '120x90', 'm' => '200x160', 'l' => '300x240', 'xl' => '400x320', 'xxl' => '500x400'); +$GLOBALS['config']['onlyThumb'] = TRUE; // list of available size for thumb +$GLOBALS['config']['thumbSize'] = array( + 's' => '120x90', + 'm' => '200x160', + 'l' => '300x240', + 'xl' => '400x320', + 'xxl' => '500x400' +); +// Remove image older than 12 hours +$GLOBALS['config']['expireCache'] = 12; if (!file_exists('cache/config/genConf.php')) { install(); @@ -55,13 +63,13 @@ if (get_magic_quotes_gpc()) { function testExistImg($file) { if ($GLOBALS['config']['onlyThumb'] === true) { - if (file_exists($file . '_thumb.png')) { + if (file_exists($file.'_thumb.png')) { return true; } else { return false; } } else { - if (file_exists($file . '_thumb.png') && file_exists($file . '.png')) { + if (file_exists($file.'_thumb.png') && file_exists($file.'.png')) { return true; } else { return false; @@ -75,13 +83,13 @@ function testExistImg($file) { * @author Knah Tsaeb * @date 2013-02-12 * @param $url (string) url for thumbshot - * @param $hashUrl (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, $hashUrl, $width, $onlyThumb, $waitForResult = false) { +function launchScript($url, $hashUrl, $width, $size, $onlyThumb, $waitForResult = false) { $hashUrl = escapeshellarg($hashUrl); $url = escapeshellarg($url); $width = escapeshellarg($width); @@ -92,17 +100,21 @@ function launchScript($url, $hashUrl, $width, $onlyThumb, $waitForResult = false } if ($waitForResult === false) { - exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' > /dev/null &', $result); + exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' > /dev/null &', $result); } else { - exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' 1', $result); + exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' 1', $result); } return $result; } function testValidUrl($url) { + $url = trim($url); if (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED)) { $url = parse_url($url); - if (!in_array($url['scheme'], array('http', 'https'))) { + if (!in_array($url['scheme'], array( + 'http', + 'https' + ))) { return array('msg' => 'Url must be start by http or https.'); } return true; @@ -112,7 +124,7 @@ function testValidUrl($url) { } function genToken() { - $token = sha1(uniqid(rand(), true) . '_' . mt_rand()); + $token = sha1(uniqid(rand(), true).'_'.mt_rand()); $_SESSION['token'] = $token; return $token; } @@ -147,14 +159,14 @@ function ban() { $banList[$userIp]['lastBan'] = time(); $banList[$userIp]['nbBan'] = 1; } - file_put_contents('cache/logs/banUser.php', ""); + file_put_contents('cache/logs/banUser.php', ""); } function unBan() { require 'cache/logs/banUser.php'; $userIp = $_SERVER['REMOTE_ADDR']; unset($banList[$userIp]); - file_put_contents('cache/logs/banUser.php', ""); + file_put_contents('cache/logs/banUser.php', ""); } function install() { @@ -173,9 +185,9 @@ function install() { if (!mkdir('cache/tmp', 0705)) { die('Error on create dir "cache/tmp".'); } - $salt = sha1(uniqid(rand(), true) . '_' . mt_rand()); - $serverKey = substr(sha1(uniqid(rand(), true) . '_' . mt_rand() . $salt), 0, 12); - $encryptServerKey = sha1($serverKey . $salt); + $salt = sha1(uniqid(rand(), true).'_'.mt_rand()); + $serverKey = substr(sha1(uniqid(rand(), true).'_'.mt_rand().$salt), 0, 12); + $encryptServerKey = sha1($serverKey.$salt); if (!is_file('cache/config/genConf.php')) { file_put_contents('cache/config/genConf.php', ""); @@ -192,7 +204,13 @@ function install() { if (!is_file('cache/logs/log.txt')) { touch('cache/logs/log.txt'); } - echo '
', $serverKey, '
+ ', $serverKey, ' +
+