phpPoA2
[ class tree: phpPoA2 ] [ index: phpPoA2 ] [ all elements ]

Source for file QueryFilterAuthzEngine.php

Documentation is available at QueryFilterAuthzEngine.php

  1. <?php
  2. /**
  3.  * @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
  4.  *
  5.  *  This file is part of phpPoA2.
  6.  *
  7.  *  phpPoA2 is free software: you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation, either version 3 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  phpPoA2 is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  21.  * @version 2.0
  22.  * @author Jaime Perez <jaime.perez@rediris.es>
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * This hook is executed right after retrieving the current URI, the params (both GET and POST) and
  28.  * the arrays of allowed and denied patterns that will be checked inmediately.
  29.  * It can be used to alter parameters and the URL, and also to configure the filters on runtime.
  30.  * The hook receives the URI string, an array of parameters, the allowed and the denied patterns.
  31.  * Functions for this hook must be defined like this:
  32.  *
  33.  * function queryBeforeFilterHook(&$uri, &$params, &$allowed, &$denied);
  34.  *
  35.  * Please bear in mind that hooks must return TRUE or they'll keep other hooks from executing.
  36.  */
  37. define("QUERY_BEFORE_FILTERS""QUERY_BEFORE_FILTERS");
  38.  
  39. /**
  40.  * Authorization engine that works by checking the query string of the request.
  41.  * @package phpPoA2
  42.  * @subpackage QueryFilterAuthorizationEngine
  43.  */
  44.  
  45.     protected $valid_hooks = array(QUERY_BEFORE_FILTERS);
  46.  
  47.     public function isAuthorized($user$attrs{
  48.         $uri $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  49.         $params $this->getQueryParams();
  50.         $allowed $this->cfg->getAllowedPatterns();
  51.         $denied  $this->cfg->getDeniedPatterns();
  52.  
  53.         // run hook before checking patterns
  54.         $args array($uri$params$allowed$denied);
  55.         $this->runHooks(QUERY_BEFORE_FILTERS$args);
  56.         $uri $args[0];
  57.         $params $args[1];
  58.         $allowed $args[2];
  59.         $denied $args[3];
  60.  
  61.         // check patterns against the current URI
  62.         foreach ($allowed as $pattern// allowed URIs
  63.             if (preg_match('/'.$pattern.'/'$uri)) {
  64.                 trigger_error(msg('allowed-pattern-match'array($uri$pattern))E_USER_WARNING);
  65.                 return true;
  66.             }
  67.         }
  68.  
  69.         // denied URIs
  70.         foreach ($denied as $pattern{
  71.             if (preg_match('/'.$pattern.'/'$uri)) {
  72.                 trigger_error(msg('denied-pattern-match'array($uri$pattern))E_USER_WARNING);
  73.                 return false;
  74.             }
  75.         }
  76.  
  77.         // check patterns against the request params
  78.         foreach ($params as $param{
  79.             // allowed params
  80.             foreach ($allowed as $pattern{
  81.                 if (preg_match('/'.$pattern.'/'$param)) {
  82.                     trigger_error(msg('allowed-pattern-match'array($param$pattern))E_USER_WARNING);
  83.                     return true;
  84.                 }
  85.             }
  86.  
  87.             // denied params
  88.             foreach ($denied as $pattern{
  89.                 if (preg_match('/'.$pattern.'/'$param)) {
  90.                     trigger_error(msg('denied-pattern-match'array($param$pattern))E_USER_WARNING);
  91.                     return false;
  92.                 }
  93.             }
  94.         }
  95.  
  96.         // default response
  97.         trigger_error(msg('authz-default-fallback')E_USER_WARNING);
  98.         return $this->cfg->getDefaultBehaviour();
  99.     }
  100.  
  101.     public function getAuthorizedList({
  102.         return $this->cfg->getAllowedPatterns();
  103.     }
  104.  
  105. /*
  106.     public function getPendingInvites() {
  107.         return array();
  108.     }
  109. */
  110.     public function authorize($user$attrs$ref$expires 0{
  111.         return false;
  112.     }
  113.  
  114.     public function revoke($mail{
  115.         return false;
  116.     }
  117.  
  118. /*
  119.     public function invite($mail, $expires = 0) {
  120.         return false;
  121.     }
  122.  
  123.     public function removeInvite($ref) {
  124.         return false;
  125.     }
  126. */
  127.     /**
  128.      * Get all the parameters of the current query, either
  129.      * GET or POST method.
  130.      */
  131.     private function getQueryParams({
  132.         // GET queries
  133.         $data explode("&"$_SERVER['QUERY_STRING']);
  134.  
  135.         // POST queries
  136.         if ($_SERVER['REQUEST_METHOD'=== "POST"{
  137.             $str file_get_contents(STDIN);
  138.  
  139.             $post array();
  140.             if ($str{
  141.                 $post explode("&"$str);
  142.             }
  143.  
  144.             $data array_merge($data$post);
  145.         }
  146.  
  147.         return $data;
  148.     }
  149.  
  150. }
  151.  
  152. ?>

Documentation generated on Thu, 26 Aug 2010 13:38:56 +0200 by phpDocumentor 1.4.3