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 0000000..a794e2c
Binary files /dev/null and b/bin/error_thumb.png differ
diff --git a/bin/loadingGen_thumb.png b/bin/loadingGen_thumb.png
new file mode 100644
index 0000000..8264e66
Binary files /dev/null and b/bin/loadingGen_thumb.png differ
diff --git a/bin/mon.sh b/bin/mon.sh
index a198c37..568267d 100644
--- a/bin/mon.sh
+++ b/bin/mon.sh
@@ -10,7 +10,6 @@ do
echo "#################################################"
echo "######### PRESS CTRL+C FOR STOP MONITOR #########"
echo "#################################################"
- tail '../cache/logs/logs.txt'
sleep 3 # 3 second between two refresh
done
diff --git a/bin/rasterize.js b/bin/rasterize.js
index 5e56c70..a0056f8 100644
--- a/bin/rasterize.js
+++ b/bin/rasterize.js
@@ -7,7 +7,7 @@ if (phantom.args.length < 2) {
} else {
address = phantom.args[0];
output = phantom.args[1];
-
+ page.settings.userAgent = 'SoShot Agent';
page.viewportSize = { width: 1280, height: 1024 };
page.open(address, function (status) {
diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh
index fb5f5f9..26e8561 100755
--- a/bin/thumb_server.sh
+++ b/bin/thumb_server.sh
@@ -9,6 +9,10 @@ thumbSize=$3 # size of thumb widthxheight ex : 190x90
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
+##########################################
+##### DON'T EDIT THIS PARAM USE #####
+##### cache/config/serverOptions.php #####
+##########################################
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
log=false # log all generation success and error
@@ -20,6 +24,12 @@ firstLevel=${hashUrl:0:2}
secondLevel=${hashUrl:2:2}
startPath=$sizeNameDir/$firstLevel/$secondLevel/
+if [ $site == "manual" ]
+then
+ site=$(cat "cache/tmp/manual.txt")
+ echo '' > "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 '';
+}
+?>
\ 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 @@
+
+';
+ 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 '
+
+';
+}
+
+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
+
-
';
- echo 'This image will removed in 24h
';
- echo '';
- echo '';
- if ($GLOBALS['config']['onlyThumb'] === false) {
- echo '';
- }
- }
- echo '';
+ require getPage($ui['p']);
?>
-
+