Update of /cvsroot/phpwiki/phpwiki/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27161/lib Modified Files: IniConfig.php editpage.php main.php Added Files: Captcha.php Log Message: captcha feature by Benjamin Drieu. Patch #1110699 --- NEW FILE: Captcha.php --- <?php /* Session Captcha v1.0 by Gavin M. Roy <gm...@bt...> Modified by Benjamin Drieu <bd...@ap...> - 2005 for PhpWiki This File is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This File is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 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 File; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ function get_captcha_word () { // Load In the Word List $fp = fopen(FindFile("lib/captcha/dictionary"), "r"); while ( !feof($fp) ) $text[] = Trim(fgets($fp, 1024)); fclose($fp); // Pick a Word $word = ""; while ( strlen(Trim($word)) == 0 ) { $x = rand(0, Count($text)); return $text[$x]; } } // Draw the Spiral function spiral( &$im, $origin_x = 100, $origin_y = 100, $r = 0, $g = 0, $b = 0 ) { $theta = 1; $thetac = 6; $radius = 15; $circles = 10; $points = 35; $lcolor = imagecolorallocate( $im, $r, $g, $b ); for( $i = 0; $i < ( $circles * $points ) - 1; $i++ ) { $theta = $theta + $thetac; $rad = $radius * ( $i / $points ); $x = ( $rad * cos( $theta ) ) + $origin_x; $y = ( $rad * sin( $theta ) ) + $origin_y; $theta = $theta + $thetac; $rad1 = $radius * ( ( $i + 1 ) / $points ); $x1 = ( $rad1 * cos( $theta ) ) + $origin_x; $y1 = ( $rad1 * sin( $theta ) ) + $origin_y; imageline( $im, $x, $y, $x1, $y1, $lcolor ); $theta = $theta - $thetac; } } function captcha_image ( $word ) { $width = 250; $height = 80; // Create the Image $jpg = ImageCreate($width,$height); $bg = ImageColorAllocate($jpg,255,255,255); $tx = ImageColorAllocate($jpg,185,140,140); ImageFilledRectangle($jpg,0,0,$width,$height,$bg); $x = rand(0, $width); $y = rand(0, $height); spiral($jpg, $x, $y, 225, 190, 190); $angle = rand(-25, 25); $size = rand(14,20); if ( $angle >= 0 ) $y = rand(50,$height-20); else $y = rand(25, 50); $x = rand(10, $width-100); imagettftext($jpg, $size, $angle, $x, $y, $tx, FindFile("lib/captcha/Vera.ttf"), $word); $x = rand(0, 280); $y = rand(0, 115); spiral($jpg, $x, $y, 255,190,190); imageline($jpg, 0,0,$width-1,0,$tx); imageline($jpg, 0,0,0,$height-1,$tx); imageline($jpg, 0,$height-1,$width-1,$height-1,$tx); imageline($jpg, $width-1,0,$width-1,$height-1,$tx); header("Content-type: image/jpeg"); ImageJpeg($jpg); } ?> Index: IniConfig.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/IniConfig.php,v retrieving revision 1.87 retrieving revision 1.88 diff -u -2 -b -p -d -r1.87 -r1.88 --- IniConfig.php 8 Apr 2005 18:11:50 -0000 1.87 +++ IniConfig.php 25 Apr 2005 20:17:13 -0000 1.88 @@ -182,5 +182,5 @@ function IniConfig($file) { 'PLUGIN_CACHED_USECACHE', 'PLUGIN_CACHED_FORCE_SYNCMAP', 'BLOG_EMPTY_DEFAULT_PREFIX', 'DATABASE_PERSISTENT', - 'ENABLE_DISCUSSION_LINK' + 'ENABLE_DISCUSSION_LINK', 'ENABLE_CAPTCHA' ); @@ -832,4 +832,7 @@ function fixup_dynamic_configs($file) { // $Log$ +// Revision 1.88 2005年04月25日 20:17:13 rurban +// captcha feature by Benjamin Drieu. Patch #1110699 +// // Revision 1.87 2005年04月08日 18:11:50 rurban // guard against empty default INI values Index: editpage.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/editpage.php,v retrieving revision 1.94 retrieving revision 1.95 diff -u -2 -b -p -d -r1.94 -r1.95 --- editpage.php 28 Feb 2005 20:23:31 -0000 1.94 +++ editpage.php 25 Apr 2005 20:17:14 -0000 1.95 @@ -12,4 +12,5 @@ require_once('lib/Template.php'); if (!defined('USE_HTMLAREA')) define('USE_HTMLAREA', false); if (USE_HTMLAREA) require_once('lib/htmlarea.php'); +if (ENABLE_CAPTCHA) require_once('lib/Captcha.php'); class PageEditor @@ -87,5 +88,9 @@ class PageEditor } elseif ($this->request->getArg('save_and_redirect_to') != "") { - if ($this->savePage()) { + if (ENABLE_CAPTCHA && $this->captchaFailed()) { + $this->tokens['PAGE_LOCKED_MESSAGE'] = + HTML::p(HTML::h1(_("Typed in verification word mismatch ... are you a bot?"))); + } + elseif ( $this->savePage()) { // noreturn $this->request->redirect(WikiURL($this->request->getArg('save_and_redirect_to'))); @@ -95,7 +100,12 @@ class PageEditor } elseif ($this->editaction == 'save') { - if ($this->savePage()) { + if (ENABLE_CAPTCHA && $this->captchaFailed()) { + $this->tokens['PAGE_LOCKED_MESSAGE'] = + HTML::p(HTML::h1(_("Typed in verification word mismatch ... are you a bot?"))); + } + elseif ($this->savePage()) { return true; // Page saved. } + else $saveFailed = true; } @@ -295,4 +305,17 @@ class PageEditor } + function captchaFailed () { + if ($this->request->getSessionVar('captcha_ok') == true) + return false; + + if ( ! array_key_exists ( 'captcha_input', $this->meta ) + or ($this->request->getSessionVar('captchaword') + and ($this->request->getSessionVar('captchaword') != $this->meta['captcha_input']))) + return true; + + $this->request->setSessionVar('captcha_ok', true); + return false; + } + function isConcurrentUpdate () { assert($this->current->getVersion() >= $this->_currentVersion); @@ -487,4 +510,18 @@ class PageEditor $el['HIDDEN_INPUTS'] = HiddenInputs($h); $el['EDIT_TEXTAREA'] = $this->getTextArea(); + if ( ENABLE_CAPTCHA && ! $request->getSessionVar('captchaword')) { + $request->setSessionVar('captchaword', get_captcha_word()); + } + if ( ENABLE_CAPTCHA && ! $request->getSessionVar('captcha_ok')) { + $el['CAPTCHA_INPUT'] + = HTML::input(array('type' => 'text', + 'class' => 'wikitext', + 'id' => 'edit[captcha_input]', + 'name' => 'edit[captcha_input]', + 'size' => 20, + 'maxlength' => 256)); + $el['CAPTCHA_IMAGE'] = '<img src="?action=captcha" alt="captcha" />'; + $el['CAPTCHA_LABEL'] = '<label for="edit[captcha_input]">'._("Type word above:").' </label>'; + } $el['SUMMARY_INPUT'] = HTML::input(array('type' => 'text', @@ -578,4 +615,8 @@ class PageEditor $meta['is_minor_edit'] = !empty($posted['minor_edit']); $meta['pagetype'] = !empty($posted['pagetype']) ? $posted['pagetype'] : false; + if ( ENABLE_CAPTCHA ) + $meta['captcha_input'] = !empty($posted['captcha_input']) ? + $posted['captcha_input'] : ''; + $this->meta = array_merge($this->meta, $meta); $this->locked = !empty($posted['locked']); @@ -715,4 +756,7 @@ extends PageEditor /** $Log$ + Revision 1.95 2005年04月25日 20:17:14 rurban + captcha feature by Benjamin Drieu. Patch #1110699 + Revision 1.94 2005年02月28日 20:23:31 rurban fix error_stack Index: main.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/main.php,v retrieving revision 1.211 retrieving revision 1.212 diff -u -2 -b -p -d -r1.211 -r1.212 --- main.php 11 Apr 2005 19:42:54 -0000 1.211 +++ main.php 25 Apr 2005 20:17:14 -0000 1.212 @@ -584,4 +584,5 @@ class WikiRequest extends Request { case 'search': case 'pdf': + case 'captcha': return WIKIAUTH_ANON; @@ -1115,4 +1116,9 @@ class WikiRequest extends Request { } + function action_captcha () { + include_once "lib/Captcha.php"; + captcha_image ( $this->getSessionVar('captchaword')); + } + } @@ -1250,4 +1256,7 @@ if (!defined('PHPWIKI_NOMAIN') or !PHPWI // $Log$ +// Revision 1.212 2005年04月25日 20:17:14 rurban +// captcha feature by Benjamin Drieu. Patch #1110699 +// // Revision 1.211 2005年04月11日 19:42:54 rurban // reformatting, SESSION_SAVE_PATH check