diff --git a/AvocadoEdition_Light/plugin/kcaptcha/_common.php b/AvocadoEdition_Light/plugin/kcaptcha/_common.php index bad54a5..03b90f3 100644 --- a/AvocadoEdition_Light/plugin/kcaptcha/_common.php +++ b/AvocadoEdition_Light/plugin/kcaptcha/_common.php @@ -1,3 +1,2 @@ - \ No newline at end of file + \ No newline at end of file +'; - object += ''; - object += ''; - object += ''; - object += ''; - object += ''; - object += ''; - if ($("#mp3_object").length) - $("#mp3_object").remove(); - $("#captcha_mp3").after(object); - } - - $("body").css("cursor", "default"); - return false; - - }).css('cursor', 'pointer'); - - $("#captcha_reload").trigger("click"); -}); - -// 출력된 캡챠이미지의 키값과 입력한 키값이 같은지 비교한다. -function chk_captcha() -{ - var captcha_result = false; - var captcha_key = document.getElementById('captcha_key'); - $.ajax({ - type: 'POST', - url: g5_captcha_url+'/kcaptcha_result.php', - data: { - 'captcha_key': captcha_key.value - }, - cache: false, - async: false, - success: function(text) { - captcha_result = text; - } - }); - - if (!captcha_result) { - alert('자동등록방지 입력 글자가 틀렸거나 입력 횟수가 넘었습니다.\n\n새로고침을 클릭하여 다시 입력해 주십시오.'); - captcha_key.select(); - captcha_key.focus(); - return false; - } - - return true; +$(function(){ + var mp3_url = ""; + + $(document).on( "click", "#captcha_reload", function(){ + $.ajax({ + type: 'POST', + url: g5_captcha_url+'/kcaptcha_session.php', + cache: false, + async: false, + success: function(text) { + $('#captcha_img').attr('src', g5_captcha_url+'/kcaptcha_image.php?t=' + (new Date).getTime()); + } + }); + + $.ajax({ + type: 'POST', + url: g5_captcha_url+'/kcaptcha_mp3.php', + cache: false, + async: false, + success: function(url) { + if (url) { + mp3_url = url + "?t="+new Date().getTime(); + $("#captcha_audio").attr("src", mp3_url); + } + } + }); + }); + + $(document).on( "click", "#captcha_mp3", function(){ + $("body").css("cursor", "wait"); + + $.ajax({ + type: 'POST', + url: g5_captcha_url+'/kcaptcha_mp3.php', + cache: false, + async: false, + success: function(url) { + if (url) { + mp3_url = url + "?t="+new Date().getTime(); + } + } + }); + + var html5use = false; + var html5audio = document.createElement("audio"); + if (html5audio.canPlayType && html5audio.canPlayType("audio/mpeg")) { + var wav = new Audio(mp3_url); + wav.id = "mp3_audio"; + wav.autoplay = true; + wav.controls = false; + wav.autobuffer = false; + wav.loop = false; + + if ($("#mp3_audio").length) $("#mp3_audio").remove(); + $("#captcha_mp3").after(wav); + + html5use = true; + } + + if (!html5use) { + var object = ''; + object += ''; + object += ''; + object += ''; + object += ''; + object += ''; + object += ''; + if ($("#mp3_object").length) + $("#mp3_object").remove(); + $("#captcha_mp3").after(object); + } + + $("body").css("cursor", "default"); + return false; + + }).css('cursor', 'pointer'); + + $("#captcha_reload").trigger("click"); +}); + +// 출력된 캡챠이미지의 키값과 입력한 키값이 같은지 비교한다. +function chk_captcha() +{ + var captcha_result = false; + var captcha_key = document.getElementById('captcha_key'); + $.ajax({ + type: 'POST', + url: g5_captcha_url+'/kcaptcha_result.php', + data: { + 'captcha_key': captcha_key.value + }, + cache: false, + async: false, + success: function(text) { + captcha_result = text; + } + }); + + if (!captcha_result) { + alert('자동등록방지 입력 글자가 틀렸거나 입력 횟수가 넘었습니다.\n\n새로고침을 클릭하여 다시 입력해 주십시오.'); + captcha_key.select(); + captcha_key.focus(); + return false; + } + + return true; } \ No newline at end of file diff --git a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha.lib.php b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha.lib.php index 8d345d9..9270701 100644 --- a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha.lib.php +++ b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha.lib.php @@ -18,6 +18,8 @@ class KCAPTCHA{ + private $keystring; + // generates keystring and image function image(){ require(dirname(__FILE__).'/kcaptcha_config.php'); @@ -50,13 +52,13 @@ class KCAPTCHA{ $transparent = (imagecolorat($font, $i, 0) >> 24) == 127; if(!$reading_symbol && !$transparent){ - $font_metrics[$alphabet{$symbol}]=array('start'=>$i); + $font_metrics[$alphabet[$symbol]]=array('start'=>$i); $reading_symbol=true; continue; } if($reading_symbol && $transparent){ - $font_metrics[$alphabet{$symbol}]['end']=$i; + $font_metrics[$alphabet[$symbol]]['end']=$i; $reading_symbol=false; $symbol++; continue; @@ -75,7 +77,9 @@ class KCAPTCHA{ $odd=mt_rand(0,1); if($odd==0) $odd=-1; for($i=0;$i<$length;$i++){ - $m=$font_metrics[$this->keystring{$i}]; + + if( ! isset($this->keystring[$i]) ) continue; + $m=$font_metrics[$this->keystring[$i]]; $y=(($i%2)*$fluctuation_amplitude - $fluctuation_amplitude/2)*$odd + mt_rand(-round($fluctuation_amplitude/3), round($fluctuation_amplitude/3)) @@ -169,10 +173,10 @@ class KCAPTCHA{ if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){ continue; }else{ - $color=imagecolorat($img, $sx, $sy) & 0xFF; - $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF; - $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF; - $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF; + $color=imagecolorat($img, (int)$sx, (int)$sy) & 0xFF; + $color_x=imagecolorat($img, (int)$sx+1, (int)$sy) & 0xFF; + $color_y=imagecolorat($img, (int)$sx, (int)$sy+1) & 0xFF; + $color_xy=imagecolorat($img, (int)$sx+1, (int)$sy+1) & 0xFF; } if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){ @@ -202,7 +206,7 @@ class KCAPTCHA{ $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2]; } - imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); + imagesetpixel($img2, (int)$x, (int)$y, imagecolorallocate($img2, (int)$newred, (int)$newgreen, (int)$newblue)); } } @@ -240,17 +244,17 @@ function captcha_html($class="captcha") if(is_mobile()) $class .= ' m_captcha'; - $html .= "\n".''; + $html = "\n".''; //$html .= "\n".''; $html .= "\n".''; $html .= "\n".'
'; $html .= "\n".''; - if (is_mobile()) $html .= ''; + if (is_mobile()) $html .= ''; //$html .= "\n".''; - $html .= "\n".''; + $html .= "\n".''; + $html .= ''; if (!is_mobile()) $html .= "\n".''; $html .= "\n".''; - $html .= ''; $html .= "\n".'자동등록방지 숫자를 순서대로 입력하세요.'; $html .= "\n".'
'; return $html; @@ -260,26 +264,29 @@ function captcha_html($class="captcha") // 캡챠 사용시 자바스크립트에서 입력된 캡챠를 검사함 function chk_captcha_js() { -// return "if (!chk_captcha()) return false;\n"; - + return "if (!chk_captcha()) return false;\n"; } // 세션에 저장된 캡챠값과 $_POST 로 넘어온 캡챠값을 비교 function chk_captcha() { - /*$captcha_count = (int)get_session('ss_captcha_count'); + $captcha_count = (int)get_session('ss_captcha_count'); if ($captcha_count > 5) { return false; } - if (!isset($_POST['captcha_key'])) return false; - if (!trim($_POST['captcha_key'])) return false; - if ($_POST['captcha_key'] != get_session('ss_captcha_key')) { + $post_captcha_key = (isset($_POST['captcha_key']) && $_POST['captcha_key']) ? trim($_POST['captcha_key']) : ''; + if (!trim($post_captcha_key)) return false; + + if( $post_captcha_key && function_exists('get_string_encrypt') ){ + $ip = md5(sha1($_SERVER['REMOTE_ADDR'])); + $post_captcha_key = get_string_encrypt($ip.$post_captcha_key); + } + + if ($post_captcha_key != get_session('ss_captcha_key')) { $_SESSION['ss_captcha_count'] = $captcha_count + 1; return false; } - return true;*/ - return true; -} -?> \ No newline at end of file + return true; +} \ No newline at end of file diff --git a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_config.php b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_config.php index 90354d0..eaae544 100644 --- a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_config.php +++ b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_config.php @@ -1,52 +1,51 @@ - \ No newline at end of file +setKeyString(get_session("ss_captcha_key")); -$captcha->getKeyString(); -$captcha->image(); -?> \ No newline at end of file +setKeyString($ss_captcha_key_decrypt); +$captcha->getKeyString(); +$captcha->image(); \ No newline at end of file diff --git a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_mp3.php b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_mp3.php index 10cae73..30961de 100644 --- a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_mp3.php +++ b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_mp3.php @@ -1,44 +1,49 @@ - \ No newline at end of file += 5) { // 설정값 이상이면 자동등록방지 입력 문자가 맞아도 오류 처리 - echo false; -} else { - set_session("ss_captcha_count", $count + 1); - echo (get_session("ss_captcha_key") == $_POST['captcha_key']) ? true : false; -} -?> \ No newline at end of file += 5) { // 설정값 이상이면 자동등록방지 입력 문자가 맞아도 오류 처리 + echo false; +} else { + set_session("ss_captcha_count", $count + 1); + + if( $captcha_key && function_exists('get_string_encrypt') ){ + $ip = md5(sha1($_SERVER['REMOTE_ADDR'])); + $captcha_key = get_string_encrypt($ip.$captcha_key); + } + echo (get_session("ss_captcha_key") === $captcha_key) ? true : false; +} \ No newline at end of file diff --git a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_session.php b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_session.php index 657f088..c9b527d 100644 --- a/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_session.php +++ b/AvocadoEdition_Light/plugin/kcaptcha/kcaptcha_session.php @@ -1,18 +1,22 @@ -setKeyString(get_session("ss_captcha_key")); -?> \ No newline at end of file +setKeyString(get_session("ss_captcha_key")); \ No newline at end of file