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

Source for file ClientBlacklistFilter.inc

Documentation is available at ClientBlacklistFilter.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/filters/AlphaFilterInterface.inc';
  4. require_once $config->get('sysRoot').'alpha/model/BlacklistedClientObject.inc';
  5. require_once $config->get('sysRoot').'alpha/exceptions/BONotFoundException.inc';
  6. require_once $config->get('sysRoot').'alpha/exceptions/ResourceNotAllowedException.inc';
  7.  
  8. /**
  9.  * Class for filtering requests from blacklisted HTTP clients
  10.  * 
  11.  * @package alpha::util::filters
  12.  * @since 1.0
  13.  * @author John Collins <dev@alphaframework.org>
  14.  * @version $Id: ClientBlacklistFilter.inc 1454 2011-12-04 15:14:05Z johnc $
  15.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  16.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  17.  *  All rights reserved.
  18.  * 
  19.  *  <pre>
  20.  *  Redistribution and use in source and binary forms, with or
  21.  *  without modification, are permitted provided that the
  22.  *  following conditions are met:
  23.  * 
  24.  *  * Redistributions of source code must retain the above
  25.  *    copyright notice, this list of conditions and the
  26.  *    following disclaimer.
  27.  *  * Redistributions in binary form must reproduce the above
  28.  *    copyright notice, this list of conditions and the
  29.  *    following disclaimer in the documentation and/or other
  30.  *    materials provided with the distribution.
  31.  *  * Neither the name of the Alpha Framework nor the names
  32.  *    of its contributors may be used to endorse or promote
  33.  *    products derived from this software without specific
  34.  *    prior written permission.
  35.  *   
  36.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  37.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  38.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  39.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  41.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  46.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  47.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49.  *  </pre>
  50.  *  
  51.  */
  52. class ClientBlacklistFilter implements AlphaFilterInterface {
  53.     /**
  54.      * Trace logger
  55.      * 
  56.      * @var Logger 
  57.      * @since 1.0
  58.      */
  59.     private static $logger null;
  60.     
  61.     /**
  62.      * Constructor
  63.      * 
  64.      * @since 1.0
  65.      */
  66.     public function __construct({
  67.         self::$logger new Logger('ClientBlacklistFilter');        
  68.     }
  69.     
  70.     /**
  71.      * (non-PHPdoc)
  72.      * @see alpha/util/filters/AlphaFilterInterface#process()
  73.      * 
  74.      * @throws ResourceNotAllowedException
  75.      */
  76.     public function process({
  77.         $client $_SERVER['HTTP_USER_AGENT'];
  78.         
  79.         if(!empty($client)) {
  80.             $badClient new BlacklistedClientObject();
  81.             try {
  82.                 $badClient->loadByAttribute('client'$client);
  83.             }catch (BONotFoundException $bonf{
  84.                 // client is not on the list!
  85.                 return;
  86.             }
  87.             // if we got this far then the client is bad
  88.             self::$logger->warn('The client ['.$client.'] was blocked from accessing the resource ['.$_SERVER['REQUEST_URI'].']');
  89.             throw new ResourceNotAllowedException('Not allowed!');
  90.         }
  91.     }
  92. }
  93.  
  94. ?>

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