Source for file class.php5.DefensiveAttack.php

Documentation is available at class.php5.DefensiveAttack.php

  1. <?php 
  2. /**
  3.  * File containing DefensiveAttack class.
  4.  *
  5.  * @package     DefensiveAttack
  6.  * @version     1.0.0
  7.  * @copyright     Copyright (C)2006 TheLordOfWeb. All rights reserved.
  8.  * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
  9.  * @filesource
  10.  */
  11.  
  12. /**
  13.  *     LICENSE
  14.  *     This program is free software; you can redistribute it and/or
  15.  *     modify it under the terms of the GNU General Public License (GPL)
  16.  *     as published by the Free Software Foundation; either version 2
  17.  *     of the License, or (at your option) any later version.
  18.  *    This program is distributed in the hope that it will be useful,
  19.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *    GNU General Public License for more details.
  22.  *    To read the license please visit http://www.gnu.org/copyleft/gpl.html
  23.  *    ----------------------------------------------------------------------
  24.  *    Original Author of file:
  25.  *    Purpose of file:
  26.  *    ----------------------------------------------------------------------
  27.  *     Tested with IE 6, Netscape 7, Opera 9, Firefox 2
  28.  *     This is free software. Use at your own risk.
  29.  */
  30.  
  31. /**
  32.  * DefensiveAttack class for php 5.x
  33.  *
  34.  * 
  35.  * @package     DefensiveAttack
  36.  * @author         TheLordOfWeb    <http://thelordofweb.atspace.com/>
  37.  * @version     1.0.0
  38.  * @copyright     Copyright (C)2006 TheLordOfWeb. All rights reserved.
  39.  * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
  40.  * @example        example_1.php
  41.  * @example        example_2.php
  42.  * @example        example_3.php
  43.  * @example        example_4.php
  44.  * @example        example_5.php
  45.  */
  46. class DefensiveAttack  {
  47.     
  48.     /**
  49.      * My host name
  50.      *
  51.      * @access protected
  52.      * @var string 
  53.      */
  54.     protected   $mMyHostName   =   '';
  55.     
  56.     /**
  57.      * My IP address
  58.      *
  59.      * @access protected
  60.      * @var string 
  61.      */
  62.     protected  $mMyIpAddress   =   '127.0.0.1';
  63.     
  64.     /**
  65.      * Outside IP address
  66.      *
  67.      * @access protected
  68.      * @var string 
  69.      */
  70.     protected  $mIpAddress     =   '127.0.0.1';
  71.     
  72.     /**
  73.      * Referer
  74.      *
  75.      * @access protected
  76.      * @var string 
  77.      */
  78.     protected  $mReferer       =   '';
  79.     
  80.     /**
  81.      * DefensiveAttack constructor
  82.      *
  83.      * @access public
  84.      * @param string hostname
  85.      */
  86.     public function __construct($myHostName  =  null{
  87.  
  88.         //Set my host name
  89.         $this->mMyHostName     =   (!isset($myHostName)) htmlentities($_SERVER['HTTP_HOST'],ENT_QUOTES,'utf-8'$myHostName;
  90.         
  91.         //Set outside IP address
  92.         $this->mIpAddress      = $this->SetRealIp();
  93.         
  94.         //Set referer
  95.         $this->mReferer        = $this->SetReferer();
  96.         
  97.     }
  98.     
  99.     /**
  100.      * Set real outside IP address
  101.      *
  102.      * @access protected
  103.      * @return string 
  104.      */
  105.     protected function &SetRealIp(){
  106.         
  107.         $ip    =   '';
  108.         
  109.         if (isset($_SERVER['HTTP_X_FORWARDED_FOR']AND !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  110.             foreach (explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']as $values{
  111.                 $ip    .=   long2ip(ip2long($values)) ' ; ';
  112.             }
  113.         
  114.         else {
  115.             $ip long2ip(ip2long($_SERVER['REMOTE_ADDR']));
  116.         }
  117.         
  118.         return $ip;
  119.         
  120.     }
  121.     
  122.     /**
  123.      * Get IP outside address
  124.      *
  125.      * @access public
  126.      * @return string 
  127.      */
  128.     public function &GetIpAddress({
  129.         
  130.         return $this->mIpAddress;
  131.         
  132.     }
  133.     
  134.     /**
  135.      * Set my IP address
  136.      *
  137.      * @access public
  138.      * @param string $ip 
  139.      */
  140.     public function SetMyIpAddress($ip{
  141.         
  142.         $this->mMyIpAddress = long2ip(ip2long($ip));
  143.     }
  144.     
  145.     /**
  146.      * Compare my IP address with outside IP address
  147.      *
  148.      * @access public
  149.      * @return bool 
  150.      */
  151.     public function IsIpIdentity({
  152.         
  153.         return (strcmp($this->mIpAddress,$this->mMyIpAddress== 0true false;
  154.         
  155.     }
  156.         
  157.     /**
  158.      * Get host name
  159.      *
  160.      * @access public
  161.      * @return string 
  162.      */
  163.     public function GetHostName({
  164.         
  165.          return gethostbyaddr($this->mIpAddress)
  166.  
  167.     }
  168.  
  169.     /**
  170.      * Looking for proxy using
  171.      *
  172.      * @access public
  173.      * @return bool 
  174.      */
  175.     public function IsUseProxy({
  176.          
  177.         return (isset($_SERVER['HTTP_X_FORWARDED_FOR']AND !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) true false;
  178.         
  179.     }
  180.     
  181.     
  182.     /**
  183.      * Set ban cookie
  184.      *
  185.      * @access public
  186.      * @param string $path 
  187.      * @param string $cookieName 
  188.      */
  189.     public function SetSmartCookieBan($path "/",$cookieName="uid_cookie_ban_ban"{
  190.         
  191.         setcookie($cookieName,md5(rand()),time(86400 365,$path,$this->mMyHostName);
  192.         
  193.     }
  194.     
  195.     /**
  196.      * Delete ban cookie
  197.      *
  198.      * @access public
  199.      * @param string $path 
  200.      * @param string $cookieName 
  201.      */
  202.     public function DelSmartCookieBan($path "/",$cookieName="uid_cookie_ban_ban"{
  203.         
  204.         setcookie($cookieName,"",time(3600,$path,$this->mMyHostName);
  205.         
  206.     }
  207.  
  208.     /**
  209.      * Check Ban cookie
  210.      *
  211.      * @access public
  212.      * @param  string $cookieName 
  213.      * @return bool 
  214.      */
  215.     public function IsSetSmartCookieBan($cookieName="uid_cookie_ban_ban"{
  216.         
  217.         return (isset($_COOKIE[$cookieName]AND !empty($_COOKIE[$cookieName])) true false;
  218.         
  219.     }
  220.     
  221.     /**
  222.      * Set referer
  223.      * 
  224.      * @access protected
  225.      * @return string 
  226.      */
  227.     protected function &SetReferer({
  228.         
  229.         //Initialize variable
  230.         $referer   =   '';
  231.         
  232.         if (isset($_SERVER['HTTP_REFERER']AND !empty($_SERVER['HTTP_REFERER'])) {
  233.  
  234.             //Initialize variable
  235.             $url       =   array();
  236.  
  237.             //Parse referer url
  238.             $url       =   parse_url($_SERVER['HTTP_REFERER']);
  239.             
  240.             $referer   =   htmlentities($url['host'],ENT_QUOTES,'utf-8');
  241.             unset($url);
  242.         }
  243.         
  244.         return $referer;
  245.     }
  246.     
  247.     /**
  248.      * Get referer
  249.      *
  250.      * @access public
  251.      * @return string 
  252.      */
  253.     public function &GetReferer({
  254.         
  255.         return $this->mReferer;
  256.         
  257.     }
  258.     
  259.     /**
  260.      * Check referer for my url address
  261.      *
  262.      * @access public
  263.      * @return bool 
  264.      */
  265.     public function CheckReferer({
  266.         
  267.         return (strcmp($this->mMyHostName,$this->mReferer== 0true false;
  268.         
  269.     }
  270.     
  271.     /**
  272.      * Get input data
  273.      *
  274.      * @access public
  275.      * @return string 
  276.      */
  277.     public function GetInputData({
  278.         
  279.         return htmlentities($_SERVER['QUERY_STRING'],ENT_QUOTES,'utf-8');
  280.         
  281.     }
  282.     
  283.     /**
  284.      * Get cookie data
  285.      *
  286.      * @access public
  287.      * @return reference to array
  288.      */
  289.     public function &GetCookieData({
  290.         
  291.         //Initialize cookie data
  292.         $cd        =   '';
  293.         
  294.         foreach ($_COOKIE as $k => $v {
  295.             $cd    .=   "{$k}={$v},";
  296.         }
  297.         
  298.         $cd    =   htmlentities($cd,ENT_QUOTES,'utf-8');
  299.         
  300.         return $cd;
  301.         
  302.     }
  303.     
  304.     /**
  305.      * DefensiveAttack destructor
  306.      * 
  307.      * @access public
  308.      */
  309.     public function __destruct({
  310.         
  311.     }
  312.     
  313. }
  314.  
  315. ?>

Documentation generated on Tue, 31 Oct 2006 23:59:53 +0200 by phpDocumentor 1.3.1