Chora::isRestricted PHP Méthode

isRestricted() public static méthode

Check if the given item is restricted from being shown.
public static isRestricted ( string $where ) : boolean
$where string The current file path.
Résultat boolean Is item allowed to be displayed?
    public static function isRestricted($where)
    {
        // First check if the current user has access to this repository.
        if (!self::checkPerms($GLOBALS['sourceroot'])) {
            return true;
        }
        if (!isset(self::$restricted)) {
            $restricted = array();
            if (isset($GLOBALS['conf']['restrictions']) && is_array($GLOBALS['conf']['restrictions'])) {
                $restricted = $GLOBALS['conf']['restrictions'];
            }
            foreach ($GLOBALS['sourceroots'] as $key => $val) {
                if ($GLOBALS['sourceroot'] == $key && isset($val['restrictions']) && is_array($val['restrictions'])) {
                    $restricted = array_merge($restricted, $val['restrictions']);
                    break;
                }
            }
            self::$restricted = $restricted;
        }
        if (!empty($restricted)) {
            for ($i = 0; $i < count($restricted); ++$i) {
                if (preg_match('|' . str_replace('|', '\\|', $restricted[$i]) . '|', $where)) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Exemple #1
0
 /**
  * Global variables defined:
  *   $chora_conf
  *   $sourceroots
  */
 protected function _init()
 {
     global $acts, $conf, $defaultActs, $where, $atdir, $fullname, $sourceroot, $page_output;
     // TODO: If chora isn't fully/properly setup, init() will throw fatal
     // errors. Don't want that if this class is being loaded simply to
     // obtain basic chora application information.
     $initial_app = $GLOBALS['registry']->initialApp == 'chora';
     try {
         $GLOBALS['sourceroots'] = Horde::loadConfiguration('backends.php', 'sourceroots');
     } catch (Horde_Exception $e) {
         $GLOBALS['sourceroots'] = array();
         if (!$initial_app) {
             return;
         }
         $GLOBALS['notification']->push($e);
     }
     $sourceroots = Chora::sourceroots();
     /**
      * Variables we wish to propagate across web pages
      *  ha  = Hide Attic Files
      *  ord = Sort order
      *  sbt = Sort By Type (name, age, author, etc)
      *
      * Obviously, defaults go into $defaultActs :)
      * TODO: defaults of 1 will not get propagated correctly - avsm
      * XXX: Rewrite this propagation code, since it sucks - avsm
      */
     $defaultActs = $acts = array('onb' => 0, 'ord' => Horde_Vcs::SORT_ASCENDING, 'rev' => 0, 'rt' => null, 'sa' => 0, 'sbt' => constant($conf['options']['defaultsort']), 'ws' => 1);
     /* See if any actions have been passed as form variables, and if so,
      * assign them into the acts array. */
     $vars = Horde_Variables::getDefaultVariables();
     foreach (array_keys($acts) as $key) {
         if (isset($vars->{$key})) {
             $acts[$key] = $vars->{$key};
         }
     }
     /* Use the value of the 'rt' form value for the sourceroot. If not
      * present, use the last sourceroot used as the default value if the
      * user has that preference. Otherwise, use default sourceroot. */
     $last_sourceroot = $GLOBALS['prefs']->getValue('last_sourceroot');
     if (is_null($acts['rt'])) {
         if (!empty($last_sourceroot) && !empty($sourceroots[$last_sourceroot]) && is_array($sourceroots[$last_sourceroot])) {
             $acts['rt'] = $last_sourceroot;
         } else {
             foreach ($sourceroots as $key => $val) {
                 if (!isset($acts['rt']) || isset($val['default'])) {
                     $acts['rt'] = $key;
                     break;
                 }
             }
             if (is_null($acts['rt'])) {
                 if ($initial_app) {
                     Chora::fatal(new Chora_Exception(_("No repositories found.")));
                 }
                 return;
             }
         }
     }
     if (!isset($sourceroots[$acts['rt']])) {
         if ($initial_app) {
             Chora::fatal(new Chora_Exception(sprintf(_("The repository with the slug '%s' was not found"), $acts['rt'])));
         }
         return;
     }
     $sourcerootopts = $sourceroots[$acts['rt']];
     $sourceroot = $acts['rt'];
     /* Store last repository viewed */
     if ($acts['rt'] != $last_sourceroot) {
         $GLOBALS['prefs']->setValue('last_sourceroot', $acts['rt']);
     }
     // Cache.
     $cache = empty($conf['caching']) ? null : $GLOBALS['injector']->getInstance('Horde_Cache');
     $GLOBALS['chora_conf'] = array('cvsusers' => $sourcerootopts['location'] . '/' . (isset($sourcerootopts['cvsusers']) ? $sourcerootopts['cvsusers'] : ''), 'introText' => CHORA_BASE . '/config/' . (isset($sourcerootopts['intro']) ? $sourcerootopts['intro'] : ''), 'introTitle' => isset($sourcerootopts['title']) ? $sourcerootopts['title'] : '', 'sourceRootName' => $sourcerootopts['name']);
     $chora_conf =& $GLOBALS['chora_conf'];
     $GLOBALS['VC'] = Horde_Vcs::factory(Horde_String::ucfirst($sourcerootopts['type']), array('cache' => $cache, 'sourceroot' => $sourcerootopts['location'], 'paths' => array_merge($conf['paths'], array('temp' => Horde::getTempDir())), 'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '', 'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : ''));
     if (!$initial_app) {
         return;
     }
     $where = Horde_Util::getFormData('f', '/');
     /* Location relative to the sourceroot. */
     $where = preg_replace(array('|^/|', '|\\.\\.|'), '', $where);
     $fullname = $sourcerootopts['location'] . (substr($sourcerootopts['location'], -1) == '/' ? '' : '/') . $where;
     if ($sourcerootopts['type'] == 'cvs') {
         $fullname = preg_replace('|/$|', '', $fullname);
         $atdir = @is_dir($fullname);
     } else {
         $atdir = !$where || substr($where, -1) == '/';
     }
     $where = preg_replace('|/$|', '', $where);
     if ($sourcerootopts['type'] == 'cvs' && !@is_dir($sourcerootopts['location'])) {
         Chora::fatal(new Chora_Exception(_("Sourceroot not found. This could be a misconfiguration by the server administrator, or the server could be having temporary problems. Please try again later.")));
     }
     if (Chora::isRestricted($where)) {
         Chora::fatal(new Chora_Exception(sprintf(_("%s: Forbidden by server configuration"), $where)));
     }
 }
All Usage Examples Of Chora::isRestricted