#!/usr/local/bin/php * @copyright 2006 Cal Evans * @license GPL 2.0 * @package exim_deny_filter * @access public * @version 1.1 * */ $o= &new Exim_Deny_Filter($argv); $o->main(); if ($o->count_flag) echo $o->count."\n"; $o=null; die(0); class Exim_Deny_Filter { public $count; public $count_flag; public $file; public $seconds_to_keep; protected $lines; protected $verboseFlag; function __construct($arguments=array()) { $this->file = "/etc/exim_deny"; $this->seconds_to_keep = 86400; $this->lines = array(); $this->count = 0; $this->process_arguments($arguments); } // function Exim_Filter() function main() { if (!$this->read_file()) return; if ($this->count_flag) { $this->count_ips(); } else { $this->filter_ips(); $this->write_file(); } // if ($this->count_flag) return; } // function main() protected function process_arguments($arguments) { if (count($arguments)==0) return; /* * Process arguments if available. */ for ($lcvA=0;$lcvAcount_flag = true; break; case "-v": $this->verboseFlag = true; break; } // switch ($arguments[$lcvA]) } // for ($lcvA=0;$lcvAlines = file($this->file); return count($this->lines)>0; } // protected function read_file() protected function count_ips() { $this->count=0; for($lcvA=0;$lcvAlines);$lcvA++) { $this->count +=substr($this->lines[$lcvA],0,1)=="#"?1:0; } // for($lcvA=0;$lcvAlines);$lcvA++) return; } // protected function count_ips() protected function filter_ips() { $ips = array(); $break = mktime()-$this->seconds_to_keep; $holding = array(); for($lcvA=0;$lcvAlines);$lcvA++) { if (substr($this->lines[$lcvA],0,1)=="#") { $time = strtotime(substr($this->lines[$lcvA],1)); if ($time<$break) continue; $this_ip = trim(strtr($this->lines[$lcvA+1],"\n\r\t\0"," ")); if (in_array($this_ip, $ips)) continue; $ips[] = $this_ip; $holding[] = "# ".date('m/d/Y h:i:s',$time)."\n".$this_ip."\n\n"; $lcvA++; } // if (substr($lines[$lcvA],0,1)=="#") } // for($lcvA=0;$lcvAlines = $holding; } // protected function filter_ips() protected function write_file() { $file_handle = fopen($this->file,'w'); foreach($this->lines as $line) { fwrite($file_handle,$line); } // foreach($this->lines as $line) fClose($file_handle); return; } // protected function write_file() } // class Exim_Deny_Filter ?>