캡차이미지와 캡챠음성파일을 미리 만들어 놓고 img src 에 노출하는 방식으로 변경

This commit is contained in:
gnuboard
2013-01-12 15:52:32 +09:00
parent 76f6048e66
commit 508d060219
9 changed files with 124 additions and 56 deletions

View File

@ -1,7 +1,7 @@
<?
define('_CAPTCHA_', 1);
include_once('./_common.php');
include_once($g4['path'].'/lib/register.lib.php');
if ($captcha->lib) include_once($captcha->lib);
// 불법접근을 막도록 토큰생성
$token = md5(uniqid(rand(), true));
@ -102,7 +102,6 @@ if ($w == "") {
// 회원아이콘 경로
$mb_icon = $g4['path'].'/data/member/'.substr($member['mb_id'],0,2).'/'.$member['mb_id'].'.gif';
$member_skin_path = $g4['path'].'/skin/member/'.$config['cf_member_skin'];
$g4['js_file'][] = "{$g4['path']}/plugin/captcha/captcha.js";
include_once('./_head.php');

View File

@ -13,6 +13,10 @@ $g4['bbs_path'] = $g4['path'] . '/' . $g4['bbs'];
$g4['bbs_img'] = 'img';
$g4['bbs_img_path'] = $g4['path'] . '/' . $g4['bbs'] . '/' . $g4['bbs_img'];
$g4['data_dir'] = 'data';
$g4['cache_dir'] = 'cache';
$g4['captcha_dir'] = 'captcha';
$g4['admin'] = 'adm';
$g4['admin_path'] = $g4['path'] . '/' . $g4['admin'];

View File

@ -2,12 +2,17 @@
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
if (defined('_CAPTCHA_')) {
$captcha = (object)array(
'lib' => $g4['path']."/plugin/captcha/captcha.lib.php",
'js' => $g4['path']."/plugin/captcha/captcha.js"
$captcha = (object)Array(
'lib' => $g4['path']."/plugin/captcha/captcha.lib.php",
'js' => $g4['path']."/plugin/captcha/captcha.js",
'fonts' => $g4['path']."/plugin/captcha/fonts"
);
include_once($captcha->lib);
$g4['js_file'][] = $captcha->js;
$captcha_obj = new captcha();
$captcha_obj->run();
} else {
unset($_SESSION['ss_captcha_use']);
}

View File

@ -79,9 +79,6 @@ if (defined('_EDITOR_')) {
$g4['js_file'][] = $editor->js;
$g4['js_file'][] = $editor->config_js;
}
if (defined('_CAPTCHA_')) {
$g4['js_file'][] = $captcha->js;
}
?>
<!--[if lte IE 8]>
<script src="<?=$g4['path']?>/js/html5.js"></script>

View File

@ -1575,4 +1575,34 @@ function is_checked($field)
{
return !empty($_POST[$field]);
}
function mk_subdir($subdir)
{
global $g4;
$data_path = $g4['path'].'/'.$g4['data_dir'];
$data_subpath = $data_path.'/'.$subdir;
if (!is_dir($data_subpath)) {
@mkdir($data_subpath, 0707);
@chmod($data_subpath, 0707);
}
return $data_subpath;
}
// 캡챠 파일의 상대 경로를 반환
function captcha_file_path($extension='.png')
{
global $g4;
mk_subdir($g4['cache_dir']);
$captcha_path = mk_subdir($g4['cache_dir'].'/'.$g4['captcha_dir']);
return $captcha_path.'/'.abs_ip2long().'_'.$_COOKIE['PHPSESSID'].$extension;
}
function abs_ip2long($ip='')
{
$ip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
return abs(ip2long($ip));
}
?>

View File

@ -76,7 +76,9 @@ class captcha
return mt_rand($from, $to);
}
function run() {
function run()
{
global $captcha;
// The text to draw
$captcha_key = $this->get_captcha_key();
@ -85,7 +87,7 @@ class captcha
set_session('ss_captcha_cnt', 0);
// Set the content-type
header('Content-Type: image/gif');
//header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor($this->width, $this->height);
@ -97,7 +99,7 @@ class captcha
// Replace path by your own font path
$fonts = Array();
foreach (glob('fonts/*.ttf') as $filename) {
foreach (glob($captcha->fonts.'/*.ttf') as $filename) {
$fonts[] = $filename;
}
$font = $fonts[mt_rand(0, count($fonts)-1)];
@ -117,9 +119,10 @@ class captcha
imagettftext($im, $size, $angle, $x-2, $y-2, $grey, $font, $captcha_key);
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagegif($im);
imagepng($im, captcha_file_path('.png'), 0, NULL);
imagedestroy($im);
make_wav();
}
}
@ -147,9 +150,9 @@ function captcha_html($input_name, $captcha_id_suffix='')
$html = '<fieldset id="captcha'.$captcha_id_suffix.'" class="captcha">';
$html .= '<legend class="sound_only">자동등록방지</legend>';
//$html .= '<img src="" id="captcha" alt="자동등록방지 이미지" title="이미지를 클릭하시면 숫자가 바뀝니다.">';
$html .= '<iframe id="captcha_iframe" name="captcha_iframe" src="'.$g4['path'].'/plugin/captcha/run.php" scrolling="no" marginwidth="0" marginheight="0" title="자동등록방지숫자"></iframe>';
$html .= '<a href="'.$g4['path'].'/plugin/captcha/run.php" target="captcha_iframe">새로고침</a>';
$html .= '<a href="'.$g4['path'].'/plugin/captcha/wav.php" id="captcha_wav">음성듣기</a>';
$html .= '<iframe id="captcha_iframe" name="captcha_iframe" src="'.captcha_file_path('.png').'" scrolling="no" marginwidth="0" marginheight="0" title="자동등록방지숫자"></iframe>';
//$html .= '<a href="'.$g4['path'].'/plugin/captcha/run.php" target="captcha_iframe">새로고침</a>';
$html .= '<a href="'.captcha_file_path('.wav').'" id="captcha_wav">음성듣기</a>';
$html .= '<label for="captcha_key">자동등록방지 입력</label>';
$html .= '<input type="text" id="captcha_key" name="'.$input_name.'" class="captcha_box fieldset_input" size="5" maxlength="5" required title="자동등록방지 입력">';
$html .= '<p class="sound_only">이미지의 숫자를 순서대로 입력하세요. 새로고침을 클릭하시면 새로운 숫자가 나타납니다.</p>';
@ -175,4 +178,68 @@ function captcha_js($element)
{
return "if (!check_captcha({$element})) { return false; }";
}
function make_wav()
{
global $g4;
$wavs_dir = $g4['path'].'/plugin/captcha/wavs/';
$number = (string)$_SESSION['ss_captcha_key'];
$wavs = array();
for($i=0;$i<strlen($number);$i++){
$file = $wavs_dir.$number[$i].'.wav';
$wavs[] = $file;
}
$wav_filepath = captcha_file_path('.wav');
$fp = fopen($wav_filepath, 'w+');
fwrite($fp, joinwavs($wavs));
fclose($fp);
}
function joinwavs($wavs)
{
$fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format',
'H8Subchunk1ID', 'VSubchunk1Size',
'vAudioFormat', 'vNumChannels', 'VSampleRate',
'VByteRate', 'vBlockAlign', 'vBitsPerSample' ));
$data = '';
$info = array();
foreach($wavs as $wav){
$fp = fopen($wav,'rb');
$header = fread($fp,36);
$info = unpack($fields,$header);
// read optional extra stuff
if($info['Subchunk1Size'] > 16){
$header .= fread($fp,($info['Subchunk1Size']-16));
}
// read SubChunk2ID
$header .= fread($fp,4);
// read Subchunk2Size
$size = unpack('vsize',fread($fp, 4));
$size = $size['size'];
// read data
$data .= fread($fp,$size);
}
return ''
.pack('a4', 'RIFF')
.pack('V', strlen($data) + 36)
.pack('a4', 'WAVE')
.pack('a4', 'fmt ')
.pack('V', $info['Subchunk1Size']) // 16
.pack('v', $info['AudioFormat']) // 1
.pack('v', $info['NumChannels']) // 1
.pack('V', $info['SampleRate']) // 8000
.pack('V', $info['ByteRate']) // 8000
.pack('v', $info['BlockAlign']) // 1
.pack('v', $info['BitsPerSample']) // 8
.pack('a4', 'data')
.pack('V', strlen($data))
.$data;
}
?>

