FusionDirectory
 All Data Structures Files Functions Variables
class_filterLDAPBlacklist.inc
1 <?php
2 
3 /*
4  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
5  Copyright (C) 2003 Cajus Pollmeier
6  Copyright (C) 2011-2016 FusionDirectory
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
24 
25  static function query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = "")
26  {
27  $result = filterLDAP::query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage);
28  return filterLDAPBlacklist::filterByBlacklist($result);
29  }
30 
31  static function filterByBlacklist($entries)
32  {
33  if (session::is_set('filterWhitelist')) {
34  $wlist = session::get('filterWhitelist');
35  if (!empty($wlist)) {
36  foreach ($entries as $id => $entry) {
37  if (in_array($entry['dn'], $wlist['dn'])) {
38  continue;
39  }
40  foreach ($wlist['branches'] as $branch) {
41  if (preg_match('/'.preg_quote($branch, '/').'$/', $entry['dn'])) {
42  continue 2;
43  }
44  }
45  unset($entries[$id]);
46  }
47  }
48  }
49  if (session::is_set('filterBlacklist')) {
50  $blist = session::get('filterBlacklist');
51  foreach ($blist as $attr_name => $attr_values) {
52  foreach ($attr_values as $match) {
53  foreach ($entries as $id => $entry) {
54  if (isset($entry[$attr_name])) {
55  $test = $entry[$attr_name];
56  if (!is_array($test)) {
57  $test = array($test);
58  }
59  if (in_array($match, $test)) {
60  unset($entries[$id]);
61  }
62  }
63  }
64  }
65  }
66  }
67  return array_values($entries);
68  }
69 }
70 ?>
static & get($name)
Accessor of a session.
static query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage=array(""))
Query.
static is_set($name)
Check if the name of the session is set.