Location: PHPKode > scripts > PHP Scan > scan.class.php
<?php
/*
**
*/
ini_set('max_execution_time', 300);
class PHPScan
{
  /*
  ** if you need find spacified files
  ** Extention
  */
  private $infctions    = array("htm","php","html");
  /*
  ** viruses or hack code you need to remove
  ** insert Every Code You like To Scan
  */
  private $rules        =  array(   '/<iframe src=(.*?)\/iframe[^>]*>/i',
                                    '/<div.*style=.*display:none.*[^>]*>.*<iframe .*\/.*div[^>]*>/i',
                                    '/<!-- ad --><script[^>]*>.*<\/script><!-- \/ad -->/i'
                                    );

  private $dir          = "";

  /*
  **  do scan
  */
  function PHPScan($dir)
  {
    $this->dir = $dir;
    $files = $this->getfile($this->dir);
      echo "<pre>".print_r($files,true)."</pre>";
      echo "<br /><b>Result :</b> [".count($files)."] infected";
  }
  function doscan($fullpath)
  {
    $data = file_get_contents($fullpath);
    $contents .= preg_replace($this->rules, '', $data);
    file_put_contents($fullpath,$contents);
  }
  function infected($fullpath)
  {
    $data = file_get_contents($fullpath);
    foreach($this->rules as $item)
    {
     if(preg_match($item,$data))
    {
      return true;
    }
    else
    {
      return false;
    }
    }

  }
  /*
  **  Get Files
  */
  function getfile($directory)
  {
	if( substr($directory, -1) == "/" ) $directory = substr($directory, 0, strlen($directory) - 1);
	$code = explode("<br />",$this->getdir($directory));
	return $code;
  }
  /*
  ** Tree Directory
  */
  function getdir($directory)
  {
    if( function_exists("scandir") ) $file = scandir($directory); else $file = $this->php4_scandir($directory);
	natcasesort($file);
    $files = $dirs = array();
    foreach($file as $this_file)
    {
      if( is_dir("$directory/$this_file" ) )
      {
        $dirs[] = $this_file;
      }
      else
      {
        $files[] = $this_file;
      }
    }
    $file = array_merge($dirs, $files);
    if( count($file) > 2 )
    {
      foreach( $file as $this_file )
      {
        if( $this_file != "." && $this_file != ".." )
        {
          if( is_dir("$directory/$this_file") )
          {
           $file_tree .= $this->getdir($directory."/".$this_file);
          }
          else
          {
            $ext = substr($this_file, strrpos($this_file, ".") + 1);
            if(in_array($ext,$this->infctions))
            {
              if($this->infected($directory."/".$this_file))
              {
                $this->doscan($directory."/".$this_file);
                $file_tree .= $this_file .' <span style="color:red"><b>[ Infected ] Successful Clean</b></span><br />';
              }
              else
              {
                //$file_tree .= $this_file . ' <span style="color:Green"><b>[ Clean File ] </b></span><br />';
              }
            }
          }
        }
      }
    }
	return $file_tree;
}


function php4_scandir($dir) {
	$dh  = opendir($dir);
	while( false !== ($filename = readdir($dh)) ) {
	    $files[] = $filename;
	}
	sort($files);
	return($files);
}


}

echo "<B>Class PHPScan By Amin Helmy PHPTiger </b><br />";
$scan = &new PHPScan("tl4s");
?>
Return current item: PHP Scan