diff --git a/.htaccess b/.htaccess
index 8c115f6..4a81062 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,5 +1,13 @@
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
+SetOutputFilter DEFLATE
\ No newline at end of file
diff --git a/bin/000.png b/bin/000.png
new file mode 100644
index 0000000..f9bbe43
Binary files /dev/null and b/bin/000.png differ
diff --git a/bin/404.png b/bin/404.png
new file mode 100644
index 0000000..c43c470
Binary files /dev/null and b/bin/404.png differ
diff --git a/bin/error.png b/bin/error.png
new file mode 100644
index 0000000..f069dbd
Binary files /dev/null and b/bin/error.png differ
diff --git a/bin/loadingGen.png b/bin/loadingGen.png
new file mode 100644
index 0000000..eb93c51
Binary files /dev/null and b/bin/loadingGen.png differ
diff --git a/bin/mon.sh b/bin/mon.sh
new file mode 100644
index 0000000..9e83baa
--- /dev/null
+++ b/bin/mon.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+echo "PRESS CTRL+C FOR STOP MONITOR"
+sleep 5
+while [ 1 ]
+do
+ clear
+ echo "################################"
+ echo "Total request thumbshot : " $(ps -e | grep -v grep | grep thumb_ | wc -l) && # count thumb_server.sh process
+ echo "Number of thumbshot are made now : " $(ps -e | grep -v grep | grep phantomjs | wc -l) && # count phantomjs process
+ echo "Number of test error now : " $(ps -e | grep -v grep | grep curl | wc -l) # count thumb_server.sh => curl process
+ sleep 3 # 3 second between two refresh
+done
diff --git a/bin/rasterize.js b/bin/rasterize.js
index db312af..9aef4b0 100644
--- a/bin/rasterize.js
+++ b/bin/rasterize.js
@@ -2,7 +2,7 @@ var page = new WebPage(),
address, output, size;
if (phantom.args.length < 2) {
- console.log('Usage: rasterize.js URL filename');
+ //console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
@@ -12,13 +12,15 @@ if (phantom.args.length < 2) {
page.open(address, function (status) {
if (status !== 'success') {
- console.log('Unable to load the address!');
+ //console.log('Unable to load the address!');
+ page.close();
+ phantom.exit();
} else {
window.setTimeout(function () {
page.render(output);
+ page.close();
phantom.exit();
- }, 500);
+ }, 200);
}
});
}
-
diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh
index a66707e..b11bf7e 100755
--- a/bin/thumb_server.sh
+++ b/bin/thumb_server.sh
@@ -1,23 +1,54 @@
#!/bin/bash
-# inspirated source http://www.cambus.net/blog/page/3/
+# inspirated source http://www.cambus.net/blog/page/3/ for global idea
+# https://gist.github.com/rsvp/1171304 for httpstatus code
+# All info at http://forge.leslibres.org/projects/soshot
-site=$1
-md5Site=$2
-thumbWidth=$3
-onlyThumb=$4
+site=$1 # url must be encode by url_encode() or equivalent ex : http://google.com
+md5Site=$2 # md5(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=2 # max parralle work for me the best is processor 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))`
+if [ ! $waitForResult ]
+then
+ sleep `echo $((RANDOM%20))`
+ while [[ `ps -e | grep -v grep | grep phantomjs | wc -l` -ge $maxThread ]]
+ do
+ sleep `echo $((RANDOM%20))`
+ done
+fi
+start_time=`date +%s`
#firstLevel=${md5Site:0:2}
#secondLevel=${md5Site:2:2}
-#mkdir -p "cache/img/$firstLevel/$secondLevel/"
-./bin/phantomjs --ignore-ssl-errors=true /bin/rasterize.js "$site" "cache/tmp/$md5Site.png"
-#convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$firstLevel/$secondLevel/$md5Site.png"
-#convert "cache/img/$firstLevel/$secondLevel/$md5Site.png" -filter Lanczos -thumbnail "$thumbWidth" "cache/img/$firstLevel/$secondLevel/$md5Site""_thumb.png"
+#mkdir -p "bin/img/$firstLevel/$secondLevel/"
+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" ]
+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/$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$md5Site.png" ;;
+ 404) cp "bin/404.png" "cache/img/$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$md5Site.png" ;;
+ *) cp "bin/error.png" "cache/img/$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$md5Site.png" ;;
+ esac
+ if $log
+ 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'
+ fi
+ exit
+fi
if [ $onlyThumb ]
then
- convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbWidth" "cache/img/$md5Site""_thumb.png"
+ convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
else
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" &&
- convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbWidth" "cache/img/$md5Site""_thumb.png"
+ convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
fi
rm "cache/tmp/$md5Site.png"
@@ -37,3 +68,9 @@ else
echo 0
fi
fi
+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'
+fi
diff --git a/favicon.ico b/favicon.ico
new file mode 100644
index 0000000..52b3be9
Binary files /dev/null and b/favicon.ico differ
diff --git a/index.php b/index.php
index c264e7b..9533463 100644
--- a/index.php
+++ b/index.php
@@ -3,14 +3,23 @@ if (empty($_SESSION)) {
session_start();
}
date_default_timezone_set('Europe/Paris');
+// change if you want no inpact
$GLOBALS['config']['onlyLocalServer'] = false;
-$GLOBALS['config']['private'] = true;
+// soshot only accept request by 127.0.0.1
+$GLOBALS['config']['NoWebPage'] = false;
+// No form for post url only acces by GET method
$GLOBALS['config']['maxErrorBeforeBan'] = 3;
+// After 3 criticla error ban user
$GLOBALS['config']['banTime'] = 60;
+// Ban for 60 minutes
$GLOBALS['config']['defaultUrl'] = 'https://google.com';
+// default url for form
$GLOBALS['config']['defaultThumbSize'] = '120x90';
+// default size for thumbnail
$GLOBALS['config']['onlyThumb'] = true;
+// generate only thumbnail or generate thumb nail + 1280x1024 image
$GLOBALS['config']['thumbSize'] = array(1 => '100x80', '120x90', '200x160', '300x240', '400x320', '500x400');
+// list of available size for thumb
if (!file_exists('cache/config/genConf.php')) {
install();
@@ -26,6 +35,13 @@ if (($GLOBALS['config']['onlyLocalServer'] === true && $_SERVER['REMOTE_ADDR'] !
exit();
}
+if ($GLOBALS['config']['NoWebPage'] === true && empty($_GET)) {
+ header("HTTP/1.0 404 Not Found");
+ echo "
404 Not Found
";
+ echo "The page that you have requested could not be found.";
+ exit();
+}
+
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
@@ -38,18 +54,30 @@ if (get_magic_quotes_gpc()) {
}
function testExistImg($file) {
- if (file_exists($file . '_thumb.png') && file_exists($file . '.png')) {
- return true;
+ if ($GLOBALS['config']['onlyThumb'] === true) {
+ if (file_exists($file . '_thumb.png')) {
+ return true;
+ } else {
+ return false;
+ }
} else {
- return false;
+ if (file_exists($file . '_thumb.png') && file_exists($file . '.png')) {
+ return true;
+ } else {
+ return false;
+ }
}
}
-function launchScript($url, $md5Url, $width) {
+function launchScript($url, $md5Url, $width, $waitForResult = false) {
$md5Url = escapeshellarg($md5Url);
$url = escapeshellarg($url);
$width = escapeshellarg($width);
- exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . (bool)$GLOBALS['config']['onlyThumb'], $result);
+ if ($waitForResult === false) {
+ exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . (bool)$GLOBALS['config']['onlyThumb'] . ' > /dev/null &', $result);
+ } else {
+ exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . (bool)$GLOBALS['config']['onlyThumb'] . ' 1', $result);
+ }
return $result;
}
@@ -137,6 +165,9 @@ function install() {
if (!is_file('cache/logs/banUser.php')) {
file_put_contents('cache/logs/banUser.php', "");
}
+ if (!is_file('cache/logs/log.php')) {
+ touch('cache/logs/log.php');
+ }
echo 'This is the key for generate thumbnail whith GET method. Save it, this key is secret, don\'t share it.
', $serverKey, '
';
checkInstall();
}
@@ -186,13 +217,18 @@ if ($_GET) {
$file = 'cache/img/' . $md5Url;
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
- $res = launchScript($defUrl, $md5Url, $width);
- if ((int)$res !== 1) {
- die('Internal error');
+ if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
+ launchScript($defUrl, $md5Url, $width, true);
+ } else {
+ $res = launchScript($defUrl, $md5Url, $width);
+ header("Content-type: image/png");
+ header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
+ echo file_get_contents('bin/loadingGen.png');
+ exit();
}
}
-
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 {
@@ -229,10 +265,7 @@ if ($_POST) {
$file = 'cache/img/' . $md5Url;
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
- $res = launchScript($defUrl, $md5Url, $width);
- if ((int)$res !== 1) {
- die('Internal error');
- }
+ launchScript($defUrl, $md5Url, $width, true);
}
$success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png');
}
@@ -281,9 +314,13 @@ if (empty($defUrl)) {
';
+ if ($GLOBALS['config']['onlyThumb'] === true) {
+ echo '
';
+ } else {
+ echo '
';
+ }
}
?>