Changeset 19570 for plugins/sfCryptoCaptchaPlugin
- Timestamp:
- 06/26/09 01:34:44 (4 years ago)
- Files:
-
- plugins/sfCryptoCaptchaPlugin/trunk/README (modified) (4 diffs)
- plugins/sfCryptoCaptchaPlugin/trunk/config/app.yml (modified) (3 diffs)
- plugins/sfCryptoCaptchaPlugin/trunk/lib/helper/sfCryptoCaptchaHelper.php (modified) (1 diff)
- plugins/sfCryptoCaptchaPlugin/trunk/lib/sfCryptoCaptcha.class.php (modified) (8 diffs)
- plugins/sfCryptoCaptchaPlugin/trunk/package.xml (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfCryptoCaptchaPlugin/trunk/README
r19563 r19570 119 119 $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); 120 120 121 ## Configuration details 122 123 Here are some useful configuration details 124 125 The bg_img options can have many values: 126 127 1. it can be a boolean (disable background image) 128 2. it can be a image name (path from the symfony root) 129 3. or it can be a file name (an image will be randomly chosen in the file) 130 131 Here's how it looks in the configuration app.yml file 132 133 [yaml] 134 --- 135 bg_img: false #1 136 bg_img: '/plugins/sfCryptoCaptchaPlugin/media/bg/leaf_bg.png' #2 137 bg_img: '/plugins/sfCryptoCaptchaPlugin/media/bg' #3 138 139 When setting the letters for the captcha, be careful to exclude characters that look alike, 140 for example: `o` and `0` or `B` and `8` (when there is noise and funky fonts, there symbols quickly look alike). 141 142 ``You want to make it difficult for robots but not for your users.`` 143 144 For configurations needing paths (backgrounds, refresh button, fonts) 145 146 * Be careful, the path to the refresh image must be from the __web__ root and not the symfony root dir. 147 * On the contrary, the path to the background images and the fonts is relative to the symfony root and the options need to start by a '/' 148 149 The error messages are internationalized if the i18n is turned on for symfony. 150 The images displayed will be in the `/plugins/sfCryptoCaptchaPlugin/media/error/%SF_CULTURE%/...` 151 directory and the extension used will be the same as the configured `format`. If there is no i18n 152 active, the three images will be taken from the `/plugins/sfCryptoCaptchaPlugin/media/error/` directory. 153 154 The three needed images are: 155 156 * `unknown.xxx` For unknown errors 157 * `too_many.xxx` For too many requests per session (maximum 1000 requests per session) 158 * `refresh.xxx` For too fast refreshes 159 160 Each one of there images __must__ be present in each culture folder or in the main error folder. 161 By default, a french and english version is provided. You can add as many languages and needed and customize the error images in any graphic editor(Gimp, Photoshop ...) as long as it is in jpeg, png or gif format. 121 162 122 163 ## Dependencies … … 134 175 135 176 * The pear install seems to malfunction :( 136 * The fonts directory is under the web directory so if you know the font name, you can download it (not very good)137 177 * The functionality to reuse a captcha (by saving it in clear in the user session) has been removed from the original library, it could be nice to code it back in and add an option to activate that feature - still, this is a less secure method than making a new captcha everytime. 138 * The display of the error messages "refreshing too fast" is not localized and is cut if the catpcha is too small.139 178 140 179 ## Troubleshooting … … 147 186 * you have executed the `plugin:publish-assets` command (under Windows, you may have to manually copy the sfCryptoCaptchaPlugin/web to the web/ directory) 148 187 * the fonts directory is properly configured (in the `app.yml` file) 149 * the web/sfCryptoCaptchaPlugin/fonts direcotry and sub-directories have the proper permissions188 * the SF_ROOT/plugins/sfCryptoCaptchaPlugin/fonts directory and sub-directories have the proper permissions 150 189 * all the permissions of the plugin are correct 151 190 * if there is still no image, check that the image is correctly destroyed in the sfCryptoCaptcha class with `imagedestroy($this->image);` line 220 … … 154 193 * the final paths are correct (/captcha for the image and /sfCryptoCaptchaPlugin/images/refresh.png for the refresh image) 155 194 * there is no conflict in the url (/captcha not used by some other plugin or module of the same name) 156 * there is no special :format applied in the URL (the helper does not (yet) handle extensions/formats[like .html, .php etc.]) 157 * after checking all this, if it still doesn't work, you'll have to check everything directly in the source of the plugin. If you notice a glitch or a bug, please contact-me [henearkrxern [at] hotmail.fr] and I'll update the script. Thanks :) 195 * after checking all this, if it still doesn't work, you'll have to check everything directly in the source of the plugin. If you need help or you notice a glitch or a bug, please contact-me [henearkrxern [at] hotmail.fr] and I'll update the script. Thanks :) 158 196 159 197 If your captcha does not display correctly: 160 198 161 * If all the characters are not in the image , play with the character size settings(char_min_size and char_max_size) and the character spacing (char_px_spacing) and/or with the image size.199 * If all the characters are not in the image (overflow), play with the character size settings(char_min_size and char_max_size) and the character spacing (char_px_spacing) and/or with the image size. 162 200 * Play with some options and see what you come up with, hopefully, you should find where the problem is coming from. 201 * You have enabled the background image but your background is black: check that the path is correct and that it starts with a "/". 202 * If there is an error with the font (usually there will be no image - but in case you run out of problem-ideas, check the path to the font files and that it starts with a "/". 163 203 164 204 ## Copyright plugins/sfCryptoCaptchaPlugin/trunk/config/app.yml
r19564 r19570 10 10 bg_blue: 255 #quantity of blue color (0->255) 11 11 bg_transparent: false #transparent background - only works for PNG images 12 bg_img: false # image or file (randomly choses an image in the file) [can be false, image or file path]12 bg_img: false # boolean or image or file (randomly choses an image in the file) [path from sf root] 13 13 bg_border: true #add a border or not 14 #Paths15 img_dir: '/sfCryptoCaptchaPlugin/images' #directory of the images in the web directory16 14 #Characters 17 15 char_red: 0 # quantity of red color (0->255) … … 27 25 char_vertical_offset: true # add a random vertical offset to letters 28 26 #Fonts 29 char_fonts: [luggerbu.ttf,SCRAWL.ttf,Alanden_.ttf] # the randomly used fonts to generate the characters30 char_fonts_dir: '/ sfCryptoCaptchaPlugin/fonts/' #directory containing the fonts in the webdirectory27 char_fonts: [luggerbu.ttf,SCRAWL.ttf,Alanden_.ttf] # the randomly used fonts to generate the characters 28 char_fonts_dir: '/plugins/sfCryptoCaptchaPlugin/media/fonts/' # directory containing the fonts in the symfony root directory 31 29 error_font: 'arial.ttf' # font used for error messages 32 30 #Authorized characters … … 58 56 noise_color: 3 # noise color to use (1=character color, 2= background color, 3= random color) 59 57 noise_on_top: false # if noise is the top layer (above the caracters) 58 #Refresh 59 refresh_image: '/sfCryptoCaptchaPlugin/images/reload_original.png' # use an other captcha reload image - must be in the web directory 60 error_images_dir: '/plugins/sfCryptoCaptchaPlugin/media/error/' # the path to the directory where the error images are - from the symfony root dir 61 62 plugins/sfCryptoCaptchaPlugin/trunk/lib/helper/sfCryptoCaptchaHelper.php
r17114 r19570 9 9 function captcha_reload_button() 10 10 { 11 $reload_img = sfConfig::get('sf_web_dir'.'/sfCryptoCaptchaPlugin/images/reload.png', '/sfCryptoCaptchaPlugin/images/reload.png'); 12 $refresh_url = url_for('sfCryptoCaptcha/captcha'); 13 $onclick = 'javascript:document.getElementById(\'captcha_img\').src=\''.$refresh_url.'/\'+Math.round(Math.random(0)*1000)+1'; 14 $ret = '<a style="cursor:pointer" onclick="'.$onclick.'">'.image_tag($reload_img).'</a>'; 11 //get the refresh image 12 $refresh_image = sfConfig::get('app_sf_crypto_captcha_refresh_image', '/sfCryptoCaptchaPlugin/images/reload_original.png'); 13 14 //extract the suffix if there is one 15 $delimiter= '_-cutter'.rand(1000,9999).'-_'; 16 $refresh_url = url_for('@captcha_refresh?random='.$delimiter); 17 $delimiter_position = strpos($refresh_url,$delimiter); 18 $delimiter_length = strlen($delimiter); 19 20 $length_normal_url = $delimiter_position - 1; 21 $suffix_offset = $delimiter_position + $delimiter_length; 22 $suffix_length = strlen($refresh_url) - $suffix_offset; 23 //cut the url in pieces 24 $normal_url = substr($refresh_url, 0, $length_normal_url); 25 $suffix = substr($refresh_url, $suffix_offset, $delimiter_length); 26 27 $onclick = 'javascript:document.getElementById(\'captcha_img\').src=\''.$normal_url.'/\'+Math.round(Math.random(0)*1000)+1+\''.$suffix.'\''; 28 $ret = '<a style="cursor:pointer" onclick="'.$onclick.'">'.image_tag($refresh_image).'</a>'; 15 29 return $ret; 16 30 } plugins/sfCryptoCaptchaPlugin/trunk/lib/sfCryptoCaptcha.class.php
r19564 r19570 59 59 if(!$this->testQueries()) { 60 60 $this->config['constructor_error_reason'] = 'Error - too many queries'; 61 $this->config['constructor_error_message'] = 'too_many'; 61 62 } 62 63 elseif(!$this->testLastRequest()) 63 64 { 64 65 $this->config['constructor_error_reason'] = 'Error - refreshing too fast'; 66 $this->config['constructor_error_message'] = 'refresh'; 65 67 } 66 68 else 67 69 { 68 70 $this->config['constructor_error_reason'] = 'Error - unknown reason'; 71 $this->config['constructor_error_message'] = 'unknown'; 69 72 } 70 73 return false; … … 149 152 if($this->config['constructor_test']===false) { 150 153 //generate error image 151 if(!$this-> generateErrorImage($this->config['constructor_error_reason']))154 if(!$this->sendErrorImage($this->config['constructor_error_message'])) 152 155 { 153 156 if (sfConfig::get('sf_logging_enabled')) 154 157 { 155 $message = '{seCaptcha}'; 158 $message = '{sfCaptcha}'; 159 $message .= ' - Critical Image Error - '; 160 $message .= 'The ERROR message(['.$this->config['constructor_error_reason'].']) image could not be sent to the user.'; 161 $message .= ' Possible problem with file access/path.'; 162 sfContext::getInstance()->getLogger()->crit($message); 163 } 164 } 165 elseif(!$this->generateErrorImage($this->config['constructor_error_reason'])) 166 { 167 if (sfConfig::get('sf_logging_enabled')) 168 { 169 $message = '{sfCaptcha}'; 156 170 $message .= ' - Critical Image Error - '; 157 171 $message .= 'The ERROR message(['.$this->config['constructor_error_reason'].']) image encoutered an error when sending to user.'; 158 $message .= ' Poss bile problem with GD2 library.';172 $message .= ' Possible problem with GD2 library.'; 159 173 sfContext::getInstance()->getLogger()->crit($message); 160 174 } … … 702 716 if($bg_type == '1') 703 717 { 704 $img_read = imagecreatefromgif($this->c onfig['bg_img']);718 $img_read = imagecreatefromgif($this->captcha['bg_img']); 705 719 } 706 720 elseif($bg_type == '2') 707 721 { 708 $img_read = imagecreatefromjpeg($this->c onfig['bg_img']);722 $img_read = imagecreatefromjpeg($this->captcha['bg_img']); 709 723 } 710 724 elseif($bg_type == '3') 711 725 { 712 $img_read = imagecreatefrompng($this->c onfig['bg_img']);726 $img_read = imagecreatefrompng($this->captcha['bg_img']); 713 727 } 714 728 else … … 1117 1131 } 1118 1132 1133 private function sendErrorImage($error_message) 1134 { 1135 // 1) read the image depending on the sf_user culture 1136 // 2) send it to the browser 1137 1138 //get culture 1139 $culture = $this->sf_user->getCulture(); 1140 1141 //set image path 1142 if($this->config['use_i18n'] == true) 1143 { 1144 $image_path = $this->config['error_images_dir'].DIRECTORY_SEPARATOR.$culture.DIRECTORY_SEPARATOR.$error_message.'.'.$this->config['format']; 1145 } 1146 else 1147 { 1148 $image_path = $this->config['error_images_dir'].DIRECTORY_SEPARATOR.$error_message.'.'.$this->config['format']; 1149 } 1150 //send the finished image in JPG, GIF or PNG format 1151 if(strtoupper($this->config['format']) == 'JPG' || strtoupper($this->config['format']) == 'JPEG') 1152 { 1153 header("Content-type: image/jpeg"); 1154 readfile($image_path); 1155 exit; 1156 } 1157 1158 if(strtoupper($this->config['format']) == 'GIF') 1159 { 1160 header("Content-type: image/gif"); 1161 readfile($image_path); 1162 exit; 1163 } 1164 1165 if(strtoupper($this->config['format']) == 'PNG') 1166 { 1167 header("Content-type: image/png"); 1168 readfile($image_path); 1169 exit; 1170 } 1171 1172 return true; 1173 } 1174 1175 1119 1176 /** 1120 1177 * Captcha configuration getter from the app.yml … … 1127 1184 private function getConfiguration() 1128 1185 { 1186 $root_dir = sfConfig::get('sf_root_dir'); 1129 1187 $web_dir = sfConfig::get('sf_web_dir'); 1130 1188 //Setting image size … … 1137 1195 $this->config['bg_blue'] = sfConfig::get('app_sf_crypto_captcha_bg_blue', 255); // quantity of blue (0->255) 1138 1196 $this->config['bg_transparent'] = sfConfig::get('app_sf_crypto_captcha_bg_transparent', false); // transparent backround, only for PNG 1139 $this->config['bg_img'] = sfConfig::get('app_sf_crypto_captcha_bg_img', false); // boolean or image or file path. 1140 //If a file path is specified, an image is randomly chosen in the file 1141 if($this->config['bg_img'] != false) { $this->config['bg_img'] = $web_dir.$this->config['bg_img']; } 1197 $this->config['bg_img'] = sfConfig::get('app_sf_crypto_captcha_bg_img', false); // boolean(false) or image(path) or file (random image from file path) 1198 if($this->config['bg_img'] != false) { $this->config['bg_img'] = $root_dir.$this->config['bg_img']; } //The background image file must be a path from the symfony root dir 1142 1199 1143 1200 $this->config['bg_border'] = sfConfig::get('app_sf_crypto_captcha_bg_border', true); //border or not 1144 1145 $this->config['img_dir'] = sfConfig::get('app_sf_crypto_captcha_img_dir', '/sfCryptoCaptchaPlugin/images/'); // directory of images1146 $this->config['img_dir'] = $web_dir.$this->config['img_dir'];1147 1201 1148 1202 //Setting characters … … 1161 1215 //Setting fonts 1162 1216 $this->config['char_fonts'] = sfConfig::get('app_sf_crypto_captcha_char_fonts', array('luggerbu.ttf')); // the fonts used randomly to generate the characters 1163 $this->config['char_fonts_dir'] = sfConfig::get('app_sf_crypto_captcha_char_fonts_dir', '/ sfCryptoCaptchaPlugin/fonts/'); // directory with the fonts1164 $this->config['char_fonts_dir'] = $ web_dir.$this->config['char_fonts_dir'];1217 $this->config['char_fonts_dir'] = sfConfig::get('app_sf_crypto_captcha_char_fonts_dir', '/plugins/sfCryptoCaptchaPlugin/media/fonts/'); // directory with the fonts 1218 $this->config['char_fonts_dir'] = $root_dir.$this->config['char_fonts_dir']; 1165 1219 $this->config['error_font'] = sfConfig::get('app_sf_crypto_captcha_error_font', 'arial.ttf'); 1166 1220 … … 1200 1254 $this->config['noise_on_top'] = sfConfig::get('app_sf_crypto_captcha_noise_on_top', false); // the noise is on the top layer 1201 1255 1256 //error config 1257 $this->config['use_i18n'] = sfConfig::get('sf_i18n', false); 1258 $this->config['error_images_dir'] = sfConfig::get('app_sf_crypto_captcha_error_images_dir', '/plugins/sfCryptoCaptchaPlugin/media/error/'); //the dir where the images are - from symfony root dir 1259 $this->config['error_images_dir'] = $root_dir.$this->config['error_images_dir']; 1260 1202 1261 return true; 1203 1262 } plugins/sfCryptoCaptchaPlugin/trunk/package.xml
r19565 r19570 11 11 <active>yes</active> 12 12 </lead> 13 <date>2009-06-2 5</date>14 <time> 20:26:27</time>13 <date>2009-06-26</date> 14 <time>01:29:36</time> 15 15 <version> 16 <release>0.0. 5</release>17 <api>0.0. 5</api>16 <release>0.0.6</release> 17 <api>0.0.6</api> 18 18 </version> 19 19 <stability> … … 50 50 </dir> 51 51 </dir> 52 <dir name=" web">53 <dir name="fonts">52 <dir name="media"> 53 <dir name="fonts"> 54 54 <file role="data" name="Alanden_.ttf" /> 55 55 <file role="data" name="arial.ttf" /> … … 61 61 <file role="data" name="WAVY.ttf" /> 62 62 </dir> 63 <dir name="bg"> 64 <file role="data" name="beige_marble.jpg" /> 65 <file role="data" name="leaf_bg.jpg" /> 66 <file role="data" name="metal_bg.jpg" /> 67 <file role="data" name="styrofoam.jpg" /> 68 </dir> 69 <dir name="error"> 70 <file role="data" name="refresh.png" /> 71 <file role="data" name="too_many.png" /> 72 <file role="data" name="unknown.png" /> 73 <dir name="en"> 74 <file role="data" name="refresh.png" /> 75 <file role="data" name="too_many.png" /> 76 <file role="data" name="unknown.png" /> 77 </dir> 78 <dir name="fr"> 79 <file role="data" name="refresh.png" /> 80 <file role="data" name="too_many.png" /> 81 <file role="data" name="unknown.png" /> 82 </dir> 83 </dir> 84 </dir> 85 <dir name="web"> 63 86 <dir name="images"> 64 <file role="data" name="reload.png" /> 65 <dir name="bg"> 66 <file role="data" name="clear.gif" /> 67 </dir> 87 <file role="data" name="refresh_blue_big.png" /> 88 <file role="data" name="refresh_green_cw_small.png" /> 89 <file role="data" name="refresh_blue_ccw_small.png" /> 90 <file role="data" name="reload_blue_medium.png" /> 91 <file role="data" name="refresh_blue_cw_medium.png" /> 92 <file role="data" name="reload_blue_small.gif" /> 93 <file role="data" name="refresh_blue_medium.png" /> 94 <file role="data" name="reload_dark_green_small.gif" /> 95 <file role="data" name="refresh_clear_blue_medium.png" /> 96 <file role="data" name="reload_green_small.gif" /> 97 <file role="data" name="refresh_clear_blue_small.png" /> 98 <file role="data" name="reload_green_small.png" /> 99 <file role="data" name="refresh_dark_blue_big.png" /> 100 <file role="data" name="reload_original.png" /> 101 <file role="data" name="refresh_green_ccw_small.png" /> 102 <file role="data" name="web_refresh_green_big.png" /> 103 <file role="data" name="refresh_green_cw_small.gif" /> 68 104 </dir> 69 105 </dir> … … 90 126 <release> 91 127 <version> 128 <release>0.0.6</release> 129 <api>0.0.6</api> 130 </version> 131 <stability> 132 <release>beta</release> 133 <api>beta</api> 134 </stability> 135 <license uri="http://www.symfony-project.com/license">MIT license</license> 136 <license>MIT</license> 137 <date>2009-06-25</date> 138 <notes> 139 * henearkrxern: reorganisation of the plugin (media directory, fonts, backgrounds) 140 * henearkrxern: fonts dir specified from the symfony root and not the web dir and moved 141 * henearkrxern: added support for url suffixes (.php, .html, ...) 142 * henearkrxern: added free and/or GPL icons for the refresh button (check out the plugin web/images folder) 143 * henearkrxern: added some organic backgrounds 144 * henearkrxern: errors are now pre-generated graphics that can be internationalized 145 </notes> 146 </release> 147 <release> 148 <version> 92 149 <release>0.0.5</release> 93 150 <api>0.0.5</api>