removed old cache

This commit is contained in:
Roland Gruber 2010-11-23 21:23:25 +00:00
parent 57f49a0e1f
commit 6e5f7757b6
8 changed files with 13 additions and 242 deletions

View File

@ -3,6 +3,7 @@
<link rel="stylesheet" type="text/css" href="style/layout.css"><link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body>
<div style="text-align: center;">
<h1>LDAP Account Manager - Code overview</h1>
@ -64,7 +65,7 @@ lists</a></li>
</li>
</ul>
<ul>
<li><a href="other_libs.htm#cache">LDAP cache</a></li>
<li><a href="other_libs.htm#lists">Account lists</a></li>
<li><a href="other_libs.htm#status">Status messages</a></li>
<li><a href="other_libs.htm#treeSchema">Tree view and schema

View File

@ -1,21 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-15"
http-equiv="content-type">
<title>Other libraries</title>
<html><head>
<meta content="text/html; charset=ISO-8859-15" http-equiv="content-type"><title>Other libraries</title>
<link rel="stylesheet" type="text/css" href="style/layout.css">
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">
</head>
<body>
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body>
<h1 style="text-align: center;">Other libraries<br>
</h1>
<br>
<h2><a name="lamdaemon"></a>Lamdaemon (lamdaemon.pl)<br>
</h2>
<br>
<h2><a name="cache"></a>LDAP cache (cache.inc)</h2>
<br>
<h2><a name="lists"></a>Account lists (lists.inc)</h2>
This file provides basic functions used by the account lists. They
cover major parts of the HTML output.<br>
@ -24,8 +20,7 @@ They allow to have translated descriptions of the most common
attributes.<br>
<br>
<h2><a name="status"></a>Status messages (status.inc)</h2>
Status.inc provides the function <span
style="font-weight: bold; font-style: italic;">StatusMessage()</span>
Status.inc provides the function <span style="font-weight: bold; font-style: italic;">StatusMessage()</span>
which can be used to display error, warning and information messages.<br>
The function uses preg_replace() to convert the special tags to HTML
tags. The message variables are included with printf().<br>
@ -36,8 +31,7 @@ The parameters of <span style="font-weight: bold; font-style: italic;">StatusMes
<h2><a name="treeSchema"></a>Tree view and schema browser</h2>
The files tree.inc and schema.inc contain functions which are needed by
the tree view and the schema browser.<br>
These functions were copied from <a
href="http://sourceforge.net/projects/phpldapadmin/">phpLDAPadmin</a>
These functions were copied from <a href="http://sourceforge.net/projects/phpldapadmin/">phpLDAPadmin</a>
(PLA).<br>
<br>
<ul>
@ -47,5 +41,4 @@ These functions were copied from <a
browser (from schema_functions.php in PLA)<br>
</li>
</ul>
</body>
</html>
</body></html>

View File

@ -933,10 +933,8 @@ Have fun!
of LDAP entries. If you would like to use it then enter the LDAP
suffix at "Tree suffix".</para>
<para>Some LDAP queries are internally cached by LAM. You can
specify how long LAM should use cached data. The search limit is
used to reduce the number of search results which are returned by
your LDAP server.</para>
<para>The search limit is used to reduce the number of search
results which are returned by your LDAP server.</para>
<para>The access level specifies if LAM should allow to modify LDAP
entries. This feature is only available in LAM Pro. LAM non-Pro

View File

