Commit c8ca940b authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Removed config attribute from all objects, using global var instead

Conflicts:
	include/class_CopyPasteHandler.inc
	include/simpleplugin/class_simplePlugin.inc
parent 9bf25982
......@@ -25,7 +25,6 @@ require_once("functions.inc");
require_once("variables.inc");
class passwordRecovery {
var $config;
var $uid;
var $message = array();
var $email_address;
......@@ -72,15 +71,13 @@ class passwordRecovery {
exit;
}
$this->config = $config;
$this->setupSmarty();
$smarty = get_smarty();
/* Generate server list */
$servers = array();
foreach ($this->config->data['LOCATIONS'] as $key => $ignored) {
foreach ($config->data['LOCATIONS'] as $key => $ignored) {
$servers[$key] = $key;
}
......@@ -91,7 +88,7 @@ class passwordRecovery {
} elseif (isset($_GET['directory']) && isset($servers[$_GET['directory']])) {
$this->directory = validate($_GET['directory']);
} else {
$this->directory = $this->config->data['MAIN']['DEFAULT'];
$this->directory = $config->data['MAIN']['DEFAULT'];
if (!isset($servers[$this->directory])) {
$this->directory = key($servers);
......@@ -105,9 +102,8 @@ class passwordRecovery {
}
/* Set config to selected one */
$this->config->set_current($this->directory);
session::global_set('config', $this->config);
$config = $this->config;
$config->set_current($this->directory);
session::global_set('config', $config);
$this->activated = $this->readLdapConfig();
if (!$this->activated) { /* Password recovery has been disabled */
......@@ -231,28 +227,30 @@ class passwordRecovery {
*/
function readLdapConfig()
{
$this->salt = $this->config->get_cfg_value('passwordRecoverySalt');
$this->delay_allowed = $this->config->get_cfg_value('passwordRecoveryValidity');
global $config;
$this->salt = $config->get_cfg_value('passwordRecoverySalt');
$this->delay_allowed = $config->get_cfg_value('passwordRecoveryValidity');
$this->mail_subject = $this->config->get_cfg_value('passwordRecoveryMailSubject');
$this->mail_body = $this->config->get_cfg_value('passwordRecoveryMailBody');
$this->mail2_subject = $this->config->get_cfg_value('passwordRecoveryMail2Subject');
$this->mail2_body = $this->config->get_cfg_value('passwordRecoveryMail2Body');
$this->mail_subject = $config->get_cfg_value('passwordRecoveryMailSubject');
$this->mail_body = $config->get_cfg_value('passwordRecoveryMailBody');
$this->mail2_subject = $config->get_cfg_value('passwordRecoveryMail2Subject');
$this->mail2_body = $config->get_cfg_value('passwordRecoveryMail2Body');
$this->from_mail = $this->config->get_cfg_value('passwordRecoveryEmail');
$this->from_mail = $config->get_cfg_value('passwordRecoveryEmail');
$this->usealternates = $this->config->get_cfg_value('passwordRecoveryUseAlternate');
$this->usealternates = $config->get_cfg_value('passwordRecoveryUseAlternate');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->config->get_cfg_value('passwordRecoveryActivated'), "passwordRecoveryActivated");
return ($this->config->get_cfg_value('passwordRecoveryActivated') == "TRUE");
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $config->get_cfg_value('passwordRecoveryActivated'), "passwordRecoveryActivated");
return ($config->get_cfg_value('passwordRecoveryActivated') == "TRUE");
}
function setupSmarty()
{
global $config;
$smarty = get_smarty();
/* Set template compile directory */
$smarty->compile_dir = $this->config->get_cfg_value("templateCompileDirectory", SPOOL_DIR);
$smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR);
/* Check for compile directory */
if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))) {
......@@ -289,18 +287,19 @@ class passwordRecovery {
function storeToken($temp_password)
{
global $config;
/* Store it in ldap with the salt */
$salt_temp_password = $this->salt.$temp_password.$this->salt;
$sha1_temp_password = "{SHA}".base64_encode(pack("H*", sha1($salt_temp_password)));
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
// Check if token branch is here
$token = get_ou('tokenRDN').get_ou('fusiondirectoryRDN').$this->config->current['BASE'];
$token = get_ou('tokenRDN').get_ou('fusiondirectoryRDN').$config->current['BASE'];
$ldap->cat($token, array('dn'));
if (!$ldap->count()) {
/* It's not, let's create it */
$ldap->cd ($this->config->current['BASE']);
$ldap->cd ($config->current['BASE']);
$ldap->create_missing_trees($token);
if (!$ldap->success()) {
return msgPool::ldaperror($ldap->get_error(),
......@@ -336,13 +335,14 @@ class passwordRecovery {
function checkToken($token)
{
global $config;
$salt_token = $this->salt.$token.$this->salt;
$sha1_token = "{SHA}".base64_encode(pack("H*", sha1($salt_token)));
/* Retrieve hash from the ldap */
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
$token = get_ou('tokenRDN').get_ou('fusiondirectoryRDN').$this->config->current['BASE'];
$token = get_ou('tokenRDN').get_ou('fusiondirectoryRDN').$config->current['BASE'];
$dn = "ou=".$this->uid.",$token";
$ldap->cat($dn);
$attrs = $ldap->fetch();
......@@ -357,6 +357,7 @@ class passwordRecovery {
function checkForSSL()
{
global $config;
$smarty = get_smarty();
/* Check for SSL connection */
......@@ -370,10 +371,10 @@ class passwordRecovery {
}
/* If SSL is forced, just forward to the SSL enabled site */
if ($this->config->get_cfg_value("forcessl") == 'TRUE') {
if ($config->get_cfg_value("forcessl") == 'TRUE') {
header("Location: $ssl");
exit;
} elseif ($this->config->get_cfg_value("warnssl") == 'TRUE') {
} elseif ($config->get_cfg_value("warnssl") == 'TRUE') {
/* Display SSL mode warning? */
$smarty->assign("ssl", "<b>"._("Warning").":</b> ".
_("Session will not be encrypted.").
......@@ -412,18 +413,19 @@ class passwordRecovery {
function getUserDn()
{
global $config;
/* Retrieve dn from the ldap */
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
$objectClasses = array('gosaMailAccount');
if (class_available('personalInfo') && ($this->config->get_cfg_value('privateEmailPasswordRecovery', 'FALSE') == 'TRUE')) {
if (class_available('personalInfo') && ($config->get_cfg_value('privateEmailPasswordRecovery', 'FALSE') == 'TRUE')) {
$objectClasses[] = 'fdPersonalInfo';
}
if (class_available('supannAccount') && ($this->config->get_cfg_value('supannPasswordRecovery', 'TRUE') == 'TRUE')) {
if (class_available('supannAccount') && ($config->get_cfg_value('supannPasswordRecovery', 'TRUE') == 'TRUE')) {
$objectClasses[] = 'supannPerson';
}
$filter = '(&(|(objectClass='.join(')(objectClass=', $objectClasses).'))(uid='.$this->uid.'))';
$ldap->cd($this->config->current['BASE']);
$ldap->cd($config->current['BASE']);
$ldap->search($filter, array('dn'));
if ($ldap->count() < 1) {
......@@ -442,6 +444,7 @@ class passwordRecovery {
/* find the uid of for the given email address */
function step2()
{
global $config;
if ($_POST['email_address'] == "") {
$this->message[] = msgPool::required(_("Email address"));
return;
......@@ -454,14 +457,14 @@ class passwordRecovery {
} else {
$filter = "(&(objectClass=gosaMailAccount)(mail=".$this->email_address."))";
}
if (class_available('personalInfo') && ($this->config->get_cfg_value('privateEmailPasswordRecovery', 'FALSE') == 'TRUE')) {
if (class_available('personalInfo') && ($config->get_cfg_value('privateEmailPasswordRecovery', 'FALSE') == 'TRUE')) {
$filter = '(|'.$filter.'(&(objectClass=fdPersonalInfo)(fdPrivateMail='.$this->email_address.')))';
}
if (class_available('supannAccount') && ($this->config->get_cfg_value('supannPasswordRecovery', 'TRUE') == 'TRUE')) {
if (class_available('supannAccount') && ($config->get_cfg_value('supannPasswordRecovery', 'TRUE') == 'TRUE')) {
$filter = '(|'.$filter.'(&(objectClass=supannPerson)(supannMailPerso='.$this->email_address.')))';
}
$uids = get_list( $filter, "",
$this->config->current['BASE'], array("uid"),
$config->current['BASE'], array("uid"),
GL_SUBSEARCH | GL_NO_ACL_CHECK);
/* Only one uid should be found */
......
......@@ -30,7 +30,6 @@
*/
class CopyPasteHandler
{
var $config;
var $current;
/*!
......@@ -48,16 +47,13 @@ class CopyPasteHandler
var $clean_objects = array();
var $require_update = FALSE;
/*!
* \brief Create CP handler
*
* \param string $config
*/
function __construct(&$config)
function __construct()
{
$this->config = &$config;
$this->current = NULL;
$this->queue = array();
}
......@@ -86,6 +82,7 @@ class CopyPasteHandler
*/
function add_to_queue()
{
global $config;
$dn = func_get_arg(0);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, "add_to_queue");
$action = func_get_arg(1);
......@@ -121,7 +118,7 @@ class CopyPasteHandler
return FALSE;
}
if (!isset($this->config->data['TABS'][$tab_object])) {
if (!isset($config->data['TABS'][$tab_object])) {
trigger_error(sprintf("Specified tab object '%s' does not exists.", $tab_object));
return FALSE;
}
......@@ -164,7 +161,8 @@ class CopyPasteHandler
*/
function load_entry_from_queue($entry, $base)
{
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $entry['dn'], "load_entry_from_queue");
global $config;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $entry['dn'], 'load_entry_from_ldap');
if (!isset($entry['tab_class']) && !isset($entry['type'])) {
return array();
}
......@@ -179,7 +177,7 @@ class CopyPasteHandler
$tab_a = $entry['tab_acl_category'];
// Deprecated
$entry['object'] = new $tab_c($this->config, $this->config->data['TABS'][$tab_o], $entry['dn'], $tab_a);
$entry['object'] = new $tab_c(NULL, $config->data['TABS'][$tab_o], $entry['dn'], $tab_a);
}
$entry['object']->set_acl_base($base);
......
......@@ -46,9 +46,9 @@ class SnapshotCreateDialog extends simplePlugin
);
}
function __construct (&$config, $dn, $parent, $aclCategory)
function __construct ($unused, $dn, $parent, $aclCategory)
{
parent::__construct($config);
parent::__construct();
$this->attributesAccess['description']->setInLdap(FALSE);
$this->object_dn = $dn;
$this->parent = $parent;
......@@ -191,9 +191,9 @@ class SnapshotRestoreDialog extends simplePlugin
);
}
function __construct (&$config, $dn, $parent, $global, $aclCategory)
function __construct ($unused, $dn, $parent, $global, $aclCategory)
{
parent::__construct($config);
parent::__construct();
$this->object_dn = $dn;
$this->parent = $parent;
$this->global = $global;
......
......@@ -29,7 +29,6 @@
* the snapshot functionality
*/
class SnapshotHandler {
var $config;
var $snapshotBases = array();
/*!
......@@ -37,14 +36,13 @@ class SnapshotHandler {
*
* \param config $config
*/
function __construct(&$config)
function __construct()
{
$this->config = $config;
global $config;
/* Prepare base */
$this->snapshotRDN = $this->config->get_cfg_value("snapshotBase");
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$this->snapshotRDN = $config->get_cfg_value("snapshotBase");
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees($this->snapshotRDN);
if (!$ldap->success()) {
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->snapshotRDN, "", get_class()), LDAP_ERROR);
......@@ -58,7 +56,8 @@ class SnapshotHandler {
*/
function enabled()
{
return $this->config->snapshotEnabled();
global $config;
return $config->snapshotEnabled();
}
/*!
......@@ -85,7 +84,8 @@ class SnapshotHandler {
*/
protected function snapshot_dn($dn)
{
return preg_replace("/".preg_quote($this->config->current['BASE'], '/')."$/", "", $dn)
global $config;
return preg_replace("/".preg_quote($config->current['BASE'], '/')."$/", "", $dn)
.$this->snapshotRDN;
}
......@@ -98,11 +98,12 @@ class SnapshotHandler {
*/
function getDeletedSnapshots($objectBase, $raw = FALSE)
{
global $config;
if (!$this->enabled()) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
// Initialize base
$base = $this->snapshot_dn($objectBase);
......@@ -163,11 +164,12 @@ class SnapshotHandler {
*/
function getSnapshots($dn, $raw = FALSE)
{
global $config;
if (!$this->enabled()) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
$objectBase = preg_replace("/^[^,]*./", "", $dn);
......@@ -210,6 +212,7 @@ class SnapshotHandler {
*/
function createSnapshot($dn, $description = array())
{
global $config;
if (!$this->enabled()) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot are disabled but tried to create snapshot');
return;
......@@ -222,7 +225,7 @@ class SnapshotHandler {
$dns = array($dn);
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
/* check if the dn exists */
if (!$ldap->dn_exists($dn)) {
......@@ -285,8 +288,9 @@ class SnapshotHandler {
*/
function removeSnapshot($dn)
{
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn), LDAP_ERROR);
......@@ -300,11 +304,12 @@ class SnapshotHandler {
*/
function getAvailableSnapsShots($dn, $raw = FALSE)
{
global $config;
if (!$this->enabled()) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
/* Prepare bases and some other infos */
$base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
......@@ -345,11 +350,12 @@ class SnapshotHandler {
*/
function getAllDeletedSnapshots($base_of_object, $raw = FALSE)
{
global $config;
if (!$this->enabled()) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
/* Prepare bases */
$new_base = $this->snapshot_dn($base_of_object);
......@@ -398,12 +404,13 @@ class SnapshotHandler {
*/
function restoreSnapshot($dn)
{
global $config;
if (!$this->enabled()) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot are disabled but tried to restore snapshot');
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap = $config->get_ldap_link();
/* Get the snapshot */
$ldap->cat($dn);
......
......@@ -316,7 +316,7 @@ class config {
*
* Example usage:
* \code
* $ldap = $this->config->get_ldap_link();
* $ldap = $config->get_ldap_link();
* \endcode
*
* \param boolean $sizelimit Weither to impose a sizelimit on the LDAP object or not.
......@@ -772,7 +772,7 @@ class config {
*
* Example usage:
* \code
* if ($this->config->boolValueIsTrue("main", "copyPaste")) {
* if ($config->boolValueIsTrue("main", "copyPaste")) {
* echo "Copy Paste Handling is enabled";
* }
* \endcode
......@@ -804,7 +804,7 @@ class config {
*
* Example usage:
* \code
* $postcmd = $this->config->search(get_class($this), 'POSTMODIFY');
* $postcmd = $config->search(get_class($this), 'POSTMODIFY');
* \endcode
*
* \param string $class The class name
......
......@@ -542,20 +542,20 @@ class filter
*
* \param string $value
*/
function getCompletitionList($config, $tag, $value = "*")
function getCompletitionList($cfg, $tag, $value = "*")
{
global $class_mapping;
$res = array();
// Is backend available?
$backend = "filter".$config['backend'];
$backend = "filter".$cfg['backend'];
if (!isset($class_mapping["$backend"])) {
die("Invalid backend specified in search config.");
}
// Load filter and attributes
$filter = $config['filter'];
$attributes = $config['attribute'];
$filter = $cfg['filter'];
$attributes = $cfg['attribute'];
if (!is_array($attributes)) {
$attributes = array($attributes);
}
......@@ -567,9 +567,9 @@ class filter
// Make filter
$filter = preg_replace("/\\$$tag/", ldap_escape_f($value), $filter);
if (isset($config['base']) && isset($config['scope']) && isset($config['category'])) {
$result = call_user_func(array($backend, 'query'), $this, $config['base'], $config['scope'], $filter, $attributes,
$config["category"], $config["objectStorage"]);
if (isset($cfg['base']) && isset($cfg['scope']) && isset($cfg['category'])) {
$result = call_user_func(array($backend, 'query'), $this, $cfg['base'], $cfg['scope'], $filter, $attributes,
$cfg["category"], $cfg["objectStorage"]);
} else {
$result = call_user_func(array($backend, 'query'), $this, $this->base, $this->scope, $filter, $attributes,
$this->category, $this->objectStorage);
......@@ -602,9 +602,9 @@ class filter
// Introduce maximum number of entries
$max = 25;
foreach ($this->autocompleters as $tag => $config) {
foreach ($this->autocompleters as $tag => $cfg) {
if (isset($_POST[$tag])) {
$result = $this->getCompletitionList($config, $tag, $_POST[$tag]);
$result = $this->getCompletitionList($cfg, $tag, $_POST[$tag]);
$result = array_unique($result);
asort($result);
......
......@@ -258,8 +258,8 @@ class listing {
// Evaluate columns to be exported
if (isset($this->xmlData['table']['column'])) {
foreach ($this->xmlData['table']['column'] as $index => $config) {
if (isset($config['export']) && $config['export'] == "true") {
foreach ($this->xmlData['table']['column'] as $index => $cfg) {
if (isset($cfg['export']) && $cfg['export'] == "true") {
$this->exportColumns[] = $index;
}
}
......@@ -292,29 +292,29 @@ class listing {
}
if (isset($this->xmlData['table']['column'])) {
foreach ($this->xmlData['table']['column'] as $index => $config) {
foreach ($this->xmlData['table']['column'] as $index => $cfg) {
// Initialize everything to one direction
if ($sortInit) {
$this->sortDirection[$index] = FALSE;
}
$sorter = "";
if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
isset($config['sortType'])) {
$this->sortAttribute = $config['sortAttribute'];
$this->sortType = $config['sortType'];
if ($index == $this->sortColumn && isset($cfg['sortAttribute']) &&
isset($cfg['sortType'])) {
$this->sortAttribute = $cfg['sortAttribute'];
$this->sortType = $cfg['sortType'];
$sorter = "&nbsp;<img class='center' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='geticon.php?context=actions&amp;size=16&amp;icon=view-sort-".($this->sortDirection[$index]?"descending":"ascending")."' alt='".($this->sortDirection[$index]?_('Sort up'):_('Sort down'))."'>";
}
$sortable = (isset($config['sortAttribute']));
$sortable = (isset($cfg['sortAttribute']));
$link = "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
if (isset($config['label'])) {
if (isset($cfg['label'])) {
if ($sortable) {
$this->header[$index] = "<th ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></th>";
$this->header[$index] = "<th ".$this->colprops[$index]."><a $link>"._($cfg['label'])."$sorter</a></th>";
} else {
$this->header[$index] = "<th ".$this->colprops[$index].">"._($config['label'])."</th>";
$this->header[$index] = "<th ".$this->colprops[$index].">"._($cfg['label'])."</th>";
}
$this->plainHeader[] = _($config['label']);
$this->plainHeader[] = _($cfg['label']);
} else {
if ($sortable) {
$this->header[$index] = "<th ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></th>";
......@@ -398,13 +398,13 @@ class listing {
// Render defined department columns, fill the rest with some stuff
$rest = $this->numColumns - 1;
foreach ($this->xmlData['table']['department'] as $index => $config) {
foreach ($this->xmlData['table']['department'] as $index => $cfg) {
$colspan = 1;
if (isset($config['span'])) {
$colspan = $config['span'];
if (isset($cfg['span'])) {
$colspan = $cfg['span'];
$this->useSpan = TRUE;
}
$result .= "<td colspan='$colspan' ".$this->colprops[$index].">".$this->renderCell($config['value'], $entry, $row)."</td>";
$result .= "<td colspan='$colspan' ".$this->colprops[$index].">".$this->renderCell($cfg['value'], $entry, $row)."</td>";
$rest -= $colspan;
}
......@@ -429,8 +429,8 @@ class listing {
$trow .= "<td style='text-align:center;width:20px;'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
}
foreach ($this->xmlData['table']['column'] as $index => $config) {
$renderedCell = $this->renderCell($config['value'], $entry, $row);
foreach ($this->xmlData['table']['column'] as $index => $cfg) {
$renderedCell = $this->renderCell($cfg['value'], $entry, $row);
$trow .= "<td ".$this->colprops[$index].">".$renderedCell."</td>\n";
// Save rendered column
......@@ -689,11 +689,11 @@ class listing {
$layout = preg_replace("/\|$/", "", $layout);
$cols = explode("|", $layout);
foreach ($cols as $index => $config) {
if ($config != "") {
foreach ($cols as $index => $cfg) {
if ($cfg != "") {
$res = "";
$classes = "";
$components = explode(';', $config);
$components = explode(';', $cfg);
foreach ($components as $part) {
if (preg_match("/^r$/", $part)) {
$res .= "text-align:right;";
......@@ -740,22 +740,22 @@ class listing {
}
function renderCell($data, $config, $row)
function renderCell($data, $cfg, $row)
{
// Replace flat attributes in data string
for ($i = 0; $i < $config['count']; $i++) {
$attr = $config[$i];
for ($i = 0; $i < $cfg['count']; $i++) {
$attr = $cfg[$i];
$value = "";
if (is_array($config[$attr])) {