Alpha Framework alpha--model
[ class tree: alpha--model ] [ index: alpha--model ] [ all elements ]

Source for file BadRequestObject.inc

Documentation is available at BadRequestObject.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/AlphaDAO.inc';
  4.  
  5. /**
  6.  *
  7.  * A HTTP request that resulted in a 404 response.  The class is only used when the
  8.  * sysEnableClientTempBlacklistFiler setting is set to true to enable the filter.
  9.  * 
  10.  * @package alpha::model
  11.  * @since 1.0
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @version $Id: BadRequestObject.inc 1453 2011-12-04 15:12:54Z johnc $
  14.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  15.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  16.  *  All rights reserved.
  17.  * 
  18.  *  <pre>
  19.  *  Redistribution and use in source and binary forms, with or
  20.  *  without modification, are permitted provided that the
  21.  *  following conditions are met:
  22.  * 
  23.  *  * Redistributions of source code must retain the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer.
  26.  *  * Redistributions in binary form must reproduce the above
  27.  *    copyright notice, this list of conditions and the
  28.  *    following disclaimer in the documentation and/or other
  29.  *    materials provided with the distribution.
  30.  *  * Neither the name of the Alpha Framework nor the names
  31.  *    of its contributors may be used to endorse or promote
  32.  *    products derived from this software without specific
  33.  *    prior written permission.
  34.  *   
  35.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  36.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  37.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  40.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  46.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  47.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48.  *  </pre>
  49.  *  
  50.  */
  51. class BadRequestObject extends AlphaDAO {
  52.     /**
  53.      * The HTTP user-agent client string
  54.      * 
  55.      * @var String 
  56.      * @since 1.0
  57.      */
  58.     protected $client;
  59.     
  60.     /**
  61.      * The IP of the client
  62.      * 
  63.      * @var String 
  64.      * @since 1.0
  65.      */
  66.     protected $IP;
  67.     
  68.     /**
  69.      * The non-existant resource that the client requested
  70.      * 
  71.      * @var String 
  72.      * @since 1.0
  73.      */
  74.     protected $requestedResource;
  75.     
  76.     /**
  77.      * An array of data display labels for the class properties
  78.      * 
  79.      * @var array 
  80.      * @since 1.0
  81.      */
  82.     protected $dataLabels = array('OID'=>'Bad request ID#','client'=>'Client string','IP'=>'IP','requestedResource'=>'Requested resource');
  83.     
  84.     /**
  85.      * The name of the database table for the class
  86.      * 
  87.      * @var string 
  88.      * @since 1.0
  89.      */
  90.     const TABLE_NAME = 'BadRequest';
  91.     
  92.     /**
  93.      * Trace logger
  94.      * 
  95.      * @var Logger 
  96.      * @since 1.0
  97.      */
  98.     private static $logger null;
  99.     
  100.     /**
  101.      * Constructor for the class
  102.      * 
  103.      * @since 1.0
  104.      */
  105.     public function __construct({
  106.         self::$logger new Logger('BadRequestObject');
  107.         self::$logger->debug('>>__construct()');
  108.         
  109.         // ensure to call the parent constructor
  110.         parent::__construct();
  111.         
  112.         $this->client = new String();
  113.         $this->IP = new String();
  114.         $this->requestedResource = new String();
  115.         
  116.         self::$logger->debug('<<__construct');
  117.     }
  118.     
  119.     /**
  120.      * Gets the count of bad requests for the client with this IP and client string in the past
  121.      * configurable period (sysTempBlacklistFilerPeriod)
  122.      * 
  123.      * @return integer 
  124.      * @since 1.0
  125.      * @throws AlphaException
  126.      */
  127.     public function getBadRequestCount({
  128.         global $config;
  129.         
  130.         $sqlQuery "SELECT COUNT(OID) AS request_count FROM ".$this->getTableName()." WHERE IP = '".$this->IP->getValue()."' AND client = '".$this->client->getValue()."' AND created_ts > NOW()-INTERVAL '".$config->get('sysTempBlacklistFilerPeriod')."' MINUTE";
  131.         
  132.         $result $this->query($sqlQuery);
  133.         
  134.         if(isset($result[0]))
  135.             $row $result[0];
  136.         else
  137.             throw new AlphaException('No result set returned when querying the bad request table');
  138.         
  139.         if(isset($row['request_count'])) {
  140.             return $row['request_count'];
  141.         }else{
  142.             return 0;
  143.         }
  144.     }
  145. }
  146.  
  147. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:30 +0000 by phpDocumentor 1.4.3