[24215] | 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'] ]); |
---|
[26025] | 30 | $conf['EasyCaptcha']['key'] = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']); |
---|
[24215] | 31 | } |
---|
| 32 | // Tic-tac-toe |
---|
| 33 | else if ($conf['EasyCaptcha']['challenge'] == 'tictac') |
---|
| 34 | { |
---|
[26025] | 35 | $conf['EasyCaptcha']['key'] = $conf['EasyCaptcha']['challenge'] .'-0'; |
---|
[24215] | 36 | } |
---|
| 37 | else |
---|
| 38 | { |
---|
| 39 | return; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | load_language('plugin.lang', EASYCAPTCHA_PATH); |
---|
| 43 | |
---|
| 44 | $template->assign(array( |
---|
[26025] | 45 | 'EASYCAPTCHA' => $conf['EasyCaptcha'], |
---|
[24215] | 46 | 'EASYCAPTCHA_PATH' => EASYCAPTCHA_PATH, |
---|
| 47 | 'EASYCAPTCHA_ABS_PATH' => realpath(EASYCAPTCHA_PATH).'/', |
---|
| 48 | )); |
---|
| 49 | |
---|
| 50 | $template->set_filename('EasyCaptcha', realpath(EASYCAPTCHA_PATH.'template/'.$conf['EasyCaptcha']['template'].'.tpl')); |
---|
[26025] | 51 | $template->assign_var_from_handle('EASYCAPTCHA_CONTENT', 'EasyCaptcha'); |
---|
[24215] | 52 | |
---|
| 53 | |
---|
| 54 | function easycaptcha_check() |
---|
| 55 | { |
---|
| 56 | global $conf; |
---|
| 57 | |
---|
| 58 | if (empty($_POST['easycaptcha_key']) || empty($_POST['easycaptcha'])) |
---|
| 59 | { |
---|
| 60 | return false; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | list($challenge, $key) = explode('-', $_POST['easycaptcha_key']); |
---|
| 64 | |
---|
| 65 | if ($challenge == 'drag') |
---|
| 66 | { |
---|
| 67 | $check = easycaptcha_decode_image_url($_POST['easycaptcha']); |
---|
| 68 | return pwg_password_verify($conf['secret_key'] . $check, $key); |
---|
| 69 | } |
---|
| 70 | else if ($challenge == 'tictac') |
---|
| 71 | { |
---|
| 72 | return $_POST['easycaptcha'] == pwg_get_session_var('easycaptcha', '33'); |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | return false; |
---|
| 77 | } |
---|
| 78 | } |
---|