2013-03-14 11:56:21 +01:00
< ? php
2018-10-01 14:08:36 +02:00
use Embed\Embed ;
2013-05-31 12:28:30 +02:00
session_start ();
if ( empty ( $_SESSION [ 'login' ])) {
2018-09-26 09:20:09 +02:00
$_SESSION [ 'login' ] = false ;
2013-03-14 11:56:21 +01:00
}
2013-03-19 17:07:13 +01:00
// change if you want no inpact
2013-05-03 11:01:17 +02:00
date_default_timezone_set ( 'Europe/Paris' );
2013-03-19 17:07:13 +01:00
// soshot only accept request by 127.0.0.1
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'onlyLocalServer' ] = false ;
2013-03-19 17:07:13 +01:00
// No form for post url only acces by GET method
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'NoWebPage' ] = false ;
2013-05-31 12:28:30 +02:00
// After 3 critical error ban user
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'maxErrorBeforeBan' ] = 3 ;
2013-03-19 17:07:13 +01:00
// Ban for 60 minutes
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'banTime' ] = 60 ;
2013-03-19 17:07:13 +01:00
// default url for form
2013-05-31 12:28:30 +02:00
$GLOBALS [ 'config' ][ 'defaultUrl' ] = 'https://duckduckgo.com/' ;
2013-03-19 17:07:13 +01:00
// default size for thumbnail
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'defaultThumbSize' ] = '120x90' ;
2013-03-19 17:07:13 +01:00
// list of available size for thumb
2013-05-03 11:01:17 +02:00
$GLOBALS [ 'config' ][ 'thumbSize' ] = array (
2018-09-26 09:20:09 +02:00
's' => '120x90' ,
'm' => '200x160' ,
'l' => '300x240' ,
'xl' => '400x320' ,
'xxl' => '500x400' ,
2013-05-03 11:01:17 +02:00
);
2015-07-09 17:21:32 +02:00
// create thumshot 1280x1024
$GLOBALS [ 'config' ][ 'activeFullSize' ] = false ;
// create thumbshot of complete page
$GLOBALS [ 'config' ][ 'activeComplete' ] = false ;
2018-10-01 14:08:36 +02:00
// create favicon
$GLOBALS [ 'config' ][ 'favicon' ] = false ;
2013-05-03 11:01:17 +02:00
// Remove image older than 12 hours
$GLOBALS [ 'config' ][ 'expireCache' ] = 12 ;
2013-08-16 11:56:15 +02:00
// Disable exec command and use cron task
2018-02-13 11:35:01 +01:00
$GLOBALS [ 'config' ][ 'disableExec' ] = false ;
2013-05-31 12:28:30 +02:00
// Enable log for success, suspect, error
2015-07-09 17:21:32 +02:00
$GLOBALS [ 'config' ][ 'log' ] = true ;
2013-05-31 13:32:51 +02:00
if ( file_exists ( 'cache/config/options.php' )) {
2018-09-26 09:20:09 +02:00
require 'cache/config/options.php' ;
2013-05-31 13:32:51 +02:00
}
2013-05-31 12:28:30 +02:00
if ( get_magic_quotes_gpc ()) {
2018-09-26 09:20:09 +02:00
function stripslashes_deep ( $value )
{
$value = is_array ( $value ) ? array_map ( 'stripslashes_deep' , $value ) : stripslashes ( $value );
return $value ;
}
2015-07-10 11:04:56 +02:00
2018-09-26 09:20:09 +02:00
$_POST = array_map ( 'stripslashes_deep' , $_POST );
$_GET = array_map ( 'stripslashes_deep' , $_GET );
$_COOKIE = array_map ( 'stripslashes_deep' , $_COOKIE );
2013-05-31 12:28:30 +02:00
}
if ( ! empty ( $_POST )) {
2018-09-26 09:20:09 +02:00
$ui = $_POST ;
$ui [ 'request' ] = 'form' ;
$ui [ 'iw' ] = 1 ;
unset ( $_POST );
2013-05-31 12:28:30 +02:00
}
if ( ! empty ( $_GET )) {
2018-09-26 09:20:09 +02:00
$ui = $_GET ;
$ui [ 'request' ] = 'api' ;
unset ( $_GET );
2013-05-31 12:28:30 +02:00
}
if ( empty ( $ui [ 'request' ])) {
2018-09-26 09:20:09 +02:00
$ui [ 'request' ] = '' ;
2013-05-31 12:28:30 +02:00
}
if ( empty ( $ui [ 'p' ])) {
2018-09-26 09:20:09 +02:00
$ui [ 'p' ] = 'index' ;
2013-05-31 12:28:30 +02:00
}
if ( empty ( $ui [ 'fr' ])) {
2018-09-26 09:20:09 +02:00
$ui [ 'fr' ] = '' ;
2013-05-31 12:28:30 +02:00
}
2015-07-09 17:21:32 +02:00
if ( empty ( $ui [ 't' ])) {
2018-09-26 09:20:09 +02:00
$ui [ 't' ] = 't' ;
2015-07-09 17:21:32 +02:00
}
2018-09-26 09:20:09 +02:00
if ( isset ( $ui [ 'logout' ]) && ( int ) $ui [ 'logout' ] === 1 ) {
session_destroy ();
header ( " Location:? " );
exit ();
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
if ( ! file_exists ( 'cache/config/genConf.php' )) {
2018-09-26 09:20:09 +02:00
$serverKey = install ();
$ui [ 'p' ] = 'install' ;
2013-03-14 11:56:21 +01:00
}
require 'cache/config/genConf.php' ;
2013-05-31 12:28:30 +02:00
if ( $GLOBALS [ 'config' ][ 'pwd' ] === 'install' && $ui [ 'p' ] !== 'install' ) {
2018-09-26 09:20:09 +02:00
reloadInstall ();
header ( " Location:? " );
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
if (( $GLOBALS [ 'config' ][ 'onlyLocalServer' ] === true && $_SERVER [ 'REMOTE_ADDR' ] !== '127.0.0.1' ) || checkIfBan () === true ) {
2018-09-26 09:20:09 +02:00
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 ();
2013-03-14 11:56:21 +01:00
}
2013-03-19 17:07:13 +01:00
if ( $GLOBALS [ 'config' ][ 'NoWebPage' ] === true && empty ( $_GET )) {
2018-09-26 09:20:09 +02:00
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 ();
}
2018-10-01 14:08:36 +02:00
function testExistImg ( $file , $type )
2018-09-26 09:20:09 +02:00
{
2018-10-01 14:08:36 +02:00
/*
type :
- c complete
- r full
- thumbnail
- fav favicon
*/
switch ( $type ) {
case 'c' :
if ( file_exists ( $file . '_complete.png' )) {
return true ;
}
break ;
case 'r' :
if ( file_exists ( $file . '_full.png' )) {
return true ;
}
break ;
case 'fav' :
if ( file_exists ( $file . '_favicon.png' )) {
return true ;
}
break ;
case 't' :
if ( file_exists ( $file . '_thumb.png' )) {
return true ;
}
break ;
default :
2018-09-26 09:20:09 +02:00
return false ;
2018-10-01 14:08:36 +02:00
break ;
2015-07-09 17:21:32 +02:00
}
2018-10-01 14:08:36 +02:00
return false ;
2013-03-14 11:56:21 +01:00
}
2013-03-29 14:27:43 +01:00
/**
* Run the bash script for generate thumbnail
*
* @ author Knah Tsaeb
* @ date 2013 - 02 - 12
* @ param $url ( string ) url for thumbshot
2013-05-31 12:28:30 +02:00
* @ param $hashUrl ( hash ) hash ( $url )
2013-03-29 14:27:43 +01:00
* @ param $width ( string ) size of thumbnail 190 x90
* @ param $onlyThumb ( bool )
2013-05-31 12:28:30 +02:00
* @ param $waitForResult ( bool )
2013-03-29 14:27:43 +01:00
* @ return
*/
2018-09-26 09:20:09 +02:00
function launchScript ( $url , $hashUrl , $width , $size , $waitForResult = false )
{
$oriHash = $hashUrl ;
$hashUrl = escapeshellarg ( $hashUrl );
$url = escapeshellarg ( $url );
$width = escapeshellarg ( $width );
if ( $GLOBALS [ 'config' ][ 'activeFullSize' ] && $GLOBALS [ 'config' ][ 'activeComplete' ]) {
$renderType = 'trc' ;
} elseif ( $GLOBALS [ 'config' ][ 'activeFullSize' ]) {
$renderType = 'tr' ;
} elseif ( $GLOBALS [ 'config' ][ 'activeComplete' ]) {
$renderType = 'tc' ;
} else {
$renderType = 't' ;
}
if ( $GLOBALS [ 'config' ][ 'disableExec' ] === false ) {
if ( ! file_exists ( 'cache/tmp/' . $oriHash . '.lock' )) {
touch ( 'cache/tmp/' . $oriHash . '.lock' );
chdir ( 'bin/' );
if ( $waitForResult === false ) {
exec ( 'bash thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $size . ' ' . $renderType . ' > /dev/null &' , $result );
} else {
exec ( 'bash thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $size . ' ' . $renderType . ' 1' , $result );
}
chdir ( '../' );
} else {
return 0 ;
}
2013-05-31 12:28:30 +02:00
} else {
2018-09-26 09:20:09 +02:00
makeQueueFile ( $url , $hashUrl , $width , $size , $renderType );
$result = 0 ;
2013-05-31 12:28:30 +02:00
}
2018-09-26 09:20:09 +02:00
return $result ;
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function makeQueueFile ( $url , $hashUrl , $width , $size , $renderType )
{
$url = str_replace ( '\'' , '' , $url );
$hashUrl = str_replace ( '\'' , '' , $hashUrl );
$width = str_replace ( '\'' , '' , $width );
if ( ! file_exists ( 'cache/cronTask/' . $hashUrl . '.hash' )) {
$data = $url . ' ' . $hashUrl . ' ' . $width . ' ' . $size . ' ' . $renderType . " \n " ;
file_put_contents ( 'cache/cronTask/' . $hashUrl . '.hash' , $data );
}
2013-08-16 11:56:15 +02:00
}
2018-09-26 09:20:09 +02:00
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' ,
))) {
return array ( 'msg' => 'Url must be start by http or https.' );
}
return true ;
} else {
return array ( 'msg' => 'Not a valid url.' );
2013-03-14 11:56:21 +01:00
}
}
2018-09-26 09:20:09 +02:00
function genToken ()
{
$token = sha1 ( uniqid ( rand (), true ) . '_' . mt_rand ());
$_SESSION [ 'token' ] = $token ;
$_SESSION [ 'tokenTime' ] = time ();
return $token ;
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function verifToken ( $token )
{
if ( $token !== $_SESSION [ 'token' ] || $_SESSION [ 'tokenTime' ] <= time () - 24000 ) {
ban ();
die ( 'So Long, and Thanks for All the Fish.' );
}
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function checkIfBan ()
{
require 'cache/logs/banUser.php' ;
$userIp = $_SERVER [ 'REMOTE_ADDR' ];
if ( isset ( $banList [ $userIp ]) && $banList [ $userIp ][ 'nbBan' ] >= $GLOBALS [ 'config' ][ 'maxErrorBeforeBan' ] && $banList [ $userIp ][ 'lastBan' ] + $GLOBALS [ 'config' ][ 'banTime' ] > time ()) {
return true ;
} elseif ( isset ( $banList [ $userIp ]) && $banList [ $userIp ][ 'lastBan' ] + $GLOBALS [ 'config' ][ 'banTime' ] < time ()) {
unban ();
return false ;
} else {
return false ;
}
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function ban ()
{
require 'cache/logs/banUser.php' ;
$userIp = $_SERVER [ 'REMOTE_ADDR' ];
if ( isset ( $banList [ $userIp ])) {
$banList [ $userIp ][ 'lastBan' ] = time ();
$banList [ $userIp ][ 'nbBan' ] ++ ;
} else {
$banList [ $userIp ][ 'lastBan' ] = time ();
$banList [ $userIp ][ 'nbBan' ] = 1 ;
}
file_put_contents ( 'cache/logs/banUser.php' , " <?php \n \$ banList= " . var_export ( $banList , true ) . " ; \n ?> " );
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function unBan ()
{
require 'cache/logs/banUser.php' ;
$userIp = $_SERVER [ 'REMOTE_ADDR' ];
unset ( $banList [ $userIp ]);
file_put_contents ( 'cache/logs/banUser.php' , " <?php \n \$ banList= " . var_export ( $banList , true ) . " ; \n ?> " );
2013-03-14 11:56:21 +01:00
}
2018-10-01 14:08:36 +02:00
function createDir ()
2018-09-26 09:20:09 +02:00
{
if ( ! is_writable ( 'cache' )) {
die ( 'Make dir "cache" writable' );
}
if ( ! is_dir ( 'cache/config' ) && ! mkdir ( 'cache/config' , 0705 )) {
die ( 'Error on create dir "cache/config".' );
}
if ( ! is_dir ( 'cache/img' ) && ! mkdir ( 'cache/img' , 0705 )) {
die ( 'Error on create dir "cache/img".' );
}
if ( ! is_dir ( 'cache/logs' ) && ! mkdir ( 'cache/logs' , 0705 )) {
die ( 'Error on create dir "cache/logs".' );
}
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".' );
}
if ( ! is_dir ( 'cache/cronTask' ) && ! mkdir ( 'cache/cronTask' , 0705 )) {
die ( 'Error on create dir "cache/cronTask".' );
}
2018-10-01 14:08:36 +02:00
}
function install ()
{
createDir ();
2018-09-26 09:20:09 +02:00
$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' , "
2018-02-13 11:35:01 +01:00
< ? php
\ $GLOBALS [ 'config' ][ 'serverKey' ] = '$encryptServerKey' ;
\ $GLOBALS [ 'config' ][ 'salt' ] = '$salt' ;
\ $GLOBALS [ 'config' ][ 'pwd' ] = 'install' ;
\ $GLOBALS [ 'config' ][ 'apikey' ] = '$serverKey' ;
?> ");
2018-09-26 09:20:09 +02:00
}
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' , " <?php \n \n ?> " );
}
if ( ! is_file ( 'cache/logs/banUser.php' )) {
file_put_contents ( 'cache/logs/banUser.php' , " <?php \n \n ?> " );
}
$GLOBALS [ 'config' ][ 'serverKey' ] = $encryptServerKey ;
$GLOBALS [ 'config' ][ 'salt' ] = $salt ;
$GLOBALS [ 'config' ][ 'pwd' ] = 'install' ;
$GLOBALS [ 'config' ][ 'apikey' ] = $serverKey ;
return $serverKey ;
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function checkInstall ()
{
if ( ! is_file ( '.htaccess' )) {
file_put_contents ( '.htaccess' , " AddDefaultCharset UTF-8 \n Options -Indexes \n DirectoryIndex index.php index.html \n FileETag none \n SetOutputFilter DEFLATE \n " );
}
if ( ! is_file ( 'cache/logs/.htaccess' )) {
file_put_contents ( 'cache/logs/.htaccess' , " Allow from none \n Deny from all \n " );
}
if ( ! is_file ( 'cache/config/.htaccess' )) {
file_put_contents ( 'cache/config/.htaccess' , " Allow from none \n Deny from all \n " );
}
if ( ! is_file ( 'cache/cronTask/.htaccess' )) {
file_put_contents ( 'cache/config/.htaccess' , " Allow from none \n Deny from all \n " );
}
if ( ! is_file ( 'bin/.htaccess' )) {
file_put_contents ( 'bin/.htaccess' , " Allow from none \n Deny from all \n " );
}
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function removeOlderThan ( $dir = 'cache/img/shortLive' )
{
if ( is_dir ( $dir )) {
$objects = scandir ( $dir );
foreach ( $objects as $object ) {
if ( $object !== '.' && $object !== '..' && $object ) {
if ( filetype ( $dir . '/' . $object ) === 'dir' ) {
removeOlderThan ( $dir . '/' . $object );
} else {
if ( fileatime ( $dir . '/' . $object ) < time () - 3600 * $GLOBALS [ 'config' ][ 'expireCache' ]) {
unlink ( $dir . '/' . $object );
}
}
}
2013-05-03 11:01:17 +02:00
}
2018-09-26 09:20:09 +02:00
reset ( $objects );
2013-05-03 11:01:17 +02:00
}
}
2018-09-26 09:20:09 +02:00
function pathForFile ( $size , $hashUrl )
{
$startPath = substr ( $hashUrl , 0 , 2 ) . '/' . substr ( $hashUrl , 2 , 2 ) . '/' ;
if ( empty ( $size )) {
$size = tryDetectSize ( $startPath . $hashUrl );
}
$file = 'cache/img/' . $size . '/' . $startPath . $hashUrl ;
return $file ;
2013-05-31 12:28:30 +02:00
}
2018-09-26 09:20:09 +02:00
function tryDetectSize ( $file )
{
if ( is_file ( 'cache/img/s/' . $file . '_thumb.png' )) {
return 's' ;
}
if ( is_file ( 'cache/img/m/' . $file . '_thumb.png' )) {
return 'm' ;
}
if ( is_file ( 'cache/img/l/' . $file . '_thumb.png' )) {
return 'l' ;
}
if ( is_file ( 'cache/img/xl/' . $file . '_thumb.png' )) {
return 'xl' ;
}
if ( is_file ( 'cache/img/xxl/' . $file . '_thumb.png' )) {
return 'xxl' ;
}
2015-07-10 11:04:56 +02:00
}
2018-09-26 09:20:09 +02:00
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 ;
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2018-09-26 09:20:09 +02:00
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 ;
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2018-09-26 09:20:09 +02:00
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' ];
$apikey = $GLOBALS [ 'config' ][ 'apikey' ];
$confFile = '
2013-05-31 12:28:30 +02:00
< ? php
2018-09-26 09:20:09 +02:00
$GLOBALS [ \ 'config\'][\'serverKey\'] = \'' . $confServerKey . ' \ ' ;
$GLOBALS [ \ 'config\'][\'salt\'] = \'' . $confSalt . ' \ ' ;
$GLOBALS [ \ 'config\'][\'pwd\'] = \'' . $confPwd . ' \ ' ;
$GLOBALS [ \ 'config\'][\'apikey\'] = \'' . $apikey . ' \ ' ;
2013-05-31 12:28:30 +02:00
?> ';
2018-09-26 09:20:09 +02:00
file_put_contents ( 'cache/config/genConf.php' , $confFile );
}
header ( " Location:? " );
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2018-09-26 09:20:09 +02:00
function reloadInstall ()
{
array_map ( 'unlink' , glob ( " cache/config/* " ));
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2013-05-31 12:28:30 +02:00
/**
* 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' );
*/
2018-09-26 09:20:09 +02:00
function n_print ( $data , $name = '' )
{
$aBackTrace = debug_backtrace ();
echo '<h2>' , $name , '</h2>' ;
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">' ;
echo ' < legend style = " border:1px solid orange;padding: 1px;background-color:#eee;color:orange; " >
', basename($aBackTrace[0][' file ']), ' ligne => ', $aBackTrace[0][' line '], '
2013-05-31 12:28:30 +02:00
</ legend > ' ;
2018-09-26 09:20:09 +02:00
echo '<pre>' , htmlentities ( print_r ( $data , 1 )), '</pre>' ;
echo '
2013-05-31 12:28:30 +02:00
</ fieldset >
< br />
' ;
}
2018-09-26 09:20:09 +02:00
function printThumbShot ( $file , $renderType )
{
ob_end_clean ();
header ( " Content-type: image/png " );
header ( 'Expires: ' , gmdate ( 'D, d M Y H:i:s' , time ()) . ' GMT' );
switch ( $renderType ) {
case 'c' :
echo file_get_contents ( $file . '_complete.png' );
break ;
case 'r' :
echo file_get_contents ( $file . '.png' );
break ;
2018-10-01 14:08:36 +02:00
case 'fav' :
echo file_get_contents ( $file . '_favicon.png' );
break ;
2018-09-26 09:20:09 +02:00
default :
echo file_get_contents ( $file . '_thumb.png' );
break ;
}
exit ();
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
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 ;
}
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2018-09-26 09:20:09 +02:00
function testIfImg ( $url )
{
2018-10-01 14:08:36 +02:00
$ext = strtolower ( pathinfo ( strtok ( $url , '?' ), PATHINFO_EXTENSION ));
2018-09-26 09:20:09 +02:00
if ( $ext === 'jpg' || $ext === 'jpeg' || $ext === 'png' || $ext === 'gif' || $ext === 'ico' ) {
return $ext ;
} else {
return false ;
}
2013-05-31 12:28:30 +02:00
}
2013-03-14 11:56:21 +01:00
2018-10-01 14:08:36 +02:00
function makeImgThumb ( $url , $ext , $hashUrl , $width , $path , $renderType = null )
2018-09-26 09:20:09 +02:00
{
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 ;
}
2013-03-14 11:56:21 +01:00
}
2018-09-26 09:20:09 +02:00
function checkHmac ( $receiveHmac , $url )
{
if ( $receiveHmac === makeHmac ( $url , $GLOBALS [ 'config' ][ 'apikey' ])) {
return true ;
} else {
return false ;
}
2018-02-13 11:35:01 +01:00
}
2018-09-26 09:20:09 +02:00
function makeHmac ( $url )
{
return hash_hmac ( 'sha1' , $url , $GLOBALS [ 'config' ][ 'apikey' ]);
2018-02-13 11:35:01 +01:00
}
2018-10-01 14:08:36 +02:00
function makeHashPath ( $hashUrl )
{
return substr ( $hashUrl , 0 , 2 ) . '/' . substr ( $hashUrl , 2 , 2 );
}
function makeFavicon ( $hash , $url , $filePath )
{
require_once 'vendor/autoload.php' ;
$resResize = '' ;
$data = array ();
$data [ 'hashPath' ] = $hashPath = $filePath ;
$data [ 'file' ] = $file = $filePath . $hash . '_favicon.png' ;
$info = Embed :: create ( $url , [
'follow_canonical' => true ,
'external_images' => true ,
]);
$faviconUrl = $info -> providerIcon ;
$data [ 'ext' ] = testIfImg ( $faviconUrl );
$data [ 'favicon' ] = $faviconUrl ;
$image = file_get_contents ( $faviconUrl );
$fullSize = file_put_contents ( 'cache/tmp/' . $hash . '.' . $data [ 'ext' ], $image );
$tmpFile = 'cache/tmp/' . $hash . '.' . $data [ 'ext' ];
if ( $data [ 'ext' ] === 'ico' ) {
$getBestSize = exec ( 'identify ' . escapeshellarg ( $tmpFile ), $originalFav );
if ( is_array ( $originalFav )) {
end ( $originalFav );
$key = key ( $originalFav );
if ( ! is_dir ( $hashPath )) {
mkdir ( $hashPath , 0700 , true );
}
exec ( 'convert -background transparent ' . escapeshellarg ( $tmpFile [ ' . $key . ' ]) . ' -resize x32 ' . $file , $resResize );
unlink ( 'cache/tmp/' . $hash . '.' . $data [ 'ext' ]);
}
} else {
if ( ! is_dir ( $hashPath )) {
mkdir ( $hashPath , 0700 , true );
}
exec ( 'convert -background transparent ' . escapeshellarg ( $tmpFile ) . ' -resize x32 ' . $file , $resResize );
unlink ( 'cache/tmp/' . $hash . '.' . $data [ 'ext' ]);
}
//n_print($data);
if ( file_exists ( $file )) {
return $file ;
}
}
function makeHashUrl ( $url )
{
return sha1 ( $GLOBALS [ 'config' ][ 'salt' ] . $url );
}
2013-05-31 12:28:30 +02:00
/*
2018-09-26 09:20:09 +02:00
$image = file_get_contents ( 'http://www.url.com/image.jpg' );
file_put_contents ( '/images/image.jpg' , $image ); //save the image on your server
2013-05-31 12:28:30 +02:00
*
*
*/
checkInstall ();
removeOlderThan ();
2013-03-14 11:56:21 +01:00
if ( empty ( $defUrl )) {
2018-09-26 09:20:09 +02:00
$defUrl = $GLOBALS [ 'config' ][ 'defaultUrl' ];
2013-03-14 11:56:21 +01:00
}
2013-05-31 12:28:30 +02:00
if ( isset ( $ui [ 's' ]) && array_key_exists ( $ui [ 's' ], $GLOBALS [ 'config' ][ 'thumbSize' ])) {
2018-09-26 09:20:09 +02:00
$width = $GLOBALS [ 'config' ][ 'thumbSize' ][ $ui [ 's' ]];
2013-05-31 12:28:30 +02:00
} else {
2018-09-26 09:20:09 +02:00
$width = $GLOBALS [ 'config' ][ 'defaultThumbSize' ];
2013-03-28 16:51:50 +01:00
}
2013-05-31 12:28:30 +02:00
// Generate or return img
if ( ! empty ( $ui [ 'request' ]) && $ui [ 'p' ] !== 'install' && $ui [ 'p' ] !== 'login' && $ui [ 'p' ] !== 'admin' ) {
2018-09-26 09:20:09 +02:00
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.' );
2013-05-31 12:28:30 +02:00
}
2018-10-01 14:08:36 +02:00
if ( $ui [ 'request' ] === 'form' ) {
//$file = 'cache/img/shortLive/' . $startPath . $hashUrl;
$ui [ 's' ] = 'shortLive' ;
}
2018-09-26 09:20:09 +02:00
$ui [ 'sendUrl' ] = $ui [ 'url' ];
$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 ) . '/' ;
2018-10-01 14:08:36 +02:00
$filePath = 'cache/img/' . $ui [ 's' ] . '/' . $startPath ;
2018-09-26 09:20:09 +02:00
$file = 'cache/img/' . $ui [ 's' ] . '/' . $startPath . $hashUrl ;
$testUrl = testValidUrl ( $ui [ 'url' ]);
$defUrl = $ui [ 'url' ];
2018-10-01 14:08:36 +02:00
// file exist we return img
if ( testExistImg ( $file , $ui [ 't' ]) === true && ( int ) $ui [ 'fr' ] !== 1 ) {
2013-05-31 12:28:30 +02:00
if ( $ui [ 'request' ] === 'api' ) {
2018-09-26 09:20:09 +02:00
if ( checkHmac ( $ui [ 'hm' ], $ui [ 'sendUrl' ])) {
printThumbShot ( $file , $ui [ 't' ]);
} else {
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.' );
}
2013-05-31 12:28:30 +02:00
}
2018-09-26 09:20:09 +02:00
if ( $ui [ 'request' ] === 'form' ) {
2013-05-31 12:28:30 +02:00
$success = array (
2018-09-26 09:20:09 +02:00
'normal' => $file . '.png' ,
'thumb' => $file . '_thumb.png' ,
'complete' => $file . '_complete.png' ,
2018-10-01 14:08:36 +02:00
'favicon' => $file . '_favicon.png' ,
2013-05-31 12:28:30 +02:00
);
}
2018-09-26 09:20:09 +02:00
} else {
if ( $ui [ 'request' ] === 'api' ) {
if ( empty ( $ui [ 'hm' ]) || empty ( $ui [ 'hm' ])) {
die ( 'Are you Ken ?' );
}
if ( ! checkHmac ( $ui [ 'hm' ], $ui [ 'sendUrl' ])) {
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' ]);
}
2018-10-01 14:08:36 +02:00
// url isn't correct put it in suspect log
2018-09-26 09:20:09 +02:00
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' ] . ' --- ' . $renderType . ' --- true' . " \n " );
}
if ( $ui [ 'request' ] === 'api' ) {
printThumbShot ( 'bin/error' , $ui [ 't' ]);
} else {
$success = array (
'normal' => 'bin/error.png' ,
'thumb' => 'bin/error_thumb.png' ,
'complete' => 'bin/error.png' ,
2018-10-01 14:08:36 +02:00
'favicon' => 'bin/error.png' ,
2018-09-26 09:20:09 +02:00
);
}
} 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 , $ui [ 't' ]);
} else {
$makeImg = makeImgThumb ( $ui [ 'url' ], $ext , $hashUrl , $genWidth [ 0 ], 'cache/img/shortLive/' . $startPath , $ui [ 't' ]);
}
if ( $makeImg === true ) {
2018-10-01 14:08:36 +02:00
//
2018-09-26 09:20:09 +02:00
$GLOBALS [ 'config' ][ 'disableExec' ] = true ;
if ( $ui [ 'request' ] === 'api' ) {
printThumbShot ( $file , $ui [ 't' ]);
} else {
$success = array (
'normal' => $file . '.png' ,
'thumb' => $file . '_thumb.png' ,
'complete' => $file . '_complete.png' ,
2018-10-01 14:08:36 +02:00
'favicon' => $file . '_favicon.png' ,
2018-09-26 09:20:09 +02:00
);
}
}
}
2018-10-01 14:08:36 +02:00
2018-09-26 09:20:09 +02:00
if (( isset ( $ui [ 'iw' ]) && ( int ) $ui [ 'iw' ] === 1 && $ui [ 'request' ] === 'api' )) {
$res = launchScript ( $defUrl , $hashUrl , $width , $ui [ 's' ], true );
2018-10-01 14:08:36 +02:00
} elseif ( isset ( $ui [ 'iw' ]) && ( int ) $ui [ 'iw' ] === 1 && $ui [ 'request' ] === 'form' ) { // img not exist or force refresh make it and return it
2018-09-26 09:20:09 +02:00
$res = launchScript ( $defUrl , $hashUrl , $width , 'shortLive' , true );
2018-10-01 14:08:36 +02:00
makeFavicon ( $hashUrl , $ui [ 'url' ], $filePath );
2018-09-26 09:20:09 +02:00
} else {
2018-10-01 14:08:36 +02:00
if ( $ui [ 't' ] === 'fav' ) {
$res = makeFavicon ( $hashUrl , $ui [ 'url' ], $filePath );
} else {
$res = launchScript ( $defUrl , $hashUrl , $width , $ui [ 's' ], false );
}
2018-09-26 09:20:09 +02:00
}
if ( $ui [ 'request' ] === 'api' ) {
$file = 'bin/loadingGen' ;
printThumbShot ( $file , $ui [ 't' ]);
2018-10-01 14:08:36 +02:00
die ();
2018-09-26 09:20:09 +02:00
} else {
if ( $GLOBALS [ 'config' ][ 'disableExec' ] === true ) {
$file = 'bin/loadingGen' ;
}
$success = array (
'normal' => $file . '.png' ,
'thumb' => $file . '_thumb.png' ,
'complete' => $file . '_complete.png' ,
2018-10-01 14:08:36 +02:00
'favicon' => $file . '_favicon.png' ,
2018-09-26 09:20:09 +02:00
);
}
2013-08-16 11:56:15 +02:00
}
2013-05-31 12:28:30 +02:00
}
}
2013-03-14 11:56:21 +01:00
?>
<! DOCTYPE html >
< html >
< head >
< meta charset = " utf-8 " >
2013-05-31 12:28:30 +02:00
< title > SoShot </ title >
< meta name = " description " content = " Personal webshot " >
2013-08-16 11:56:15 +02:00
< link rel = " stylesheet " href = " style.css " >
2013-03-14 11:56:21 +01:00
</ head >
< body >
2013-03-28 16:51:50 +01:00
< ? php
2018-09-26 09:20:09 +02:00
require getPage ( $ui [ 'p' ]);
?>
2013-03-14 11:56:21 +01:00
</ body >
2018-02-13 11:35:01 +01:00
</ html >