Ticket #954: captcha.diff
| File captcha.diff, 44.6 kB (added by mstahv, 4 years ago) |
|---|
-
modules/captcha/conf.ini
old new 1 [CaptchaMgr] 2 requiresAuth = false 3 setHeaders=false 4 -
modules/captcha/fonts/COPYRIGHT.TXT
old new 1 Bitstream Vera Fonts Copyright 2 3 The fonts have a generous copyright, allowing derivative works (as 4 long as "Bitstream" or "Vera" are not in the names), and full 5 redistribution (so long as they are not *sold* by themselves). They 6 can be be bundled, redistributed and sold with any software. 7 8 The fonts are distributed under the following copyright: 9 10 Copyright 11 ========= 12 13 Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream 14 Vera is a trademark of Bitstream, Inc. 15 16 Permission is hereby granted, free of charge, to any person obtaining 17 a copy of the fonts accompanying this license ("Fonts") and associated 18 documentation files (the "Font Software"), to reproduce and distribute 19 the Font Software, including without limitation the rights to use, 20 copy, merge, publish, distribute, and/or sell copies of the Font 21 Software, and to permit persons to whom the Font Software is furnished 22 to do so, subject to the following conditions: 23 24 The above copyright and trademark notices and this permission notice 25 shall be included in all copies of one or more of the Font Software 26 typefaces. 27 28 The Font Software may be modified, altered, or added to, and in 29 particular the designs of glyphs or characters in the Fonts may be 30 modified and additional glyphs or characters may be added to the 31 Fonts, only if the fonts are renamed to names not containing either 32 the words "Bitstream" or the word "Vera". 33 34 This License becomes null and void to the extent applicable to Fonts 35 or Font Software that has been modified and is distributed under the 36 "Bitstream Vera" names. 37 38 The Font Software may be sold as part of a larger software package but 39 no copy of one or more of the Font Software typefaces may be sold by 40 itself. 41 42 THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 43 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 44 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 45 OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL 46 BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR 47 OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, 48 OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR 49 OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT 50 SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. 51 52 Except as contained in this notice, the names of Gnome, the Gnome 53 Foundation, and Bitstream Inc., shall not be used in advertising or 54 otherwise to promote the sale, use or other dealings in this Font 55 Software without prior written authorization from the Gnome Foundation 56 or Bitstream Inc., respectively. For further information, contact: 57 fonts at gnome dot org. 58 59 Copyright FAQ 60 ============= 61 62 1. I don't understand the resale restriction... What gives? 63 64 Bitstream is giving away these fonts, but wishes to ensure its 65 competitors can't just drop the fonts as is into a font sale system 66 and sell them as is. It seems fair that if Bitstream can't make money 67 from the Bitstream Vera fonts, their competitors should not be able to 68 do so either. You can sell the fonts as part of any software package, 69 however. 70 71 2. I want to package these fonts separately for distribution and 72 sale as part of a larger software package or system. Can I do so? 73 74 Yes. A RPM or Debian package is a "larger software package" to begin 75 with, and you aren't selling them independently by themselves. 76 See 1. above. 77 78 3. Are derivative works allowed? 79 Yes! 80 81 4. Can I change or add to the font(s)? 82 Yes, but you must change the name(s) of the font(s). 83 84 5. Under what terms are derivative works allowed? 85 86 You must change the name(s) of the fonts. This is to ensure the 87 quality of the fonts, both to protect Bitstream and Gnome. We want to 88 ensure that if an application has opened a font specifically of these 89 names, it gets what it expects (though of course, using fontconfig, 90 substitutions could still could have occurred during font 91 opening). You must include the Bitstream copyright. Additional 92 copyrights can be added, as per copyright law. Happy Font Hacking! 93 94 6. If I have improvements for Bitstream Vera, is it possible they might get 95 adopted in future versions? 96 97 Yes. The contract between the Gnome Foundation and Bitstream has 98 provisions for working with Bitstream to ensure quality additions to 99 the Bitstream Vera font family. Please contact us if you have such 100 additions. Note, that in general, we will want such additions for the 101 entire family, not just a single font, and that you'll have to keep 102 both Gnome and Jim Lyles, Vera's designer, happy! To make sense to add 103 glyphs to the font, they must be stylistically in keeping with Vera's 104 design. Vera cannot become a "ransom note" font. Jim Lyles will be 105 providing a document describing the design elements used in Vera, as a 106 guide and aid for people interested in contributing to Vera. 107 108 7. I want to sell a software package that uses these fonts: Can I do so? 109 110 Sure. Bundle the fonts with your software and sell your software 111 with the fonts. That is the intent of the copyright. 112 113 8. If applications have built the names "Bitstream Vera" into them, 114 can I override this somehow to use fonts of my choosing? 115 116 This depends on exact details of the software. Most open source 117 systems and software (e.g., Gnome, KDE, etc.) are now converting to 118 use fontconfig (see www.fontconfig.org) to handle font configuration, 119 selection and substitution; it has provisions for overriding font 120 names and subsituting alternatives. An example is provided by the 121 supplied local.conf file, which chooses the family Bitstream Vera for 122 "sans", "serif" and "monospace". Other software (e.g., the XFree86 123 core server) has other mechanisms for font substitution. 124 -
modules/captcha/fonts/RELEASENOTES.TXT
old new 1 Bitstream Vera Fonts - April 16, 2003 2 ===================================== 3 4 The version number of these fonts is 1.10 to distinguish them from the 5 beta test fonts. 6 7 Note that the Vera copyright is incorporated in the fonts themselves. 8 The License field in the fonts contains the copyright license as it 9 appears below. The TrueType copyright field is not large enough to 10 contain the full license, so the license is incorporated (as you might 11 think if you thought about it) into the license field, which 12 unfortunately can be obscure to find. (In pfaedit, see: Element->Font 13 Info->TTFNames->License). 14 15 Our apologies for it taking longer to complete the fonts than planned. 16 Beta testers requested a tighter line spacing (less leading) and Jim 17 Lyles redesigned Vera's accents to bring its line spacing to more 18 typical of other fonts. This took additional time and effort. Our 19 thanks to Jim for this effort above and beyond the call of duty. 20 21 There are four monospace and sans faces (normal, oblique, bold, bold 22 oblique) and two serif faces (normal and bold). Fontconfig/Xft2 (see 23 www.fontconfig.org) can artificially oblique the serif faces for you: 24 this loses hinting and distorts the faces slightly, but is visibly 25 different than normal and bold, and reasonably pleasing. 26 27 On systems with fontconfig 2.0 or 2.1 installed, making your sans, 28 serif and monospace fonts default to these fonts is very easy. Just 29 drop the file local.conf into your /etc/fonts directory. This will 30 make the Bitstream fonts your default fonts for all applications using 31 fontconfig (if sans, serif, or monospace names are used, as they often 32 are as default values in many desktops). The XML in local.conf may 33 need modification to enable subpixel decimation, if appropriate, 34 however, the commented out phrase does so for XFree86 4.3, in the case 35 that the server does not have sufficient information to identify the 36 use of a flat panel. Fontconfig 2.2 adds Vera to the list of font 37 families and will, by default use it as the default sans, serif and 38 monospace fonts. 39 40 During the testing of the final Vera fonts, we learned that screen 41 fonts in general are only typically hinted to work correctly at 42 integer pixel sizes. Vera is coded internally for integer sizes only. 43 We need to investigate further to see if there are commonly used fonts 44 that are hinted to be rounded but are not rounded to integer sizes due 45 to oversights in their coding. 46 47 Most fonts work best at 8 pixels and below if anti-aliased only, as 48 the amount of work required to hint well at smaller and smaller sizes 49 becomes astronomical. GASP tables are typically used to control 50 whether hinting is used or not, but Freetype/Xft does not currently 51 support GASP tables (which are present in Vera). 52 53 To mitigate this problem, both for Vera and other fonts, there will be 54 (very shortly) a new fontconfig 2.2 release that will, by default not 55 apply hints if the size is below 8 pixels. if you should have a font 56 that in fact has been hinted more agressively, you can use fontconfig 57 to note this exception. We believe this should improve many hinted 58 fonts in addition to Vera, though implemeting GASP support is likely 59 the right long term solution. 60 61 Font rendering in Gnome or KDE is the combination of algorithms in 62 Xft2 and Freetype, along with hinting in the fonts themselves. It is 63 vital to have sufficient information to disentangle problems that you 64 may observe. 65 66 Note that having your font rendering system set up correctly is vital 67 to proper judgement of problems of the fonts: 68 69 * Freetype may or may not be configured to in ways that may 70 implement execution of possibly patented (in some parts of the world) 71 TrueType hinting algorithms, particularly at small sizes. Best 72 results are obtained while using these algorithms. 73 74 * The freetype autohinter (used when the possibly patented 75 algorithms are not used) continues to improve with each release. If 76 you are using the autohinter, please ensure you are using an up to 77 date version of freetype before reporting problems. 78 79 * Please identify what version of freetype you are using in any 80 bug reports, and how your freetype is configured. 81 82 * Make sure you are not using the freetype version included in 83 XFree86 4.3, as it has bugs that significantly degrade most fonts, 84 including Vera. if you build XFree86 4.3 from source yourself, you may 85 have installed this broken version without intending it (as I 86 did). Vera was verified with the recently released Freetype 2.1.4. On 87 many systems, 'ldd" can be used to see which freetype shared library 88 is actually being used. 89 90 * Xft/X Render does not (yet) implement gamma correction. This 91 causes significant problems rendering white text on a black background 92 (causing partial pixels to be insufficiently shaded) if the gamma of 93 your monitor has not been compensated for, and minor problems with 94 black text on a while background. The program "xgamma" can be used to 95 set a gamma correction value in the X server's color pallette. Most 96 monitors have a gamma near 2. 97 98 * Note that the Vera family uses minimal delta hinting. Your 99 results on other systems when not used anti-aliased may not be 100 entirely satisfying. We are primarily interested in reports of 101 problems on open source systems implementing Xft2/fontconfig/freetype 102 (which implements antialiasing and hinting adjustements, and 103 sophisticated subpixel decimation on flatpanels). Also, the 104 algorithms used by Xft2 adjust the hints to integer widths and the 105 results are crisper on open source systems than on Windows or 106 MacIntosh. 107 108 * Your fontconfig may (probably does) predate the release of 109 fontconfig 2.2, and you may see artifacts not present when the font is 110 used at very small sizes with hinting enabled. "vc-list -V" can be 111 used to see what version you have installed. 112 113 We believe and hope that these fonts will resolve the problems 114 reported during beta test. The largest change is the reduction of 115 leading (interline spacing), which had annoyed a number of people, and 116 reduced Vera's utility for some applcations. The Vera monospace font 117 should also now make '0' and 'O' and '1' and 'l' more clearly 118 distinguishable. 119 120 The version of these fonts is version 1.10. Fontconfig should be 121 choosing the new version of the fonts if both the released fonts and 122 beta test fonts are installed (though please discard them: they have 123 names of form tt20[1-12]gn.ttf). Note that older versions of 124 fontconfig sometimes did not rebuild their cache correctly when new 125 fonts are installed: please upgrade to fontconfig 2.2. "fc-cache -f" 126 can be used to force rebuilding fontconfig's cache files. 127 128 If you note problems, please send them to fonts at gnome dot org, with 129 exactly which face and size and unicode point you observe the problem 130 at. The xfd utility from XFree86 CVS may be useful for this (e.g. "xfd 131 -fa sans"). A possibly more useful program to examine fonts at a 132 variety of sizes is the "waterfall" program found in Keith Packard's 133 CVS. 134 135 $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS login 136 Logging in to :pserver:anoncvs@keithp.com:2401/local/src/CVS 137 CVS password: <hit return> 138 $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS co waterfall 139 $ cd waterfall 140 $ xmkmf -a 141 $ make 142 # make install 143 # make install.man 144 145 Again, please make sure you are running an up-to-date freetype, and 146 that you are only examining integer sizes. 147 148 Reporting Problems 149 ================== 150 151 Please send problem reports to fonts at gnome org, with the following 152 information: 153 154 1. Version of Freetype, Xft2 and fontconfig 155 2. Whether TT hinting is being used, or the autohinter 156 3. Application being used 157 4. Character/Unicode code point that has problems (if applicable) 158 5. Version of which operating system 159 6. Please include a screenshot, when possible. 160 161 Please check the fonts list archives before reporting problems to cut 162 down on duplication. -
modules/captcha/fonts/README.TXT
old new 1 Contained herin is the Bitstream Vera font family. 2 3 The Copyright information is found in the COPYRIGHT.TXT file (along 4 with being incoporated into the fonts themselves). 5 6 The releases notes are found in the file "RELEASENOTES.TXT". 7 8 We hope you enjoy Vera! 9 10 Bitstream, Inc. 11 The Gnome Project -
modules/captcha/classes/CaptchaMgr.php
old new 1 <?php 2 /* Reminder: always indent with 4 spaces (no tabs). */ 3 // +---------------------------------------------------------------------------+ 4 // | Copyright (c) 2006, Demian Turner | 5 // | All rights reserved. | 6 // | | 7 // | Redistribution and use in source and binary forms, with or without | 8 // | modification, are permitted provided that the following conditions | 9 // | are met: | 10 // | | 11 // | o Redistributions of source code must retain the above copyright | 12 // | notice, this list of conditions and the following disclaimer. | 13 // | o Redistributions in binary form must reproduce the above copyright | 14 // | notice, this list of conditions and the following disclaimer in the | 15 // | documentation and/or other materials provided with the distribution. | 16 // | o The names of the authors may not be used to endorse or promote | 17 // | products derived from this software without specific prior written | 18 // | permission. | 19 // | | 20 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 21 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 22 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 23 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 24 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 25 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 26 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 27 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 28 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 29 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 30 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 31 // | | 32 // +---------------------------------------------------------------------------+ 33 // | Seagull 0.6 | 34 // +---------------------------------------------------------------------------+ 35 // | captchaMgr.php | 36 // +---------------------------------------------------------------------------+ 37 // | Author: <> | 38 // +---------------------------------------------------------------------------+ 39 // $Id: ManagerTemplate.html,v 1.2 2005/04/17 02:15:02 demian Exp $ 40 41 require_once SGL_MOD_DIR . '/captcha/classes/Captcha.php'; 42 43 /** 44 * General CAPTCHA solution 45 * Usage: 46 * - In this module only the image is generated 47 * - In other classes (that use this captcha module) 48 * - import modules/capthca/classes/Capthca.php 49 * - call SGL_Captcha::validateKey('typed_keyword_from_form') to validate 50 * 51 * 52 * 53 * @package captcha 54 * @author matti@nettirasia.com 55 * @todo add voice captcha 56 */ 57 class CaptchaMgr extends SGL_Manager 58 { 59 function CaptchaMgr() 60 { 61 SGL::logMessage(null, PEAR_LOG_DEBUG); 62 parent::SGL_Manager(); 63 64 $this->_aActionsMapping = array( 65 'textcaptcha' => array('textcaptcha'), 66 ); 67 } 68 69 function validate($req, &$input) 70 { 71 SGL::logMessage(null, PEAR_LOG_DEBUG); 72 $this->validated = true; 73 $input->masterTemplate = 'empty.html'; 74 $input->action = ($req->get('action')) ? $req->get('action') : 'textcaptcha'; 75 76 } 77 78 79 function _cmd_textcaptcha(&$input, &$output) 80 { 81 SGL::logMessage(null, PEAR_LOG_DEBUG); 82 Captcha::printTextCaptcha(); 83 } 84 85 } 86 ?> -
modules/captcha/classes/php-captcha.inc.php
old new 1 <?php 2 /***************************************************************/ 3 /* PhpCaptcha - A visual and audio CAPTCHA generation library 4 5 Software License Agreement (BSD License) 6 7 Copyright (C) 2005-2006, Edward Eliot. 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions are met: 12 13 * Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 * Redistributions in binary form must reproduce the above copyright 16 notice, this list of conditions and the following disclaimer in the 17 documentation and/or other materials provided with the distribution. 18 * Neither the name of Edward Eliot nor the names of its contributors 19 may be used to endorse or promote products derived from this software 20 without specific prior written permission of Edward Eliot. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY 23 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY 26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 33 Last Updated: 18th April 2006 */ 34 /***************************************************************/ 35 36 /************************ Documentation ************************/ 37 /* 38 39 Documentation is available at http://www.ejeliot.com/pages/2 40 41 */ 42 /************************ Default Options **********************/ 43 44 // start a PHP session - this class uses sessions to store the generated 45 // code. Comment out if you are calling already from your application 46 // session_start(); 47 48 // class defaults - change to effect globally 49 50 define('CAPTCHA_SESSION_ID', 'php_captcha'); 51 define('CAPTCHA_WIDTH', 200); // max 500 52 define('CAPTCHA_HEIGHT', 50); // max 200 53 define('CAPTCHA_NUM_CHARS', 5); 54 define('CAPTCHA_NUM_LINES', 70); 55 define('CAPTCHA_CHAR_SHADOW', false); 56 define('CAPTCHA_OWNER_TEXT', ''); 57 define('CAPTCHA_CHAR_SET', ''); // defaults to A-Z 58 define('CAPTCHA_CASE_INSENSITIVE', true); 59 define('CAPTCHA_BACKGROUND_IMAGES', ''); 60 define('CAPTCHA_MIN_FONT_SIZE', 16); 61 define('CAPTCHA_MAX_FONT_SIZE', 25); 62 define('CAPTCHA_USE_COLOUR', false); 63 define('CAPTCHA_FILE_TYPE', 'jpeg'); 64 define('CAPTCHA_FLITE_PATH', '/usr/bin/flite'); 65 define('CAPTCHA_AUDIO_PATH', '/tmp/'); // must be writeable by PHP process 66 67 /************************ End Default Options **********************/ 68 69 // don't edit below this line (unless you want to change the class!) 70 71 class PhpCaptcha { 72 var $oImage; 73 var $aFonts; 74 var $iWidth; 75 var $iHeight; 76 var $iNumChars; 77 var $iNumLines; 78 var $iSpacing; 79 var $bCharShadow; 80 var $sOwnerText; 81 var $aCharSet; 82 var $bCaseInsensitive; 83 var $vBackgroundImages; 84 var $iMinFontSize; 85 var $iMaxFontSize; 86 var $bUseColour; 87 var $sFileType; 88 var $sCode = ''; 89 90 function PhpCaptcha( 91 $aFonts, // array of TrueType fonts to use - specify full path 92 $iWidth = CAPTCHA_WIDTH, // width of image 93 $iHeight = CAPTCHA_HEIGHT // height of image 94 ) { 95 // get parameters 96 $this->aFonts = $aFonts; 97 $this->SetNumChars(CAPTCHA_NUM_CHARS); 98 $this->SetNumLines(CAPTCHA_NUM_LINES); 99 $this->DisplayShadow(CAPTCHA_CHAR_SHADOW); 100 $this->SetOwnerText(CAPTCHA_OWNER_TEXT); 101 $this->SetCharSet(CAPTCHA_CHAR_SET); 102 $this->CaseInsensitive(CAPTCHA_CASE_INSENSITIVE); 103 $this->SetBackgroundImages(CAPTCHA_BACKGROUND_IMAGES); 104 $this->SetMinFontSize(CAPTCHA_MIN_FONT_SIZE); 105 $this->SetMaxFontSize(CAPTCHA_MAX_FONT_SIZE); 106 $this->UseColour(CAPTCHA_USE_COLOUR); 107 $this->SetFileType(CAPTCHA_FILE_TYPE); 108 $this->SetWidth($iWidth); 109 $this->SetHeight($iHeight); 110 } 111 112 function CalculateSpacing() { 113 $this->iSpacing = (int)($this->iWidth / $this->iNumChars); 114 } 115 116 function SetWidth($iWidth) { 117 $this->iWidth = $iWidth; 118 if ($this->iWidth > 500) $this->iWidth = 500; // to prevent perfomance impact 119 $this->CalculateSpacing(); 120 } 121 122 function SetHeight($iHeight) { 123 $this->iHeight = $iHeight; 124 if ($this->iHeight > 200) $this->iHeight = 200; // to prevent performance impact 125 } 126 127 function SetNumChars($iNumChars) { 128 $this->iNumChars = $iNumChars; 129 $this->CalculateSpacing(); 130 } 131 132 function SetNumLines($iNumLines) { 133 $this->iNumLines = $iNumLines; 134 } 135 136 function DisplayShadow($bCharShadow) { 137 $this->bCharShadow = $bCharShadow; 138 } 139 140 function SetOwnerText($sOwnerText) { 141 $this->sOwnerText = $sOwnerText; 142 } 143 144 function SetCharSet($vCharSet) { 145 // check for input type 146 if (is_array($vCharSet)) { 147 $this->aCharSet = $vCharSet; 148 } else { 149 if ($vCharSet != '') { 150 // split items on commas 151 $aCharSet = explode(',', $vCharSet); 152 153 // initialise array 154 $this->aCharSet = array(); 155 156 // loop through items 157 foreach ($aCharSet as $sCurrentItem) { 158 // a range should have 3 characters, otherwise is normal character 159 if (strlen($sCurrentItem) == 3) { 160 // split on range character 161 $aRange = explode('-', $sCurrentItem); 162 163 // check for valid range 164 if (count($aRange) == 2 && $aRange[0] < $aRange[1]) { 165 // create array of characters from range 166 $aRange = range($aRange[0], $aRange[1]); 167 168 // add to charset array 169 $this->aCharSet = array_merge($this->aCharSet, $aRange); 170 } 171 } else { 172 $this->aCharSet[] = $sCurrentItem; 173 } 174 } 175 } 176 } 177 } 178 179 function CaseInsensitive($bCaseInsensitive) { 180 $this->bCaseInsensitive = $bCaseInsensitive; 181 } 182 183 function SetBackgroundImages($vBackgroundImages) { 184 $this->vBackgroundImages = $vBackgroundImages; 185 } 186 187 function SetMinFontSize($iMinFontSize) { 188 $this->iMinFontSize = $iMinFontSize; 189 } 190 191 function SetMaxFontSize($iMaxFontSize) { 192 $this->iMaxFontSize = $iMaxFontSize; 193 } 194 195 function UseColour($bUseColour) { 196 $this->bUseColour = $bUseColour; 197 } 198 199 function SetFileType($sFileType) { 200 // check for valid file type 201 if (in_array($sFileType, array('gif', 'png', 'jpeg'))) { 202 $this->sFileType = $sFileType; 203 } else { 204 $this->sFileType = 'jpeg'; 205 } 206 } 207 208 function DrawLines() { 209 for ($i = 0; $i < $this->iNumLines; $i++) { 210 // allocate colour 211 if ($this->bUseColour) { 212 $iLineColour = imagecolorallocate($this->oImage, rand(100, 250), rand(100, 250), rand(100, 250)); 213 } else { 214 $iRandColour = rand(100, 250); 215 $iLineColour = imagecolorallocate($this->oImage, $iRandColour, $iRandColour, $iRandColour); 216 } 217 218 // draw line 219 imageline($this->oImage, rand(0, $this->iWidth), rand(0, $this->iHeight), rand(0, $this->iWidth), rand(0, $this->iHeight), $iLineColour); 220 } 221 } 222 223 function DrawOwnerText() { 224 // allocate owner text colour 225 $iBlack = imagecolorallocate($this->oImage, 0, 0, 0); 226 // get height of selected font 227 $iOwnerTextHeight = imagefontheight(2); 228 // calculate overall height 229 $iLineHeight = $this->iHeight - $iOwnerTextHeight - 4; 230 231 // draw line above text to separate from CAPTCHA 232 imageline($this->oImage, 0, $iLineHeight, $this->iWidth, $iLineHeight, $iBlack); 233 234 // write owner text 235 imagestring($this->oImage, 2, 3, $this->iHeight - $iOwnerTextHeight - 3, $this->sOwnerText, $iBlack); 236 237 // reduce available height for drawing CAPTCHA 238 $this->iHeight = $this->iHeight - $iOwnerTextHeight - 5; 239 } 240 241 function GenerateCode() { 242 // reset code 243 $this->sCode = ''; 244 245 // loop through and generate the code letter by letter 246 for ($i = 0; $i < $this->iNumChars; $i++) { 247 if (count($this->aCharSet) > 0) { 248 // select random character and add to code string 249 $this->sCode .= $this->aCharSet[array_rand($this->aCharSet)]; 250 } else { 251 // select random character and add to code string 252 $this->sCode .= chr(rand(65, 90)); 253 } 254 } 255 256 // save code in session variable 257 if ($this->bCaseInsensitive) { 258 $_SESSION[CAPTCHA_SESSION_ID] = strtoupper($this->sCode); 259 } else { 260 $_SESSION[CAPTCHA_SESSION_ID] = $this->sCode; 261 } 262 } 263 264 function DrawCharacters() { 265 // loop through and write out selected number of characters 266 for ($i = 0; $i < strlen($this->sCode); $i++) { 267 // select random font 268 $sCurrentFont = $this->aFonts[array_rand($this->aFonts)]; 269 270 // select random colour 271 if ($this->bUseColour) { 272 $iTextColour = imagecolorallocate($this->oImage, rand(0, 100), rand(0, 100), rand(0, 100)); 273 274 if ($this->bCharShadow) { 275 // shadow colour 276 $iShadowColour = imagecolorallocate($this->oImage, rand(0, 100), rand(0, 100), rand(0, 100)); 277 } 278 } else { 279 $iRandColour = rand(0, 100); 280 $iTextColour = imagecolorallocate($this->oImage, $iRandColour, $iRandColour, $iRandColour); 281 282 if ($this->bCharShadow) { 283 // shadow colour 284 $iRandColour = rand(0, 100); 285 $iShadowColour = imagecolorallocate($this->oImage, $iRandColour, $iRandColour, $iRandColour); 286 } 287 } 288 289 // select random font size 290 $iFontSize = rand($this->iMinFontSize, $this->iMaxFontSize); 291 292 // select random angle 293 $iAngle = rand(-30, 30); 294 295 // get dimensions of character in selected font and text size 296 $aCharDetails = imageftbbox($iFontSize, $iAngle, $sCurrentFont, $this->sCode[$i], array()); 297 298 // calculate character starting coordinates 299 $iX = $this->iSpacing / 4 + $i * $this->iSpacing; 300 $iCharHeight = $aCharDetails[2] - $aCharDetails[5]; 301 $iY = $this->iHeight / 2 + $iCharHeight / 4; 302 303 // write text to image 304 imagefttext($this->oImage, $iFontSize, $iAngle, $iX, $iY, $iTextColour, $sCurrentFont, $this->sCode[$i], array()); 305 306 if ($this->bCharShadow) { 307 $iOffsetAngle = rand(-30, 30); 308 309 $iRandOffsetX = rand(-5, 5); 310 $iRandOffsetY = rand(-5, 5); 311 312 imagefttext($this->oImage, $iFontSize, $iOffsetAngle, $iX + $iRandOffsetX, $iY + $iRandOffsetY, $iShadowColour, $sCurrentFont, $this->sCode[$i], array()); 313 } 314 } 315 } 316 317 function WriteFile($sFilename) { 318 if ($sFilename == '') { 319 // tell browser that data is jpeg 320 header("Content-type: image/$this->sFileType"); 321 } 322 323 switch ($this->sFileType) { 324 case 'gif': 325 $sFilename != '' ? imagegif($this->oImage, $sFilename) : imagegif($this->oImage); 326 break; 327 case 'png': 328 $sFilename != '' ? imagepng($this->oImage, $sFilename) : imagepng($this->oImage); 329 break; 330 default: 331 $sFilename != '' ? imagejpeg($this->oImage, $sFilename) : imagejpeg($this->oImage); 332 } 333 } 334 335 function Create($sFilename = '') { 336 // check for required gd functions 337 if (!function_exists('imagecreate') || !function_exists("image$this->sFileType") || ($this->vBackgroundImages != '' && !function_exists('imagecreatetruecolor'))) { 338 return false; 339 } 340 341 // get background image if specified and copy to CAPTCHA 342 if (is_array($this->vBackgroundImages) || $this->vBackgroundImages != '') { 343 // create new image 344 $this->oImage = imagecreatetruecolor($this->iWidth, $this->iHeight); 345 346 // create background image 347 if (is_array($this->vBackgroundImages)) { 348 $iRandImage = array_rand($this->vBackgroundImages); 349 $oBackgroundImage = imagecreatefromjpeg($this->vBackgroundImages[$iRandImage]); 350 } else { 351 $oBackgroundImage = imagecreatefromjpeg($this->vBackgroundImages); 352 } 353 354 // copy background image 355 imagecopy($this->oImage, $oBackgroundImage, 0, 0, 0, 0, $this->iWidth, $this->iHeight); 356 357 // free memory used to create background image 358 imagedestroy($oBackgroundImage); 359 } else { 360 // create new image 361 $this->oImage = imagecreate($this->iWidth, $this->iHeight); 362 } 363 364 // allocate white background colour 365 imagecolorallocate($this->oImage, 255, 255, 255); 366 367 // check for owner text 368 if ($this->sOwnerText != '') { 369 $this->DrawOwnerText(); 370 } 371 372 // check for background image before drawing lines 373 if (!is_array($this->vBackgroundImages) && $this->vBackgroundImages == '') { 374 $this->DrawLines(); 375 } 376 377 $this->GenerateCode(); 378 $this->DrawCharacters(); 379 380 // write out image to file or browser 381 $this->WriteFile($sFilename); 382 383 // free memory used in creating image 384 imagedestroy($this->oImage); 385 386 return true; 387 } 388 389 // call this method statically 390 function Validate($sUserCode, $bCaseInsensitive = true) { 391 if ($bCaseInsensitive) { 392 $sUserCode = strtoupper($sUserCode); 393 } 394 395 if (!empty($_SESSION[CAPTCHA_SESSION_ID]) && $sUserCode == $_SESSION[CAPTCHA_SESSION_ID]) { 396 // clear to prevent re-use 397 unset($_SESSION[CAPTCHA_SESSION_ID]); 398 399 return true; 400 } 401 402 return false; 403 } 404 } 405 406 // this class will only work correctly if a visual CAPTCHA has been created first using PhpCaptcha 407 class AudioPhpCaptcha { 408 var $sFlitePath; 409 var $sAudioPath; 410 var $sCode; 411 412 function AudioPhpCaptcha( 413 $sFlitePath = CAPTCHA_FLITE_PATH, // path to flite binary 414 $sAudioPath = CAPTCHA_AUDIO_PATH // the location to temporarily store the generated audio CAPTCHA 415 ) { 416 $this->SetFlitePath($sFlitePath); 417 $this->SetAudioPath($sAudioPath); 418 419 // retrieve code if already set by previous instance of visual PhpCaptcha 420 if (isset($_SESSION[CAPTCHA_SESSION_ID])) { 421 $this->sCode = $_SESSION[CAPTCHA_SESSION_ID]; 422 } 423 } 424 425 function SetFlitePath($sFlitePath) { 426 $this->sFlitePath = $sFlitePath; 427 } 428 429 function SetAudioPath($sAudioPath) { 430 $this->sAudioPath = $sAudioPath; 431 } 432 433 function Mask($sText) { 434 $iLength = strlen($sText); 435 436 // loop through characters in code and format 437 $sFormattedText = ''; 438 for ($i = 0; $i < $iLength; $i++) { 439 // comma separate all but first and last characters 440 if ($i > 0 && $i < $iLength - 1) { 441 $sFormattedText .= ', '; 442 } elseif ($i == $iLength - 1) { // precede last character with "and" 443 $sFormattedText .= ' and '; 444 } 445 $sFormattedText .= $sText[$i]; 446 } 447 448 $aPhrases = array( 449 "The %1\$s characters are as follows: %2\$s", 450 "%2\$s, are the %1\$s letters", 451 "Here are the %1\$s characters: %2\$s", 452 "%1\$s characters are: %2\$s", 453 "%1\$s letters: %2\$s" 454 ); 455 456 $iPhrase = array_rand($aPhrases); 457 458 return sprintf($aPhrases[$iPhrase], $iLength, $sFormattedText); 459 } 460 461 function Create() { 462 $sText = $this->Mask($this->sCode); 463 $sFile = md5($this->sCode.time()); 464 465 // create file with flite 466 shell_exec("$this->sFlitePath -t \"$sText\" -o $this->sAudioPath$sFile.wav"); 467 468 // set headers 469 header('Content-type: audio/x-wav'); 470 header("Content-Disposition: attachment;filename=$sFile.wav"); 471 472 // output to browser 473 echo file_get_contents("$this->sAudioPath$sFile.wav"); 474 475 // delete temporary file 476 @unlink("$this->sAudioPath$sFile.wav"); 477 } 478 } 479 480 // example sub class 481 class PhpCaptchaColour extends PhpCaptcha { 482 function PhpCaptchaColour($aFonts, $iWidth = CAPTCHA_WIDTH, $iHeight = CAPTCHA_HEIGHT) { 483 // call parent constructor 484 parent::PhpCaptcha($aFonts, $iWidth, $iHeight); 485 486 // set options 487 $this->UseColour(true); 488 } 489 } 490 ?> -
modules/captcha/classes/Captcha.php
old new 1 <?php 2 /* Reminder: always indent with 4 spaces (no tabs). */ 3 // +---------------------------------------------------------------------------+ 4 // | Copyright (c) 2006, Demian Turner | 5 // | All rights reserved. | 6 // | | 7 // | Redistribution and use in source and binary forms, with or without | 8 // | modification, are permitted provided that the following conditions | 9 // | are met: | 10 // | | 11 // | o Redistributions of source code must retain the above copyright | 12 // | notice, this list of conditions and the following disclaimer. | 13 // | o Redistributions in binary form must reproduce the above copyright | 14 // | notice, this list of conditions and the following disclaimer in the | 15 // | documentation and/or other materials provided with the distribution. | 16 // | o The names of the authors may not be used to endorse or promote | 17 // | products derived from this software without specific prior written | 18 // | permission. | 19 // | | 20 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 21 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 22 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 23 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 24 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 25 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 26 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 27 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 28 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 29 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 30 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 31 // | | 32 // +---------------------------------------------------------------------------+ 33 // | Seagull 0.6 | 34 // +---------------------------------------------------------------------------+ 35 // | Captcha.php | 36 // +---------------------------------------------------------------------------+ 37 // | Author: <> | 38 // +---------------------------------------------------------------------------+ 39 // $Id: ManagerTemplate.html,v 1.2 2005/04/17 02:15:02 demian Exp $ 40 41 require_once(SGL_MOD_DIR . '/captcha/classes/php-captcha.inc.php'); 42 43 /** 44 * This is an interface"" for classes and captcha generation module 45 * all (currently both) functions should be able to be called statically 46 * 47 * This first implementation uses LGPL solution: http://www.ejeliot.com/pages/2 48 * 49 * @package captcha 50 * @author matti@nettirasia.com 51 * @todo add voice captcha 52 */ 53 class Captcha 54 { 55 56 function printTextCaptcha() 57 { 58 $aFonts = array( 59 SGL_MOD_DIR . '/captcha/fonts/VeraSeBd.ttf', 60 SGL_MOD_DIR . '/captcha/fonts/VeraIt.ttf', 61 SGL_MOD_DIR . '/captcha/fonts/Vera.ttf' 62 ); 63 $oVisualCaptcha = new PhpCaptcha($aFonts, 200, 60); 64 $oVisualCaptcha->Create(); 65 } 66 67 68 function validateKey($key) 69 { 70 return PhpCaptcha::Validate($key); 71 } 72 73 74 } 75 ?> -
modules/captcha/templates/empty.html
old new
