1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

secure_image work.

This commit is contained in:
CaMer0n 2011-06-26 20:09:45 +00:00
parent af36a22695
commit db5c9726df
3 changed files with 140 additions and 136 deletions

View File

@ -194,7 +194,7 @@ class redirection
return;
}
if(e107::getPref('maintainance_flag'))
if(e107::getPref('maintainance_flag') && e_PAGE != 'secure_img_render.php')
{
// if not admin
if(!ADMIN

View File

@ -90,5 +90,131 @@ class secure_image
$code = $this->create_code();
return "<img src='".e_HTTP.$this->HANDLERS_DIRECTORY."secure_img_render.php?{$code}' class='icon secure-image' alt='' />";
}
/**
* Render the generated Image.
*/
function render()
{
$sql = e107::getDb();
$imgtypes = array('jpg'=>"jpeg",'png'=>"png",'gif'=>"gif");
$recnum = preg_replace("#\D#","",e_QUERY);
if($recnum == false){ exit; }
$sql->db_Select_gen("SELECT tmp_info FROM #tmp WHERE tmp_ip = '{$recnum}' LIMIT 1");
if(!$row = $sql->db_Fetch(MYSQL_ASSOC))
{
echo "Render Failed";
exit;
}
list($code, $url) = explode(",",$row['tmp_info']);
$type = "none";
foreach($imgtypes as $k=>$t)
{
if(function_exists("imagecreatefrom".$t))
{
$ext = ".".$k;
$type = $t;
break;
}
}
$path = e_IMAGE;
// TODO - add support for adding it in the THEME folder.
if(is_readable(e_IMAGE."secure_image_custom.php"))
{
require_once(e_IMAGE."secure_image_custom.php");
$bg_file = $secureimg['image'];
if(!is_readable(e_IMAGE.$secureimg['font']))
{
echo "Font missing"; // for debug only. translation not necessary.
exit;
}
if(!is_readable(e_IMAGE.$secureimg['image'].$ext))
{
echo "Missing Background-Image: ".$secureimg['image'].$ext; // for debug only. translation not necessary.
exit;
}
// var_dump($secureimg);
}
else
{
$bg_file = "generic/code_bg";
}
switch($type)
{
case "jpeg":
$image = ImageCreateFromJPEG($path.$bg_file.".jpg");
break;
case "png":
$image = ImageCreateFromPNG($path.$bg_file.".png");
break;
case "gif":
$image = ImageCreateFromGIF($path.$bg_file.".gif");
break;
}
if(isset($secureimg['color']))
{
$tmp = explode(",",$secureimg['color']);
$text_color = ImageColorAllocate($image,$tmp[0],$tmp[1],$tmp[2]);
}
else
{
$text_color = ImageColorAllocate($image, 90, 90, 90);
}
header("Content-type: image/{$type}");
if(isset($secureimg['font']) && is_readable($path.$secureimg['font']))
{
imagettftext($image, $secureimg['size'],$secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color,$path.$secureimg['font'], $code);
}
else
{
imagestring ($image, 5, 12, 2, $code, $text_color);
}
ob_end_clean();
switch($type)
{
case "jpeg":
imagejpeg($image);
break;
case "png":
imagepng($image);
break;
case "gif":
imagegif($image);
break;
}
}
}
?>
?>

View File

@ -14,86 +14,9 @@
* $Author$
*/
while (@ob_end_clean());
ob_start();
function e107_ini_set($var, $value)
{
if (function_exists('ini_set'))
{
ini_set($var, $value);
}
}
// setup some php options
e107_ini_set('magic_quotes_runtime', 0);
e107_ini_set('magic_quotes_sybase', 0);
e107_ini_set('arg_separator.output', '&amp;');
e107_ini_set('session.use_only_cookies', 1);
e107_ini_set('session.use_trans_sid', 0);
while (list($global) = each($GLOBALS))
{
if (!preg_match('/^(_SERVER|GLOBALS)$/', $global))
{
unset($$global);
}
}
unset($global);
$imgtypes = array("jpeg", "png", "gif");
define("e_QUERY", preg_replace("#&|/?PHPSESSID.*#i", "", $_SERVER['QUERY_STRING']));
$recnum = preg_replace("#\D#","",e_QUERY);
if($recnum == false){ exit; }
$mySQLserver = "";
$a = 0;
$p = "";
$ifile = dirname(__FILE__);
if (substr($ifile,-1,1) != '/') $ifile .= '/';
@include_once($ifile."e107_config.php");
while(!$mySQLserver && $a < 5)
{
$a ++;
$p .= "../";
@include_once($ifile.$p.'e107_config.php'); // *** Revised
}
mysql_connect($mySQLserver, $mySQLuser, $mySQLpassword);
mysql_select_db($mySQLdefaultdb);
$result = mysql_query("SELECT tmp_info FROM {$mySQLprefix}tmp WHERE tmp_ip = '{$recnum}'");
if(!$row = mysql_fetch_array($result))
{
exit;
}
list($code, $url) = explode(",",$row['tmp_info']);
$type = "none";
foreach($imgtypes as $t)
{
if(function_exists("imagecreatefrom".$t))
{
$type = $t;
break;
}
}
$path = realpath(dirname(__FILE__)."/../")."/".$IMAGES_DIRECTORY;
if(is_readable($path."secure_image_custom.php"))
{
require_once($path."secure_image_custom.php");
/* Example secure_image_custom.php file:
/* Example Custom secure_image_custom.php file:
<?php
$secureimg['image'] = "code_bg_custom"; // filename excluding the .ext
$secureimg['size'] = "15";
$secureimg['angle'] = "0";
@ -101,61 +24,16 @@ if(is_readable($path."secure_image_custom.php"))
$secureimg['y'] = "22";
$secureimg['font'] = "imagecode.ttf";
$secureimg['color'] = "90,90,90"; // red,green,blue
?>
*/
*/
$bg_file = $secureimg['image'];
}
else
{
$bg_file = "generic/code_bg";
}
require_once(realpath(dirname(__FILE__).'/../class2.php'));
switch($type)
{
case "jpeg":
$image = ImageCreateFromJPEG($path.$bg_file.".jpg");
break;
case "png":
$image = ImageCreateFromPNG($path.$bg_file.".png");
break;
case "gif":
$image = ImageCreateFromGIF($path.$bg_file.".gif");
break;
}
require_once(e_HANDLER."secure_img_handler.php");
if(isset($secureimg['color']))
{
$tmp = explode(",",$secureimg['color']);
$text_color = ImageColorAllocate($image,$tmp[0],$tmp[1],$tmp[2]);
}
else
{
$text_color = ImageColorAllocate($image, 90, 90, 90);
}
$sim = new secure_image;
$sim->render();
header("Content-type: image/{$type}");
if(isset($secureimg['font']) && is_readable($path.$secureimg['font']))
{
imagettftext($image, $secureimg['size'],$secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color,$path.$secureimg['font'], $code);
}
else
{
imagestring ($image, 5, 12, 2, $code, $text_color);
}
ob_end_clean();
switch($type)
{
case "jpeg":
imagejpeg($image);
break;
case "png":
imagepng($image);
break;
case "gif":
imagegif($image);
break;
}
imagedestroy($image);
exit;
?>