prefix . SCAPTCHA_TABLE ."` SET `conf_val`='". $value ."' WHERE `conf_key`='". $index ."'");
return mysql_query($sql);
}
function runUpdates()
{
global $wpdb;
$sql = mysql_query("SELECT * FROM `". $wpdb->prefix . SCAPTCHA_TABLE ."`");
while($ary = mysql_fetch_array($sql))
{
$key = $ary['conf_key'];
if(isset($_POST[$key]))
{
if($_POST[$key] == 'on')
{
$_POST[$key] = 'true';
}
updateConfigs($key,$_POST[$key]);
// $feedback .=('Trying... ' . $_POST[$key] . '
');
} else {
updateConfigs($key,'');
// $feedback .= ($key . ' failed to update!
');
}
}
return $feedback;
}
function restoreDefaults()
{
global $wpdb;
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='false' WHERE `conf_key`='display::login'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='false' WHERE `conf_key`='display::sgup'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='200' WHERE `conf_key`='demensions::width'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='75' WHERE `conf_key`='demensions::height'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='true' WHERE `conf_key`='type::word'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='ttf' WHERE `conf_key`='font::type'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='./includes/elephant.ttf' WHERE `conf_key`='font::path'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='30' WHERE `conf_key`='format::size'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='30' WHERE `conf_key`='format::spacing'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='50' WHERE `conf_key`='format::angle'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='#e3daed' WHERE `conf_key`='color::background'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='#0a68dd,#f65c47,#8d32fd' WHERE `conf_key`='color::text'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='40' WHERE `conf_key`='color::transparent'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='#80BFFF' WHERE `conf_key`='color::lines'");
mysql_query("UPDATE `". $wpdb->prefix . SCAPTCHA_TABLE ."` SET `conf_val`='#8080ff' WHERE `conf_key`='color::arc'");
}
function getConfigVal($index)
{
global $wpdb;
$sql = ("SELECT * FROM `". $wpdb->prefix . SCAPTCHA_TABLE ."` WHERE `conf_key`='". $index ."'");
$ary = mysql_fetch_array(mysql_query($sql));
//
/// THE FOLLOWING COMMENT IS A DEBUG LINE, UNCOMMENT THE LINE FOR A FULL LIST OF READ-QUERIES.
//
// echo('' . $sql . ' :: QUERIES: '. $ary['conf_val'] .'
');
return $ary['conf_val'];
}
function checkIt($key)
{
global $wpdb;
$sql = ("SELECT * FROM `". $wpdb->prefix . SCAPTCHA_TABLE ."` WHERE `conf_key`='". $key ."'");
$ary = mysql_fetch_array(mysql_query($sql));
if($ary['conf_val'] == 1 || $ary['conf_val'] == 'true')
{
$ret = (' CHECKED');
} else {
$ret = NULL;
}
return $ret;
}
function selectIt($key,$val)
{
global $wpdb;
$sql = ("SELECT * FROM `". $wpdb->prefix . SCAPTCHA_TABLE ."` WHERE `conf_key`='". $key ."'");
$ary = mysql_fetch_array(mysql_query($sql));
if($ary['conf_val'] == $val)
{
$ret = (' SELECTED');
} else {
$ret = NULL;
}
return $ret;
}
define('SI_IMAGE_JPEG', 1);
define('SI_IMAGE_PNG', 2);
define('SI_IMAGE_GIF', 3);
function GDorTFF($reqtype)
{
if($reqtype == 'gd')
{
if(getConfigVal('font::type') == 'gd')
{
return true;
} else {
return false;
}
} else {
if(getConfigVal('font::type') == 'ttf')
{
return true;
} else {
return false;
}
}
}
define('IMG_WIDTH', getConfigVal('demensions::width'));
define('IMG_HEIGHT', getConfigVal('demensions::height'));
define('WORD_LIST', getConfigVal('type::word'));
define('USE_GD_FONT', GDorTFF('gd'));
define('FONT_PATH', getConfigVal('font::path'));
define('FONT_SIZE', getConfigVal('format::size'));
define('ANGLE_MIN', 0-getConfigVal('format::angle'));
define('ANGLE_MAX', getConfigVal('format::angle'));
define('SPACE_MIN', getConfigVal('format::spacing'));
define('SPACE_MAX', getConfigVal('format::spacing')+4);
define('BG_COLOR', getConfigVal('color::background'));
define('TXT_COLOR', getConfigVal('color::text'));
define('TRANS_PCT', getConfigVal('color::transparent'));
define('LINE_COLOR', getConfigVal('color::lines'));
define('ARC_COLOR', getConfigVal('color::arc'));
// Start up the plugin...
if(isset($_REQUEST['sid']) && isset($_REQUEST['img']) && !isset($_POST['SpamCode']))
{
$img = new securimage();
$img->show(); // alternate use: $img->show('/path/to/background.jpg');
exit;
}
elseif(isset($_REQUEST['audio']) && !isset($_POST['SpamCode']))
{
$img = new Securimage();
header('Content-type: audio/x-wav');
header('Content-Disposition: attachment; name="securimage.wav"');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
echo $img->getAudibleCode();
exit;
} else {
class RandomCaptchaSpam
{
var $adminOptionsName = "scaptcha_options";
var $db_table_name = '';
function scaptcha(){$this->RandomCaptchaSpam();} // Backwards compatability...
function RandomCaptchaSpam()
{ // This is the main construct...
global $wpdb;
register_activation_hook(__FILE__,array(&$this,"install_on_activation"));
add_action("admin_menu", array(&$this,"configure_pages"));
add_action('wp_footer', array(&$this,'copyright_credits')); // REMOVAL OF THIS LINE OF CODE WILL RESULT IN COPYRIGHT VIOLATIONS -- AS YOU ARE ALLOWED TO RETAIN A COPY OF THIS SOFTWARE FROM THE AUTHOR WHILE THIS IS IN TACT. REMOVAL WILL REVOLK THAT PRIVLAGE.
if(getConfigVal('display::sgup') == 'true')
{
add_action('signup_extra_fields', array( &$this, 'signup_form' )); // add image and input field to signup form
add_filter('wpmu_validate_user_signup', array( &$this, 'signup_post')); // add post signup post security code check
}
if(getConfigVal('display::login') == 'true')
{
add_action('login_form', array( &$this, 'wpmulogin_form' ) ); //add captcha into login form
add_filter('wp_authenticate', array( &$this, 'wpmulogin_authenticate')); // add post login security code check
}
$this->db_table_name = $wpdb->prefix . SCAPTCHA_TABLE;
$this->adminOptions = $this->getAdminOptions();
}
function configure_pages()
{ // This adds the pages in the admin panel... If you don't want them there, delete them.
add_menu_page('sCAPTCHA', 'sCAPTCHA', 10, __FILE__, array(&$this,"configure_page_1"));
add_submenu_page(__FILE__, "Configure", "Configure", 10, "super-captcha/Configure", array(&$this,"configure_page_4"));
add_submenu_page(__FILE__, "ReadMe", "ReadMe", 10, "super-captcha/ReadMe", array(&$this,"configure_page_2"));
add_submenu_page(__FILE__, "License", "License", 10, "super-captcha/License", array(&$this,"configure_page_3"));
}
function getAdminOptions()
{ // This is just for testing right now...
$adminOptions = array("optionName" => "Value",
"optionName2" => "Value",
"optionName3" => "Value");
$savedOptions = get_option($this->adminOptionsName);
if (!empty($savedOptions))
{
foreach ($savedOptions as $key => $option)
{
$adminOptions[$key] = $option;
}
}
update_option($this->adminOptionsName, $adminOptions);
return $adminOptions;
}
function configure_page_1()
{ // Welcome & Configuration Page.
?>
Thank you for using Super-CAPTCHA! This particular CAPTCHA system was origionally designed to run on the WordPress Multi User edition and may not function properly on the regular WordPress installs. I have tested it, and it seem sto work fine, but there may be some issues I'm not aware of. If you find any bugs, please report them here. Feel free to leave you feature requests, questions, comments, and donations there as well. Note that the automatic upgrades of this software is only supported 2 version releases back. So version 2.0.0 will only be upgradeable to 2.0.2, afterwards you'll have to manually find the older versions to upgrade each version yourself.
DONATE! | Configure Super-CAPTCHA | Support Super-CAPTCHA (Donate) | View README | View LICENSE
Secured by Super-CAPTCHA © 2009 MLW & Associates, LLP. All rights reserved.
check($_POST['SpamCode']); if($valid == true) { unset( $_POST['SpamCode'] ); } else { $errors['login_captcha'] = __('ERROR: Please enter correct verification.'); } } elseif(!isset($_POST['SpamCode']) && isset($_POST['log'])) { $errors['login_captcha'] = __('ERROR: The verification field is empty.'); } return $errors; } function signup_form( $errors ) { $error = $errors->get_error_message('captcha'); ?> check($_POST['SpamCode']); if($valid == true) { // GOAL! } else { $myerror = "Please enter correct verification."; } } elseif(!isset($_POST['SpamCode']) && isset($_POST['user_name'])) { $errors = "Please enter verification."; } */ if( isset($myerror) ) { echo '
' . $error . '
'; } ?> check($_POST['SpamCode']); if($valid == true) { unset( $_POST['SpamCode'] ); $_SESSION['capcha'] = 'pass'; } else { $content['errors']->add('captcha', __('Please enter correct verification.')); $_SESSION['capcha'] = 'fail'; } } elseif($_POST['SpamCode'] == '' && isset($_POST['user_name'])) { $content['errors']->add('captcha', __('Please enter verification.')); $_SESSION['capcha'] = 'fail'; } return( $content ); } function install_on_activation() { global $wpdb; chmod(THIS_DIR, 0755); chmod(THIS_DIR . '/super-captcha.php', 0755); chmod(THIS_DIR . '/includes', 0755); chmod(THIS_DIR . '/includes/elephant.ttf', 0755); chmod(THIS_DIR . '/includes/images', 0755); chmod(THIS_DIR . '/includes/images/audio_icon.gif', 0755); chmod(THIS_DIR . '/includes/images/refresh.gif', 0755); chmod(THIS_DIR . '/includes/words/words.txt', 0755); echo('
* $securimage = new Securimage();
*
*
*/
function Securimage()
{
if ( session_id() == '') { // no session has been started yet, which is needed for validation
session_start();
}
}
/**
* Generate a code and output the image to the browser.
*
*
* show('bg.jpg');
* ?>
*
*
* @param string $background_image The path to an image to use as the background for the CAPTCHA
*/
function show($background_image = "")
{
if($background_image != "" && is_readable($background_image)) {
$this->bgimg = $background_image;
}
$this->doImage();
}
/**
* Validate the code entered by the user.
*
*
* $code = $_POST['code'];
* if ($securimage->check($code) == false) {
* die("Sorry, the code entered did not match.");
* } else {
* $valid = true;
* }
*
* @param string $code The code the user entered
* @return boolean true if the code was correct, false if not
*/
function check($code)
{
$this->code_entered = $code;
$this->validate();
return $this->correct_code;
}
/**
* Generate and output the image
*
* @access private
*
*/
function doImage()
{
if($this->use_transparent_text == true || $this->bgimg != "") {
$this->im = imagecreatetruecolor($this->image_width, $this->image_height);
$bgcolor = imagecolorallocate($this->im, hexdec(substr($this->image_bg_color, 1, 2)), hexdec(substr($this->image_bg_color, 3, 2)), hexdec(substr($this->image_bg_color, 5, 2)));
imagefilledrectangle($this->im, 0, 0, imagesx($this->im), imagesy($this->im), $bgcolor);
} else { //no transparency
$this->im = imagecreate($this->image_width, $this->image_height);
$bgcolor = imagecolorallocate($this->im, hexdec(substr($this->image_bg_color, 1, 2)), hexdec(substr($this->image_bg_color, 3, 2)), hexdec(substr($this->image_bg_color, 5, 2)));
}
if($this->bgimg != "") { $this->setBackground(); }
$this->createCode();
if (!$this->draw_lines_over_text && $this->draw_lines) $this->drawLines();
$this->drawWord();
if ($this->arc_linethrough == true) $this->arcLines();
if ($this->draw_lines_over_text && $this->draw_lines) $this->drawLines();
$this->output();
}
/**
* Set the background of the CAPTCHA image
*
* @access private
*
*/
function setBackground()
{
$dat = @getimagesize($this->bgimg);
if($dat == false) { return; }
switch($dat[2]) {
case 1: $newim = @imagecreatefromgif($this->bgimg); break;
case 2: $newim = @imagecreatefromjpeg($this->bgimg); break;
case 3: $newim = @imagecreatefrompng($this->bgimg); break;
case 15: $newim = @imagecreatefromwbmp($this->bgimg); break;
case 16: $newim = @imagecreatefromxbm($this->bgimg); break;
default: return;
}
if(!$newim) return;
imagecopy($this->im, $newim, 0, 0, 0, 0, $this->image_width, $this->image_height);
}
/**
* Draw arced lines over the text
*
* @access private
*
*/
function arcLines()
{
$colors = explode(',', $this->arc_line_colors);
imagesetthickness($this->im, 3);
$color = $colors[rand(0, sizeof($colors) - 1)];
$linecolor = imagecolorallocate($this->im, hexdec(substr($color, 1, 2)), hexdec(substr($color, 3, 2)), hexdec(substr($color, 5, 2)));
$xpos = $this->text_x_start + ($this->font_size * 2) + rand(-5, 5);
$width = $this->image_width / 2.66 + rand(3, 10);
$height = $this->font_size * 2.14 - rand(3, 10);
if ( rand(0,100) % 2 == 0 ) {
$start = rand(0,66);
$ypos = $this->image_height / 2 - rand(5, 15);
$xpos += rand(5, 15);
} else {
$start = rand(180, 246);
$ypos = $this->image_height / 2 + rand(5, 15);
}
$end = $start + rand(75, 110);
imagearc($this->im, $xpos, $ypos, $width, $height, $start, $end, $linecolor);
$color = $colors[rand(0, sizeof($colors) - 1)];
$linecolor = imagecolorallocate($this->im, hexdec(substr($color, 1, 2)), hexdec(substr($color, 3, 2)), hexdec(substr($color, 5, 2)));
if ( rand(1,75) % 2 == 0 ) {
$start = rand(45, 111);
$ypos = $this->image_height / 2 - rand(5, 15);
$xpos += rand(5, 15);
} else {
$start = rand(200, 250);
$ypos = $this->image_height / 2 + rand(5, 15);
}
$end = $start + rand(75, 100);
imagearc($this->im, $this->image_width * .75, $ypos, $width, $height, $start, $end, $linecolor);
}
/**
* Draw lines on the image
*
* @access private
*
*/
function drawLines()
{
$linecolor = imagecolorallocate($this->im, hexdec(substr($this->line_color, 1, 2)), hexdec(substr($this->line_color, 3, 2)), hexdec(substr($this->line_color, 5, 2)));
imagesetthickness($this->im, $this->line_thickness);
//vertical lines
for($x = 1; $x < $this->image_width; $x += $this->line_distance) {
imageline($this->im, $x, 0, $x, $this->image_height, $linecolor);
}
//horizontal lines
for($y = 11; $y < $this->image_height; $y += $this->line_distance) {
imageline($this->im, 0, $y, $this->image_width, $y, $linecolor);
}
if ($this->draw_angled_lines == true) {
for ($x = -($this->image_height); $x < $this->image_width; $x += $this->line_distance) {
imageline($this->im, $x, 0, $x + $this->image_height, $this->image_height, $linecolor);
}
for ($x = $this->image_width + $this->image_height; $x > 0; $x -= $this->line_distance) {
imageline($this->im, $x, 0, $x - $this->image_height, $this->image_height, $linecolor);
}
}
}
/**
* Draw the CAPTCHA code over the image
*
* @access private
*
*/
function drawWord()
{
if ($this->use_gd_font == true) {
if (!is_int($this->gd_font_file)) { //is a file name
$font = @imageloadfont($this->gd_font_file);
if ($font == false) {
trigger_error("Failed to load GD Font file {$this->gd_font_file} ", E_USER_WARNING);
return;
}
} else { //gd font identifier
$font = $this->gd_font_file;
}
$color = imagecolorallocate($this->im, hexdec(substr($this->text_color, 1, 2)), hexdec(substr($this->text_color, 3, 2)), hexdec(substr($this->text_color, 5, 2)));
imagestring($this->im, $font, $this->text_x_start, ($this->image_height / 2) - ($this->gd_font_size / 2), $this->code, $color);
} else { //ttf font
if($this->use_transparent_text == true) {
$alpha = intval($this->text_transparency_percentage / 100 * 127);
$font_color = imagecolorallocatealpha($this->im, hexdec(substr($this->text_color, 1, 2)), hexdec(substr($this->text_color, 3, 2)), hexdec(substr($this->text_color, 5, 2)), $alpha);
} else { //no transparency
$font_color = imagecolorallocate($this->im, hexdec(substr($this->text_color, 1, 2)), hexdec(substr($this->text_color, 3, 2)), hexdec(substr($this->text_color, 5, 2)));
}
$x = $this->text_x_start;
$strlen = strlen($this->code);
$y_min = ($this->image_height / 2) + ($this->font_size / 2) - 2;
$y_max = ($this->image_height / 2) + ($this->font_size / 2) + 2;
$colors = explode(',', $this->multi_text_color);
for($i = 0; $i < $strlen; ++$i) {
$angle = rand($this->text_angle_minimum, $this->text_angle_maximum);
$y = rand($y_min, $y_max);
if ($this->use_multi_text == true) {
$idx = rand(0, sizeof($colors) - 1);
$r = substr($colors[$idx], 1, 2);
$g = substr($colors[$idx], 3, 2);
$b = substr($colors[$idx], 5, 2);
if($this->use_transparent_text == true) {
$font_color = imagecolorallocatealpha($this->im, "0x$r", "0x$g", "0x$b", $alpha);
} else {
$font_color = imagecolorallocate($this->im, "0x$r", "0x$g", "0x$b");
}
}
@imagettftext($this->im, $this->font_size, $angle, $x, $y, $font_color, $this->ttf_file, $this->code{$i});
$x += rand($this->text_minimum_distance, $this->text_maximum_distance);
} //for loop
} //else ttf font
} //function
/**
* Create a code and save to the session
*
* @since 1.0.1
*
*/
function createCode()
{
$this->code = false;
if ($this->use_wordlist && is_readable($this->wordlist_file)) {
$this->code = $this->readCodeFromFile();
}
if ($this->code == false) {
$this->code = $this->generateCode($this->code_length);
}
$this->saveData();
}
/**
* Generate a code
*
* @access private
* @param int $len The code length
* @return string
*/
function generateCode($len)
{
$code = '';
for($i = 1, $cslen = strlen($this->charset); $i <= $len; ++$i) {
$code .= strtoupper( $this->charset{rand(0, $cslen - 1)} );
}
return $code;
}
/**
* Reads a word list file to get a code
*
* @access private
* @since 1.0.2
* @return mixed false on failure, a word on success
*/
function readCodeFromFile()
{
$fp = @fopen($this->wordlist_file, 'rb');
if (!$fp) return false;
$fsize = filesize($this->wordlist_file);
if ($fsize < 32) return false; // too small of a list to be effective
if ($fsize < 128) {
$max = $fsize; // still pretty small but changes the range of seeking
} else {
$max = 128;
}
fseek($fp, rand(0, $fsize - $max), SEEK_SET);
$data = fread($fp, 128); // read a random 128 bytes from file
fclose($fp);
$data = preg_replace("/\r?\n/", "\n", $data);
$start = strpos($data, "\n", rand(0, 100)) + 1; // random start position
$end = strpos($data, "\n", $start); // find end of word
return strtolower(substr($data, $start, $end - $start)); // return substring in 128 bytes
}
/**
* Output image to the browser
*
* @access private
*
*/
function output()
{
header("Expires: Sun, 1 Jan 2000 12:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
switch($this->image_type)
{
case SI_IMAGE_JPEG:
header("Content-Type: image/jpeg");
imagejpeg($this->im, null, 90);
break;
case SI_IMAGE_GIF:
header("Content-Type: image/gif");
imagegif($this->im);
break;
default:
header("Content-Type: image/png");
imagepng($this->im);
break;
}
imagedestroy($this->im);
}
/**
* Get WAV file data of the spoken code.