Revision 227
Added by ryan almost 20 years ago
| trunk/wb/include/captcha.php | ||
|---|---|---|
| 32 | 32 |
|
| 33 | 33 |
*/ |
| 34 | 34 |
|
| 35 |
$image = imagecreate(120, 30);
|
|
| 35 |
require_once("../config.php");
|
|
| 36 | 36 |
|
| 37 |
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); |
|
| 38 |
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); |
|
| 39 |
$darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50); |
|
| 40 |
|
|
| 41 |
srand((double)microtime()*1000000); |
|
| 42 |
|
|
| 43 |
for ($i = 0; $i < 30; $i++) {
|
|
| 44 |
$x1 = rand(0,120); |
|
| 45 |
$y1 = rand(0,30); |
|
| 46 |
$x2 = rand(0,120); |
|
| 47 |
$y2 = rand(0,30); |
|
| 48 |
imageline($image, $x1, $y1, $x2, $y2 , $gray); |
|
| 37 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg') AND isset($_SESSION['captcha'])) {
|
|
| 38 |
|
|
| 39 |
$image = imagecreate(120, 30); |
|
| 40 |
|
|
| 41 |
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); |
|
| 42 |
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); |
|
| 43 |
$darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50); |
|
| 44 |
|
|
| 45 |
srand((double)microtime()*1000000); |
|
| 46 |
|
|
| 47 |
for($i = 0; $i < 30; $i++) {
|
|
| 48 |
$x1 = rand(0,120); |
|
| 49 |
$y1 = rand(0,30); |
|
| 50 |
$x2 = rand(0,120); |
|
| 51 |
$y2 = rand(0,30); |
|
| 52 |
imageline($image, $x1, $y1, $x2, $y2 , $gray); |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
for ($i = 0; $i < 5; $i++) {
|
|
| 56 |
$fnt = rand(3,5); |
|
| 57 |
$x = $x + rand(12 , 20); |
|
| 58 |
$y = rand(7 , 12); |
|
| 59 |
imagestring($image, $fnt, $x, $y, substr($_SESSION['captcha'], $i, 1), $darkgray); |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
header('Content-type: image/png');
|
|
| 63 |
imagepng($image); |
|
| 64 |
imagedestroy($image); |
|
| 65 |
|
|
| 49 | 66 |
} |
| 50 | 67 |
|
| 51 |
for ($i = 0; $i < 5; $i++) {
|
|
| 52 |
$cnum[$i] = rand(0,9); |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
for ($i = 0; $i < 5; $i++) {
|
|
| 56 |
$fnt = rand(3,5); |
|
| 57 |
$x = $x + rand(12 , 20); |
|
| 58 |
$y = rand(7 , 12); |
|
| 59 |
imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray); |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
$digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]"; |
|
| 63 |
|
|
| 64 |
session_start(); |
|
| 65 |
$_SESSION['captcha'] = $digit; |
|
| 66 |
|
|
| 67 |
header('Content-type: image/png');
|
|
| 68 |
imagepng($image); |
|
| 69 |
imagedestroy($image); |
|
| 70 |
|
|
| 71 | 68 |
?> |
| trunk/wb/languages/EN.php | ||
|---|---|---|
| 387 | 387 |
$TEXT['BACKUP_MEDIA'] = 'Backup Media'; |
| 388 | 388 |
$TEXT['RESTORE_MEDIA'] = 'Restore Media'; |
| 389 | 389 |
$TEXT['ADMINISTRATION_TOOL'] = 'Administration tool'; |
| 390 |
$TEXT['CAPTCHA_VERIFICATION'] = 'Captcha Verification'; |
|
| 390 | 391 |
|
| 391 | 392 |
|
| 392 | 393 |
// Success/error messages |
| ... | ... | |
| 524 | 525 |
$MESSAGE['MOD_RELOAD']['TEMPLATES_RELOADED'] = 'Templates reloaded successfully'; |
| 525 | 526 |
$MESSAGE['MOD_RELOAD']['LANGUAGES_RELOADED'] = 'Languages reloaded successfully'; |
| 526 | 527 |
|
| 527 |
?> |
|
| 528 |
?> |
|
| trunk/wb/modules/form/install.php | ||
|---|---|---|
| 56 | 56 |
. ' `email_subject` VARCHAR(255) NOT NULL ,' |
| 57 | 57 |
. ' `success_message` TEXT NOT NULL ,' |
| 58 | 58 |
. ' `stored_submissions` INT NOT NULL,' |
| 59 |
. ' `max_submissions` INT NOT NULL,' |
|
| 59 |
. ' `max_submissions` INT NOT NULL,' |
|
| 60 |
. ' `use_captcha` INT NOT NULL,' |
|
| 60 | 61 |
. ' PRIMARY KEY ( `section_id` ) )' |
| 61 | 62 |
. ' '; |
| 62 | 63 |
$database->query($mod_form); |
| trunk/wb/modules/form/modify_settings.php | ||
|---|---|---|
| 124 | 124 |
<td class="setting_name"> |
| 125 | 125 |
<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" /> |
| 126 | 126 |
</td> |
| 127 |
</tr> |
|
| 127 |
</tr> |
|
| 128 |
<?php if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */ ?>
|
|
| 129 |
<tr> |
|
| 130 |
<td class="setting_name"><?php echo $TEXT['CAPTCHA_VERIFICATION']; ?>:</td> |
|
| 131 |
<td> |
|
| 132 |
<input type="radio" name="use_captcha" id="use_captcha_true" value="1"<?php if($setting['use_captcha'] == true) { echo ' checked'; } ?> />
|
|
| 133 |
<label for="use_captcha_true"><?php echo $TEXT['ENABLED']; ?></label> |
|
| 134 |
<input type="radio" name="use_captcha" id="use_captcha_false" value="0"<?php if($setting['use_captcha'] == false) { echo ' checked'; } ?> />
|
|
| 135 |
<label for="use_captcha_false"><?php echo $TEXT['DISABLED']; ?></label> |
|
| 136 |
</td> |
|
| 137 |
</tr> |
|
| 138 |
<?php } ?> |
|
| 128 | 139 |
</table> |
| 129 | 140 |
<table cellpadding="0" cellspacing="0" border="0" width="100%"> |
| 130 | 141 |
<tr> |
| trunk/wb/modules/form/view.php | ||
|---|---|---|
| 110 | 110 |
<?php |
| 111 | 111 |
|
| 112 | 112 |
// Get settings |
| 113 |
$query_settings = $database->query("SELECT header,field_loop,footer FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
|
|
| 113 |
$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
|
|
| 114 | 114 |
if($query_settings->numRows() > 0) {
|
| 115 | 115 |
$fetch_settings = $query_settings->fetchRow(); |
| 116 | 116 |
$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
|
| 117 | 117 |
$field_loop = $fetch_settings['field_loop']; |
| 118 |
$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
|
|
| 118 |
$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
|
|
| 119 |
$use_captcha = $fetch_settings['use_captcha']; |
|
| 119 | 120 |
} else {
|
| 120 | 121 |
$header = ''; |
| 121 | 122 |
$field_loop = ''; |
| ... | ... | |
| 182 | 183 |
if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop; |
| 183 | 184 |
} |
| 184 | 185 |
} |
| 186 |
|
|
| 187 |
// Captcha |
|
| 188 |
if($use_captcha) {
|
|
| 189 |
$_SESSION['captcha'] = ''; |
|
| 190 |
for($i = 0; $i < 5; $i++) {
|
|
| 191 |
$_SESSION['captcha'] .= rand(0,9); |
|
| 192 |
} |
|
| 193 |
?><tr><td class="field_title">Verification:</td><td> |
|
| 194 |
<table cellpadding="2" cellspacing="0" border="0"> |
|
| 195 |
<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php" alt="Captcha" /></td> |
|
| 196 |
<td><input type="text" name="captcha" maxlength="5" /></td> |
|
| 197 |
</tr></table> |
|
| 198 |
</td></tr> |
|
| 199 |
<?php |
|
| 200 |
} |
|
| 185 | 201 |
|
| 186 | 202 |
// Print footer |
| 187 | 203 |
echo $footer; |
| ... | ... | |
| 251 | 267 |
|
| 252 | 268 |
// Captcha |
| 253 | 269 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */
|
| 254 |
if(isset($_POST['captcha']) AND $_POST['CAPTCHA']!=''){
|
|
| 255 |
// User-supplied captcha |
|
| 256 |
$user_captcha = $_POST['captcha']; |
|
| 257 |
// Computer generated |
|
| 258 |
if(isset($_SESSION['captcha'])) {
|
|
| 259 |
$system_captcha = $_SESSION['captcha']; |
|
| 260 |
} |
|
| 270 |
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
|
| 261 | 271 |
// Check for a mismatch |
| 262 |
if($user_captcha != $system_captcha) {
|
|
| 272 |
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR !$_POST['captcha'] == $_SESSION['captcha']) {
|
|
| 263 | 273 |
$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA']; |
| 264 |
} else {
|
|
| 265 |
unset($_SESSION['captcha']); |
|
| 266 | 274 |
} |
| 267 | 275 |
} else {
|
| 268 | 276 |
$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA']; |
| 269 | 277 |
} |
| 270 | 278 |
} |
| 279 |
if(isset($_SESSION['catpcha'])) { unset($_SESSION['captcha']); }
|
|
| 271 | 280 |
|
| 272 | 281 |
// Addslashes to email body - proposed by Icheb in topic=1170.0 |
| 273 | 282 |
// $email_body = $wb->add_slashes($email_body); |
| trunk/wb/modules/form/save_settings.php | ||
|---|---|---|
| 41 | 41 |
$field_loop = $admin->add_slashes($_POST['field_loop']); |
| 42 | 42 |
$footer = $admin->add_slashes($_POST['footer']); |
| 43 | 43 |
$email_to = $admin->add_slashes($_POST['email_to']); |
| 44 |
$use_captcha = $_POST['use_captcha']; |
|
| 44 | 45 |
if($_POST['email_from_field'] == '') {
|
| 45 | 46 |
$email_from = $admin->add_slashes($_POST['email_from']); |
| 46 | 47 |
} else {
|
| ... | ... | |
| 64 | 65 |
} |
| 65 | 66 |
|
| 66 | 67 |
// Update settings |
| 67 |
$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions' WHERE section_id = '$section_id'");
|
|
| 68 |
$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");
|
|
| 68 | 69 |
|
| 69 | 70 |
// Check if there is a db error, otherwise say successful |
| 70 | 71 |
if($database->is_error()) {
|
| trunk/wb/modules/form/add.php | ||
|---|---|---|
| 53 | 53 |
$success_message = 'Thank-you.'; |
| 54 | 54 |
$max_submissions = 50; |
| 55 | 55 |
$stored_submissions = 100; |
| 56 |
$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_settings (page_id,section_id,header,field_loop,footer,email_to,email_from,email_subject,success_message,max_submissions,stored_submissions) VALUES ('$page_id','$section_id','$header','$field_loop','$footer','$email_to','$email_from','$email_subject','$success_message','$max_submissions','$stored_submissions')");
|
|
| 56 |
$use_captcha = true; |
|
| 57 |
$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_settings (page_id,section_id,header,field_loop,footer,email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha) VALUES ('$page_id','$section_id','$header','$field_loop','$footer','$email_to','$email_from','$email_subject','$success_message','$max_submissions','$stored_submissions','$use_captcha')");
|
|
| 57 | 58 |
|
| 58 | 59 |
?> |
| trunk/wb/config.php | ||
|---|---|---|
| 1 |
<?php ?> |
|
| 1 |
<?php |
|
| 2 |
|
|
| 3 |
define('DB_TYPE', 'mysql');
|
|
| 4 |
define('DB_HOST', 'localhost');
|
|
| 5 |
define('DB_USERNAME', 'root');
|
|
| 6 |
define('DB_PASSWORD', 'password');
|
|
| 7 |
define('DB_NAME', 'wb');
|
|
| 8 |
define('TABLE_PREFIX', '');
|
|
| 9 |
|
|
| 10 |
define('WB_PATH', dirname(__FILE__));
|
|
| 11 |
define('WB_URL', 'http://localhost/workspace/websitebaker2/wb');
|
|
| 12 |
define('ADMIN_PATH', WB_PATH.'/admin');
|
|
| 13 |
define('ADMIN_URL', 'http://localhost/workspace/websitebaker2/wb/admin');
|
|
| 14 |
|
|
| 15 |
require_once(WB_PATH.'/framework/initialize.php'); |
|
| 16 |
|
|
| 17 |
?> |
|
Also available in: Unified diff
Finished correct Captcha implementation in form mod