1
|
<?php
|
2
|
|
3
|
// $Id: captcha.php 858 2008-09-18 21:24:41Z thorn $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, 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
|
function display_captcha_real($kind='image') {
|
28
|
$t = time();
|
29
|
$_SESSION['captcha_time'] = $t;
|
30
|
if($kind=='image') {
|
31
|
?><a title="reload" href="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=2'; ?>">
|
32
|
<img style="border: none;" src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" />
|
33
|
</a><?php
|
34
|
} elseif($kind=='text') {
|
35
|
?><a style="text-decoration:none;" title="reload" href="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=2'; ?>"><?php
|
36
|
include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
|
37
|
?></a><?php
|
38
|
} else {
|
39
|
echo 'error';
|
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 'text':
|
48
|
case 'calc_text':
|
49
|
display_captcha_real('text');
|
50
|
break;
|
51
|
case 'calc_image':
|
52
|
case 'calc_ttf_image':
|
53
|
case 'ttf_image':
|
54
|
case 'old_image':
|
55
|
display_captcha_real('image');
|
56
|
break;
|
57
|
}
|
58
|
exit(0);
|
59
|
}
|
60
|
|
61
|
|
62
|
// Make sure page cannot be accessed directly
|
63
|
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
|
64
|
|
65
|
// check if module language file exists for the language set by the user (e.g. DE, EN)
|
66
|
global $MOD_CAPTCHA;
|
67
|
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
|
68
|
// no module language file exists for the language set by the user, include default module language file EN.php
|
69
|
require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
|
70
|
} else {
|
71
|
// a module language file exists for the language defined by the user, load it
|
72
|
require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
|
73
|
}
|
74
|
|
75
|
// output-handler for image-captchas to determine size of image
|
76
|
if(!function_exists('captcha_header')) {
|
77
|
function captcha_header() {
|
78
|
header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
|
79
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
80
|
header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
|
81
|
header("Cache-Control: post-check=0, pre-check=0", false); // MS made there own headers :-(
|
82
|
header("Pragma: no-cache");
|
83
|
header("Content-type: image/png");
|
84
|
return;
|
85
|
}
|
86
|
}
|
87
|
|
88
|
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
|
89
|
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
|
90
|
$useable_captchas = array(
|
91
|
'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
|
92
|
'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
|
93
|
'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
|
94
|
'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
|
95
|
'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
|
96
|
'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
|
97
|
);
|
98
|
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
|
99
|
$useable_captchas = array(
|
100
|
'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
|
101
|
'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
|
102
|
'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
|
103
|
'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
|
104
|
);
|
105
|
} else {
|
106
|
$useable_captchas = array(
|
107
|
'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
|
108
|
'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
|
109
|
);
|
110
|
}
|
111
|
|
112
|
if(!function_exists('call_captcha')) {
|
113
|
function call_captcha($action='all', $style='') {
|
114
|
global $MOD_CAPTCHA;
|
115
|
$t = time();
|
116
|
$_SESSION['captcha_time'] = $t;
|
117
|
|
118
|
// get width and height of captcha image or text for use in <iframe>
|
119
|
switch(CAPTCHA_TYPE) {
|
120
|
case 'text':
|
121
|
$captcha_width = 250;
|
122
|
$captcha_height = 100;
|
123
|
break;
|
124
|
case 'calc_text':
|
125
|
$captcha_width = 120;
|
126
|
$captcha_height = 20;
|
127
|
break;
|
128
|
case 'calc_image':
|
129
|
$captcha_width = 142;
|
130
|
$captcha_height = 30;
|
131
|
break;
|
132
|
case 'calc_ttf_image':
|
133
|
$captcha_width = 162;
|
134
|
$captcha_height = 40;
|
135
|
break;
|
136
|
case 'ttf_image':
|
137
|
$captcha_width = 162;
|
138
|
$captcha_height = 40;
|
139
|
break;
|
140
|
case 'old_image':
|
141
|
$captcha_width = 142;
|
142
|
$captcha_height = 30;
|
143
|
break;
|
144
|
default:
|
145
|
$captcha_width = 250;
|
146
|
$captcha_height = 100;
|
147
|
}
|
148
|
|
149
|
if($action=='all') {
|
150
|
switch(CAPTCHA_TYPE) {
|
151
|
// one special case
|
152
|
case 'text': // text-captcha - we don't use an <iframe> in this case
|
153
|
?><table class="captcha_table"><tr>
|
154
|
<td class="text_captcha">
|
155
|
<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
|
156
|
</td>
|
157
|
<td></td>
|
158
|
<td><input type="text" name="captcha" maxlength="50" style="width:150px;" /></td>
|
159
|
<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
|
160
|
</tr></table><?php
|
161
|
break;
|
162
|
// two special cases
|
163
|
case 'calc_text': // calculation as text
|
164
|
?><table class="captcha_table"><tr>
|
165
|
<td class="text_captcha">
|
166
|
<iframe class="captcha_iframe" width="<?php echo $captcha_width; ?>" height="<?php echo $captcha_height; ?>" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" name="captcha_iframe" src="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=1'; ?>">
|
167
|
<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
|
168
|
</iframe>
|
169
|
</td>
|
170
|
<td> = </td>
|
171
|
<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
|
172
|
<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
|
173
|
</tr></table><?php
|
174
|
break;
|
175
|
case 'calc_image': // calculation with image (old captcha)
|
176
|
case 'calc_ttf_image': // calculation with varying background and ttf-font
|
177
|
?><table class="captcha_table"><tr>
|
178
|
<td class="image_captcha">
|
179
|
<iframe class="captcha_iframe" width="<?php echo $captcha_width; ?>" height="<?php echo $captcha_height; ?>" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" name="captcha_iframe" src="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=1'; ?>">
|
180
|
<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" />
|
181
|
</iframe>
|
182
|
</td>
|
183
|
<td> = </td>
|
184
|
<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
|
185
|
<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
|
186
|
</tr></table><?php
|
187
|
break;
|
188
|
// normal images
|
189
|
case 'ttf_image': // captcha with varying background and ttf-font
|
190
|
case 'old_image': // old captcha
|
191
|
?><table class="captcha_table"><tr>
|
192
|
<td class="image_captcha">
|
193
|
<iframe class="captcha_iframe" width="<?php echo $captcha_width; ?>" height="<?php echo $captcha_height; ?>" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" name="captcha_iframe" src="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=1'; ?>">
|
194
|
<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" />
|
195
|
</iframe>
|
196
|
</td>
|
197
|
<td></td>
|
198
|
<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
|
199
|
<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
|
200
|
</tr></table><?php
|
201
|
break;
|
202
|
}
|
203
|
} elseif($action=='image') {
|
204
|
switch(CAPTCHA_TYPE) {
|
205
|
case 'text': // text-captcha
|
206
|
case 'calc_text': // calculation as text
|
207
|
echo ($style?"<span $style>":'');
|
208
|
include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
|
209
|
echo ($style?'</span>':'');
|
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
|
echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
|
216
|
break;
|
217
|
}
|
218
|
} elseif($action=='image_iframe') {
|
219
|
switch(CAPTCHA_TYPE) {
|
220
|
case 'text': // text-captcha
|
221
|
echo ($style?"<span $style>":'');
|
222
|
include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
|
223
|
echo ($style?'</span>':'');
|
224
|
break;
|
225
|
case 'calc_text': // calculation as text
|
226
|
?><iframe class="captcha_iframe" width="<?php echo $captcha_width; ?>" height="<?php echo $captcha_height; ?>" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" name="captcha_iframe" src="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=1'; ?>"><?php
|
227
|
include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
|
228
|
?></iframe><?php
|
229
|
break;
|
230
|
case 'calc_image': // calculation with image (old captcha)
|
231
|
case 'calc_ttf_image': // calculation with varying background and ttf-font
|
232
|
case 'ttf_image': // captcha with varying background and ttf-font
|
233
|
case 'old_image': // old captcha
|
234
|
?><iframe class="captcha_iframe" width="<?php echo $captcha_width; ?>" height="<?php echo $captcha_height; ?>" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" name="captcha_iframe" src="<?php echo WB_URL.'/include/captcha/captcha.php?display_captcha_X986E21=1'; ?>"><?php
|
235
|
echo "<img $style alt=\"Captcha\" src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
|
236
|
?></iframe><?php
|
237
|
break;
|
238
|
}
|
239
|
} elseif($action=='input') {
|
240
|
switch(CAPTCHA_TYPE) {
|
241
|
case 'text': // text-captcha
|
242
|
echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
|
243
|
break;
|
244
|
case 'calc_text': // calculation as text
|
245
|
case 'calc_image': // calculation with image (old captcha)
|
246
|
case 'calc_ttf_image': // calculation with varying background and ttf-font
|
247
|
echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
|
248
|
break;
|
249
|
case 'ttf_image': // captcha with varying background and ttf-font
|
250
|
case 'old_image': // old captcha
|
251
|
echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
|
252
|
break;
|
253
|
}
|
254
|
} elseif($action=='text') {
|
255
|
echo ($style?"<span $style>":'');
|
256
|
switch(CAPTCHA_TYPE) {
|
257
|
case 'text': // text-captcha
|
258
|
echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
|
259
|
break;
|
260
|
case 'calc_text': // calculation as text
|
261
|
case 'calc_image': // calculation with image (old captcha)
|
262
|
case 'calc_ttf_image': // calculation with varying background and ttf-font
|
263
|
echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
|
264
|
break;
|
265
|
case 'ttf_image': // captcha with varying background and ttf-font
|
266
|
case 'old_image': // old captcha
|
267
|
echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
|
268
|
break;
|
269
|
}
|
270
|
echo ($style?'</span>':'');
|
271
|
}
|
272
|
}
|
273
|
}
|
274
|
|