Location: PHPKode > scripts > Security System > security-system/security.class.php
<?
/*
Copyright: 2009 êîò, àäìèí, øðåäåð.
Author: ß àöêèé îäìèí, éà ñ÷àñ â ñåðâåðíîé êîòà ÷åðåç øðåäåð çà 25 ñåêíä ïðîïóñòèë o_0
*/
class Security
{
	private $files = array ();
	private $temp_dir = array ();
	private $content;
	private $seach = array ();
	private $risky = array ();
	private $admin_mail;

	function __construct ($start_folder = '/')
	{
	$this->create_structure ($start_folder);
	}

	private function create_structure ($start_folder)
	{
		if (is_dir ($start_folder))
		{
		$this->scan_dir ($start_folder, true);
			while (count ($this->temp_dir) > 0)
			{
			$dir = reset ($this->temp_dir);
				if (empty ($dir))
				{
				break;
				}
				else
				{
				$this->scan_dir ($dir);
				}
			}
		}
		else
		{
			throw new Exception("$start_folder is not directory");
		}
	}

	private function scan_dir ($dir, $first = false)
	{
	$array = scandir ($dir);
	array_splice($array, 0, 2);
		if (!$first)
		{
		unset ($this->temp_dir [array_search ($dir, $this->temp_dir)]);
		}

		if (count ($array) > 1)
		{
			foreach ($array as $value)
			{
			$a = substr ($dir, - 1);
			$temp = (substr ($dir, - 1)==='/' ? $dir : $dir.'/').$value;
				if (is_dir ($temp))
				{
				$this->temp_dir[] = $temp;
				}
				else if (is_file ($temp))
				{
				$this->files[] = $temp;
				}
			}
		}
	}

	public function search ()
	{
	$this->seach = func_get_args ();
	}

	public function scan ()
	{
		if (count ($this->seach) > 0)
		{
		$gc = true;
		}

		foreach ($this->files as $value)
		{
			if (is_executable ($value))
			{
			$this->risky['executable'][] = $value;
			}

			if ($gc)
			{
			$temp = file_get_contents ($value);
				foreach ($this->seach as $val)
				{
					if (stristr ($temp, $val))
					{
					$this->risky[$val][] = $value;
					}
				}
			$temp = null;
			}
		}

		if (count ($this->risky) > 0)
		{
			if (!empty ($this->admin_mail))
			{
			$this->send_mail ();
			}

			return $this->risky;
		}
		else
		{
			return false;
		}
	}

	public function mail_alert ($mail)
	{
	$this->admin_mail = $mail;
	}

	private function send_mail ()
	{
	$count = count($this->risky, 0);
	mail($this->admin_mail, "Founded risky files", "It is PHP Security class.\nNow was found $count risky files.\nPlease check its.");
	}
}
Return current item: Security System