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

🚑 fix(core) Lots of sonar fixes

issue #5831
parent e3934338
......@@ -35,8 +35,6 @@ class config
var $config_found = FALSE;
var $tags = array();
var $level = 0;
var $gpc = 0;
var $section = '';
var $currentLocation = '';
/*!
......@@ -107,8 +105,6 @@ class config
$this->config_found = FALSE;
$this->tags = array();
$this->level = 0;
$this->gpc = 0;
$this->section = '';
$this->currentLocation = '';
$this->parse($this->filename);
......@@ -569,17 +565,17 @@ class config
continue;
}
$dn = $attrs['dn'];
$data = objects::infos($oc);
$dn = $attrs['dn'];
$infos = objects::infos($oc);
$this->department_info[$dn] = array(
'img' => $data['icon'],
'img' => $infos['icon'],
'description' => (isset($attrs['description'][0]) ? $attrs['description'][0] : ''),
'name' => $attrs[$data['mainAttr']][0]
'name' => $attrs[$infos['mainAttr']][0]
);
/* Only assign non-root departments */
if ($dn != $result['/']) {
$c_dn = convert_department_dn($dn).' ('.$data['mainAttr'].')';
$c_dn = convert_department_dn($dn).' ('.$infos['mainAttr'].')';
$result[$c_dn] = $dn;
}
}
......@@ -882,8 +878,8 @@ class config
if (isset($plInfo['plCategory'])) {
/* Walk through supplied list and feed only translated categories */
$cats = array();
foreach ($plInfo['plCategory'] as $idx => $data) {
$cat = (is_numeric($idx) ? $data : $idx);
foreach ($plInfo['plCategory'] as $idx => $infos) {
$cat = (is_numeric($idx) ? $infos : $idx);
$cats[] = $cat;
if (!isset($this->data['CATEGORIES'][$cat])) {
$this->data['CATEGORIES'][$cat] = array( 'classes' => array('0') );
......@@ -893,11 +889,11 @@ class config
}
if (!is_numeric($idx)) {
/* Non numeric index means -> base object containing more informations */
$this->data['CATEGORIES'][$cat]['description'] = $data['description'];
if (!is_array($data['objectClass'])) {
$data['objectClass'] = array($data['objectClass']);
$this->data['CATEGORIES'][$cat]['description'] = $infos['description'];
if (!is_array($infos['objectClass'])) {
$infos['objectClass'] = array($infos['objectClass']);
}
$this->data['CATEGORIES'][$cat]['objectClass'] = $data['objectClass'];
$this->data['CATEGORIES'][$cat]['objectClass'] = $infos['objectClass'];
}
}
$plInfo['plCategory'] = $cats;
......
......@@ -753,11 +753,11 @@ class listing
function processElementFilter($type, $index, $data, $cfg, $row)
{
if (isset($this->filterCache[$type.$index])) {
$filters = $this->filterCache[$type.$index];
$filtersData = $this->filterCache[$type.$index];
} else {
preg_match_all('/%{filter:([^(]+)\((.*)\)}/', $data, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
$filters = array();
$filtersData = array();
foreach ($matches as $match) {
$cl = '';
$method = '';
......@@ -772,13 +772,13 @@ class listing
// Prepare params for function call
preg_match_all('/"[^"]+"|[^,]+/', $match[2][0], $parts);
$filters[$match[0][0]] = array($cl, $method, $parts[0], $match[0][1]);
$filtersData[$match[0][0]] = array($cl, $method, $parts[0], $match[0][1]);
}
$this->filterCache[$type.$index] = $filters;
$this->filterCache[$type.$index] = $filtersData;
}
foreach ($filters as $filterstring => $filter) {
foreach ($filtersData as $filterstring => $filter) {
list ($cl, $method, $parts, $offset) = $filter;
$params = array();
foreach ($parts as $param) {
......
......@@ -985,10 +985,8 @@ class userinfo
$blacklist = $config->get_cfg_value('PluginsMenuBlacklist', array());
foreach ($blacklist as $item) {
list ($group, $p) = explode('|', $item, 2);
if ($plugin == $p) {
if (in_array($group, $this->groups) || in_array($group, $this->roles)) {
return TRUE;
}
if (($plugin == $p) && (in_array($group, $this->groups) || in_array($group, $this->roles))) {
return TRUE;
}
}
......
......@@ -1718,21 +1718,17 @@ function scan_directory($path, $sort_desc = FALSE)
$ret = FALSE;
/* is this a dir ? */
if (is_dir($path)) {
/* is this path a readable one */
if (is_dir($path) && is_readable($path)) {
/* Get contents and write it into an array */
$ret = array();
/* is this path a readable one */
if (is_readable($path)) {
$dir = opendir($path);
/* Get contents and write it into an array */
$ret = array();
$dir = opendir($path);
/* Is this a correct result ?*/
if ($dir) {
while ($fp = readdir($dir)) {
$ret[] = $fp;
}
/* Is this a correct result ?*/
if ($dir) {
while ($fp = readdir($dir)) {
$ret[] = $fp;
}
}
}
......@@ -1766,14 +1762,11 @@ function clean_smarty_compile_dir($directory)
if (!compare_revision($revision_file, FD_VERSION)) {
// If revision differs, clean compile directory
foreach (scan_directory($directory) as $file) {
if (($file == ".") || ($file == "..")) {
if (($file == '.') || ($file == '..')) {
continue;
}
if (is_file($directory."/".$file)) {
// delete file
if (!unlink($directory."/".$file)) {
msg_dialog::display(_("Internal error"), sprintf(_("File '%s' could not be deleted. Try fusiondirectory-setup --check-directories to fix permissions."), $directory."/".$file), ERROR_DIALOG);
}
if (is_file($directory.'/'.$file) && !unlink($directory.'/'.$file)) {
msg_dialog::display(_("Internal error"), sprintf(_("File '%s' could not be deleted. Try fusiondirectory-setup --check-directories to fix permissions."), $directory."/".$file), ERROR_DIALOG);
}
}
} else {
......
......@@ -42,12 +42,12 @@ class management
public static $skipSnapshots = FALSE;
// The currently used object(s) (e.g. in edit, removal)
protected $dn = '';
protected $dns = array();
protected $currentDn = '';
protected $currentDns = array();
// The last used object(s).
protected $last_dn = '';
protected $last_dns = array();
protected $previousDn = '';
protected $previousDns = array();
// The opened object.
protected $tabObject = NULL;
......@@ -480,11 +480,11 @@ class management
*/
function remove_lock()
{
if (!empty($this->dn) && $this->dn != 'new') {
del_lock($this->dn);
if (!empty($this->currentDn) && ($this->currentDn != 'new')) {
del_lock($this->currentDn);
}
if (count($this->dns)) {
del_lock($this->dns);
if (count($this->currentDns)) {
del_lock($this->currentDns);
}
}
......@@ -518,10 +518,10 @@ class management
*/
public function closeDialogs()
{
$this->last_dn = $this->dn;
$this->dn = '';
$this->last_dns = $this->dns;
$this->dns = array();
$this->previousDn = $this->currentDn;
$this->currentDn = '';
$this->previousDns = $this->currentDns;
$this->currentDns = array();
$this->last_tabObject = $this->tabObject;
$this->tabObject = NULL;
......@@ -568,7 +568,7 @@ class management
$str .= '<p class="plugbottom">'."\n";
$str .= '<input type="submit" name="edit_finish" value="'.msgPool::okButton().'"/>'."\n";
$str .= "&nbsp;\n";
if ($this->dn != 'new') {
if ($this->currentDn != 'new') {
$str .= '<input type="submit" name="edit_apply" value="'.msgPool::applyButton().'"/>'."\n";
$str .= "&nbsp;\n";
}
......@@ -593,16 +593,16 @@ class management
return;
} else {
if (!$cancel) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Template applied!');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Template applied!');
}
del_lock($this->dn);
if (empty($this->dns)) {
del_lock($this->currentDn);
if (empty($this->currentDns)) {
$this->closeDialogs();
} else {
$this->last_tabObject = $this->tabObject;
$this->tabObject = NULL;
$this->dn = array_shift($this->dns);
$this->dialogObject->setNextTarget($this->dn);
$this->currentDn = array_shift($this->currentDns);
$this->dialogObject->setNextTarget($this->currentDn);
$this->dialogObject->save_object();
}
}
......@@ -630,13 +630,13 @@ class management
{
$type = $action['subaction'];
$this->dn = 'new';
$this->currentDn = 'new';
set_object_info($this->dn);
set_object_info($this->currentDn);
// Open object
$this->openTabObject(objects::create($type), $this->listing->getBase());
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Create entry initiated');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Create entry initiated');
}
function newEntryTemplate(array $action)
......@@ -679,19 +679,19 @@ class management
if (empty($action['targets'])) {
return;
}
$type = preg_replace('/^template_apply_to_/', '', $action['action']);
$this->dns = $action['targets'];
$type = preg_replace('/^template_apply_to_/', '', $action['action']);
$this->currentDns = $action['targets'];
// check locks
if ($locks = get_locks($this->dns)) {
return gen_locked_message($locks, $this->dns);
if ($locks = get_locks($this->currentDns)) {
return gen_locked_message($locks, $this->currentDns);
}
// Add locks
add_lock ($this->dns, $ui->dn);
add_lock ($this->currentDns, $ui->dn);
$this->dn = array_shift($this->dns);
$this->dialogObject = new templateDialog($this, $type, NULL, $this->dn);
$this->currentDn = array_shift($this->currentDns);
$this->dialogObject = new templateDialog($this, $type, NULL, $this->currentDn);
}
......@@ -721,16 +721,16 @@ class management
}
// Get the dn of the object and create lock
$this->dn = $target;
set_object_info($this->dn);
if ($locks = get_locks($this->dn, TRUE)) {
return gen_locked_message($locks, $this->dn, TRUE);
$this->currentDn = $target;
set_object_info($this->currentDn);
if ($locks = get_locks($this->currentDn, TRUE)) {
return gen_locked_message($locks, $this->currentDn, TRUE);
}
add_lock ($this->dn, $ui->dn);
add_lock ($this->currentDn, $ui->dn);
// Open object
$this->openTabObject(objects::open($this->dn, $entry->getTemplatedType()), $this->dn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Edit entry initiated');
$this->openTabObject(objects::open($this->currentDn, $entry->getTemplatedType()), $this->currentDn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Edit entry initiated');
if (isset($action['subaction'])
&& ($this->handleSubAction($action) === FALSE)) {
trigger_error('Was not able to handle subaction: '.$action['subaction']);
......@@ -770,7 +770,7 @@ class management
msg_dialog::displayChecks($msgs);
return;
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Entry saved');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry saved');
$this->remove_lock();
$this->closeDialogs();
}
......@@ -782,7 +782,7 @@ class management
return;
} else {
$this->dialogObject->save();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Dialog saved');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Dialog saved');
$this->remove_lock();
$this->closeDialogs();
}
......@@ -800,7 +800,7 @@ class management
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Modifications applied');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Modifications applied');
$this->tabObject->re_init();
}
}
......@@ -812,8 +812,8 @@ class management
function removeRequested(array $action)
{
global $ui;
$disallowed = array();
$this->dns = array();
$disallowed = array();
$this->currentDns = array();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Entry deletion requested');
......@@ -822,7 +822,7 @@ class management
$entry = $this->listing->getEntry($dn);
try {
if ($entry->checkAcl('d')) {
$this->dns[] = $dn;
$this->currentDns[] = $dn;
} else {
$disallowed[] = $dn;
}
......@@ -835,15 +835,15 @@ class management
}
// We've at least one entry to delete.
if (count($this->dns)) {
if (count($this->currentDns)) {
// check locks
if ($locks = get_locks($this->dns)) {
return gen_locked_message($locks, $this->dns);
if ($locks = get_locks($this->currentDns)) {
return gen_locked_message($locks, $this->currentDns);
}
// Add locks
$objects = array();
foreach ($this->dns as $dn) {
foreach ($this->currentDns as $dn) {
$entry = $this->listing->getEntry($dn);
$infos = objects::infos($entry->getTemplatedType());
if ($entry->isTemplate()) {
......@@ -856,7 +856,7 @@ class management
'type' => $infos['name']
);
}
add_lock ($this->dns, $ui->dn);
add_lock ($this->currentDns, $ui->dn);
// Display confirmation dialog.
$smarty = get_smarty();
......@@ -872,21 +872,21 @@ class management
function removeConfirmed(array $action)
{
global $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Entry deletion confirmed');
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry deletion confirmed');
foreach ($this->dns as $dn) {
foreach ($this->currentDns as $dn) {
$entry = $this->listing->getEntry($dn);
if (empty($entry)) {
continue;
}
if ($entry->checkAcl('d')) {
// Delete the object
$this->dn = $dn;
$this->openTabObject(objects::open($this->dn, $entry->getTemplatedType()), $this->dn);
$this->currentDn = $dn;
$this->openTabObject(objects::open($this->currentDn, $entry->getTemplatedType()), $this->currentDn);
$this->tabObject->delete();
// Remove the lock for the current object.
del_lock($this->dn);
del_lock($this->currentDn);
} else {
msg_dialog::display(_('Permission error'), msgPool::permDelete($dn), ERROR_DIALOG);
logging::log('security', 'simpleManagement/'.get_class($this), $dn, array(), 'Tried to trick deletion.');
......@@ -964,16 +964,16 @@ class management
global $config, $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Snaptshot creation initiated!');
$this->dn = array_pop($action['targets']);
if (empty($this->dn)) {
$this->currentDn = array_pop($action['targets']);
if (empty($this->currentDn)) {
return;
}
$entry = $this->listing->getEntry($this->dn);
$entry = $this->listing->getEntry($this->currentDn);
if ($entry->snapshotCreationAllowed()) {
$this->dialogObject = new SnapshotCreateDialog($this->dn, $this, '');
$this->dialogObject->set_acl_base($this->dn);
$this->dialogObject = new SnapshotCreateDialog($this->currentDn, $this, '');
$this->dialogObject->set_acl_base($this->currentDn);
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to create a snapshot for %s.'), $this->dn),
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to create a snapshot for %s.'), $this->currentDn),
ERROR_DIALOG);
}
}
......@@ -988,22 +988,22 @@ class management
if (empty($action['targets'])) {
// No target, open the restore removed object dialog.
$this->dn = $this->listing->getBase();
$aclCategory = $this->listAclCategories();
$this->currentDn = $this->listing->getBase();
$aclCategory = $this->listAclCategories();
} else {
// Display the restore points for a given object.
$this->dn = $action['targets'][0];
if (empty($this->dn)) {
$this->currentDn = $action['targets'][0];
if (empty($this->currentDn)) {
return;
}
$aclCategory = objects::infos($this->listing->getEntry($this->dn)->getTemplatedType())['aclCategory'];
$aclCategory = objects::infos($this->listing->getEntry($this->currentDn)->getTemplatedType())['aclCategory'];
}
if ($ui->allow_snapshot_restore($this->dn, $aclCategory, empty($action['targets']))) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Snaptshot restoring initiated!');
$this->dialogObject = new SnapshotRestoreDialog($this->dn, $this, empty($action['targets']), $aclCategory);
if ($ui->allow_snapshot_restore($this->currentDn, $aclCategory, empty($action['targets']))) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Snaptshot restoring initiated!');
$this->dialogObject = new SnapshotRestoreDialog($this->currentDn, $this, empty($action['targets']), $aclCategory);
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to restore a snapshot for %s.'), $this->dn),
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to restore a snapshot for %s.'), $this->currentDn),
ERROR_DIALOG);
}
}
......@@ -1083,7 +1083,7 @@ class management
function createSnapshot($dn, $description)
{
global $ui;
if ($this->dn !== $dn) {
if ($this->currentDn !== $dn) {
trigger_error('There was a problem with the snapshot workflow');
return;
}
......
......@@ -81,20 +81,19 @@ class BaseSelectorAttribute extends Attribute
function applyPostValue ()
{
if (!$this->disabled && $this->isVisible()) {
if (!$this->disabled && $this->isVisible()
&& ($this->plugin->acl_is_moveable($this->value) || ($this->plugin->dn == 'new'))) {
/* Refresh base */
if ($this->plugin->acl_is_moveable($this->value) || ($this->plugin->dn == 'new')) {
if (!$this->baseSelector->update()) {
if ($this->plugin->dn == 'new') {
msg_dialog::display(_('Error'), msgPool::permCreate(), ERROR_DIALOG);
} else {
msg_dialog::display(_('Error'), msgPool::permMove($this->plugin->dn), ERROR_DIALOG);
}
}
if ($this->value != $this->baseSelector->getBase()) {
$this->setValue($this->baseSelector->getBase());
if (!$this->baseSelector->update()) {
if ($this->plugin->dn == 'new') {
msg_dialog::display(_('Error'), msgPool::permCreate(), ERROR_DIALOG);
} else {
msg_dialog::display(_('Error'), msgPool::permMove($this->plugin->dn), ERROR_DIALOG);
}
}
if ($this->value != $this->baseSelector->getBase()) {
$this->setValue($this->baseSelector->getBase());
}
}
}
......
......@@ -153,15 +153,15 @@ class SelectAttribute extends Attribute
$id = $this->getHtmlId();
$smarty->assign($id."_choices", $this->choices);
if ($this->outputs !== NULL) {
$outputs = array_values($this->outputs);
$smartyOutputs = array_values($this->outputs);
} else {
$outputs = $this->choices;
$smartyOutputs = $this->choices;
}
$key = array_search('', $outputs, TRUE);
$key = array_search('', $smartyOutputs, TRUE);
if ($key !== FALSE) {
$outputs[$key] = '&nbsp;';
$smartyOutputs[$key] = '&nbsp;';
}
$smarty->assign($id."_outputs", $outputs);
$smarty->assign($id."_outputs", $smartyOutputs);
$smarty->assign($id."_selected", $this->getValue());
$display = '<select name="'.$id.'" id="'.$id.'" ';
if ($this->disabled || (count($this->choices) == 0)) {
......@@ -189,11 +189,11 @@ class SelectAttribute extends Attribute
parent::serializeAttribute($attributes, $form);
if ($this->outputs !== NULL) {
$outputs = array_values($this->outputs);
$tmpOutputs = array_values($this->outputs);
} else {
$outputs = $this->choices;
$tmpOutputs = $this->choices;
}
$attributes[$this->getLdapName()]['choices'] = array_combine($this->choices, $outputs);
$attributes[$this->getLdapName()]['choices'] = array_combine($this->choices, $tmpOutputs);
}
}
......
......@@ -761,7 +761,7 @@ class SubNodesAttribute extends OrderedArrayAttribute
{
/* Later we might want to be able to choose which attribute to use in the dn */
reset($this->attribute->attributes);
$attribute = key($this->attribute->attributes);
return $attribute.'='.$this->attribute->attributes[$attribute]->computeLdapValue().','.$this->plugin->dn;
$firstAttribute = key($this->attribute->attributes);
return $firstAttribute.'='.$this->attribute->attributes[$firstAttribute]->computeLdapValue().','.$this->plugin->dn;
}
}
......@@ -375,8 +375,8 @@ class Attribute
foreach ($this->managedAttributes as $array) {
foreach ($array as $value => $attributes) {
foreach ($attributes as $attribute) {
$disabled = $this->isValueManagingValue($myvalue, $value);
$this->plugin->attributesAccess[$attribute]->setManagingDisabled($this->getLdapName(), $disabled);
$disable = $this->isValueManagingValue($myvalue, $value);
$this->plugin->attributesAccess[$attribute]->setManagingDisabled($this->getLdapName(), $disable);
}
}
}
......@@ -416,9 +416,9 @@ class Attribute
function fillLdapValue (array &$attrs)
{
if ($this->inLdap) {
$value = $this->computeLdapValue();
if ($value !== '') {
$attrs[$this->getLdapName()] = $value;
$ldapValue = $this->computeLdapValue();
if ($ldapValue !== '') {
$attrs[$this->getLdapName()] = $ldapValue;
} else {
$attrs[$this->getLdapName()] = array();
}
......
......@@ -678,10 +678,8 @@ class ButtonAttribute extends Attribute
function loadPostValue ()
{
$this->postValue = FALSE;
if ($this->isVisible()) {
if (isset($_POST[$this->getHtmlId()])) {
$this->setPostValue(TRUE);
}
if ($this->isVisible() && isset($_POST[$this->getHtmlId()])) {
$this->setPostValue(TRUE);
}