http://www.fsf.org/ or write * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /* This plugin generates an image that can be used to fight form Spam flooding. */ include ("plugins/despam_imgtxt/configure.php"); Class CmsDam_Despam_Imgtxt { var $conf; function CmsDam_Despam_Imgtxt() { // Constructor $this->conf = new CmsDam_Despam_Imgtxt_Conf; // Drop Expired images $this->Drop_Expired_Images(); return true; } private function Randomize_Letters() { // Return a randomized string of $this->conf->max_string_lenght letters // from letters in file $this->conf->letters_filename $filename = $this->conf->letters_filename; $limit = $this->conf->max_string_lenght; $FileDes = fopen ($filename, 'r'); $buffer = fread ($FileDes, filesize ($filename)); fclose ($FileDes); // Shuffle a string limiting the number of chars return (substr(str_shuffle($buffer), 0, $limit)); } private function Drop_Expired_Images() { // Delete Expired images $expired_time = time() - $this->conf->image_lifetime; $dir = $this->conf->image_path; if (is_dir($dir)) { $dh = opendir($dir); while (($file = readdir($dh)) !== false) { $extension = substr($file, strrpos($file, ".")); if ($extension == ".png") { //echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; echo "DEBUG: Image File: " . $file . "
\n"; $token = strtok($file, "_"); $token = strtok("_"); $token = strtok($token, "."); echo "DEUG: Created: $token" . "
\n"; if ($expired_time > $token) { // This image was expired echo "DEBUG: Image file was expired: $file" . "
\n"; @unlink ($this->conf->image_path . "/" . $file); } } } closedir($dh); } } function CmsDam_Despam_Imgtxt_CreateImage() { $h = $this->conf->height; $w = $this->conf->width; $str = $this->Randomize_Letters(); // Don't drop this line... it's a very simple way to avoid Denial Of Service attacks sleep ($this->conf->dos_sleep); $handle = ImageCreate ($h, $w); if ($handle === false) return false; $bg_color = ImageColorAllocate ($handle, $this->conf->bg_red_color, $this->conf->bg_green_color, $this->conf->bg_blue_color); $txt_color = ImageColorAllocate ($handle, $this->conf->txt_red_color, $this->conf->txt_green_color, $this->conf->txt_blue_color); ImageString ($handle, 6, 5, 2, $str, $txt_color); ImagePng ($handle, $this->conf->image_path . "/" . stripslashes($str) . "_" . time() . ".png", 9); return $str; } function CmsDam_Despam_Imgtxt_DeleteImage($str) { @unlink($this->conf->image_path . "/" . stripslashes($str) . ".png"); return true; } /* function CmsDam_Despam_Imgtxt_GetImage($str) { @unlink($this->conf->image_path . "/" . stripslashes($str) . ".png"); return true; } */ } $this->included->despam_imgtxt->api = new CmsDam_Despam_Imgtxt; ?>