From e557660d2848dcca1f1750d050ed3218d27aea2c Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 31 May 2013 12:28:30 +0200 Subject: [PATCH] [add] #465 #459 #458 #457 #455 : Make a admin interface for this feature. Not exactly the same, but same idea. --- .gitignore | 1 + .htaccess | 10 +- bin/error_thumb.png | Bin 0 -> 1770 bytes bin/loadingGen_thumb.png | Bin 0 -> 1981 bytes bin/mon.sh | 1 - bin/rasterize.js | 2 +- bin/thumb_server.sh | 25 +- cache/index.html | 1 - inc/admin.php | 196 +++++++++++++++ inc/index.php | 41 +++ inc/install.php | 32 +++ inc/login.php | 11 + inc/style.css | 54 +++- index.php | 525 ++++++++++++++++++++++++++------------- robots.txt | 2 + 15 files changed, 704 insertions(+), 197 deletions(-) create mode 100644 bin/error_thumb.png create mode 100644 bin/loadingGen_thumb.png delete mode 100644 cache/index.html create mode 100644 inc/admin.php create mode 100644 inc/index.php create mode 100644 inc/install.php create mode 100644 inc/login.php create mode 100644 robots.txt diff --git a/.gitignore b/.gitignore index 3cc30f3..1a17728 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ cache/* !cache/index.html .project +.settings diff --git a/.htaccess b/.htaccess index 4a81062..8c115f6 100644 --- a/.htaccess +++ b/.htaccess @@ -1,13 +1,5 @@ AddDefaultCharset UTF-8 Options -Indexes DirectoryIndex index.php index.html -Header set cache-control: public - - ExpiresActive On - ExpiresDefault "access plus 1 month" - ExpiresByType image/png "access plus 1 days" - ExpiresByType image/vnd.microsoft.icon "access plus 10 years" - ExpiresByType image/x-icon "access plus 10 years" - FileETag none -SetOutputFilter DEFLATE \ No newline at end of file +SetOutputFilter DEFLATE diff --git a/bin/error_thumb.png b/bin/error_thumb.png new file mode 100644 index 0000000000000000000000000000000000000000..a794e2cd07c2ba6fc4c63031e34143dc44be4314 GIT binary patch literal 1770 zcmVJ1N*+i?YwHj1}nx%1)?!&^$T5y{m3B_4hsbvvHWwkYiZ4Aa3V`w`!+y|IaD3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9*_j*3QB$>X%`nI z={nn1RoMOg*`%8Qg};=f0I43c2Eyg^$F4UUVI3#$l+?qf?(t~s+Np*$6b>J%DEnH3 z#J}!df*(jjEtQ3V>gTT9Gm!U!aE?3EquDb21P|V73quy+WQ4nQxHQxecW-EjJX5;q zgu;i)LeE>+t=7~ZfuvUenllME0aS&}DjsyA&Yahh zb&c;i*ZWv_+0iMx$H7_(-$4so_<%VX>7gx&B|~1)T;*aw3&6=tKItKBdqH|=bNfUh z "cache/tmp/manual.txt" +fi + mkdir -p "cache/img/$startPath" if [ -f "cache/config/serverOptions.php" ] @@ -43,12 +53,18 @@ 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/$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)` + if [ $site == 'manual' ] + then + errorCode='manual' + fi case $errorCode in 000) cp "bin/000.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$hashUrl.png" ;; + 200) cp "bin/error.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/error.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 @@ -56,7 +72,12 @@ then then end_time=`date +%s` logDate=`date +'[%a %d %b %Y] [%H:%M:%S]'` - echo $logDate `expr $end_time - $start_time`s --- ERROR --- httpstatus $errorCode --- $site >> 'cache/logs/logs.txt' + if [ $errorCode == 200 ] + then + echo "none --- "$site" --- "$hashUrl" --- "$thumbSize" --- "$sizeNameDir" --- "$onlyThumb" --- true --- "$errorCode > "cache/logs/retry/"$hashUrl".log" + else + echo "none --- "$site" --- "$hashUrl" --- "$thumbSize" --- "$sizeNameDir" --- "$onlyThumb" --- true --- "$errorCode > "cache/logs/other/"$hashUrl".log" + fi fi exit fi @@ -97,5 +118,5 @@ if $log then end_time=`date +%s` logDate=`date +'[%a %d %b %Y] [%H:%M:%S]'` - echo $logDate `expr $end_time - $start_time`s --- $site >> 'cache/logs/logs.txt' + echo $logDate `expr $end_time - $start_time`s >> 'cache/logs/success.txt' fi diff --git a/cache/index.html b/cache/index.html deleted file mode 100644 index 0519ecb..0000000 --- a/cache/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/inc/admin.php b/inc/admin.php new file mode 100644 index 0000000..1a66771 --- /dev/null +++ b/inc/admin.php @@ -0,0 +1,196 @@ + +
+ +
+
+'; + 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'; + } + echo '

