Project

General

Profile

1
<?php
2

    
3
// $Id: captcha.php 1371 2011-01-09 15:12:09Z Luisehahne $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
// displays the image or text inside an <iframe>
27
if(!function_exists('display_captcha_real')) {
28
	function display_captcha_real($kind='image') {
29
		$t = time();
30
		$_SESSION['captcha_time'] = $t;
31
		$sec_id = '';
32
		if(isset($_GET['s']) && is_numeric($_GET['s'])) $sec_id = $_GET['s'];
33
		if($kind=='image') {
34
			?><a title="reload" href="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=2'; ?>">
35
			  <img style="border: none;" src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id"; ?>" alt="Captcha" />
36
				</a><?php
37
		} else {
38
			echo 'error';
39
		}
40
	}
41
}
42

    
43
// called from an <iframe>
44
if(isset($_GET['display_captcha_X986E21'])) {
45
	require('../../config.php');
46
	switch(CAPTCHA_TYPE) {
47
	case 'calc_image':
48
	case 'calc_ttf_image':
49
	case 'ttf_image':
50
	case 'old_image':
51
		display_captcha_real('image');
52
		break;
53
	}
54
	exit(0);
55
}
56

    
57

    
58
// Make sure page cannot be accessed directly
59
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
60

    
61
// check if module language file exists for the language set by the user (e.g. DE, EN)
62
global $MOD_CAPTCHA;
63
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
64
	// no module language file exists for the language set by the user, include default module language file EN.php
65
	require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
66
} else {
67
	// a module language file exists for the language defined by the user, load it
68
	require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
69
}
70

    
71
// output-handler for image-captchas to determine size of image
72
if(!function_exists('captcha_header')) {
73
	function captcha_header() {
74
		header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
75
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
76
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
77
		header("Pragma: no-cache");
78
		header("Content-type: image/png");
79
		return;
80
	}
81
}
82

    
83
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
84
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
85
	$useable_captchas = array(
86
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
87
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
88
		'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
89
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
90
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
91
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
92
	);
93
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
94
	$useable_captchas = array(
95
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
96
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
97
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
98
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
99
	);
100
} else {
101
	$useable_captchas = array(
102
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
103
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
104
	);
105
}
106

    
107
if(!function_exists('call_captcha')) {
108
	function call_captcha($action='all', $style='', $sec_id='') {
109
		global $MOD_CAPTCHA;
110
		$t = time();
111
		$_SESSION['captcha_time'] = $t;
112

    
113
		// get width and height of captcha image for use in <iframe>
114
		switch(CAPTCHA_TYPE) {
115
		case 'calc_image':
116
			$captcha_width = 142;
117
			$captcha_height = 30;
118
			break;
119
		case 'calc_ttf_image':
120
			$captcha_width = 162;
121
			$captcha_height = 40;
122
			break;
123
		case 'ttf_image':
124
			$captcha_width = 162;
125
			$captcha_height = 40;
126
			break;
127
		case 'old_image':
128
			$captcha_width = 142;
129
			$captcha_height = 30;
130
			break;
131
		default:
132
			$captcha_width = 250;
133
			$captcha_height = 100;
134
		}
135

    
136
		if($action=='all') {
137
			switch(CAPTCHA_TYPE) {
138
				case 'text': // text-captcha
139
					?><table class="captcha_table"><tr>
140
					<td class="text_captcha">
141
						<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
142
					</td>
143
					<td></td>
144
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
145
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
146
					</tr></table><?php
147
					break;
148
				case 'calc_text': // calculation as text
149
					?><table class="captcha_table"><tr>
150
					<td class="text_captcha">
151
						<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
152
					</td>
153
					<td>&nbsp;=&nbsp;</td>
154
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px;" /></td>
155
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
156
					</tr></table><?php
157
					break;
158
				case 'calc_image': // calculation with image (old captcha)
159
				case 'calc_ttf_image': // calculation with varying background and ttf-font
160
				  ?><table class="captcha_table"><tr>
161
					<td class="image_captcha">
162
						<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?>">
163
						<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id"; ?>" alt="Captcha" />
164
						</iframe>
165
					</td>
166
					<td>&nbsp;=&nbsp;</td>
167
					<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
168
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
169
					</tr></table><?php
170
					break;
171
				// normal images
172
				case 'ttf_image': // captcha with varying background and ttf-font
173
				case 'old_image': // old captcha
174
					?><table class="captcha_table"><tr>
175
					<td class="image_captcha">
176
						<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?>">
177
						<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id"; ?>" alt="Captcha" />
178
						</iframe>
179
					</td>
180
					<td></td>
181
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
182
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
183
					</tr></table><?php
184
					break;
185
			}
186
		} elseif($action=='image') {
187
			switch(CAPTCHA_TYPE) {
188
				case 'text': // text-captcha
189
				case 'calc_text': // calculation as text
190
					echo ($style?"<span $style>":'');
191
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
192
					echo ($style?'</span>':'');
193
					break;
194
				case 'calc_image': // calculation with image (old captcha)
195
				case 'calc_ttf_image': // calculation with varying background and ttf-font
196
				case 'ttf_image': // captcha with varying background and ttf-font
197
				case 'old_image': // old captcha
198
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id\" />";
199
					break;
200
			}
201
		} elseif($action=='image_iframe') {
202
			switch(CAPTCHA_TYPE) {
203
				case 'text': // text-captcha
204
					echo ($style?"<span $style>":'');
205
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
206
					echo ($style?'</span>':'');
207
					break;
208
				case 'calc_text': // calculation as text
209
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
210
					break;
211
				case 'calc_image': // calculation with image (old captcha)
212
				case 'calc_ttf_image': // calculation with varying background and ttf-font
213
				case 'ttf_image': // captcha with varying background and ttf-font
214
				case 'old_image': // old captcha
215
					?>
216
					<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?>">
217
					<?php
218
					echo "<img $style alt=\"Captcha\" src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
219
					?></iframe><?php
220
					break;
221
			}
222
		} elseif($action=='input') {
223
			switch(CAPTCHA_TYPE) {
224
				case 'text': // text-captcha
225
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
226
					break;
227
				case 'calc_text': // calculation as text
228
				case 'calc_image': // calculation with image (old captcha)
229
				case 'calc_ttf_image': // calculation with varying background and ttf-font
230
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
231
					break;
232
				case 'ttf_image': // captcha with varying background and ttf-font
233
				case 'old_image': // old captcha
234
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
235
					break;
236
			}
237
		} elseif($action=='text') {
238
			echo ($style?"<span $style>":'');
239
			switch(CAPTCHA_TYPE) {
240
				case 'text': // text-captcha
241
					echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
242
					break;
243
				case 'calc_text': // calculation as text
244
				case 'calc_image': // calculation with image (old captcha)
245
				case 'calc_ttf_image': // calculation with varying background and ttf-font
246
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
247
					break;
248
				case 'ttf_image': // captcha with varying background and ttf-font
249
				case 'old_image': // old captcha
250
					echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
251
					break;
252
			}
253
			echo ($style?'</span>':'');
254
		}
255
	}
256
}
257

    
(1-1/5)