Project

General

Profile

1
<?php
2

    
3
// $Id: captcha.php 1443 2011-04-19 19:38:37Z 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
		$output  = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ";
31
		$output .= "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
32
		$output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"";
33
		$output .= strtolower(LANGUAGE)."\" lang=\"".strtolower(LANGUAGE)."\">\n";
34
		$output .= "\t<head>\n\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n";
35
		$output .= "\t\t<title>captcha</title>\n\t</head>\n\t<body>\n";
36
		$_SESSION['captcha_time'] = $t;
37
		if($kind=='image') {
38
			$output .= "\t\t<a title=\"reload\" href=\"".WB_REL."/include/captcha/captcha.php?display_captcha_X986E21=2\">";
39
			$output .= "<img style=\"border: none;\" src=\"".WB_REL."/include/captcha/captchas/";
40
			$output .= CAPTCHA_TYPE.".php?t=".$t."\" alt=\"Captcha\" /></a>\n";
41
		} else {
42
			$output .= "\t\t<h2>error</h2>";
43
		}
44
		$output .= "\t</body>\n</html>";
45
		echo $output;
46
	}
47
}
48

    
49
// called from an <iframe>
50
if(isset($_GET['display_captcha_X986E21'])) {
51
	require('../../config.php');
52
	switch(CAPTCHA_TYPE) {
53
	case 'calc_image':
54
	case 'calc_ttf_image':
55
	case 'ttf_image':
56
	case 'old_image':
57
		display_captcha_real('image');
58
		break;
59
	}
60
	exit(0);
61
}
62

    
63

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

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

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

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

    
113
if(!function_exists('call_captcha')) {
114
	function call_captcha($action='all', $style='', $sec_id='') {
115
		global $MOD_CAPTCHA;
116
		$t = time();
117
		$_SESSION['captcha_time'] = $t;
118

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

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

    
(1-1/5)