Clear success log

'; +} +if ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || $ui['log'] === 'other') { + 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']); + } + if (isset($ui['cache']) && (int)$ui['cache'] === 1) { + $success['filePath'] = pathForFile($ui['s'], $ui['hash']).'.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']); + } + $logs = parseFailLog($ui['log']); + if (!empty($logs)) { + echo ''; + } else { + echo 'No result'; + } +} +echo '
'; + +if (!empty($success)) { + echo '
'; + echo ''; + echo '

'; + echo 'Try with root domain / '; + echo 'Keep this thumbshot'; + echo '
'; +} +?> \ No newline at end of file diff --git a/inc/index.php b/inc/index.php new file mode 100644 index 0000000..ee91fbf --- /dev/null +++ b/inc/index.php @@ -0,0 +1,41 @@ +
+

+ +

+

+ + +

+

+ + +

+

+ + +

+

+ Homepage +

+
+'; + echo '

This image will be removed in ', $GLOBALS['config']['expireCache'], 'h

'; + echo ''; + echo '

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

'; + } + echo ''; +} diff --git a/inc/install.php b/inc/install.php new file mode 100644 index 0000000..7d205bf --- /dev/null +++ b/inc/install.php @@ -0,0 +1,32 @@ + +
+ This is the key for generate thumbnail whith GET method. Save it ! +

+ +

+
+
+

+ + +

+

+ + +

+

+ + + +

+
diff --git a/inc/login.php b/inc/login.php new file mode 100644 index 0000000..82608b9 --- /dev/null +++ b/inc/login.php @@ -0,0 +1,11 @@ +
+

+ + +

+

+ + + +

