Просмотр файла includes/usercp_confirm.php

Размер файла: 6.16Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. if ( !defined('IN_PHPBB') )
  7. {
  8. die('Hacking attempt');
  9. exit;
  10. }
  11.  
  12. if (empty($HTTP_GET_VARS['id']))
  13. {
  14. exit;
  15. }
  16.  
  17. $confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);
  18.  
  19. if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
  20. {
  21. $confirm_id = '';
  22. }
  23.  
  24. $sql = 'SELECT code
  25. FROM ' . CONFIRM_TABLE . "
  26. WHERE session_id = '" . $userdata['session_id'] . "'
  27. AND confirm_id = '$confirm_id'";
  28. $result = $db->sql_query($sql);
  29.  
  30. if ($row = $db->sql_fetchrow($result))
  31. {
  32. $db->sql_freeresult($result);
  33. $code = $row['code'];
  34. }
  35. else
  36. {
  37. exit;
  38. }
  39.  
  40. class KCAPTCHA{
  41.  
  42. function KCAPTCHA(){
  43. global $code;
  44. require(dirname(__FILE__).'/kcaptcha_config.php');
  45. $fonts=array();
  46. $fontsdir_absolute=dirname(__FILE__).'/'.$fontsdir;
  47. if ($handle = opendir($fontsdir_absolute)) {
  48. while (false !== ($file = readdir($handle))) {
  49. if (preg_match('/\.png$/i', $file)) {
  50. $fonts[]=$fontsdir_absolute.'/'.$file;
  51. }
  52. }
  53. closedir($handle);
  54. }
  55. $alphabet_length=strlen($alphabet);
  56. while(true){
  57. $this->keystring = $code;
  58. $font_file=$fonts[mt_rand(0, count($fonts)-1)];
  59. $font=imagecreatefrompng($font_file);
  60. imagealphablending($font, true);
  61. $fontfile_width=imagesx($font);
  62. $fontfile_height=imagesy($font)-1;
  63. $font_metrics=array();
  64. $symbol=0;
  65. $reading_symbol=false;
  66.  
  67. for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){
  68. $transparent = (imagecolorat($font, $i, 0) >> 24) == 127;
  69.  
  70. if(!$reading_symbol && !$transparent){
  71. $font_metrics[$alphabet{$symbol}]=array('start'=>$i);
  72. $reading_symbol=true;
  73. continue;
  74. }
  75.  
  76. if($reading_symbol && $transparent){
  77. $font_metrics[$alphabet{$symbol}]['end']=$i;
  78. $reading_symbol=false;
  79. $symbol++;
  80. continue;
  81. }
  82. }
  83.  
  84. $img=imagecreatetruecolor($width, $height);
  85. imagealphablending($img, true);
  86. $white=imagecolorallocate($img, 255, 255, 255);
  87. $black=imagecolorallocate($img, 0, 0, 0);
  88.  
  89. imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white);
  90.  
  91. $x=1;
  92. for($i=0;$i<$length;$i++){
  93. $m=$font_metrics[$this->keystring{$i}];
  94.  
  95. $y=mt_rand(-$fluctuation_amplitude, $fluctuation_amplitude)+($height-$fontfile_height)/2+2;
  96.  
  97. if($no_spaces){
  98. $shift=0;
  99. if($i>0){
  100. $shift=1000;
  101. for($sy=7;$sy<$fontfile_height-20;$sy+=1){
  102. //for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){
  103. for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){
  104. $rgb=imagecolorat($font, $sx, $sy);
  105. $opacity=$rgb>>24;
  106. if($opacity<127){
  107. $left=$sx-$m['start']+$x;
  108. $py=$sy+$y;
  109. if($py>$height) break;
  110. for($px=min($left,$width-1);$px>$left-12 && $px>=0;$px-=1){
  111. $color=imagecolorat($img, $px, $py) & 0xff;
  112. if($color+$opacity<190){
  113. if($shift>$left-$px){
  114. $shift=$left-$px;
  115. }
  116. break;
  117. }
  118. }
  119. break;
  120. }
  121. }
  122. }
  123. if($shift==1000){
  124. $shift=mt_rand(4,6);
  125. }
  126.  
  127. }
  128. }else{
  129. $shift=1;
  130. }
  131. imagecopy($img,$font,$x-$shift,$y,$m['start'],1,$m['end']-$m['start'],$fontfile_height);
  132. $x+=$m['end']-$m['start']-$shift;
  133. }
  134. if($x<$width-10) break;
  135. }
  136. $center=$x/2;
  137.  
  138. $img2=imagecreatetruecolor($width, $height+($show_credits?12:0));
  139. $foreground=imagecolorallocate($img2, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
  140. $background=imagecolorallocate($img2, $background_color[0], $background_color[1], $background_color[2]);
  141. imagefilledrectangle($img2, 0, $height, $width-1, $height+12, $foreground);
  142. $credits=empty($credits)?$_SERVER['HTTP_HOST']:$credits;
  143. imagestring($img2, 2, $width/2-ImageFontWidth(2)*strlen($credits)/2, $height-2, $credits, $background);
  144.  
  145. $rand1=mt_rand(750000,1200000)/10000000;
  146. $rand2=mt_rand(750000,1200000)/10000000;
  147. $rand3=mt_rand(750000,1200000)/10000000;
  148. $rand4=mt_rand(750000,1200000)/10000000;
  149. $rand5=mt_rand(0,3141592)/500000;
  150. $rand6=mt_rand(0,3141592)/500000;
  151. $rand7=mt_rand(0,3141592)/500000;
  152. $rand8=mt_rand(0,3141592)/500000;
  153. $rand9=mt_rand(330,420)/110;
  154. $rand10=mt_rand(330,450)/110;
  155.  
  156. for($x=0;$x<$width;$x++){
  157. for($y=0;$y<$height;$y++){
  158. $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1;
  159. $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;
  160.  
  161. if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){
  162. $color=255;
  163. $color_x=255;
  164. $color_y=255;
  165. $color_xy=255;
  166. }else{
  167. $color=imagecolorat($img, $sx, $sy) & 0xFF;
  168. $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF;
  169. $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF;
  170. $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF;
  171. }
  172.  
  173. if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){
  174. $newred=$foreground_color[0];
  175. $newgreen=$foreground_color[1];
  176. $newblue=$foreground_color[2];
  177. }else if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){
  178. $newred=$background_color[0];
  179. $newgreen=$background_color[1];
  180. $newblue=$background_color[2];
  181. }else{
  182. $frsx=$sx-floor($sx);
  183. $frsy=$sy-floor($sy);
  184. $frsx1=1-$frsx;
  185. $frsy1=1-$frsy;
  186.  
  187. $newcolor=(
  188. $color*$frsx1*$frsy1+
  189. $color_x*$frsx*$frsy1+
  190. $color_y*$frsx1*$frsy+
  191. $color_xy*$frsx*$frsy);
  192.  
  193. if($newcolor>255) $newcolor=255;
  194. $newcolor=$newcolor/255;
  195. $newcolor0=1-$newcolor;
  196.  
  197. $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
  198. $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
  199. $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
  200. }
  201.  
  202. imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
  203. }
  204. }
  205.  
  206. if(function_exists("imagejpeg")){
  207. header("Content-Type: image/jpeg");
  208. imagejpeg($img2, null, $jpeg_quality);
  209. }else if(function_exists("imagegif")){
  210. header("Content-Type: image/gif");
  211. imagegif($img2);
  212. }else if(function_exists("imagepng")){
  213. header("Content-Type: image/x-png");
  214. imagepng($img2);
  215. }
  216. }
  217.  
  218. }
  219.  
  220. new KCAPTCHA();
  221.  
  222. ?>