View File

@ -15,6 +15,7 @@ header('Content-Disposition: attachment;filename=captcha.wav');
echo joinwavs($wavs);
/**
* Join multiple wav files
*

View File

@ -162,7 +162,7 @@ var member_skin_path = "<?=$member_skin_path?>";
</tr>
<? } ?>
<? if (isset($member['mb_open_date']) && $member['mb_open_date'] <= date("Y-m-d", $g4['server_time'] - ($config['cf_open_modify'] * 86400)) || !$member['mb_open_date']) { // 정보공개 수정일이 지났다면 수정가능 ?>
<? if (isset($member['mb_open_date']) && $member['mb_open_date'] <= date("Y-m-d", $g4['server_time'] - ($config['cf_open_modify'] * 86400)) || empty($member['mb_open_date'])) { // 정보공개 수정일이 지났다면 수정가능 ?>
<tr>
<th scope="row"><label for="reg_mb_open">정보공개</label></th>
<td>
@ -195,7 +195,7 @@ var member_skin_path = "<?=$member_skin_path?>";
<? } ?>
</table>
<?=$captcha_html?>
<?=captcha_html('wr_key');?>
<div class="btn_confirm">
<input type="submit" class="btn_submit" value="회원가입" accesskey="s">

View File

@ -1,39 +1,4 @@
<?
$str = "xx";
$len = 2;
//echo ord($str{$len});
?>
<!doctype html>
<html lang="ko">
<head>
<title>테스트</title>
<meta charset="utf-8">
<style>
input {
border-radius:7px; /*모서리 깍이는 정도*/
border:1px solid #dedede; /*선두께, 스타일(점선), 컬러*/
background-color:#f7f7f7; /*배경 컬러*/
padding:5px;
box-shadow:0 0 10px silver;
}
input:focus {
border-radius:7px; /*모서리 깍이는 정도*/
border:1px solid #ff3061; /*선두께, 스타일(점선), 컬러*/
background-color:#f7f7f7; /*배경 컬러*/
padding:5px;
box-shadow:0 0 10px #ff3061;
outline:0;
}
</style>
</head>
<body>
<label for="text">테스트 필수</label>
<input type="text" id="text" title="테스트">
<input type="checkbox">
</body>
</html>
include_once('./_common.php');
echo abs_ip2long();
?>