Commit ab83d235 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2595 Cleaning some code

parent 47794f97
......@@ -83,8 +83,8 @@ class baseSelector {
function setBase($base)
{
if (isset($this->pathMapping[$base])) {
$this->base = $base;
$this->lastState = TRUE;
$this->base = $base;
$this->lastState = TRUE;
return $this->update(TRUE);
} else {
$this->lastState = FALSE;
......@@ -124,17 +124,14 @@ class baseSelector {
global $config;
$this->pathMapping = array();
$selected = ($this->base == $config->current['BASE']?"Selected":"");
$first = TRUE;
$last_indent = 2;
$selected = ($this->base == $config->current['BASE']);
foreach ($bases as $base => $dummy) {
// Build path style display
$elements = explode(',', substr($base, 0, strlen($base) - strlen($config->current['BASE'])));
$elements = array_reverse($elements, TRUE);
$this->pathMapping[$base] = ($base == $config->current['BASE']? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements))));
$this->pathMapping[$base] = ($selected? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements))));
}
// Save bases to session for autocompletion
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
......@@ -30,7 +29,6 @@
*/
class filter
{
var $xmlData;
var $elements = array();
var $elementValues = array();
......@@ -55,8 +53,6 @@ class filter
*/
function filter($filename)
{
global $config;
// Load eventually passed filename
if (!$this->load($filename)) {
die("Cannot parse $filename!");
......@@ -629,7 +625,6 @@ class filter
*/
function processAutocomplete()
{
global $class_mapping;
$result = array();
// Introduce maximum number of entries
......
......@@ -34,8 +34,8 @@ define("SPECIALS_OVERRIDE", TRUE);
* ldap operations easy
*/
class LDAP{
class LDAP
{
var $hascon = FALSE;
var $reconnect = FALSE;
var $tls = FALSE;
......@@ -1073,7 +1073,6 @@ class LDAP{
$admin = escapeshellarg($this->binddn);
$filter = escapeshellarg($filter);
$cmd = "ldapsearch -x -LLLL -D {$admin} {$filter} {$limit} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
// Create list of process pipes
......@@ -1248,8 +1247,9 @@ class LDAP{
trigger_error("Can't import ldif, can't read config object.");
}
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$ret = FALSE;
$rows = preg_split("/\n/", $str_attr);
......@@ -1520,7 +1520,7 @@ class LDAP{
die ("Can't bind to LDAP. No check possible!");
}
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r = ldap_bind ($ds, $admin, $password);
ldap_bind ($ds, $admin, $password);
/* Get base to look for naming contexts */
$sr = @ldap_read ($ds, "", "objectClass=*", array("+"));
......@@ -1538,7 +1538,7 @@ class LDAP{
die ("Can't bind to LDAP. No check possible!");
}
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r = ldap_bind ($ds, $admin, $password);
ldap_bind ($ds, $admin, $password);
/* Get base to look for naming contexts */
$sr = @ldap_read ($ds, "", "objectClass=*", array("+"));
......
......@@ -396,8 +396,7 @@ class management
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $target, "Entry removel confirmed!");
foreach ($this->dns as $key => $dn) {
foreach ($this->dns as $dn) {
// Check permissions, are we allowed to remove this object?
$acl = $this->ui->get_permissions($dn, $aclCategory."/".$this->aclPlugin);
if (preg_match("/d/", $acl)) {
......@@ -758,7 +757,7 @@ class management
$msgs = $this->tabObject->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return "";
return;
} else {
$this->tabObject->save();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, "Entry saved!");
......@@ -770,7 +769,7 @@ class management
$msgs = $this->dialogObject->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return "";
return;
} else {
$this->dialogObject->save();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, "Entry saved!");
......
......@@ -41,8 +41,6 @@ class objects
*/
static function ls ($type, $attrs = NULL, $ou = NULL, $filter = '')
{
global $config;
if ($attrs === NULL) {
$infos = self::infos($type);
$attrs = $infos['mainAttr'];
......@@ -95,8 +93,6 @@ class objects
*/
static function count ($type, $ou = NULL, $filter = '')
{
global $config;
try {
$ldap = self::search($type, array('dn'), $ou, $filter);
} catch (EmptyFilterException $e) {
......@@ -229,8 +225,6 @@ class objects
static function isOfType ($attrs, $type)
{
global $config;
//TODO : cache ldapFilter objects?
$infos = self::infos($type);
$filter = ldapFilter::parse($infos['filter']);
......
......@@ -106,9 +106,6 @@ class xml {
//Initializations
$xml_array = array();
$parents = array();
$opened_tags = array();
$arr = array();
$current = &$xml_array; //Refference
......
......@@ -734,7 +734,6 @@ function add_lock($object, $user)
unset($cache['READ_ONLY'][$object]);
}
/* Just a sanity check... */
if ($object == "" || $user == "") {
msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
......@@ -1342,7 +1341,6 @@ function convert_department_dn($dn, $base = NULL)
return "/";
}
$dep = "";
foreach (explode(',', $dn) as $rdn) {
$dep = preg_replace("/^[^=]+=/", "", $rdn)."/".$dep;
......@@ -1873,7 +1871,6 @@ function range_selector($dcnt, $start, $range = 25, $post_var = FALSE)
}
$ppage = (int)(($start / $range) + 0.5);
/* Align selected page to +/- max_entries/2 */
$begin = $ppage - $max_entries / 2;
$end = $ppage + $max_entries / 2;
......@@ -3098,13 +3095,14 @@ function generate_smb_nt_hash($password)
/* Lock or unlock samba account */
function lock_samba_account($mode, $attrs)
{
global $config;
$modify = array('sambaNTPassword' => $attrs['sambaNTPassword'][0]);
if ($config->get_cfg_value("sambaGenLMPassword", "FALSE") == "TRUE") {
$modify['sambaLMPassword'] = $attrs['sambaLMPassword'][0];
} else {
$modify['sambaLMPassword'] = array();
}
foreach ($modify as $key => &$pwd) {
foreach ($modify as &$pwd) {
if (is_array($pwd)) {
continue;
}
......@@ -3118,7 +3116,7 @@ function lock_samba_account($mode, $attrs)
$pwd = preg_replace("/^\!/", "", $pwd);
}
}
unset($value);
unset($pwd);
return $modify;
}
......@@ -3659,7 +3657,8 @@ function fix_dos_linebreaks($str)
return preg_replace('/\\r\\n/', "\n", $str);
}
function load_all_classes() {
function load_all_classes()
{
global $BASE_DIR, $class_list, $class_mapping;
/* Initially load all classes */
$class_list = get_declared_classes();
......
......@@ -291,10 +291,10 @@ class ogroup_old extends plugin
msg_dialog::display(_("Error"), sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>", $str), ERROR_DIALOG);
}
foreach($objects as $object){
foreach ($objects as $object){
$tmp = "";
foreach($this->memberList as $obj){
foreach ($this->memberList as $obj){
$tmp .= $obj['type'];
}
......
......@@ -56,9 +56,9 @@ class Step_Checks extends setup_step
/* Execute all checks */
function run_checks()
{
$this->basic_checks = array();
$this->config_checks = array();
$this->is_writeable = array();
$this->basic_checks = array();
$this->config_checks = array();
$this->is_writeable = array();
/* PHP version check */
$N = _("Checking PHP version");
......@@ -157,7 +157,6 @@ class Step_Checks extends setup_step
$M = FALSE;
$this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
/* PHP Configuration checks */
/* Register_globals off */
......@@ -168,7 +167,6 @@ class Step_Checks extends setup_step
$M = FALSE;
$this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
/* session lifetime set to >=86400 seconds ? */
$N = "session.gc_maxlifetime &gt;= <b>86400</b>";
$D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
......@@ -227,9 +225,7 @@ class Step_Checks extends setup_step
$M = FALSE;
$this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
/* Configuration file
*/
/* Configuration file */
/* Check if we can create a config file.*/
$N = _("Configuration writeable");
......@@ -240,7 +236,6 @@ class Step_Checks extends setup_step
|| (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR));
$M = FALSE;
$this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
}
......
......@@ -163,7 +163,6 @@ class Step_Config3 extends setup_step
function save_config_in_ldap ()
{
global $BASE_DIR;
$cv = $this->parent->captured_values;
$attrs = array(
......
......@@ -77,7 +77,8 @@ class Step_Finish extends setup_step
function execute()
{
global $config, $BASE_DIR;
global $BASE_DIR;
if (!function_exists("posix_getgrgid")) {
$webgroup = "";
} else {
......@@ -94,7 +95,7 @@ class Step_Finish extends setup_step
* - Permisssion are set correctly
*/
if(isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
if (isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
$this->insertConfigDefaults();
session::destroy();
header("Location: index.php");
......@@ -110,13 +111,13 @@ class Step_Finish extends setup_step
if ($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
$err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
} elseif(!$exists) {
} elseif (!$exists) {
$err_msg = _("The configuration is currently not readable or it does not exists.");
}
$smarty = get_smarty();
$smarty->assign("err_msg", $err_msg);
$smarty->assign("msg2", sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't."),CONFIG_DIR,CONFIG_FILE));
$smarty->assign("msg2", sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't."), CONFIG_DIR, CONFIG_FILE));
$smarty->assign("cv", $this->parent->captured_values);
return $smarty->fetch("$BASE_DIR/setup/setup_finish.tpl");
......
......@@ -112,7 +112,7 @@ class Step_Migrate extends setup_step
/* One valid admin dn */
var $valid_admin = FALSE;
function Step_Migrate()
function __construct()
{
$this->update_strings();
}
......@@ -554,7 +554,6 @@ class Step_Migrate extends setup_step
$this->show_details = $only_ldif;
/* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap = $this->get_ldap_link();
/* Add gosaAccount objectClass to the selected users */
......@@ -679,7 +678,6 @@ class Step_Migrate extends setup_step
$this->show_details = $only_ldif;
/* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap = $this->get_ldap_link();
/* Add gosaDepartment objectClass to each selected entry */
......@@ -785,7 +783,7 @@ class Step_Migrate extends setup_step
$valid_admin = $member;
}
$valid_users .= $users[$member].", ";
$FD_1_0_8_found = TRUE;
$FD_1_0_8_found = TRUE;
}
if (isset($groups[$member])) {
$ldap->cat($member);
......@@ -832,7 +830,7 @@ class Step_Migrate extends setup_step
$valid_admin = $member;
}
$valid_users .= $users[$member].", ";
$FD_1_0_7_found = TRUE;
$FD_1_0_7_found = TRUE;
}
}
if (isset($groups[$member])) {
......@@ -878,7 +876,7 @@ class Step_Migrate extends setup_step
$valid_admin = $member;
}
$valid_users .= $users[$member].", ";
$FD_1_0_7_found = TRUE;
$FD_1_0_7_found = TRUE;
}
if (isset($groups[$member])) {
$ldap->cat($member);
......@@ -963,12 +961,11 @@ class Step_Migrate extends setup_step
if ($attrs = $ldap->fetch()) {
$roledn = $attrs['dn'];
} else {
$roledn = 'cn=admin,'.get_ou(aclRoleRDN).$cv['base'];
if ($only_ldif) {
} else {
$roledn = 'cn=admin,'.get_ou('aclRoleRDN').$cv['base'];
if (!$only_ldif) {
$ldap->create_missing_trees($roledn);
$ldap->cd($roledn);
$attrs_role = array(
$attrs_role = array(
'cn' => 'admin',
'objectclass' => array( 'top', 'gosaRole' ),
'gosaAclTemplate' => '0:all;cmdrw'
......@@ -1992,7 +1989,6 @@ class Step_Migrate extends setup_step
function move($source, $destination)
{
/* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap = $this->get_ldap_link();
/* Update object references in gosaGroupOfNames */
......@@ -2304,7 +2300,6 @@ class Step_Migrate extends setup_step
function migrate_services()
{
/* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap = $this->get_ldap_link();
/* Handle each service */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment