improved captcha, rename files

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@588 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2009-07-18 13:54:45 +00:00
parent ae2300b312
commit 00d895e41c
10 changed files with 129 additions and 104 deletions

View File

@ -0,0 +1,23 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2009 Mibew Messenger Community
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once('libs/common.php');
require_once('libs/captcha.php');
$captchaCode = gen_captcha();
$_SESSION["captcha"] = $captchaCode;
draw_captcha($captchaCode);
exit;
?>

View File

@ -59,6 +59,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
setup_logo();
$page['formname'] = topage(getgetparam('name'));
$page['formemail'] = topage($email);
$page['showcaptcha'] = $settings["enablecaptcha"] == "1" ? "1" : "";
$page['info'] = topage($info);
expand("styles", getchatstyle(), "leavemessage.tpl");
exit;

View File

@ -35,23 +35,28 @@ if( !$email ) {
$errors[] = wrong_field("form.field.email");
}
}
if ( ($_REQUEST["txtCaptcha"] == $_SESSION["security_code"]) &&
(!empty($_REQUEST["txtCaptcha"]) && !empty($_SESSION["security_code"])) ) {
} else {
$errors[] = no_field('errors.captcha');
loadsettings();
if($settings["enablecaptcha"] == "1") {
$captcha = getparam('captcha');
$original = $_SESSION['captcha'];
if(empty($original) || empty($captcha) || $captcha != $original) {
$errors[] = getlocal('errors.captcha');
}
unset($_SESSION['captcha']);
}
if( count($errors) > 0 ) {
$page['formname'] = topage($visitor_name);
$page['formemail'] = $email;
$page['formmessage'] = topage($message);
$page['showcaptcha'] = $settings["enablecaptcha"] == "1" ? "1" : "";
$page['info'] = topage($info);
setup_logo();
expand("styles", getchatstyle(), "leavemessage.tpl");
exit;
}
loadsettings();
$message_locale = $settings['left_messages_locale'];
if(!locale_exists($message_locale)) {
$message_locale = $home_locale;

View File

@ -1,6 +1,7 @@
<?
/*
This is PHP file that generates CAPTCHA image for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
This is PHP file that generates CAPTCHA image for the How to Create CAPTCHA
Protection using PHP and AJAX Tutorial
You may use this code in your own projects as long as this
copyright is left in place. All code is provided AS-IS.
@ -11,48 +12,41 @@
For the rest of the code visit http://www.WebCheatSheet.com
Copyright 2006 WebCheatSheet.com
*/
//Start the session so we can store what the security code actually is
session_start();
function gen_captcha() {
$md5_hash = md5(rand(0,9999));
return substr($md5_hash, 15, 5);
}
//Send a generated image to the browser
create_image();
exit();
function create_image()
{
//Let's generate a totally random string using md5
$md5_hash = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5
$security_code = substr($md5_hash, 15, 5);
//Set the session to store the security code
$_SESSION["security_code"] = $security_code;
function draw_captcha($security_code) {
//Set the image width and height
$width = 100;
$height = 20;
$height = 25;
//Create the image resource
$image = ImageCreate($width, $height);
imageantialias($image, true);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$black = ImageColorAllocate($image, 15, 50, 15);
$grey = ImageColorAllocate($image, 204, 204, 204);
$ellipsec = ImageColorAllocate($image, 0, 100, 60);
//Make the background black
ImageFill($image, 0, 0, $black);
imagefilledellipse($image, 56,15,30,17, $ellipsec);
//Add randomly generated string in white to the image
ImageString($image, 3, 30, 3, $security_code, $white);
ImageString($image, 5, 30, 4, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image,0,0,$width-1,$height-1,$grey);
imageline($image, 0, $height/2, $width, $height/2, $grey);
imageline($image, $width/2, 0, $width/2, $height, $grey);
imageline($image, 0, $height/2+3, $width, $height/2+5, $grey);
imageline($image, $width/2-14, 0, $width/2+7, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
@ -63,4 +57,5 @@ function create_image()
//Free up resources
ImageDestroy($image);
}
?>

View File

@ -574,6 +574,7 @@ $settings = array(
'surveyaskgroup' => '1',
'surveyaskmessage' => '0',
'enablepopupnotification' => '0',
'enablecaptcha' => '1',
'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
'updatefrequency_operator' => 2,

View File

@ -103,6 +103,7 @@ content.logoff=Log out of the system.
data.saved=Changes saved
demo.chat.question=There are so many browsers to choose from. Which one(s) do you recommend?
demo.chat.welcome=Hello, how may I help you?
errors.captcha=The letters you typed don't match the letters that were shown in the picture.
errors.failed.uploading.file=Error uploading file "{0}": {1}.
errors.file.move.error=Error moving file
errors.file.size.exceeded=Uploaded file size exceeded
@ -113,7 +114,6 @@ errors.prefix=<li class="error">
errors.required=Please fill "{0}".
errors.suffix=</li>
errors.wrong_field=Please fill "{0}" correctly.
errors.captcha=Captcha is incorrect!
features.saved=Features activated
form.field.address.description=Ex: 12.23.45.123 or todo.com
form.field.address=Visitor's Address

View File

@ -103,6 +103,7 @@ content.logoff=
data.saved=Изменения сохранены
demo.chat.question=Посоветуйте мне, пожалуйста, хороший браузер?
demo.chat.welcome=Здравствуйте! Чем я могу Вам помочь?
errors.captcha=Введенные символы не соответствуют изображению.
errors.failed.uploading.file=Ошибка выгрузки файла "{0}": {1}.
errors.file.move.error=Ошибка копирования файла
errors.file.size.exceeded=Превышен допустимый размер файла

View File

@ -113,21 +113,16 @@ ${endif:errors}
</tr>
<tr>
<td class="text">${msg:form.field.message}:</td>
<td height="120" valign="top">
<textarea name="message" tabindex="0" cols="40" rows="8" style="border:1px solid #878787; overflow:auto">${form:message}</textarea>
</tr>
<td>
<img id="imgCaptcha" src="create_image.php" />
</td><td>
<input id="txtCaptcha" type="text" name="txtCaptcha" value="" maxlength="10" size="32" />
</td>
</tr>
</tr>
<td valign="top">
<textarea name="message" tabindex="0" cols="40" rows="6" style="border:1px solid #878787; overflow:auto">${form:message}</textarea>
</td>
</tr>
${if:showcaptcha}
<tr>
<td class="text"><img src="captcha.php"/></td>
<td><input type="text" name="captcha" size="50" maxlength="15" value="" class="username"/></td>
</tr>
${endif:showcaptcha}
<tr>
<td colspan="2" align="right">
<table cellspacing="0" cellpadding="0" border="0">

View File

@ -74,20 +74,22 @@ ${endif:errors}
<td width="20"></td>
<td><input type="text" name="name" size="50" value="${form:name}" class="username"/></td>
</tr>
<tr><td height="7" colspan="3"></td></tr>
<tr>
<td class="text">${msg:form.field.message}:</td>
<td width="20"></td>
<td height="120" valign="top"><table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="3" bgcolor="#A1A1A1"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td bgcolor="#A1A1A1"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td><td width="100%" height="100%" bgcolor="#FFFFFF" valign="top">
<textarea rows="8" cols="45" name="message" class="message" tabindex="0" style="width:90%;">${form:message}</textarea>
</td><td bgcolor="#A1A1A1"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td colspan="3" bgcolor="#A1A1A1"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td></tr></table></td>
</tr>
${if:showcaptcha}
<tr><td height="7" colspan="3"></td></tr>
<tr>
<td><img id="imgCaptcha" src="create_image.php" /></td>
<td><input id="txtCaptcha" type="text" aligh="right" name="txtCaptcha"" /></td>
<td class="text"><img src="captcha.php"/></td>
<td width="20"></td>
<td><input type="text" name="captcha" size="50" maxlength="15" value="" class="username"/></td>
</tr>
${endif:showcaptcha}
</table></td><td bgcolor="#E8A400"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td><img class="tplimage icrnlb" src="${webimroot}/images/free.gif" border="0" alt=""/></td><td style="background-image: url(${tplroot}/images/winbg.gif)" class="bgcy"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td><td><img class="tplimage icrnrb" src="${webimroot}/images/free.gif" border="0" alt=""/></td></tr></table>
</td>

View File

@ -48,10 +48,12 @@
<td class="text" valign="top">${msg:form.field.message}:</td>
<td><textarea name="message" cols="45" rows="8" class="field" tabindex="0">${form:message}</textarea></td>
</tr>
${if:showcaptcha}
<tr>
<td><img id="imgCaptcha" src="create_image.php" /></td>
<td><input id="txtCaptcha" type="text" aligh="right" name="txtCaptcha"" /></td>
<td class="text"><img src="captcha.php"/></td>
<td><input type="text" name="captcha" size="50" maxlength="15" value="" class="username"/></td>
</tr>
${endif:showcaptcha}
</table>
</td>
</tr>