class_pluglist.inc 17.78 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2016  FusionDirectory
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
/*!
 * \file class_pluglist.inc
 * Source code for the class pluglist
/*!
 * \brief This class contains all the function needed to make list
 * of plugin and manage them
 * \see class_plugin
class pluglist
  var $menu             = "";
  var $iconmenu         = "";
  var $current          = "";
  /*!
   * \brief The plInfo result for all plugin, using class as key.
   * Contains the plugin index in 'INDEX' and the path in 'PATH'
  var $info             = [];
  /*!
   * \brief Foreign references on DNs
  var $dnForeignRefs = [];
  /*!
   * \brief Using the plugin index as a key, the class of the plugin.
  var $dirlist          = [];
  /*!
   * \brief List plugin indexes of all plugin that the user have acl for
  var $allowed_plugins  = [];
  var $silly_cache      = [];
  /*!
   * \brief List the plugins
  function __construct ()
    global $class_mapping;
    /* Fill info part of pluglist */
    $classes = get_declared_classes();
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
/* To avoid plugins changing index when reloading */ sort($classes); $index = 0; $depends_infos = []; $conflicts_infos = []; $foreign_refs = []; foreach ($classes as $cname) { $cmethods = get_class_methods($cname); if (in_array_ics('plInfo', $cmethods)) { $infos = call_user_func([$cname, 'plInfo']); if (empty($infos)) { continue; } if (is_subclass_of($cname, 'simpleService')) { $infos['plSelfModify'] = FALSE; /* services are not part of any objectType */ unset($infos['plObjectType']); $infos['plCategory'] = ['server']; } else { if (!isset($infos['plSelfModify'])) { $infos['plSelfModify'] = FALSE; } } if (isset($class_mapping[$cname])) { $infos['PATH'] = dirname($class_mapping[$cname]); } if (isset($infos['plDepends'])) { $depends_infos[] = $cname; } if (isset($infos['plConflicts'])) { $conflicts_infos[] = $cname; } if (isset($infos['plForeignKeys'])) { foreach ($infos['plForeignKeys'] as $ofield => &$pfks) { if (!is_array($pfks)) { $pfks = [$pfks]; } if (!is_array($pfks[0])) { $pfks = [$pfks]; } foreach ($pfks as &$pfk) { $class = $pfk[0]; if (isset($pfk[1])) { $field = $pfk[1]; } else { $field = 'dn'; $pfk[1] = $field; } $filter = NULL; if (isset($pfk[2])) { $filter = $pfk[2]; } if ($filter === NULL) { $filter = "$ofield=%oldvalue%"; } $pfk[2] = $filter; if (!isset($foreign_refs[$class])) { $foreign_refs[$class] = []; } if (!isset($foreign_refs[$class][$field])) { $foreign_refs[$class][$field] = []; } $foreign_refs[$class][$field][] = [$cname, $ofield, $filter]; if ($field == 'dn') { $this->dnForeignRefs[] = [$cname, $ofield, $filter, (isset($pfk[3]) ? $pfk[3] : "$ofield=*%oldvalue%")]; } } unset($pfk); }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
unset($pfks); } else { $infos['plForeignKeys'] = []; } if (!isset($infos['plProvidedAcls'])) { $infos['plProvidedAcls'] = []; } if (!isset($infos['plCategory'])) { $infos['plCategory'] = []; } if (!isset($infos['plTitle']) && isset($infos['plShortName'])) { $infos['plTitle'] = $infos['plShortName']; } if (!empty($infos['plObjectClass']) && !isset($infos['plFilter'])) { if (count($infos['plObjectClass']) == 1) { $infos['plFilter'] = '(objectClass='.$infos['plObjectClass'][0].')'; } else { $infos['plFilter'] = '(&(objectClass='.implode(')(objectClass=', $infos['plObjectClass']).'))'; } } if (isset($infos['plFilter'])) { $infos['plFilterObject'] = ldapFilter::parse($infos['plFilter']); } $infos['plForeignRefs'] = []; $infos['INDEX'] = $index; $this->info[$cname] = $infos; $this->dirlist[$index++] = $cname; } } foreach ($depends_infos as $cname) { foreach ($this->info[$cname]['plDepends'] as $depend) { if (isset($this->info[$depend])) { if (isset($this->info[$depend]['plDepending'])) { $this->info[$depend]['plDepending'][] = $cname; } else { $this->info[$depend]['plDepending'] = [$cname]; } } else { trigger_error("$cname depends of the inexisting plugin $depend"); } } } foreach ($conflicts_infos as $cname) { foreach ($this->info[$cname]['plConflicts'] as $conflict) { if (isset($this->info[$conflict])) { if (isset($this->info[$conflict]['plConflicts'])) { if (!in_array($cname, $this->info[$conflict]['plConflicts'])) { $this->info[$conflict]['plConflicts'][] = $cname; } } else { $this->info[$conflict]['plConflicts'] = [$cname]; } } } } foreach ($foreign_refs as $cname => $refs) { if (isset($this->info[$cname])) { $this->info[$cname]['plForeignRefs'] = $refs; } } /* Provide field for 'all' */ $this->info['all'] = []; $this->info['all']['plProvidedAcls'] = []; $this->info['all']['plDescription'] = _("All objects in this category"); $this->info['all']['plSelfModify'] = FALSE; uasort($this->info,
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
function ($a, $b) { if (isset($a['plPriority']) && isset($b['plPriority'])) { if ($a['plPriority'] == $b['plPriority']) { return 0; } elseif ($a['plPriority'] < $b['plPriority']) { return -1; } else { return 1; } } elseif (isset($a['plPriority'])) { return -1; } elseif (isset($b['plPriority'])) { return 1; } else { return 0; } } ); } /*! * \brief Check whether we are allowed to modify the given acl or not * * This function is used to check which plugins are visible. * * \param array $infos The acl infos, may contain keys CLASS and/or ACL * * \return Boolean TRUE on success FALSE otherwise */ function check_access ($infos) { global $ui; if (isset($infos['CLASS']) && $ui->isBlacklisted($infos['CLASS'])) { return FALSE; } if (!isset($infos['ACL'])) { return TRUE; } $aclname = $infos['ACL']; if (isset($this->silly_cache[$aclname])) { return $this->silly_cache[$aclname]; } /* Split given acl string into an array. e.g. "user,systems" => array("user","systems"); */ $acls_to_check = []; if (preg_match("/,/", $aclname)) { $acls_to_check = explode(",", $aclname); } else { $acls_to_check = [$aclname]; } foreach ($acls_to_check as $acl_to_check) { $acl_to_check = trim($acl_to_check); /* Check if the given acl tag is only valid for self acl entries <plugin acl="user/user:self" class="user"... */ if (preg_match("/:self$/", $acl_to_check)) { $acl_to_check = preg_replace("/:self$/", "", $acl_to_check); if (strpos($acl_to_check, '/')) { if ($ui->get_permissions($ui->dn, $acl_to_check, "") != "") { $this->silly_cache[$aclname] = TRUE; return TRUE; }
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
} else { if ($ui->get_category_permissions($ui->dn, $acl_to_check) != '') { $this->silly_cache[$aclname] = TRUE; return TRUE; } } } else { /* No self acls. Check if we have any acls for the given ACL type */ $deps = $ui->get_module_departments($acl_to_check, TRUE); if (count($deps)) { $this->silly_cache[$aclname] = TRUE; return TRUE; } } } $this->silly_cache[$aclname] = FALSE; return FALSE; } /*! * \brief Get headline, description and icon of a plugin */ function get_infos ($cname) { $plHeadline = FALSE; $plIcon = FALSE; $plDescription = FALSE; $index = $this->get_index($cname); $href = "main.php?plug=$index&amp;reset=1"; if (isset($this->info[$cname])) { if (isset($this->info[$cname]['plShortName'])) { $plHeadline = $this->info[$cname]['plShortName']; } if (isset($this->info[$cname]['plIcon'])) { $plIcon = $this->info[$cname]['plIcon']; } if (isset($this->info[$cname]['plDescription'])) { $plDescription = $this->info[$cname]['plDescription']; } if ($plHeadline && $plIcon && $plDescription) { return [$plHeadline,$plDescription,$href,$plIcon]; } } $vars = get_class_vars($cname); if ($vars) { if (!$plHeadline && isset($vars['plHeadline'])) { $plHeadline = _($vars['plHeadline']); } if (!$plDescription && isset($vars['plDescription'])) { $plDescription = _($vars['plDescription']); } if (!$plIcon && isset($vars['plIcon'])) { $plIcon = $vars['plIcon']; } } else { die('Unknown class '.$cname); } if (!$plIcon) { $plIcon = "icon.png"; } return [$plHeadline,$plDescription,$href,$plIcon]; } /*! * \brief Generate menu */ function gen_menu () {