From db5c9726df236785ad7f50b8eeda499abf9e3726 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Sun, 26 Jun 2011 20:09:45 +0000 Subject: [PATCH] secure_image work. --- e107_handlers/redirection_class.php | 2 +- e107_handlers/secure_img_handler.php | 128 ++++++++++++++++++++++- e107_handlers/secure_img_render.php | 146 +++------------------------ 3 files changed, 140 insertions(+), 136 deletions(-) diff --git a/e107_handlers/redirection_class.php b/e107_handlers/redirection_class.php index c3a78cd74..f22891f91 100644 --- a/e107_handlers/redirection_class.php +++ b/e107_handlers/redirection_class.php @@ -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 diff --git a/e107_handlers/secure_img_handler.php b/e107_handlers/secure_img_handler.php index b7096e8c7..1435753ea 100644 --- a/e107_handlers/secure_img_handler.php +++ b/e107_handlers/secure_img_handler.php @@ -90,5 +90,131 @@ class secure_image $code = $this->create_code(); return ""; } + + + + /** + * 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; + } + + + } + + + + + + + } -?> +?> \ No newline at end of file diff --git a/e107_handlers/secure_img_render.php b/e107_handlers/secure_img_render.php index 103bca35e..8002a259c 100644 --- a/e107_handlers/secure_img_render.php +++ b/e107_handlers/secure_img_render.php @@ -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', '&'); -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: + +*/ - */ - $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; +?> \ No newline at end of file