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(); setup_logo();
$page['formname'] = topage(getgetparam('name')); $page['formname'] = topage(getgetparam('name'));
$page['formemail'] = topage($email); $page['formemail'] = topage($email);
$page['showcaptcha'] = $settings["enablecaptcha"] == "1" ? "1" : "";
$page['info'] = topage($info); $page['info'] = topage($info);
expand("styles", getchatstyle(), "leavemessage.tpl"); expand("styles", getchatstyle(), "leavemessage.tpl");
exit; exit;

View File

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

View File

@ -1,66 +1,61 @@
<? <?
/* /*
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. You may use this code in your own projects as long as this
This code is distributed in the hope that it will be useful, copyright is left in place. All code is provided AS-IS.
but WITHOUT ANY WARRANTY; without even the implied warranty of This code is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the rest of the code visit http://www.WebCheatSheet.com
For the rest of the code visit http://www.WebCheatSheet.com
Copyright 2006 WebCheatSheet.com
Copyright 2006 WebCheatSheet.com
*/ */
//Start the session so we can store what the security code actually is function gen_captcha() {
session_start(); $md5_hash = md5(rand(0,9999));
return substr($md5_hash, 15, 5);
//Send a generated image to the browser }
create_image();
exit(); function draw_captcha($security_code) {
function create_image() //Set the image width and height
{ $width = 100;
//Let's generate a totally random string using md5 $height = 25;
$md5_hash = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5 //Create the image resource
$security_code = substr($md5_hash, 15, 5); $image = ImageCreate($width, $height);
imageantialias($image, true);
//Set the session to store the security code
$_SESSION["security_code"] = $security_code; //We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
//Set the image width and height $black = ImageColorAllocate($image, 15, 50, 15);
$width = 100; $grey = ImageColorAllocate($image, 204, 204, 204);
$height = 20; $ellipsec = ImageColorAllocate($image, 0, 100, 60);
//Create the image resource //Make the background black
$image = ImageCreate($width, $height); ImageFill($image, 0, 0, $black);
imagefilledellipse($image, 56,15,30,17, $ellipsec);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255); //Add randomly generated string in white to the image
$black = ImageColorAllocate($image, 0, 0, 0); ImageString($image, 5, 30, 4, $security_code, $white);
$grey = ImageColorAllocate($image, 204, 204, 204);
//Throw in some lines to make it a little bit harder for any bots to break
//Make the background black ImageRectangle($image,0,0,$width-1,$height-1,$grey);
ImageFill($image, 0, 0, $black); imageline($image, 0, $height/2+3, $width, $height/2+5, $grey);
imageline($image, $width/2-14, 0, $width/2+7, $height, $grey);
//Add randomly generated string in white to the image
ImageString($image, 3, 30, 3, $security_code, $white);
//Tell the browser what kind of file is come in
//Throw in some lines to make it a little bit harder for any bots to break header("Content-Type: image/jpeg");
ImageRectangle($image,0,0,$width-1,$height-1,$grey);
imageline($image, 0, $height/2, $width, $height/2, $grey); //Output the newly created image in jpeg format
imageline($image, $width/2, 0, $width/2, $height, $grey); ImageJpeg($image);
//Tell the browser what kind of file is come in //Free up resources
header("Content-Type: image/jpeg"); ImageDestroy($image);
}
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
?> ?>

View File

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

View File

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

View File

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

View File

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

View File

@ -60,34 +60,36 @@ ${endif:errors}
<table cellspacing="0" cellpadding="0" border="0"><tr><td width="15"><img class="tplimage icrnlt" src="${webimroot}/images/free.gif" border="0" alt=""/></td><td width="100%" 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 width="15"><img class="tplimage icrnrt" src="${webimroot}/images/free.gif" border="0" alt=""/></td></tr><tr><td height="100%" bgcolor="#FED840"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td><td style="background-image: url(${tplroot}/images/winbg.gif)" class="bgcy"><table cellspacing="0" cellpadding="0" border="0"> <table cellspacing="0" cellpadding="0" border="0"><tr><td width="15"><img class="tplimage icrnlt" src="${webimroot}/images/free.gif" border="0" alt=""/></td><td width="100%" 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 width="15"><img class="tplimage icrnrt" src="${webimroot}/images/free.gif" border="0" alt=""/></td></tr><tr><td height="100%" bgcolor="#FED840"><img src="${webimroot}/images/free.gif" width="1" height="1" border="0" alt="" /></td><td style="background-image: url(${tplroot}/images/winbg.gif)" class="bgcy"><table cellspacing="0" cellpadding="0" border="0">
<tr> <tr>
<td colspan="3" class="text">${msg:leavemessage.descr}</td> <td colspan="3" class="text">${msg:leavemessage.descr}</td>
</tr> </tr>
<tr><td height="20" colspan="3"></td></tr> <tr><td height="20" colspan="3"></td></tr>
<tr> <tr>
<td class="text">${msg:form.field.email}:</td> <td class="text">${msg:form.field.email}:</td>
<td width="20"></td> <td width="20"></td>
<td><input type="text" name="email" size="50" value="${form:email}" class="username"/></td> <td><input type="text" name="email" size="50" value="${form:email}" class="username"/></td>
</tr> </tr>
<tr><td height="7" colspan="3"></td></tr> <tr><td height="7" colspan="3"></td></tr>
<tr> <tr>
<td class="text">${msg:form.field.name}:</td> <td class="text">${msg:form.field.name}:</td>
<td width="20"></td> <td width="20"></td>
<td><input type="text" name="name" size="50" value="${form:name}" class="username"/></td> <td><input type="text" name="name" size="50" value="${form:name}" class="username"/></td>
</tr> </tr>
<tr><td height="7" colspan="3"></td></tr>
<tr> <tr>
<td class="text">${msg:form.field.message}:</td>
<td class="text">${msg:form.field.message}:</td> <td width="20"></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 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"> </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>
<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> </tr>
<tr > ${if:showcaptcha}
<td><img id="imgCaptcha" src="create_image.php" /></td> <tr><td height="7" colspan="3"></td></tr>
<td><input id="txtCaptcha" type="text" aligh="right" name="txtCaptcha"" /></td> <tr>
<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> </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> </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> </td>

View File

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