function plugin_install_captcha() { global $pi_name, $pi_version, $gl_version, $pi_url, $NEWTABLE, $DEFVALUES, $NEWFEATURE; global $_TABLES, $_CONF, $LANG_CP00, $_DB_dbms; COM_errorLog("Attempting to install the {$pi_name} Plugin", 1); $_SQL['cp_config'] = "CREATE TABLE {$_TABLES['cp_config']} ( " . " `config_name` varchar(255) NOT NULL default '', " . " `config_value` varchar(255) NOT NULL default '', " . " PRIMARY KEY (`config_name`) " . " );"; $_SQL['cp_sessions'] = "CREATE TABLE {$_TABLES['cp_sessions']} ( " . " `session_id` varchar(40) NOT NULL default '', " . " `cptime` INT(11) NOT NULL default 0, " . " `validation` varchar(40) NOT NULL default '', " . " `counter` TINYINT(4) NOT NULL default 0, " . " PRIMARY KEY (`session_id`) " . " );"; foreach ($_SQL as $table => $sql) { COM_errorLog("Creating {$table} table", 1); DB_query($sql, 1); if (DB_error()) { COM_errorLog("Error Creating {$table} table", 1); plugin_uninstall_captcha(); return false; exit; } COM_errorLog("Success - Created {$table} table", 1); } $SQL_DEFAULTS = "INSERT INTO `{$_TABLES['cp_config']}` (`config_name`, `config_value`) VALUES " . " ('anonymous_only', '1'), " . " ('remoteusers','0'), " . " ('debug', '0'), " . " ('enable_comment', '0'), " . " ('enable_contact', '0'), " . " ('enable_emailstory', '0'), " . " ('enable_forum', '0'), " . " ('enable_registration', '0'), " . " ('enable_story', '0'), " . " ('gfxDriver', '2'), " . " ('gfxFormat', 'jpg'), " . " ('gfxPath', '');"; DB_query($SQL_DEFAULTS, 1); // Register the plugin with Geeklog COM_errorLog("Registering {$pi_name} plugin with Geeklog", 1); DB_delete($_TABLES['plugins'], 'pi_name', 'captcha'); DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) " . "VALUES ('{$pi_name}', '{$pi_version}', '{$gl_version}', '{$pi_url}', 1)"); if (DB_error()) { COM_errorLog("Failure registering plugin with Geeklog"); plugin_uninstall_captcha(); return false; exit; } // Create initial log entry CAPTCHA_errorLog("CAPTCHA Plugin Successfully Installed"); COM_errorLog("Successfully installed the {$pi_name} Plugin!", 1); return true; }
function makeCaptcha() { global $cString, $_CONF, $_TABLES, $LANG_CP00; if ($this->session_id != 0) { $sql = "UPDATE {$_TABLES['cp_sessions']} SET validation='" . $this->getCaptchaString() . "' WHERE session_id='" . DB_escapeString($this->session_id) . "'"; DB_query($sql); } else { CAPTCHA_errorLog("CAPTCHA: No valid session id passed"); exit; } switch ($this->driver) { case 0: case 1: if ($this->gfxformat != 'png' && $this->gfxformat != 'jpg') { header('Content-type: image/gif'); COM_errorLog("CAPTCHA: No valid gfxFormat specified"); $errormgr = new error(); $errormgr->addError(''); $errormgr->displayError(); die; } $header = 'Content-type: image/' . $this->gfxformat; header($header); if ($this->driver == 0) { $imagelength = $this->Length * 25 + 16; $imageheight = 75; $image = imagecreate($imagelength, $imageheight); $bgcolor = imagecolorallocate($image, 255, 255, 255); $stringcolor = imagecolorallocate($image, 0, 0, 0); $filter = new filters(); $filter->signs($image, $this->getRandFont()); for ($i = 0; $i < strlen($this->CaptchaString); $i++) { imagettftext($image, 25, mt_rand(-15, 15), $i * 25 + 10, mt_rand(30, 70), $stringcolor, $this->getRandFont(), $this->CaptchaString[$i]); } switch ($this->gfxformat) { case 'png': imagepng($image); break; case 'jpg': imagejpeg($image); break; } imagedestroy($image); } else { // ImageMagick code originally written by // Thom Skrtich (email : bisohpthom@supertwist.net) // used in SecureImage a CAPTCHA plugin for WordPress. $gravity = 'Center'; # modify the image according to the generated settings $size = rand($this->sizemin, $this->sizemax); $blur = rand($this->blurmin, $this->blurmax); $angle = rand($this->anglemin, $this->anglemax); $swirl = rand($this->swirlmin, $this->swirlmax); $wave = rand($this->wavemin, $this->wavemax); $cString = $this->CaptchaString; $i = strlen($cString); $newString = ''; for ($x = 0; $x < $i; $x++) { $newString .= $cString[$x]; $newString .= ' '; } # prepare our image magick command $cmd = '"' . $this->convertpath . '"'; $cmd .= ' -font "' . $this->getRandFont() . '"'; $cmd .= ' -pointsize ' . $size; $cmd .= ' -gravity "' . $gravity . '"'; $cmd .= ' -annotate 0 "' . $newString . '"'; $cmd .= ' -blur ' . $blur; $cmd .= ' -rotate ' . $angle; $cmd .= ' -swirl ' . $swirl; $cmd .= ' -wave ' . $wave . 'x80'; $cmd .= ' ' . $this->getRandBackground() . ' - '; if (PHP_OS == "WINNT") { $pcmd = 'cmd /c " ' . $cmd . '"'; } else { $pcmd = $cmd; } if ($this->debug) { COM_errorLog("CAPTCHA cmd: " . $pcmd); } passthru($pcmd); } break; case 2: header('Content-type: image/jpeg'); $filename = $cString[$this->CaptchaString] . '.jpg'; $fp = fopen($_CONF['path'] . 'plugins/captcha/images/static/' . $this->imageset . '/' . $filename, 'rb'); if ($fp != NULL) { while (!feof($fp)) { $buf = fgets($fp, 8192); echo $buf; } fclose($fp); } else { COM_errorLog("CAPTCHA: Unable to open static image file"); } break; case 3: case 4: case 5: break; case 6: /* $output = $this->first . ' '.$this->operator . ' ' . $this->second . ' = '; $imagelength = $this->Length * 25 + 16; $imageheight = 75; $im = imagecreate($imagelength, $imageheight); // White background and blue text $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 255); // Write the string at the top left imagestring($im, 5, 35, 15, $output, $textcolor); imagestring($im, 25, 5, 45, $LANG_CP00['captcha_help'], $textcolor); // Output the image header('Content-type: image/png'); imagepng($im); imagedestroy($im); */ $output = $this->first . '' . $this->operator . '' . $this->second . '='; $font = $this->fontpath . 'bluehigl.ttf'; $imagelength = $this->Length * 25 + 16; $imageheight = 75; $image = imagecreate($imagelength, $imageheight); $bgcolor = imagecolorallocate($image, 255, 255, 255); $stringcolor = imagecolorallocate($image, 0, 0, 0); for ($i = 0; $i < strlen($output); $i++) { imagettftext($image, 25, mt_rand(-15, 15), $i * 25 + 10, 45, $stringcolor, $font, $output[$i]); } switch ($this->gfxformat) { case 'png': imagepng($image); break; case 'jpg': imagejpeg($image); break; } imagedestroy($image); break; default: break; } }
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software Foundation, | // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | // | | // +-------------------------------------------------------------------------- // // Prevent PHP from reporting uninitialized variables error_reporting(E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR); require_once '../../lib-common.php'; $aResponse['error'] = false; $vars = array('action' => 'text', 'qaptcha_key' => 'text', 'csid' => 'alpha'); CAPTCHA_filterVars($vars, $_POST); if (isset($_POST['action']) && isset($_POST['qaptcha_key'])) { if (htmlentities($_POST['action'], ENT_QUOTES, 'UTF-8') == 'qaptcha' && $_POST['csid'] != '') { $sql = "UPDATE {$_TABLES['cp_sessions']} SET validation='" . $_POST['qaptcha_key'] . "' WHERE session_id='" . $_POST['csid'] . "'"; if ($_CP_CONF['debug'] == 1) { CAPTCHA_errorLog("Debug: qaptcha ajax " . $sql, 1); } DB_query($sql); echo json_encode($aResponse); } else { $aResponse['error'] = true; echo json_encode($aResponse); } } else { $aResponse['error'] = true; echo json_encode($aResponse); }