mirror of
https://github.com/Mibew/tray.git
synced 2025-01-22 18:10:34 +03:00
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:
parent
ae2300b312
commit
00d895e41c
23
src/messenger/webim/captcha.php
Normal file
23
src/messenger/webim/captcha.php
Normal 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;
|
||||
?>
|
@ -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;
|
||||
|
@ -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;
|
||||
|
125
src/messenger/webim/create_image.php → src/messenger/webim/libs/captcha.php
Executable file → Normal file
125
src/messenger/webim/create_image.php → src/messenger/webim/libs/captcha.php
Executable file → Normal 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
|
||||
|
||||
You may use this code in your own projects as long as this
|
||||
copyright is left in place. All code is provided AS-IS.
|
||||
This code is distributed in the hope that it will be useful,
|
||||
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
|
||||
|
||||
Copyright 2006 WebCheatSheet.com
|
||||
|
||||
*/
|
||||
|
||||
//Start the session so we can store what the security code actually is
|
||||
session_start();
|
||||
|
||||
//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;
|
||||
|
||||
//Set the image width and height
|
||||
$width = 100;
|
||||
$height = 20;
|
||||
|
||||
//Create the image resource
|
||||
$image = ImageCreate($width, $height);
|
||||
|
||||
//We are making three colors, white, black and gray
|
||||
$white = ImageColorAllocate($image, 255, 255, 255);
|
||||
$black = ImageColorAllocate($image, 0, 0, 0);
|
||||
$grey = ImageColorAllocate($image, 204, 204, 204);
|
||||
|
||||
//Make the background black
|
||||
ImageFill($image, 0, 0, $black);
|
||||
|
||||
//Add randomly generated string in white to the image
|
||||
ImageString($image, 3, 30, 3, $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);
|
||||
|
||||
//Tell the browser what kind of file is come in
|
||||
header("Content-Type: image/jpeg");
|
||||
|
||||
//Output the newly created image in jpeg format
|
||||
ImageJpeg($image);
|
||||
|
||||
//Free up resources
|
||||
ImageDestroy($image);
|
||||
}
|
||||
<?
|
||||
/*
|
||||
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.
|
||||
This code is distributed in the hope that it will be useful,
|
||||
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
|
||||
|
||||
Copyright 2006 WebCheatSheet.com
|
||||
*/
|
||||
|
||||
function gen_captcha() {
|
||||
$md5_hash = md5(rand(0,9999));
|
||||
return substr($md5_hash, 15, 5);
|
||||
}
|
||||
|
||||
function draw_captcha($security_code) {
|
||||
|
||||
//Set the image width and height
|
||||
$width = 100;
|
||||
$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, 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, 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+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");
|
||||
|
||||
//Output the newly created image in jpeg format
|
||||
ImageJpeg($image);
|
||||
|
||||
//Free up resources
|
||||
ImageDestroy($image);
|
||||
}
|
||||
|
||||
?>
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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=Превышен допустимый размер файла
|
||||
|
@ -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">
|
||||
|
@ -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">
|
||||
<tr>
|
||||
<td colspan="3" class="text">${msg:leavemessage.descr}</td>
|
||||
<td colspan="3" class="text">${msg:leavemessage.descr}</td>
|
||||
</tr>
|
||||
<tr><td height="20" colspan="3"></td></tr>
|
||||
<tr>
|
||||
<td class="text">${msg:form.field.email}:</td>
|
||||
<td width="20"></td>
|
||||
<td><input type="text" name="email" size="50" value="${form:email}" class="username"/></td>
|
||||
<td class="text">${msg:form.field.email}:</td>
|
||||
<td width="20"></td>
|
||||
<td><input type="text" name="email" size="50" value="${form:email}" class="username"/></td>
|
||||
</tr>
|
||||
<tr><td height="7" colspan="3"></td></tr>
|
||||
<tr>
|
||||
<td class="text">${msg:form.field.name}:</td>
|
||||
<td width="20"></td>
|
||||
<td><input type="text" name="name" size="50" value="${form:name}" class="username"/></td>
|
||||
<td class="text">${msg:form.field.name}:</td>
|
||||
<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>
|
||||
<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>
|
||||
<tr >
|
||||
<td><img id="imgCaptcha" src="create_image.php" /></td>
|
||||
<td><input id="txtCaptcha" type="text" aligh="right" name="txtCaptcha"" /></td>
|
||||
${if:showcaptcha}
|
||||
<tr><td height="7" colspan="3"></td></tr>
|
||||
<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>
|
||||
|
||||
${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>
|
||||
|
@ -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>
|
||||
<tr >
|
||||
<td><img id="imgCaptcha" src="create_image.php" /></td>
|
||||
<td><input id="txtCaptcha" type="text" aligh="right" name="txtCaptcha"" /></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}
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user