+
\ No newline at end of file diff --git a/inc/style.css b/inc/style.css index 024e378..1546d98 100644 --- a/inc/style.css +++ b/inc/style.css @@ -6,11 +6,24 @@ html { background-color: #dedede; } -form, #result, #header{ +a { + text-decoration: none; + color:#8AC007; +} + +a:hover { + text-decoration: underline; +} + +a:visited { + color : #8AC007; +} + +form, #result, #header, .message, .hMenu, #log { padding: 1em; text-align: center; width: 50%; - margin: 0 auto; + margin: 1em auto; background-color: #ffffff; border-radius: 5px; box-shadow: 0 0 8px rgba(0, 0, 0, 0.50), 0 85px 180px 0 #FFFFFF, 0 12px 8px -5px rgba(0, 0, 0, 0.95); @@ -31,16 +44,16 @@ input[type=url] { #result label { margin-right: 1em; - width : 15%; + width: 15%; display: inline-block; - text-align:center; + text-align: center; } form .info { - text-align : right; - margin:0 0; - line-height : 0.8em; - font-size : 0.8em; + text-align: right; + margin: 0 0; + line-height: 0.8em; + font-size: 0.8em; } #result, #header { @@ -55,6 +68,31 @@ form .info { border-radius: 5px; } +.message { + background-color: orange; +} + +.hMenu li { + display: inline-block; + font-size: 1.2em; +} + +.hMenu li:after { + content: " / "; +} + +.hMenu li:last-child:after { + content: ""; +} + +.clear { + text-align: right; +} + +#log li { + text-align: left; +} + @media screen and (min-width: 320px) and (max-width: 800px) { html { diff --git a/index.php b/index.php index bce7ebf..a22d81c 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,8 @@ '120x90', @@ -28,13 +30,63 @@ $GLOBALS['config']['thumbSize'] = array( ); // Remove image older than 12 hours $GLOBALS['config']['expireCache'] = 12; +// Disable exec command for launch script and use cron task +$GLOBALS['config']['disableExec'] = false; +// Enable log for success, suspect, error +$GLOBALS['config']['log'] = false; + +if (get_magic_quotes_gpc()) { + function stripslashes_deep($value) { + $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); + return $value; + } + + $_POST = array_map('stripslashes_deep', $_POST); + $_GET = array_map('stripslashes_deep', $_GET); + $_COOKIE = array_map('stripslashes_deep', $_COOKIE); +} + +if (!empty($_POST)) { + $ui = $_POST; + $ui['request'] = 'form'; + $ui['iw'] = 1; + unset($_POST); +} +if (!empty($_GET)) { + $ui = $_GET; + $ui['request'] = 'api'; + unset($_GET); +} + +if (empty($ui['request'])) { + $ui['request'] = ''; +} + +if (empty($ui['p'])) { + $ui['p'] = 'index'; +} + +if (empty($ui['fr'])) { + $ui['fr'] = ''; +} + +if (isset($ui['logout']) && (int)$ui['logout'] === 1) { + session_destroy(); + header("Location:?"); + exit(); +} if (!file_exists('cache/config/genConf.php')) { - install(); + $serverKey = install(); + $ui['p'] = 'install'; } require 'cache/config/genConf.php'; -$ui = ''; + +if ($GLOBALS['config']['pwd'] === 'install' && $ui['p'] !== 'install') { + reloadInstall(); + header("Location:?"); +} if (($GLOBALS['config']['onlyLocalServer'] === true && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1') || checkIfBan() === true) { header("HTTP/1.0 404 Not Found"); @@ -50,17 +102,6 @@ if ($GLOBALS['config']['NoWebPage'] === true && empty($_GET)) { exit(); } -if (get_magic_quotes_gpc()) { - function stripslashes_deep($value) { - $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); - return $value; - } - - $_POST = array_map('stripslashes_deep', $_POST); - $_GET = array_map('stripslashes_deep', $_GET); - $_COOKIE = array_map('stripslashes_deep', $_COOKIE); -} - function testExistImg($file) { if ($GLOBALS['config']['onlyThumb'] === true) { if (file_exists($file.'_thumb.png')) { @@ -83,10 +124,10 @@ function testExistImg($file) { * @author Knah Tsaeb * @date 2013-02-12 * @param $url (string) url for thumbshot - * @param $hashUrl (md5) md5($url) + * @param $hashUrl (hash) hash($url) * @param $width (string) size of thumbnail 190x90 * @param $onlyThumb (bool) - * @param $waiForResult (bool) + * @param $waitForResult (bool) * @return */ function launchScript($url, $hashUrl, $width, $size, $onlyThumb, $waitForResult = false) { @@ -99,10 +140,14 @@ function launchScript($url, $hashUrl, $width, $size, $onlyThumb, $waitForResult $onlyThumb = 0; } - if ($waitForResult === false) { - exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' > /dev/null &', $result); + if ($GLOBALS['config']['disableExec'] === false) { + if ($waitForResult === false) { + exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' > /dev/null &', $result); + } else { + exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' 1', $result); + } } else { - exec('bin/thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$onlyThumb.' 1', $result); + return 0; } return $result; } @@ -126,11 +171,12 @@ function testValidUrl($url) { function genToken() { $token = sha1(uniqid(rand(), true).'_'.mt_rand()); $_SESSION['token'] = $token; + $_SESSION['tokenTime'] = time(); return $token; } function verifToken($token) { - if ($token !== $_SESSION['token']) { + if ($token !== $_SESSION['token'] || $_SESSION['tokenTime'] <= time() - 24000) { ban(); die('So Long, and Thanks for All the Fish.'); } @@ -173,16 +219,25 @@ function install() { if (!is_writable('cache')) { die('Make dir "cache" writable'); } - if (!mkdir('cache/config', 0705)) { + if (!is_dir('cache/config') && !mkdir('cache/config', 0705)) { die('Error on create dir "cache/config".'); } - if (!mkdir('cache/img', 0705)) { + if (!is_dir('cache/img') && !mkdir('cache/img', 0705)) { die('Error on create dir "cache/img".'); } - if (!mkdir('cache/logs', 0705)) { + if (!is_dir('cache/logs') && !mkdir('cache/logs', 0705)) { die('Error on create dir "cache/logs".'); } - if (!mkdir('cache/tmp', 0705)) { + if (!is_dir('cache/logs/suspect') && !mkdir('cache/logs/suspect', 0705)) { + die('Error on create dir "cache/logs/suspect".'); + } + if (!is_dir('cache/logs/retry') && !mkdir('cache/logs/retry', 0705)) { + die('Error on create dir "cache/logs/retry".'); + } + if (!is_dir('cache/logs/other') && !mkdir('cache/logs/other', 0705)) { + die('Error on create dir "cache/logs/other".'); + } + if (!is_dir('cache/tmp') && !mkdir('cache/tmp', 0705)) { die('Error on create dir "cache/tmp".'); } $salt = sha1(uniqid(rand(), true).'_'.mt_rand()); @@ -190,28 +245,24 @@ function install() { $encryptServerKey = sha1($serverKey.$salt); if (!is_file('cache/config/genConf.php')) { - file_put_contents('cache/config/genConf.php', ""); + file_put_contents('cache/config/genConf.php', ""); } if (!is_file('cache/config/serverOptions.php')) { touch('cache/config/serverOptions.php'); } + if (!is_file('cache/index.html')) { + touch('cache/index.html'); + } if (!is_file('cache/config/options.php')) { file_put_contents('cache/config/options.php', ""); } if (!is_file('cache/logs/banUser.php')) { file_put_contents('cache/logs/banUser.php', ""); } - if (!is_file('cache/logs/log.txt')) { - touch('cache/logs/log.txt'); - } - echo ' -
- This is the key for generate thumbnail whith GET method. Save it, this key is secret, don\'t share it. -

- ', $serverKey, ' -

-
'; - checkInstall(); + $GLOBALS['config']['serverKey'] = $encryptServerKey; + $GLOBALS['config']['salt'] = $salt; + $GLOBALS['config']['pwd'] = 'install'; + return $serverKey; } function checkInstall() { @@ -229,7 +280,7 @@ function checkInstall() { } } -function removeOlderThan($dir = 'cache/img/shortLived') { +function removeOlderThan($dir = 'cache/img/shortLive') { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { @@ -237,8 +288,8 @@ function removeOlderThan($dir = 'cache/img/shortLived') { if (filetype($dir.'/'.$object) === 'dir') { removeOlderThan($dir.'/'.$object); } else { - if(fileatime($dir.'/'.$object) < time() - 3600*$GLOBALS['config']['expireCache']){ - unlink($dir.'/'.$object); + if (fileatime($dir.'/'.$object) < time() - 3600 * $GLOBALS['config']['expireCache']) { + unlink($dir.'/'.$object); } } } @@ -247,161 +298,285 @@ function removeOlderThan($dir = 'cache/img/shortLived') { } } -checkInstall(); -removeOlderThan(); -if ($_GET) { - $ui = $_GET; - unset($_GET); - if (empty($ui['key']) || empty($ui['url'])) { - die('Are you Ken ?'); - } - if (sha1($ui['key'].$GLOBALS['config']['salt']) !== $GLOBALS['config']['serverKey']) { - ban(); - die('I take a chips and give it to Godzilla. I print a shoes and .............. KAMOULOX ! Well done Jean Pierre.'); - } - if (!array_key_exists($ui['s'], $GLOBALS['config']['thumbSize'])) { - die('Die another day !'); - } - - $ui['url'] = rawurldecode($ui['url']); - $testUrl = testValidUrl($ui['url']); - if ($testUrl !== true) { - header("Content-type: image/png"); - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); - echo file_get_contents('bin/error.png'); - exit(); - } - - $defUrl = $ui['url']; - if (isset($ui['s']) && array_key_exists($ui['s'], $GLOBALS['config']['thumbSize'])) { - $width = $GLOBALS['config']['thumbSize'][$ui['s']]; - } else { - $width = $GLOBALS['config']['defaultThumbSize']; - } - - $hashUrl = sha1($GLOBALS['config']['serverKey'].$defUrl); +function pathForFile($size, $hashUrl) { $startPath = substr($hashUrl, 0, 2).'/'.substr($hashUrl, 2, 2).'/'; - $file = 'cache/img/'.$ui['s'].'/'.$startPath.$hashUrl; + $file = 'cache/img/'.$size.'/'.$startPath.$hashUrl; + return $file; +} - if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { - if (isset($ui['iw']) && (int)$ui['iw'] === 1) { - launchScript($defUrl, $hashUrl, $width, $ui['s'], $GLOBALS['config']['onlyThumb'], true); - } else { - $res = launchScript($defUrl, $hashUrl, $width, $ui['s'], $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'); - exit(); - } +function validHash($hash) { + if (empty($hash)) { + die('You talking to me'); } + if (!preg_match('/^[0-9a-f]{40}$/i', $hash)) { + die('I don\'t understand biiip bip bip biiiip bip bip bip biiiiiiip biip ...'); + } + return $hash; +} + +function checkAdmin($pwd) { + $pwd = sha1($GLOBALS['config']['salt'].$pwd.$GLOBALS['config']['serverKey']); + if (validHash($pwd) !== $GLOBALS['config']['pwd']) { + ban(); + die('1, 2, 3, 4, 5 ? That\'s amazing ! I\'ve got the same combination on my luggage !'); + } + $_SESSION['login'] = true; + return true; +} + +function savePass($passOne, $passTwo, $token) { + verifToken($token); + if ($passOne !== $passTwo || empty($passOne) || empty($passTwo)) { + reloadInstall(); + } else { + $GLOBALS['config']['pwd'] = sha1($GLOBALS['config']['salt'].$passOne.$GLOBALS['config']['serverKey']); + $confServerKey = $GLOBALS['config']['serverKey']; + $confSalt = $GLOBALS['config']['salt']; + $confPwd = $GLOBALS['config']['pwd']; + $confFile = ' + '; + file_put_contents('cache/config/genConf.php',$confFile); + } + header("Location:?"); +} + +function reloadInstall() { + array_map('unlink', glob("cache/config/*")); +} + +/** + * Améliore la sortie print + * + * @author Tatane http://www.tatane.info/index.php/print_rn + * @author http://www.blog.cactuscrew.com/77-print_rn.html + * @param $data (array) tableau ou variable à examiner + * @param $name (string) nom a afficher + * @return false affiche les clef valeur du tableau $data + * @example n_print($array, 'Tableau de valeur'); + */ +function n_print($data, $name = '') { + $aBackTrace = debug_backtrace(); + echo '

', $name, '

'; + echo '
'; + echo ' + ', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ' + '; + echo '
',  htmlentities(print_r($data, 1)), '
'; + echo ' +
+
+'; +} + +function printThumbShot($file) { + ob_end_clean(); header("Content-type: image/png"); header('Expires: ', gmdate('D, d M Y H:i:s', time()).' GMT'); - if (!empty($ui['t']) && $ui['t'] === 'full') { - echo file_get_contents($file.'.png'); - } else { - echo file_get_contents($file.'_thumb.png'); - } - exit(); + echo file_get_contents($file.'_thumb.png'); + exit() ; } -if ($_POST) { - $ui = $_POST; - unset($_POST); - if (empty($ui['url'])) { - die('No url, no thumb'); +function getPage($page) { + $page = htmlspecialchars($page); + switch ($page) { + case 'login' : + return 'inc/login.php'; + break; + case 'install' : + return 'inc/install.php'; + break; + case 'admin' : + return 'inc/admin.php'; + break; + default : + return 'inc/index.php'; + break; } - verifToken($ui['token']); - - $ui['url'] = rawurldecode($ui['url']); - - $testUrl = testValidUrl($ui['url']); - if ($testUrl !== true) { - echo $testUrl['msg']; - exit(); - } - - if (!array_key_exists($ui['s'], $GLOBALS['config']['thumbSize'])) { - die('Die another day !'); - } - - $defUrl = $ui['url']; - - if (isset($ui['s']) && array_key_exists($ui['s'], $GLOBALS['config']['thumbSize'])) { - $width = $GLOBALS['config']['thumbSize'][$ui['s']]; - } else { - $width = $GLOBALS['config']['defaultThumbSize']; - } - - $hashUrl = sha1($GLOBALS['config']['serverKey'].$defUrl); - $startPath = substr($hashUrl, 0, 2).'/'.substr($hashUrl, 2, 2).'/'; - $file = 'cache/img/shortLived/'.$startPath.$hashUrl; - - if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { - launchScript($defUrl, $hashUrl, $width, 'shortLived', $GLOBALS['config']['onlyThumb'], true); - } - $success = array( - 'normal' => $file.'.png', - 'thumb' => $file.'_thumb.png' - ); } +function testIfImg($url) { + $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION)); + if ($ext === 'jpg' || $ext === 'jpeg' || $ext === 'png' || $ext === 'gif') { + return $ext; + } else { + return false; + } +} + +function makeImgThumb($url, $ext, $hashUrl, $width, $path, $onlyThumb) { + if (!function_exists('imagecreatefromjpeg')) { + return false; + } + + $image = file_get_contents($url); + $fullSize = file_put_contents('cache/tmp/'.$hashUrl.'.'.$ext, $image); + if ($ext === 'jpg' || $ext === 'jpeg') { + $tmpImg = imagecreatefromjpeg('cache/tmp/'.$hashUrl.'.'.$ext); + } + if ($ext === 'png') { + $tmpImg = imagecreatefrompng('cache/tmp/'.$hashUrl.'.'.$ext); + } + if ($ext === 'gif') { + $tmpImg = imagecreatefromgif('cache/tmp/'.$hashUrl.'.'.$ext); + } + if (!$tmpImg) { + unlink('cache/tmp/'.$hashUrl.'.'.$ext); + return false; + } + + $w = imagesx($tmpImg); + $h = imagesy($tmpImg); + $ystart = 0; + $yheight = $h; + if ($h > $w) { $ystart = ($h / 2) - ($w / 2); + $yheight = $w / 2; + } + $nh = min(floor(($h * $width) / $w), $width); + $im2 = imagecreatetruecolor($width, $nh); + imagecopyresampled($im2, $tmpImg, 0, 0, 0, $ystart, $width, $nh, $w, $yheight); + $tempname = 'cache/tmp/'.$hashUrl.'_TEMP.png'; + imagepng($im2, $tempname, 9); + if (!is_dir($path)) { + mkdir($path, 0775, true); + } + imagedestroy($tmpImg); + imagedestroy($im2); + unlink('cache/tmp/'.$hashUrl.'.'.$ext); + rename($tempname, $path.$hashUrl.'_thumb.png'); + if (file_exists($path.$hashUrl.'_thumb.png')) { + return true; + } else { + return false; + } +} + +/* + $image = file_get_contents('http://www.url.com/image.jpg'); + file_put_contents('/images/image.jpg', $image); //save the image on your server + * + * + */ +checkInstall(); +removeOlderThan(); + if (empty($defUrl)) { $defUrl = $GLOBALS['config']['defaultUrl']; } -if (empty($width)) { + +if (isset($ui['s']) && array_key_exists($ui['s'], $GLOBALS['config']['thumbSize'])) { + $width = $GLOBALS['config']['thumbSize'][$ui['s']]; +} else { $width = $GLOBALS['config']['defaultThumbSize']; } + +// Generate or return img +if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && $ui['p'] !== 'admin') { + if (empty($ui['url'])) { + die('You see in this world there\'s two kinds of people, my friend. Those with loaded guns, and those who dig. You dig.'); + } + $ui['url'] = trim(rawurldecode($ui['url'])); + $ui['url'] = rtrim($ui['url'], '/'); + $hashUrl = sha1($GLOBALS['config']['salt'].$ui['url']); + $startPath = substr($hashUrl, 0, 2).'/'.substr($hashUrl, 2, 2).'/'; + $file = 'cache/img/'.$ui['s'].'/'.$startPath.$hashUrl; + $testUrl = testValidUrl($ui['url']); + $defUrl = $ui['url']; + if ($ui['request'] === 'form') { + $file = 'cache/img/shortLive/'.$startPath.$hashUrl; + $file = 'cache/img/shortLive/'.$startPath.$hashUrl; + } + + if (testExistImg($file) === true && (int)$ui['fr'] !== 1) { + if ($ui['request'] === 'api') { + printThumbShot($file); + } + if ($ui['request'] === 'form') { + $success = array( + 'normal' => $file.'.png', + 'thumb' => $file.'_thumb.png' + ); + } + } else { + if ($ui['request'] === 'api') { + if (empty($ui['key']) || empty($ui['url'])) { + die('Are you Ken ?'); + } + if (sha1($ui['key'].$GLOBALS['config']['salt']) !== $GLOBALS['config']['serverKey']) { + ban(); + die('I take a chips and give it to Godzilla. I give high kick in Chuck Norris face and I go to ... Humm .... Ehh .... Arg ....... KAMOULOX ! Well done Jean Pierre.'); + } + } else { + verifToken($ui['token']); + } + if ($testUrl !== true) { + if (!file_exists('cache/logs/'.$hashUrl.'log')) { + file_put_contents('cache/logs/suspect/'.$hashUrl.'.log', $_SERVER['REMOTE_ADDR'].' --- '.$ui['url'].' --- '.$hashUrl.' --- '.$width.' --- '.$ui['s'].' --- '.$GLOBALS['config']['onlyThumb'].' --- true'."\n"); + } + if ($ui['request'] === 'api') { + printThumbShot('bin/error'); + } else { + $success = array( + 'normal' => 'bin/error.png', + 'thumb' => 'bin/error_thumb.png' + ); + } + } else { + $ext = testIfImg($ui['url']); + if ($ext !== false) { + $genWidth = explode("x", $width); + if ($ui['request'] === 'api') { + $makeImg = makeImgThumb($ui['url'], $ext, $hashUrl, $genWidth[0], 'cache/img/'.$ui['s'].'/'.$startPath, $GLOBALS['config']['onlyThumb']); + } else { + $makeImg = makeImgThumb($ui['url'], $ext, $hashUrl, $genWidth[0], 'cache/img/shortLive/'.$startPath, $GLOBALS['config']['onlyThumb']); + } + + if ($makeImg === true) { + $GLOBALS['config']['disableExec'] = true; + if ($ui['request'] === 'api') { + printThumbShot($file); + } else { + $success = array( + 'normal' => $file.'.png', + 'thumb' => $file.'_thumb.png' + ); + } + } + } + if ((isset($ui['iw']) && (int)$ui['iw'] === 1 && $ui['request'] === 'api')) { + $res = launchScript($defUrl, $hashUrl, $width, $ui['s'], $GLOBALS['config']['onlyThumb'], true); + } elseif ((isset($ui['iw']) && (int)$ui['iw'] === 1 && $ui['request'] === 'form')) { + $res = launchScript($defUrl, $hashUrl, $width, 'shortLive', $GLOBALS['config']['onlyThumb'], true); + } else { + $res = launchScript($defUrl, $hashUrl, $width, $ui['s'], $GLOBALS['config']['onlyThumb'], false); + } + if ($ui['request'] === 'api') { + $file = 'bin/loadingGen'; + printThumbShot($file); + } else { + $success = array( + 'normal' => $file.'.png', + 'thumb' => $file.'_thumb.png' + ); + } + } + } +} ?> - KT WebThumb - + SoShot + -
-

- -

-

- - -

-

- - -

-

- - -

-

- Homepage -

-
'; - echo '

This image will removed in 24h

'; - echo ''; - echo '

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

'; - } - } - echo ''; + require getPage($ui['p']); ?> - + \ No newline at end of file diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..77470cb --- /dev/null +++ b/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / \ No newline at end of file