Second release
This commit is contained in:
parent
fbfe8540ef
commit
88f758ba10
11 changed files with 134 additions and 32 deletions
|
@ -1,5 +1,13 @@
|
||||||
AddDefaultCharset UTF-8
|
AddDefaultCharset UTF-8
|
||||||
Options -Indexes
|
Options -Indexes
|
||||||
DirectoryIndex index.php index.html
|
DirectoryIndex index.php index.html
|
||||||
|
Header set cache-control: public
|
||||||
|
<IfModule mod_expires.c>
|
||||||
|
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"
|
||||||
|
</IfModule>
|
||||||
FileETag none
|
FileETag none
|
||||||
SetOutputFilter DEFLATE
|
SetOutputFilter DEFLATE
|
BIN
bin/000.png
Normal file
BIN
bin/000.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
bin/404.png
Normal file
BIN
bin/404.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
bin/error.png
Normal file
BIN
bin/error.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
bin/loadingGen.png
Normal file
BIN
bin/loadingGen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
12
bin/mon.sh
Normal file
12
bin/mon.sh
Normal file
|
@ -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
|
|
@ -2,7 +2,7 @@ var page = new WebPage(),
|
||||||
address, output, size;
|
address, output, size;
|
||||||
|
|
||||||
if (phantom.args.length < 2) {
|
if (phantom.args.length < 2) {
|
||||||
console.log('Usage: rasterize.js URL filename');
|
//console.log('Usage: rasterize.js URL filename');
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
} else {
|
} else {
|
||||||
address = phantom.args[0];
|
address = phantom.args[0];
|
||||||
|
@ -12,13 +12,15 @@ if (phantom.args.length < 2) {
|
||||||
|
|
||||||
page.open(address, function (status) {
|
page.open(address, function (status) {
|
||||||
if (status !== 'success') {
|
if (status !== 'success') {
|
||||||
console.log('Unable to load the address!');
|
//console.log('Unable to load the address!');
|
||||||
|
page.close();
|
||||||
|
phantom.exit();
|
||||||
} else {
|
} else {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
page.render(output);
|
page.render(output);
|
||||||
|
page.close();
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
}, 500);
|
}, 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,54 @@
|
||||||
#!/bin/bash
|
#!/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
|
site=$1 # url must be encode by url_encode() or equivalent ex : http://google.com
|
||||||
md5Site=$2
|
md5Site=$2 # md5(url) is the name of final image
|
||||||
thumbWidth=$3
|
thumbSize=$3 # size of thumb widthxheight ex : 190x90
|
||||||
onlyThumb=$4
|
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}
|
#firstLevel=${md5Site:0:2}
|
||||||
#secondLevel=${md5Site:2:2}
|
#secondLevel=${md5Site:2:2}
|
||||||
#mkdir -p "cache/img/$firstLevel/$secondLevel/"
|
#mkdir -p "bin/img/$firstLevel/$secondLevel/"
|
||||||
./bin/phantomjs --ignore-ssl-errors=true /bin/rasterize.js "$site" "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/$md5Site.png"
|
||||||
#convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$firstLevel/$secondLevel/$md5Site.png"
|
if [ ! -f "cache/tmp/$md5Site.png" ]
|
||||||
#convert "cache/img/$firstLevel/$secondLevel/$md5Site.png" -filter Lanczos -thumbnail "$thumbWidth" "cache/img/$firstLevel/$secondLevel/$md5Site""_thumb.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 ]
|
if [ $onlyThumb ]
|
||||||
then
|
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
|
else
|
||||||
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" &&
|
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
|
fi
|
||||||
rm "cache/tmp/$md5Site.png"
|
rm "cache/tmp/$md5Site.png"
|
||||||
|
|
||||||
|
@ -37,3 +68,9 @@ else
|
||||||
echo 0
|
echo 0
|
||||||
fi
|
fi
|
||||||
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
|
||||||
|
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 KiB |
63
index.php
63
index.php
|
@ -3,14 +3,23 @@ if (empty($_SESSION)) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
date_default_timezone_set('Europe/Paris');
|
date_default_timezone_set('Europe/Paris');
|
||||||
|
// change if you want no inpact
|
||||||
$GLOBALS['config']['onlyLocalServer'] = false;
|
$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;
|
$GLOBALS['config']['maxErrorBeforeBan'] = 3;
|
||||||
|
// After 3 criticla error ban user
|
||||||
$GLOBALS['config']['banTime'] = 60;
|
$GLOBALS['config']['banTime'] = 60;
|
||||||
|
// Ban for 60 minutes
|
||||||
$GLOBALS['config']['defaultUrl'] = 'https://google.com';
|
$GLOBALS['config']['defaultUrl'] = 'https://google.com';
|
||||||
|
// default url for form
|
||||||
$GLOBALS['config']['defaultThumbSize'] = '120x90';
|
$GLOBALS['config']['defaultThumbSize'] = '120x90';
|
||||||
|
// default size for thumbnail
|
||||||
$GLOBALS['config']['onlyThumb'] = true;
|
$GLOBALS['config']['onlyThumb'] = true;
|
||||||
|
// generate only thumbnail or generate thumb nail + 1280x1024 image
|
||||||
$GLOBALS['config']['thumbSize'] = array(1 => '100x80', '120x90', '200x160', '300x240', '400x320', '500x400');
|
$GLOBALS['config']['thumbSize'] = array(1 => '100x80', '120x90', '200x160', '300x240', '400x320', '500x400');
|
||||||
|
// list of available size for thumb
|
||||||
|
|
||||||
if (!file_exists('cache/config/genConf.php')) {
|
if (!file_exists('cache/config/genConf.php')) {
|
||||||
install();
|
install();
|
||||||
|
@ -26,6 +35,13 @@ if (($GLOBALS['config']['onlyLocalServer'] === true && $_SERVER['REMOTE_ADDR'] !
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($GLOBALS['config']['NoWebPage'] === true && empty($_GET)) {
|
||||||
|
header("HTTP/1.0 404 Not Found");
|
||||||
|
echo "<h1>404 Not Found</h1>";
|
||||||
|
echo "The page that you have requested could not be found.";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
if (get_magic_quotes_gpc()) {
|
if (get_magic_quotes_gpc()) {
|
||||||
function stripslashes_deep($value) {
|
function stripslashes_deep($value) {
|
||||||
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
|
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
|
||||||
|
@ -38,18 +54,30 @@ if (get_magic_quotes_gpc()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testExistImg($file) {
|
function testExistImg($file) {
|
||||||
|
if ($GLOBALS['config']['onlyThumb'] === true) {
|
||||||
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function launchScript($url, $md5Url, $width) {
|
function launchScript($url, $md5Url, $width, $waitForResult = false) {
|
||||||
$md5Url = escapeshellarg($md5Url);
|
$md5Url = escapeshellarg($md5Url);
|
||||||
$url = escapeshellarg($url);
|
$url = escapeshellarg($url);
|
||||||
$width = escapeshellarg($width);
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +165,9 @@ function install() {
|
||||||
if (!is_file('cache/logs/banUser.php')) {
|
if (!is_file('cache/logs/banUser.php')) {
|
||||||
file_put_contents('cache/logs/banUser.php', "<?php\n\n?>");
|
file_put_contents('cache/logs/banUser.php', "<?php\n\n?>");
|
||||||
}
|
}
|
||||||
|
if (!is_file('cache/logs/log.php')) {
|
||||||
|
touch('cache/logs/log.php');
|
||||||
|
}
|
||||||
echo '<div>This is the key for generate thumbnail whith GET method. Save it, this key is secret, don\'t share it. <p class="alert">', $serverKey, '</p></div>';
|
echo '<div>This is the key for generate thumbnail whith GET method. Save it, this key is secret, don\'t share it. <p class="alert">', $serverKey, '</p></div>';
|
||||||
checkInstall();
|
checkInstall();
|
||||||
}
|
}
|
||||||
|
@ -186,13 +217,18 @@ if ($_GET) {
|
||||||
$file = 'cache/img/' . $md5Url;
|
$file = 'cache/img/' . $md5Url;
|
||||||
|
|
||||||
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
||||||
|
if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
|
||||||
|
launchScript($defUrl, $md5Url, $width, true);
|
||||||
|
} else {
|
||||||
$res = launchScript($defUrl, $md5Url, $width);
|
$res = launchScript($defUrl, $md5Url, $width);
|
||||||
if ((int)$res !== 1) {
|
|
||||||
die('Internal error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
header("Content-type: image/png");
|
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') {
|
if (!empty($ui['t']) && $ui['t'] === 'full') {
|
||||||
echo file_get_contents($file . '.png');
|
echo file_get_contents($file . '.png');
|
||||||
} else {
|
} else {
|
||||||
|
@ -229,10 +265,7 @@ if ($_POST) {
|
||||||
$file = 'cache/img/' . $md5Url;
|
$file = 'cache/img/' . $md5Url;
|
||||||
|
|
||||||
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
||||||
$res = launchScript($defUrl, $md5Url, $width);
|
launchScript($defUrl, $md5Url, $width, true);
|
||||||
if ((int)$res !== 1) {
|
|
||||||
die('Internal error');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png');
|
$success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png');
|
||||||
}
|
}
|
||||||
|
@ -281,7 +314,11 @@ if (empty($defUrl)) {
|
||||||
<div id="result">
|
<div id="result">
|
||||||
<?php
|
<?php
|
||||||
if (!empty($success)) {
|
if (!empty($success)) {
|
||||||
echo '<a href="', $success['normal'], '"><img src="', $success['thumb'], '"/></a>';
|
if ($GLOBALS['config']['onlyThumb'] === true) {
|
||||||
|
echo '<img src="', $success['thumb'], '?r=', time(), '"/>';
|
||||||
|
} else {
|
||||||
|
echo '<a href="', $success['normal'], '"><img src="', $success['thumb'], '?r=', time(), '"/></a>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1 +1,7 @@
|
||||||
All info in the homepage http://forge.leslibres.org/projects/soshot
|
All info in the homepage http://forge.leslibres.org/projects/soshot
|
||||||
|
|
||||||
|
*** Thanks ***
|
||||||
|
Icon by http://www.iconfinder.com/icondetails/7917/128/camera_file_image_icon
|
||||||
|
Bash script idea by http://www.cambus.net/blog/page/3/
|
||||||
|
Httpstatus in bash by https://gist.github.com/rsvp/1171304
|
||||||
|
The engine phantomjs by http://phantomjs.org/
|
||||||
|
|
Loading…
Reference in a new issue