1 | <?php |
---|
2 | defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | include_once(EASYCAPTCHA_PATH . 'drag/functions_drag.inc.php'); |
---|
5 | |
---|
6 | global $template; |
---|
7 | |
---|
8 | // choose random challenge |
---|
9 | if ($conf['EasyCaptcha']['challenge'] == 'random') |
---|
10 | { |
---|
11 | $challenges = array('tictac', 'drag'); |
---|
12 | $conf['EasyCaptcha']['challenge'] = $challenges[ rand(0,1) ]; |
---|
13 | } |
---|
14 | |
---|
15 | // Drag & drop |
---|
16 | if ($conf['EasyCaptcha']['challenge'] == 'drag') |
---|
17 | { |
---|
18 | load_language($conf['EasyCaptcha']['drag']['theme'].'.lang', EASYCAPTCHA_PATH); |
---|
19 | |
---|
20 | $drag_images = include(EASYCAPTCHA_PATH.'drag/'.$conf['EasyCaptcha']['drag']['theme'].'/conf.inc.php'); |
---|
21 | $conf['EasyCaptcha']['drag']['nb'] = min($conf['EasyCaptcha']['drag']['nb'], count($drag_images)); |
---|
22 | |
---|
23 | foreach (array_rand($drag_images, $conf['EasyCaptcha']['drag']['nb']) as $row) |
---|
24 | { |
---|
25 | $conf['EasyCaptcha']['drag']['selection'][ $row ] = easycaptcha_encode_image_url($row); |
---|
26 | } |
---|
27 | |
---|
28 | $conf['EasyCaptcha']['drag']['selected'] = array_rand($conf['EasyCaptcha']['drag']['selection']); |
---|
29 | $conf['EasyCaptcha']['drag']['text'] = l10n($drag_images[ $conf['EasyCaptcha']['drag']['selected'] ]); |
---|
30 | $conf['EasyCaptcha']['drag']['key'] = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']); |
---|
31 | |
---|
32 | $template->assign('EASYCAPTCHA_CONF', $conf['EasyCaptcha']['drag']); |
---|
33 | } |
---|
34 | // Tic-tac-toe |
---|
35 | else if ($conf['EasyCaptcha']['challenge'] == 'tictac') |
---|
36 | { |
---|
37 | $conf['EasyCaptcha']['tictac']['key'] = $conf['EasyCaptcha']['challenge'] .'-0'; |
---|
38 | $template->assign('EASYCAPTCHA_CONF', $conf['EasyCaptcha']['tictac']); |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | return; |
---|
43 | } |
---|
44 | |
---|
45 | load_language('plugin.lang', EASYCAPTCHA_PATH); |
---|
46 | |
---|
47 | $template->assign(array( |
---|
48 | 'EASYCAPTCHA_CHALLENGE' => $conf['EasyCaptcha']['challenge'], |
---|
49 | 'EASYCAPTCHA_PATH' => EASYCAPTCHA_PATH, |
---|
50 | 'EASYCAPTCHA_ABS_PATH' => realpath(EASYCAPTCHA_PATH).'/', |
---|
51 | )); |
---|
52 | |
---|
53 | $template->set_filename('EasyCaptcha', realpath(EASYCAPTCHA_PATH.'template/'.$conf['EasyCaptcha']['template'].'.tpl')); |
---|
54 | $template->assign_var_from_handle('EASYCAPTCHA', 'EasyCaptcha'); |
---|
55 | |
---|
56 | |
---|
57 | function easycaptcha_check() |
---|
58 | { |
---|
59 | global $conf; |
---|
60 | |
---|
61 | if (empty($_POST['easycaptcha_key']) || empty($_POST['easycaptcha'])) |
---|
62 | { |
---|
63 | return false; |
---|
64 | } |
---|
65 | |
---|
66 | list($challenge, $key) = explode('-', $_POST['easycaptcha_key']); |
---|
67 | |
---|
68 | if ($challenge == 'drag') |
---|
69 | { |
---|
70 | $check = easycaptcha_decode_image_url($_POST['easycaptcha']); |
---|
71 | return pwg_password_verify($conf['secret_key'] . $check, $key); |
---|
72 | } |
---|
73 | else if ($challenge == 'tictac') |
---|
74 | { |
---|
75 | return $_POST['easycaptcha'] == pwg_get_session_var('easycaptcha', '33'); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | return false; |
---|
80 | } |
---|
81 | } |
---|