diff --git a/etemplate/inc/class.ajax_captcha_widget.inc.php b/etemplate/inc/class.ajax_captcha_widget.inc.php new file mode 100644 index 0000000000..732f071baa --- /dev/null +++ b/etemplate/inc/class.ajax_captcha_widget.inc.php @@ -0,0 +1,1125 @@ + + * are generated as well*/ +class ajax_captcha_widget +{ + var $public_functions = array( + 'pre_process' => True, + 'post_process' => True, + 'show_image' => True, + 'play_sound' => True, + ); + var $human_name = 'Captcha'; // this is the name for the editor + + private $debug = false; + + function ajax_captcha_widget($ui='') + { + + $this->img = new securimage(); + switch($ui) + { + case '': + case 'html': + $this->ui = 'html'; + break; + default: + echo "UI='$ui' not implemented"; + } + return 0; + } + + /** + * pre-processing of the extension + * + * This function is called before the extension gets rendered + * + * @param string $name form-name of the control + * @param mixed &$value value / existing content, can be modified + * @param array &$cell array with the widget, can be modified for ui-independent widgets + * @param array &$readonlys names of widgets as key, to be made readonly + * @param mixed &$extension_data data the extension can store persisten between pre- and post-process + * @param object &$tmpl reference to the template we belong too + * @return boolean true if extra label is allowed, false otherwise + */ + function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl) + { + + //sets main etemplate cell with data created in etemplate.captcha_widget + $cell['type'] = 'template'; + $cell['size'] = $cell['name']; + $widget =& new etemplate('etemplate.captcha_widget'); + $widget->no_onclick = True; + $cell['obj'] = &$widget; + + $refresh_image_wig =& $widget->get_widget_by_name('etemplate/refresh.gif'); + $refresh_image_wig['size'] = 'etemplate.captcha_widget.show_image'; + $refresh_image_wig['onclick']=' + document.getElementById(\'show_image\').src = \''.$GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=etemplate.ajax_captcha_widget.show_image&sid=\' + Math.random(); return false;'; + + $value = array('captcha'=>'','captcha_code'=>''); + + //set needed onload for refresh JS + $GLOBALS['egw']->js->set_onload('"document.getElementById(\'show_image\').src = \''.$GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=etemplate.ajax_captcha_widget.show_image&sid=\' + Math.random(); return false"' + ); + + // sets audio icon link properties + $audio_image_wig =& $widget->get_widget_by_name('etemplate/audio_icon.gif'); + $audio_image_wig['size'] = 'etemplate.ajax_captcha_widget.play_sound'; + + // sects code text field to be needed + $code_text_wig =& $widget->get_widget_by_name('captcha_code'); + //$code_text_wig['name']=$name; + $code_text_wig['needed'] = 1; + + return True; // no extra label + } + + /** + * postprocessing method, called after the submission of the form + * + * It has to copy the allowed/valid data from $value_in to $value, otherwise the widget + * will return no data (if it has a preprocessing method). The framework insures that + * the post-processing of all contained widget has been done before. + * + * Only used by select-dow so far + * + * @param string $name form-name of the widget + * @param mixed &$value the extension returns here it's input, if there's any + * @param mixed &$extension_data persistent storage between calls or pre- and post-process + * @param boolean &$loop can be set to true to request a re-submision of the form/dialog + * @param object &$tmpl the eTemplate the widget belongs too + * @param mixed &value_in the posted values (already striped of magic-quotes) + * @return boolean true if $value has valid content, on false no content will be returned! + */ + function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in) + { + // sends user back to form if no code entered + if ($value_in[captcha_code]=='' || !isset($value_in[captcha_code])) + { + $loop=TRUE; + return false; + } + // sends uder back to form with err msg if wrong code + if ($this->img->getCode() != $value_in[captcha_code]) + { + + $tmpl->set_validation_error('captcha',lang(" Your code is incorrect !!!")); + $loop=TRUE; + return false; + } + + }//post process + + + /** + * Public function to return a new image and set the code in the sessions var from within the class + * + * @return new image + */ + function show_image() { + + return $this->img->show(); + } + + + /** + * Return new wav file + * @return new wav file + */ + function play_sound() { + + header('Content-type: audio/x-wav'); + header('Content-Disposition: attachment; name="securimage.wav"'); + echo $this->img->getAudibleCode(); + } + +}//widget + +/** + * Project: Securimage: A PHP class for creating and managing form CAPTCHA images
+ * File: securimage.php
+ * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or any later version.

+ * + * This library 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 + * Lesser General Public License for more details.

+ * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

+ * + * Any modifications to the library should be indicated clearly in the source code + * to inform users that the changes are not a part of the original software.

+ * + * If you found this script useful, please take a quick moment to rate it.
+ * http://www.hotscripts.com/rate/49400.html Thanks. + * + * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA + * @link http://www.phpcaptcha.org/latest.zip Download Latest Version + * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation + * @copyright 2007 Drew Phillips + * @author drew010 + * @version 1.0.3.1 (March 24, 2008) + * @package Securimage + * + */ + +/** + ChangeLog + + 1.0.3.1 + - Error reading from wordlist in some cases caused words to be cut off 1 letter short + + 1.0.3 + - Removed shadow_text from code which could cause an undefined property error due to removal from previous version + + 1.0.2 + - Audible CAPTCHA Code wav files + - Create codes from a word list instead of random strings + + 1.0 + - Added the ability to use a selected character set, rather than a-z0-9 only. + - Added the multi-color text option to use different colors for each letter. + - Switched to automatic session handling instead of using files for code storage + - Added GD Font support if ttf support is not available. Can use internal GD fonts or load new ones. + - Added the ability to set line thickness + - Added option for drawing arced lines over letters + - Added ability to choose image type for output + +*/ + +/** + * Output images in JPEG format + */ +define('SI_IMAGE_JPEG', 1); +/** + * Output images in PNG format + */ +define('SI_IMAGE_PNG', 2); +/** + * Output images in GIF format + * Must have GD >= 2.0.28! + */ +define('SI_IMAGE_GIF', 3); + +/** + * Securimage CAPTCHA Class. + * + * @package Securimage + * @subpackage classes + * + */ +class Securimage { + + /** + * The desired width of the CAPTCHA image. + * + * @var int + */ + var $image_width = 175; + + /** + * The desired width of the CAPTCHA image. + * + * @var int + */ + var $image_height = 45; + + /** + * The image format for output.
+ * Valid options: SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF + * + * @var int + */ + var $image_type = SI_IMAGE_PNG; + + /** + * The length of the code to generate. + * + * @var int + */ + var $code_length = 4; + + /** + * The character set for individual characters in the image.
+ * Letters are converted to uppercase.
+ * The font must support the letters or there may be problematic substitutions. + * + * @var string + */ + var $charset = 'ABCDEFGHKLMNPRSTUVWYZ23456789'; + //var $charset = '0123456789'; + + /** + * Create codes using this word list + * + * @var string The path to the word list to use for creating CAPTCHA codes + */ + var $wordlist_file = '/etemplate/templates/default/words/words.txt'; + + /** + * True to use a word list file instead of a random code + * + * @var bool + */ + var $use_wordlist = true; + + /** + * Whether to use a GD font instead of a TTF font.
+ * TTF offers more support and options, but use this if your PHP doesn't support TTF.
+ * + * @var boolean + */ + var $use_gd_font = true; + + /** + * The GD font to use.
+ * Internal gd fonts can be loaded by their number.
+ * Alternatively, a file path can be given and the font will be loaded from file. + * + * @var mixed + */ + var $gd_font_file = '/etemplate/templates/default/gdfonts/automatic.gdf'; + + /** + * The approximate size of the font in pixels.
+ * This does not control the size of the font because that is determined by the GD font itself.
+ * This is used to aid the calculations of positioning used by this class.
+ * + * @var int + */ + var $gd_font_size = 20; + + // Note: These font options below do not apply if you set $use_gd_font to true with the exception of $text_color + + /** + * The path to the TTF font file to load. + * + * @var string + */ + var $ttf_file = "./elephant.ttf"; + + /** + * The font size.
+ * Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2)
+ * + * @var int + */ + var $font_size = 24; + + /** + * The minimum angle in degrees, with 0 degrees being left-to-right reading text.
+ * Higher values represent a counter-clockwise rotation.
+ * For example, a value of 90 would result in bottom-to-top reading text. + * + * @var int + */ + var $text_angle_minimum = -20; + + /** + * The minimum angle in degrees, with 0 degrees being left-to-right reading text.
+ * Higher values represent a counter-clockwise rotation.
+ * For example, a value of 90 would result in bottom-to-top reading text. + * + * @var int + */ + var $text_angle_maximum = 20; + + /** + * The X-Position on the image where letter drawing will begin.
+ * This value is in pixels from the left side of the image. + * + * @var int + */ + var $text_x_start = 8; + + /** + * Letters can be spaced apart at random distances.
+ * This is the minimum distance between two letters.
+ * This should be at least as wide as a font character.
+ * Small values can cause letters to be drawn over eachother.
+ * + * @var int + */ + var $text_minimum_distance = 30; + + /** + * Letters can be spaced apart at random distances.
+ * This is the maximum distance between two letters.
+ * This should be at least as wide as a font character.
+ * Small values can cause letters to be drawn over eachother.
+ * + * @var int + */ + var $text_maximum_distance = 33; + + /** + * The background color for the image.
+ * This should be specified in HTML hex format.
+ * Make sure to include the preceding # sign! + * + * @var string + */ + var $image_bg_color = "#e3daed"; + + /** + * The text color to use for drawing characters.
+ * This value is ignored if $use_multi_text is set to true.
+ * Make sure this contrasts well with the background color.
+ * Specify the color in HTML hex format with preceding # sign + * + * @see Securimage::$use_multi_text + * @var string + */ + var $text_color = "#ff0000"; + + /** + * Set to true to use multiple colors for each character. + * + * @see Securimage::$multi_text_color + * @var boolean + */ + var $use_multi_text = true; + + /** + * String of HTML hex colors to use.
+ * Separate each possible color with commas.
+ * Be sure to precede each value with the # sign. + * + * @var string + */ + var $multi_text_color = "#0a68dd,#f65c47,#8d32fd"; + + /** + * Set to true to make the characters appear transparent. + * + * @see Securimage::$text_transparency_percentage + * @var boolean + */ + var $use_transparent_text = true; + + /** + * The percentage of transparency, 0 to 100.
+ * A value of 0 is completely opaque, 100 is completely transparent (invisble) + * + * @see Securimage::$use_transparent_text + * @var int + */ + var $text_transparency_percentage = 15; + + + // Line options + + /** + * Draw vertical and horizontal lines on the image. + * + * @see Securimage::$line_color + * @see Securimage::$line_distance + * @see Securimage::$line_thickness + * @see Securimage::$draw_lines_over_text + * @var boolean + */ + var $draw_lines = true; + + /** + * The color of the lines drawn on the image.
+ * Use HTML hex format with preceding # sign. + * + * @see Securimage::$draw_lines + * @var string + */ + var $line_color = "#80BFFF"; + + /** + * How far apart to space the lines from eachother in pixels. + * + * @see Securimage::$draw_lines + * @var int + */ + var $line_distance = 5; + + /** + * How thick to draw the lines in pixels.
+ * 1-3 is ideal depending on distance + * + * @see Securimage::$draw_lines + * @see Securimage::$line_distance + * @var int + */ + var $line_thickness = 1; + + /** + * Set to true to draw angled lines on the image in addition to the horizontal and vertical lines. + * + * @see Securimage::$draw_lines + * @var boolean + */ + var $draw_angled_lines = false; + + /** + * Draw the lines over the text.
+ * If fales lines will be drawn before putting the text on the image.
+ * This can make the image hard for humans to read depending on the line thickness and distance. + * + * @var boolean + */ + var $draw_lines_over_text = false; + + /** + * For added security, it is a good idea to draw arced lines over the letters to make it harder for bots to segment the letters.
+ * Two arced lines will be drawn over the text on each side of the image.
+ * This is currently expirimental and may be off in certain configurations. + * + * @var boolean + */ + var $arc_linethrough = true; + + /** + * The colors or color of the arced lines.
+ * Use HTML hex notation with preceding # sign, and separate each value with a comma.
+ * This should be similar to your font color for single color images. + * + * @var string + */ + var $arc_line_colors = "#8080ff"; + + /** + * Full path to the WAV files to use to make the audio files, include trailing /.
+ * Name Files [A-Z0-9].wav + * + * @since 1.0.1 + * @var string + */ + var $audio_path = './audio/'; + + + //END USER CONFIGURATION + //There should be no need to edit below unless you really know what you are doing. + + /** + * The gd image resource. + * + * @access private + * @var resource + */ + var $im; + + /** + * The background image resource + * + * @access private + * @var resource + */ + var $bgimg; + + /** + * The code generated by the script + * + * @access private + * @var string + */ + var $code; + + /** + * The code that was entered by the user + * + * @access private + * @var string + */ + var $code_entered; + + /** + * Whether or not the correct code was entered + * + * @access private + * @var boolean + */ + var $correct_code; + + /** + * Class constructor.
+ * Because the class uses sessions, this will attempt to start a session if there is no previous one.
+ * If you do not start a session before calling the class, the constructor must be called before any + * output is sent to the browser. + * + * + * $securimage = new Securimage(); + * + * + */ + function Securimage() + { + $this->gd_font_file =EGW_SERVER_ROOT.'/etemplate/templates/default/gdfonts/automatic.gdf'; + $this->audio_path=EGW_SERVER_ROOT.'/etemplate/templates/default/audio/'; + $this->wordlist_file=EGW_SERVER_ROOT. '/etemplate/templates/default/words/words.txt'; + + + 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(); +//print_r(get_defined_constants());die(); +//print_r($this->code.'dddd');die(); + $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.
+ * This is appropriate for output to the browser as audio/x-wav + * + * @since 1.0.1 + * @return string WAV data + * + */ + function getAudibleCode() + { + $letters = array(); + $code = $this->getCode(); +//print_r($code );die(); + if ($code == '') { + $this->createCode(); + $code = $this->getCode(); + } + + for($i = 0; $i < strlen($code); ++$i) { + $letters[] = $code{$i}; + } + + return $this->generateWAV($letters); + } + + /** + * Save the code in the session + * + * @access private + * + */ + function saveData() + { + $_SESSION['securimage_code_value'] = strtolower($this->code); + } + + /** + * Validate the code to the user code + * + * @access private + * + */ + function validate() + { + if ( isset($_SESSION['securimage_code_value']) && !empty($_SESSION['securimage_code_value']) ) { + if ( $_SESSION['securimage_code_value'] == strtolower(trim($this->code_entered)) ) { + $this->correct_code = true; + $_SESSION['securimage_code_value'] = ''; + } else { + $this->correct_code = false; + } + } else { + $this->correct_code = false; + } + } + + /** + * Get the captcha code + * + * @since 1.0.1 + * @return string + */ + function getCode() + { + if (isset($_SESSION['securimage_code_value']) && !empty($_SESSION['securimage_code_value'])) { + return $_SESSION['securimage_code_value']; + } else { + return ''; + } + } + + /** + * Check if the user entered code was correct + * + * @access private + * @return boolean + */ + function checkCode() + { + return $this->correct_code; + } + + /** + * Generate a wav file by concatenating individual files + * @since 1.0.1 + * @access private + * @param array $letters Array of letters to build a file from + * @return string WAV file data + */ + function generateWAV($letters) + { + + $fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format', + 'H8Subchunk1ID', 'VSubchunk1Size', + 'vAudioFormat', 'vNumChannels', 'VSampleRate', + 'VByteRate', 'vBlockAlign', 'vBitsPerSample' )); + $data = ''; +$count=0; + foreach($letters as $letter){ + + //print($count); + //if($count!=4){$count++;continue;} + $fname=$this->audio_path . strtoupper($letter) . '.wav'; + $fp = fopen($fname,'rb'); + $header = fread($fp,36); + $info = unpack($fields,$header); +//print_r($info); + // read optional extra stuff + if($info['Subchunk1Size'] > 16){ + $header .= fread($fp,($info['Subchunk1Size']-16)); + } + // read SubChunk2ID + $header .= fread($fp,4); + // read Subchunk2Size + $sizeArray = unpack('Vsize',fread($fp, 4)); + $size += $sizeArray['size']; +//print('print:'.$size.'
'); + // read data + $data .= fread($fp,$sizeArray['size']); +//print($count); + +//print_r($size.'
'); + fclose($fp); + } + return $header.pack('V',$size).$data;// +} + /* $first = true; // use first file to write the header... + $data_len = 0; + $files = array(); + $out_data = ''; + + foreach ($letters as $letter) { + $filename = $this->audio_path . strtoupper($letter) . '.wav'; +//print($filename.'
'); + $fp = fopen($filename, 'rb'); + + $file = array(); + + $data = fread($fp, filesize($filename)); // read file in +//print($data.'
'); + $header = substr($data, 0, 36); + $body = substr($data, 44); + + + $data = unpack('NChunkID/VChunkSize/NFormat/NSubChunk1ID/VSubChunk1Size/vAudioFormat/vNumChannels/VSampleRate/VByteRate/vBlockAlign/vBitsPerSample', $header); + + $file['sub_chunk1_id'] = $data['SubChunk1ID']; + $file['bits_per_sample'] = $data['BitsPerSample']; + $file['channels'] = $data['NumChannels']; + $file['format'] = $data['AudioFormat']; + $file['sample_rate'] = $data['SampleRate']; + $file['size'] = $data['ChunkSize'] + 8; + $file['data'] = $body; + +// if ( ($p = strpos($file['data'], 'LIST')) !== false) { +// // If the LIST data is not at the end of the file, this will probably break your sound file +// $info = substr($file['data'], $p + 4, 8); +// $data = unpack('Vlength/Vjunk', $info); +// $file['data'] = substr($file['data'], 0, $p); +// $file['size'] = $file['size'] - (strlen($file['data']) - $p); +// } + + $files[] = $file; + $data = null; + $header = null; + $body = null; + + $data_len += strlen($file['data']); + + fclose($fp); + } + $data_len += strlen($file['data']); + $data_len += strlen($file['data']); +//print_r($files); + $out_data = ''; + for($i = 0; $i < sizeof($files); ++$i) { + if ($i == 0) { // output header + $out_data .= pack('C4VC8', ord('R'), ord('I'), ord('F'), ord('F'), $data_len + 36, ord('W'), ord('A'), ord('V'), ord('E'), ord('f'), ord('m'), ord('t'), ord(' ')); + + $out_data .= pack('VvvVVvv', + 16, + $files[$i]['format'], + $files[$i]['channels'], + $files[$i]['sample_rate'], + $files[$i]['sample_rate'] * (($files[$i]['bits_per_sample'] * $files[$i]['channels']) / 8), + ($files[$i]['bits_per_sample'] * $files[$i]['channels']) / 8, + $files[$i]['bits_per_sample'] ); + + $out_data .= pack('C4', ord('d'), ord('a'), ord('t'), ord('a')); + + $out_data .= pack('V', $data_len); + } + + $out_data .= $files[$i]['data']; + } +//print_r($out_data);die(); + return $out_data; + }*/ +} /* class Securimage */ diff --git a/etemplate/setup/etemplates.inc.php b/etemplate/setup/etemplates.inc.php index 763474f244..cd2847f747 100644 --- a/etemplate/setup/etemplates.inc.php +++ b/etemplate/setup/etemplates.inc.php @@ -324,3 +324,4 @@ $templ_data[] = array('name' => 'etemplate.vbox.test','template' => '','lang' => $templ_data[] = array('name' => 'etemplate.xslt_widget.test','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:7:{s:4:"type";s:4:"xslt";s:4:"size";s:14:"etemplate.test";s:4:"span";s:5:",test";s:5:"label";s:4:"Test";s:4:"name";s:4:"test";s:8:"readonly";s:1:"1";s:4:"help";s:22:"This is a help message";}}}s:4:"rows";i:1;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1033497079',); +$templ_data[] = array('name' => 'etemplate.captcha_widget','template' => '','lang' => '','group' => '0','version' => '1.7.002','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:4:{i:0;a:3:{s:2:"c1";s:7:",bottom";s:2:"c2";s:4:",top";s:2:"h3";s:10:",!@val_msg";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"image";s:4:"name";s:25:"etemplate/securimage_show";s:4:"size";s:14:",,,,show_image";}s:1:"B";a:2:{s:4:"type";s:5:"image";s:4:"name";s:24:"etemplate/audio_icon.gif";}}i:2;a:2:{s:1:"A";a:4:{s:4:"type";s:4:"text";s:4:"name";s:12:"captcha_code";s:4:"size";s:2:"24";s:6:"needed";s:1:"1";}s:1:"B";a:2:{s:4:"type";s:5:"image";s:4:"name";s:21:"etemplate/refresh.gif";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"name";s:7:"val_msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:3;s:4:"cols";i:2;s:4:"size";s:8:",,0,,0,0";s:7:"options";a:3:{i:4;s:1:"0";i:5;s:1:"0";i:2;s:1:"0";}}}','size' => ',,0,,0,0','style' => '','modified' => '1245517015',); diff --git a/etemplate/templates/default/audio/0.wav b/etemplate/templates/default/audio/0.wav new file mode 100644 index 0000000000..b01b8dd947 Binary files /dev/null and b/etemplate/templates/default/audio/0.wav differ diff --git a/etemplate/templates/default/audio/1.wav b/etemplate/templates/default/audio/1.wav new file mode 100644 index 0000000000..f37f81e758 Binary files /dev/null and b/etemplate/templates/default/audio/1.wav differ diff --git a/etemplate/templates/default/audio/2.wav b/etemplate/templates/default/audio/2.wav new file mode 100644 index 0000000000..66ed235afc Binary files /dev/null and b/etemplate/templates/default/audio/2.wav differ diff --git a/etemplate/templates/default/audio/3.wav b/etemplate/templates/default/audio/3.wav new file mode 100644 index 0000000000..45bb85fa4b Binary files /dev/null and b/etemplate/templates/default/audio/3.wav differ diff --git a/etemplate/templates/default/audio/4.wav b/etemplate/templates/default/audio/4.wav new file mode 100644 index 0000000000..b21bb65230 Binary files /dev/null and b/etemplate/templates/default/audio/4.wav differ diff --git a/etemplate/templates/default/audio/5.wav b/etemplate/templates/default/audio/5.wav new file mode 100644 index 0000000000..b7654b0f10 Binary files /dev/null and b/etemplate/templates/default/audio/5.wav differ diff --git a/etemplate/templates/default/audio/6.wav b/etemplate/templates/default/audio/6.wav new file mode 100644 index 0000000000..a8a23ad762 Binary files /dev/null and b/etemplate/templates/default/audio/6.wav differ diff --git a/etemplate/templates/default/audio/7.wav b/etemplate/templates/default/audio/7.wav new file mode 100644 index 0000000000..f76c22b567 Binary files /dev/null and b/etemplate/templates/default/audio/7.wav differ diff --git a/etemplate/templates/default/audio/8.wav b/etemplate/templates/default/audio/8.wav new file mode 100644 index 0000000000..c356ccafc9 Binary files /dev/null and b/etemplate/templates/default/audio/8.wav differ diff --git a/etemplate/templates/default/audio/9.wav b/etemplate/templates/default/audio/9.wav new file mode 100644 index 0000000000..1d828f1aed Binary files /dev/null and b/etemplate/templates/default/audio/9.wav differ diff --git a/etemplate/templates/default/audio/a.wav b/etemplate/templates/default/audio/a.wav new file mode 100644 index 0000000000..c3dcd8a23c Binary files /dev/null and b/etemplate/templates/default/audio/a.wav differ diff --git a/etemplate/templates/default/audio/b.wav b/etemplate/templates/default/audio/b.wav new file mode 100644 index 0000000000..9f380c286f Binary files /dev/null and b/etemplate/templates/default/audio/b.wav differ diff --git a/etemplate/templates/default/audio/c.wav b/etemplate/templates/default/audio/c.wav new file mode 100644 index 0000000000..a9b81ebb1a Binary files /dev/null and b/etemplate/templates/default/audio/c.wav differ diff --git a/etemplate/templates/default/audio/d.wav b/etemplate/templates/default/audio/d.wav new file mode 100644 index 0000000000..66ee3a1b5e Binary files /dev/null and b/etemplate/templates/default/audio/d.wav differ diff --git a/etemplate/templates/default/audio/e.wav b/etemplate/templates/default/audio/e.wav new file mode 100644 index 0000000000..d8fe4500be Binary files /dev/null and b/etemplate/templates/default/audio/e.wav differ diff --git a/etemplate/templates/default/audio/f.wav b/etemplate/templates/default/audio/f.wav new file mode 100644 index 0000000000..4046176db4 Binary files /dev/null and b/etemplate/templates/default/audio/f.wav differ diff --git a/etemplate/templates/default/audio/g.wav b/etemplate/templates/default/audio/g.wav new file mode 100644 index 0000000000..8700179f3d Binary files /dev/null and b/etemplate/templates/default/audio/g.wav differ diff --git a/etemplate/templates/default/audio/h.wav b/etemplate/templates/default/audio/h.wav new file mode 100644 index 0000000000..2e33c4e80b Binary files /dev/null and b/etemplate/templates/default/audio/h.wav differ diff --git a/etemplate/templates/default/audio/i.wav b/etemplate/templates/default/audio/i.wav new file mode 100644 index 0000000000..cf60cd80ee Binary files /dev/null and b/etemplate/templates/default/audio/i.wav differ diff --git a/etemplate/templates/default/audio/j.wav b/etemplate/templates/default/audio/j.wav new file mode 100644 index 0000000000..5fecfaeb71 Binary files /dev/null and b/etemplate/templates/default/audio/j.wav differ diff --git a/etemplate/templates/default/audio/k.wav b/etemplate/templates/default/audio/k.wav new file mode 100644 index 0000000000..27e1d37cdf Binary files /dev/null and b/etemplate/templates/default/audio/k.wav differ diff --git a/etemplate/templates/default/audio/l.wav b/etemplate/templates/default/audio/l.wav new file mode 100644 index 0000000000..139f7cdd00 Binary files /dev/null and b/etemplate/templates/default/audio/l.wav differ diff --git a/etemplate/templates/default/audio/m.wav b/etemplate/templates/default/audio/m.wav new file mode 100644 index 0000000000..08d5cf5373 Binary files /dev/null and b/etemplate/templates/default/audio/m.wav differ diff --git a/etemplate/templates/default/audio/n.wav b/etemplate/templates/default/audio/n.wav new file mode 100644 index 0000000000..fba69231b9 Binary files /dev/null and b/etemplate/templates/default/audio/n.wav differ diff --git a/etemplate/templates/default/audio/o.wav b/etemplate/templates/default/audio/o.wav new file mode 100644 index 0000000000..e5a3578c59 Binary files /dev/null and b/etemplate/templates/default/audio/o.wav differ diff --git a/etemplate/templates/default/audio/p.wav b/etemplate/templates/default/audio/p.wav new file mode 100644 index 0000000000..3b94c7a33c Binary files /dev/null and b/etemplate/templates/default/audio/p.wav differ diff --git a/etemplate/templates/default/audio/q.wav b/etemplate/templates/default/audio/q.wav new file mode 100644 index 0000000000..c757e54e1c Binary files /dev/null and b/etemplate/templates/default/audio/q.wav differ diff --git a/etemplate/templates/default/audio/r.wav b/etemplate/templates/default/audio/r.wav new file mode 100644 index 0000000000..c2e4b24114 Binary files /dev/null and b/etemplate/templates/default/audio/r.wav differ diff --git a/etemplate/templates/default/audio/s.wav b/etemplate/templates/default/audio/s.wav new file mode 100644 index 0000000000..8edcf8dc4c Binary files /dev/null and b/etemplate/templates/default/audio/s.wav differ diff --git a/etemplate/templates/default/audio/t.wav b/etemplate/templates/default/audio/t.wav new file mode 100644 index 0000000000..e714a4aee6 Binary files /dev/null and b/etemplate/templates/default/audio/t.wav differ diff --git a/etemplate/templates/default/audio/u.wav b/etemplate/templates/default/audio/u.wav new file mode 100644 index 0000000000..f5f35d1cf3 Binary files /dev/null and b/etemplate/templates/default/audio/u.wav differ diff --git a/etemplate/templates/default/audio/v.wav b/etemplate/templates/default/audio/v.wav new file mode 100644 index 0000000000..4234a96062 Binary files /dev/null and b/etemplate/templates/default/audio/v.wav differ diff --git a/etemplate/templates/default/audio/w.wav b/etemplate/templates/default/audio/w.wav new file mode 100644 index 0000000000..f6fba71a13 Binary files /dev/null and b/etemplate/templates/default/audio/w.wav differ diff --git a/etemplate/templates/default/audio/x.wav b/etemplate/templates/default/audio/x.wav new file mode 100644 index 0000000000..a45fd4b874 Binary files /dev/null and b/etemplate/templates/default/audio/x.wav differ diff --git a/etemplate/templates/default/audio/y.wav b/etemplate/templates/default/audio/y.wav new file mode 100644 index 0000000000..921ae5ded2 Binary files /dev/null and b/etemplate/templates/default/audio/y.wav differ diff --git a/etemplate/templates/default/audio/z.wav b/etemplate/templates/default/audio/z.wav new file mode 100644 index 0000000000..1fa83a48dc Binary files /dev/null and b/etemplate/templates/default/audio/z.wav differ diff --git a/etemplate/templates/default/images/audio_icon.gif b/etemplate/templates/default/images/audio_icon.gif new file mode 100644 index 0000000000..beafd51827 Binary files /dev/null and b/etemplate/templates/default/images/audio_icon.gif differ diff --git a/etemplate/templates/default/images/refresh.gif b/etemplate/templates/default/images/refresh.gif new file mode 100644 index 0000000000..a10b24717f Binary files /dev/null and b/etemplate/templates/default/images/refresh.gif differ diff --git a/etemplate/templates/default/words/.htaccess b/etemplate/templates/default/words/.htaccess new file mode 100644 index 0000000000..fa6ce3fd4e --- /dev/null +++ b/etemplate/templates/default/words/.htaccess @@ -0,0 +1 @@ +deny from all diff --git a/etemplate/templates/default/words/words.txt b/etemplate/templates/default/words/words.txt new file mode 100644 index 0000000000..ed410f0986 --- /dev/null +++ b/etemplate/templates/default/words/words.txt @@ -0,0 +1,250 @@ +spell +study +still +plant +along +often +until +carry +black +bring +drink +funny +seven +blast +blend +blimp +blink +bliss +block +blond +bluff +blunt +brand +brass +brunt +clamp +clasp +class +cliff +cling +clink +clump +clung +craft +cramp +crisp +crust +draft +drank +dress +drift +drill +fling +flung +flunk +frank +frill +frisk +frost +gland +glass +glint +gramp +grand +grant +grasp +grass +grill +grump +grunt +plank +plump +prank +press +print +scalp +scram +scrap +skill +skunk +slang +slant +slept +sling +slump +smack +smell +snack +sniff +spank +spend +spent +spill +splat +split +spunk +stack +stamp +stand +stiff +sting +stink +stomp +strap +strip +stuck +stump +swang +swell +swift +swing +swung +tramp +trend +trick +trunk +trust +twang +twist +admit +album +blank +clock +crack +crept +cross +index +stuff +stunt +upset +click +cluck +stick +added +attic +brick +buddy +bunny +buses +cabin +camel +candy +fifty +habit +happy +jelly +kitty +lemon +limit +model +nanny +penny +puppy +robin +salad +sandy +scrub +silly +slick +stung +sunny +truck +tummy +unzip +visit +wagon +bless +brisk +clack +clang +crick +crock +flick +flock +frizz +gloss +gruff +plums +scuff +skips +skull +smock +snuff +swept +track +given +angry +belly +empty +extra +hurry +sorry +spell +study +still +plant +along +often +until +carry +black +bring +drink +funny +seven +blast +blend +blimp +blink +bliss +block +blond +bluff +blunt +brand +brass +brunt +clamp +clasp +class +cliff +cling +clink +clump +clung +craft +cramp +crisp +crust +draft +drank +dress +drift +drill +fling +flung +flunk +frank +frill +frisk +frost +gland +glass +glint +gramp +grand +grant +grasp +grass +grill +grump +grunt +plank +plump +prank +press +print +scalp +scram +scrap \ No newline at end of file