@ -1,204 +0,0 @@
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
Copyright (C) 2007 Roland Gruber
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Provides a cache for LDAP attributes.
*
* @author Tilo Lutz
* @author Roland Gruber
* @package lib
*/
/** en/decryption functions */
include_once('ldap.inc');
/**
* This class contains all functions which are needed to manage the LDAP cache.
*
* @package lib
*/
class cache {
/** This variable contains the cache */
private $ldapcache;
/** This variable contains a list and their scope of attributes which should be cached */
private $attributes;
/** This is the last timestamp on which the LDAP cache has been refreshed */
private $time;
/**
* Constructor.
*
* @return cache cache object
*/
function __construct() {
$this->time = 0;
$this->attributes = array();
}
/**
* This function adds attributes to the cache.
*
* @param array $attributes syntax: is array( scope1 => array ( attributes ), scope2 => array ( attributes ), ...)
*/
private function add_cache($attributes) {
if (!is_array($attributes)) trigger_error('Argument of add_cache must be : array ( scope => array(attribute1(string), attribute2(string), ..), scope => ... ).', E_USER_ERROR);
foreach ($attributes as $attribute) {
if (!is_array($attribute)) trigger_error('Argument of add_cache must be : array ( scope => array(attribute1(string), attribute2(string), ..), scope => ... ).', E_USER_ERROR);
foreach ($attribute as $singleattribute) {
if (!is_string($singleattribute)) trigger_error('Argument of add_cache must be : array ( scope => array(attribute1(string), attribute2(string), ..), scope => ... ).', E_USER_ERROR);
}
}
$scopes = array_keys($attributes);
foreach ($scopes as $scope) {
for ($i=0; $i<count($attributes[$scope]); $i++ ) {
if (!@in_array($attributes[$scope][$i] ,$this->attributes[$scope])) $this->attributes[$scope][] = $attributes[$scope][$i];
}
}
// Rebuild cache
$this->refresh_cache(true);
}
/**
* Queries the cache for a list of LDAP entries and their attributes.
*
* @param mixed $attributes One (string) or many (array) attribute names.
* @param string $objectClass The resulting entries need to contain this object class.
* @param mixed $scopelist the account type(s) as string or array, all scopes if NULL given
* @return array The found LDAP entries.
* <br>Format: array(dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) if $attributes is of type string
* <br>or array(dn1 => array(uid => array(myuid), uidNumber => array(1234)), ... ) if $attributes is an array
*
*/
public function get_cache($attributes, $objectClass, $scopelist) {
$return = array();
$this->refresh_cache();
if (is_array($scopelist)) $scopes = $scopelist;
elseif (is_string($scopelist)) $scopes = array($scopelist);
else $scopes = getTypes();
// Add cache entry dynamic
if (!is_array($attributes)) $attributes = array($attributes);
$add = array();
foreach ($scopes as $scope) {
for ($i = 0; $i < sizeof($attributes); $i++) {
if (!@in_array($attributes[$i], $this->attributes[$scope])) $add[$scope][] = $attributes[$i];
}
}
if (count($add)!=0) $this->add_cache($add);
foreach ($scopes as $scope) {
if (isset($this->ldapcache[$scope])) {
$DNs = array_keys($this->ldapcache[$scope]);
foreach ($DNs as $dn) {
// skip entries which do not fit to search
if (!in_array($objectClass, $this->ldapcache[$scope][$dn]['objectClass'])) continue;
for ($i = 0; $i < sizeof($attributes); $i++) {
if (isset($this->ldapcache[$scope][$dn][$attributes[$i]])) {
if (sizeof($attributes) > 1) {
$return[$dn][$attributes[$i]] = $this->ldapcache[$scope][$dn][$attributes[$i]];
}
else {
$return[$dn] = $this->ldapcache[$scope][$dn][$attributes[$i]];
}
}
}
}
}
}
return $return;
}
/**
* This function refreshes the cache.
*
* @param boolean $rebuild forces a refresh if set to true
*/
public function refresh_cache($rebuild=false) {
if ($this->time + $_SESSION['config']->get_cacheTimeoutSec() < time() || $rebuild) {
// unset old cache
unset ($this->ldapcache);
$scopes = array_keys($this->attributes);
foreach ($scopes as $scope) {
// Get suffix
$suffix = $_SESSION['config']->get_Suffix($scope);
// Get Data from ldap
$search = $this->attributes[$scope];
$search[] = 'objectClass';
$result = @ldap_search($_SESSION['ldap']->server(), escapeDN($suffix), 'objectClass=*',
$search, 0, $_SESSION['config']->get_searchLimit(), 0, LDAP_DEREF_NEVER);
if ($result) {
// Write search result in array
$entry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
while ($entry) {
$dn = (ldap_get_dn($_SESSION['ldap']->server(), $entry));
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
// unset double entries
for ($i=0; $i<count($attr); $i++) {
if (isset($attr[$i])) unset($attr[$i]);
}
// unset every count entry
unset ($attr['count']);
$attributes = array_keys($attr);
foreach ($attributes as $attribute) {
unset ($attr[$attribute]['count']);
}
// Write new cache entry
$addcache = $attr;
unset ($addcache['objectClass']);
if (count($addcache)!=0) $this->ldapcache[$scope][$dn] = $attr;
$entry = ldap_next_entry($_SESSION['ldap']->server(), $entry);
}
ldap_free_result($result);
}
}
$this->time = time();
}
}
/**
* Encrypts LDAP cache before saving to session file.
*
* @return array list of variables to save
*/
function __sleep() {
$attrs = array("attributes", "time");
if (isset($this->ldapcache)) {
$this->ldapcache = $_SESSION['ldap']->encrypt(serialize($this->ldapcache));
$attrs[] = 'ldapcache';
}
// define which attributes to save
return $attrs;
}
/**
* Decrypts LDAP cache after loading from session file.
*/
function __wakeup() {
$this->ldapcache = unserialize($_SESSION['ldap']->decrypt($this->ldapcache));
}
}
?>

View File

@ -31,8 +31,6 @@ $Id$
* @author Roland Gruber
*/
/** LDAP caches */
include_once("cache.inc");
/** some helper functions */
include_once("account.inc");
/** parent class of account modules */
@ -2023,7 +2021,6 @@ class accountContainer {
$this->module[$singlemodule]->postModifyActions($this->isNewAccount, $currentAccountAttributes);
}
}
$_SESSION['cache']->refresh_cache(true);
return $errors;
}

View File

@ -62,9 +62,6 @@ if (!isset($_SESSION['loggedIn']) || ($_SESSION['loggedIn'] !== true)) {
// Set correct language, codepages, ....
setlanguage();
if (!isset($_SESSION['cache'])) {
$_SESSION['cache'] = new cache();
}
if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
// Create account list
foreach ($_SESSION['delete_dn'] as $dn) {
@ -233,7 +230,6 @@ if (isset($_POST['delete'])) {
echo "<br>\n";
}
}
$_SESSION['cache']->refresh_cache(true);
echo "<br>\n";
echo "<br><button class=\"smallPadding\" name=\"cancel\" id=\"backButton\">" . _('Back to list') . "</button>\n";
echo "</div>\n";

View File

@ -28,8 +28,6 @@ $Id$
* @author Roland Gruber
*/
/** LDAP attibute cache */
include_once('../lib/cache.inc');
/** config object */
include_once('../lib/config.inc');
@ -38,11 +36,6 @@ startSecureSession();
setlanguage();
// create cache object
if (!isset($_SESSION['cache'])) {
$_SESSION['cache'] = new cache();
}
// check if all suffixes in conf-file exist
$conf = $_SESSION['config'];
$new_suffs = array();

View File

@ -38,8 +38,6 @@ include_once('../lib/ldap.inc');
include_once('../lib/status.inc');
/** account modules */
include_once('../lib/modules.inc');
/** LAM cache */
include_once('../lib/cache.inc');
// Start session
@ -123,7 +121,6 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po
}
// all accounts have been created
else {
$_SESSION['cache']->refresh_cache(true);
echo "<div class=\"title\">\n";
echo "<h2 class=\"titleText\">" . _("LDAP upload has finished") . "</h2>\n";
echo "</div>";