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

Fixes: #2595 The code should follow code guidelines

parent 334ddf9e
......@@ -22,100 +22,100 @@
class filterACL {
static function query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage= "")
static function query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = "")
{
$config= session::global_get('config');
$ldap= $config->get_ldap_link(TRUE);
$flag= ($scope == "sub")?GL_SUBSEARCH:0;
$result=array();
$result= array_merge($result,filterACL::get_list($parent, $base, $filter, $attributes, $category, array(), $flag | GL_SIZELIMIT, "cat"));
if($scope == "sub"){
$result= array_merge($result,filterACL::get_list($parent, $base, $filter, $attributes, $category, array(), $flag | GL_SIZELIMIT, "search"));
$config = session::global_get('config');
$ldap = $config->get_ldap_link(TRUE);
$flag = ($scope == "sub")?GL_SUBSEARCH:0;
$result = array();
$result = array_merge($result, filterACL::get_list($parent, $base, $filter, $attributes, $category, array(), $flag | GL_SIZELIMIT, "cat"));
if ($scope == "sub") {
$result = array_merge($result, filterACL::get_list($parent, $base, $filter, $attributes, $category, array(), $flag | GL_SIZELIMIT, "search"));
}
$result= array_merge($result,filterACL::get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $flag | GL_SIZELIMIT, ""));
return(filterACL::unifyResult($result));
$result = array_merge($result, filterACL::get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $flag | GL_SIZELIMIT, ""));
return filterACL::unifyResult($result);
}
static function unifyResult($result)
{
$res=array();
foreach($result as $entry){
if(!isset($res[$entry['dn']])){
$res[$entry['dn']]=$entry;
$res = array();
foreach ($result as $entry) {
if (!isset($res[$entry['dn']])) {
$res[$entry['dn']] = $entry;
}
}
return(array_values($res));
return array_values($res);
}
static function get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH, $method= "")
static function get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $flags = GL_SUBSEARCH, $method = "")
{
$ui= session::global_get('ui');
$config= session::global_get('config');
$ui = session::global_get('ui');
$config = session::global_get('config');
// Move to arrays for category and objectStorage
if (!is_array($category)) {
$category= array($category);
$category = array($category);
}
if (!is_array($objectStorage)) {
$objectStorage= array($objectStorage);
$objectStorage = array($objectStorage);
}
if(empty($method)){
$method= (empty($objectStorage) && !($flags & GL_SUBSEARCH))?"ls":"search";
if (empty($method)) {
$method = (empty($objectStorage) && !($flags & GL_SUBSEARCH))?"ls":"search";
}
// Initialize search bases
$bases= array();
$bases = array();
// Get list of sub bases to search on
if (count($objectStorage) == 0) {
$bases[$base]= "";
$bases[$base] = "";
} else {
foreach ($objectStorage as $oc) {
$oc= preg_replace('/,$/', '', $oc);
$tmp= explode(',', $oc);
$oc = preg_replace('/,$/', '', $oc);
$tmp = explode(',', $oc);
if (count($tmp) == 1) {
preg_match('/([^=]+)=(.*)$/', $oc, $m);
if ($flags & GL_SUBSEARCH) {
$bases[$base][]= $m[1].":dn:=".$m[2];
$bases[$base][] = $m[1].":dn:=".$m[2];
} else {
$bases["$oc,$base"][]= $m[1].":dn:=".$m[2];
$bases["$oc,$base"][] = $m[1].":dn:=".$m[2];
}
} else {
// No, there's no \, in pre defined RDN values
preg_match('/^([^,]+),(.*)$/', $oc, $matches);
preg_match('/([^=]+)=(.*)$/', $matches[1], $m);
if ($flags & GL_SUBSEARCH) {
$bases[$base][]= $m[1].":dn:=".$m[2];
$bases[$base][] = $m[1].":dn:=".$m[2];
} else {
$bases[$matches[2].",$base"][]= $m[1].":dn:=".$m[2];
$bases[$matches[2].",$base"][] = $m[1].":dn:=".$m[2];
}
}
}
}
// Get LDAP link
$ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
$ldap = $config->get_ldap_link($flags & GL_SIZELIMIT);
// Do search for every base
$result= array();
$result = array();
$limit_exceeded = FALSE;
foreach($bases as $base => $dnFilters) {
foreach ($bases as $base => $dnFilters) {
// Break if the size limit is exceeded
if($limit_exceeded){
return($result);
if ($limit_exceeded) {
return $result;
}
// Switch to new base and search
if (is_array($dnFilters)){
$dnFilter= "(|";
if (is_array($dnFilters)) {
$dnFilter = "(|";
foreach ($dnFilters as $df) {
$dnFilter.= "($df)";
$dnFilter .= "($df)";
}
$dnFilter.= ")";
$dnFilter .= ")";
} else {
$dnFilter= "";
$dnFilter = "";
}
$ldap->cd($base);
if ($method == "ls") {
......@@ -127,39 +127,37 @@ class filterACL {
}
// Check for size limit exceeded messages for GUI feedback
if (preg_match("/size limit/i", $ldap->get_error())){
if (preg_match("/size limit/i", $ldap->get_error())) {
session::set('limit_exceeded', TRUE);
$limit_exceeded = TRUE;
}
/* Crawl through result entries and perform the migration to the
result array */
while($attrs = $ldap->fetch()) {
$dn= $ldap->getDN();
while ($attrs = $ldap->fetch()) {
$dn = $ldap->getDN();
/* Convert dn into a printable format */
if ($flags & GL_CONVERT){
$attrs["dn"]= convert_department_dn($dn);
if ($flags & GL_CONVERT) {
$attrs["dn"] = convert_department_dn($dn);
} else {
$attrs["dn"]= $dn;
$attrs["dn"] = $dn;
}
/* Skip ACL checks if we are forced to skip those checks */
if($flags & GL_NO_ACL_CHECK){
$result[]= $attrs;
}else{
if ($flags & GL_NO_ACL_CHECK) {
$result[] = $attrs;
} else {
/* Sort in every value that fits the permissions */
foreach ($category as $o){
if((preg_match("/\//",$o) && preg_match("/r/",$ui->get_permissions($dn,$o))) ||
(!preg_match("/\//",$o) && preg_match("/r/",$ui->get_category_permissions($dn, $o)))){
$result[]= $attrs;
foreach ($category as $o) {
if ((preg_match("/\//", $o) && preg_match("/r/", $ui->get_permissions($dn, $o))) ||
(!preg_match("/\//", $o) && preg_match("/r/", $ui->get_category_permissions($dn, $o)))) {
$result[] = $attrs;
break;
}
}
}
}
}
return $result;
......
......@@ -26,14 +26,13 @@ class country extends department
var $attributes = array( "c", "ou", "description", "manager");
var $objectclasses = array("top", "gosaDepartment");
var $structuralOC = array("country");
var $type ="country";
var $c ="";
var $orgi_c ="";
var $type = "country";
var $c = "";
var $orgi_c = "";
var $namingAttr = "c";
var $manager_enabled = FALSE;
var $manager_name ="";
var $manager ="";
var $namingAttr = "c";
var $manager_name = "";
var $manager = "";
function check()
......@@ -41,37 +40,37 @@ class country extends department
$message = plugin::check();
/* Check for presence of this department */
$ldap= $this->config->get_ldap_link();
$ldap = $this->config->get_ldap_link();
$ldap->ls ("(&(c=".$this->c.")(objectClass=country))", $this->base, array('dn'));
if ($this->orig_c == "new" && $ldap->count()){
$message[]= msgPool::duplicated(_("Name"));
} elseif ($this->orig_dn != $this->dn && $ldap->count()){
$message[]= msgPool::duplicated(_("Name"));
if ($this->orig_c == "new" && $ldap->count()) {
$message[] = msgPool::duplicated(_("Name"));
} elseif ($this->orig_dn != $this->dn && $ldap->count()) {
$message[] = msgPool::duplicated(_("Name"));
}
/* All required fields are set? */
if ($this->c == ""){
$message[]= msgPool::required(_("Name"));
}elseif(tests::is_department_name_reserved($this->c,$this->base)){
$message[]= msgPool::reserved(_("Name"));
}elseif(preg_match ('/[#+:=>\\\\\/]/', $this->c)){
$message[]= msgPool::invalid(_("Name"), $this->c, "/[^#+:=>\\\\\/]/");
if ($this->c == "") {
$message[] = msgPool::required(_("Name"));
} elseif (tests::is_department_name_reserved($this->c, $this->base)) {
$message[] = msgPool::reserved(_("Name"));
} elseif (preg_match ('/[#+:=>\\\\\/]/', $this->c)) {
$message[] = msgPool::invalid(_("Name"), $this->c, "/[^#+:=>\\\\\/]/");
}
/* Check description */
if ($this->description == ""){
$message[]= msgPool::required(_("Description"));
if ($this->description == "") {
$message[] = msgPool::required(_("Description"));
}
/* Check if we are allowed to create or move this object
*/
if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
if ($this->orig_dn == "new" && !$this->acl_is_createable($this->base)) {
$message[] = msgPool::permCreate();
}elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
} elseif ($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)) {
$message[] = msgPool::permMove();
}
return($message);
return $message;
}
......
......@@ -23,17 +23,17 @@
class dcObject extends department
{
/* attribute list for save action */
var $attributes = array( "dc", "ou", "description", "manager");
var $attributes = array("dc", "ou", "description", "manager");
var $objectclasses = array("top", "dcObject", "gosaDepartment");
var $structuralOC = array("locality");
var $type = "dcObject";
var $dc = "";
var $orgi_dc = "";
var $namingAttr = "dc";
var $manager_enabled = FALSE;
var $manager_name ="";
var $manager ="";
var $manager_name = "";
var $manager = "";
function check()
......@@ -41,37 +41,37 @@ class dcObject extends department
$message = plugin::check();
/* Check for presence of this department */
$ldap= $this->config->get_ldap_link();
$ldap = $this->config->get_ldap_link();
$ldap->ls ("(&(dc=".$this->dc.")(objectClass=dcObject))", $this->base, array('dn'));
if ($this->orig_dc == "new" && $ldap->count()){
$message[]= msgPool::duplicated(_("Name"));
} elseif ($this->orig_dn != $this->dn && $ldap->count()){
$message[]= msgPool::duplicated(_("Name"));
if ($this->orig_dc == "new" && $ldap->count()) {
$message[] = msgPool::duplicated(_("Name"));
} elseif ($this->orig_dn != $this->dn && $ldap->count()) {
$message[] = msgPool::duplicated(_("Name"));
}
/* All required fields are set? */
if ($this->dc == ""){
$message[]= msgPool::required(_("Name"));
}elseif(tests::is_department_name_reserved($this->dc,$this->base)){
$message[]= msgPool::reserved(_("Name"));
}elseif(!preg_match ('/[a-z0-9 \.,\-_]/i', $this->dc)){
$message[]= msgPool::invalid(_("Name"), $this->dc, "/[a-z0-9 \.,\-_]/");
if ($this->dc == "") {
$message[] = msgPool::required(_("Name"));
} elseif (tests::is_department_name_reserved($this->dc, $this->base)) {
$message[] = msgPool::reserved(_("Name"));
} elseif (!preg_match ('/[a-z0-9 \.,\-_]/i', $this->dc)) {
$message[] = msgPool::invalid(_("Name"), $this->dc, "/[a-z0-9 \.,\-_]/");
}
/* Check description */
if ($this->description == ""){
$message[]= msgPool::required(_("Description"));
if ($this->description == "") {
$message[] = msgPool::required(_("Description"));
}
/* Check if we are allowed to create or move this object
*/
if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
if ($this->orig_dn == "new" && !$this->acl_is_createable($this->base)) {
$message[] = msgPool::permCreate();
}elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
} elseif ($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)) {
$message[] = msgPool::permMove();
}
return($message);
return $message;
}
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
......@@ -41,7 +40,6 @@ class department extends plugin
/* Headpage attributes */
var $last_dep_sorting = "invalid";
var $departments = array();
var $must_be_tagged = FALSE;
/* attribute list for save action */
var $attributes = array("ou", "description", "businessCategory", "st", "l", "postalAddress",
......@@ -58,10 +56,9 @@ class department extends plugin
var $manager_name = "";
var $manager = "";
function department (&$config, $dn)
function __construct (&$config, $dn)
{
/* Add the default structural object class if this is a new entry
*/
/* Add the default structural object class if this is a new entry */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
if ($dn == "" || $dn == "new" || !$ldap->dn_exists($dn)) {
......@@ -81,11 +78,11 @@ class department extends plugin
}
$this->objectclasses = array_unique($this->objectclasses);
plugin::plugin($config, $dn);
parent::__construct($config, $dn);
$this->is_account = TRUE;
$this->ui = get_userinfo();
$this->dn = $dn;
$this->orig_dn = $dn;
$this->ui = get_userinfo();
$this->dn = $dn;
$this->orig_dn = $dn;
/* Save current naming attribute
*/
......@@ -106,7 +103,6 @@ class department extends plugin
} else {
$this->base = preg_replace ("/^[^,]+,/", "", $this->dn);
}
$this->orig_base = $this->base;
/* Instanciate base selector */
......@@ -132,7 +128,7 @@ class department extends plugin
function execute()
{
/* Call parent execute */
plugin::execute();
parent::execute();
/* Log view */
if ($this->is_account && !$this->view_logged) {
......@@ -161,13 +157,13 @@ class department extends plugin
if ($this->dialog && count($this->dialog->detectPostActions())) {
$users = $this->dialog->detectPostActions();
if (isset($users['targets']) && count($users['targets'])) {
$headpage = $this->dialog->getHeadpage();
$dn = $users['targets'][0];
$attrs = $headpage->getEntry($dn);
$this->manager = $dn;
$dn = $users['targets'][0];
$attrs = $headpage->getEntry($dn);
$this->manager = $dn;
$this->manager_name = $attrs['cn'][0];
$this->dialog = NULL;
$this->dialog = NULL;
}
}
if (isset($_POST['add_users_cancel'])) {
......@@ -194,20 +190,7 @@ class department extends plugin
$smarty->assign($nA, $this->getacl($this->namingAttr, TRUE));
}
/* Hide all departments, that are subtrees of this department */
$bases = $this->get_allowed_bases();
if (($this->dn == "new") || ($this->dn == "")) {
$tmp = $bases;
} else {
$tmp = array();
foreach ($bases as $dn => $base) {
/* Only attach departments which are not a subtree of this one */
if (!preg_match("/".preg_quote($this->dn)."/", $dn)) {
$tmp[$dn] = $base;
}
}
}
$this->baseSelector->setBases($tmp);
$this->baseSelector->setBases($this->get_allowed_bases());
foreach ($this->attributes as $val) {
$smarty->assign("$val", htmlentities($this->$val, ENT_COMPAT, 'UTF-8'));
......@@ -218,7 +201,7 @@ class department extends plugin
$dep_types = departmentManagement::get_support_departments();
$tpl = "";
foreach ($dep_types as $key => $data) {
foreach ($dep_types as $data) {
if ($data['OC'] == $this->type) {
$tpl = $data['TPL'];
break;
......@@ -228,16 +211,24 @@ class department extends plugin
trigger_error("No template specified for container type '".$this->type."', please update departmentManagement::get_support_departments().");
$tpl = "generic.tpl";
}
return $smarty->fetch (get_template_path($tpl, TRUE));
return $smarty->fetch(get_template_path($tpl, TRUE));
}
function clear_fields()
function get_allowed_bases()
{
$this->dn = "";
$this->base = "";
foreach ($this->attributes as $val) {
$this->$val = "";
/* Hide all departments, that are subtrees of this department */
$bases = parent::get_allowed_bases();
if (($this->dn == "new") || ($this->dn == "")) {
return $bases;
} else {
$tmp = array();
foreach ($bases as $dn => $base) {
/* Only attach departments which are not a subtree of this one */
if (!preg_match("/".preg_quote($this->dn)."/", $dn)) {
$tmp[$dn] = $base;
}
}
return $tmp;
}
}
......@@ -255,11 +246,6 @@ class department extends plugin
$this->handle_post_events('remove');
}
function must_be_tagged()
{
return $this->must_be_tagged;
}
/* Save data to object */
function save_object()
{
......@@ -272,7 +258,7 @@ class department extends plugin
base directly after calling plugin::save_object();
Base will be set seperatly a few lines below */
$base_tmp = $this->base;
plugin::save_object();
parent::save_object();
$this->base = $base_tmp;
/* Refresh base */
......@@ -295,7 +281,6 @@ class department extends plugin
}
}
/* Check values */
function check()
{
......@@ -335,7 +320,7 @@ class department extends plugin
// Check if a wrong base was supplied
if (!$this->baseSelector->checkLastBaseUpdate()) {
$message[] = msgPool::check_base();;
$message[] = msgPool::check_base();
}
/* Check if we are allowed to create or move this object
......@@ -349,7 +334,6 @@ class department extends plugin
return $message;
}
/* Save to LDAP */
function save()
{
......@@ -360,7 +344,7 @@ class department extends plugin
$nA = $this->namingAttr;
$this->ou = $this->$nA;
plugin::save();
parent::save();
/* Write back to ldap */
$ldap->cat($this->dn, array('dn'));
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
......@@ -44,45 +43,49 @@ class departmentManagement extends management
);
}
function __construct($config,$ui)
function __construct($config, $ui)
{
$this->config = $config;
$this->ui = $ui;
$this->ui = $ui;
// Build filter
if (session::global_is_set(get_class($this)."_filter")){
$filter= session::global_get(get_class($this)."_filter");
if (session::global_is_set(get_class($this)."_filter")) {
$filter = session::global_get(get_class($this)."_filter");
} else {
$filter = new filter(get_template_path("dep-filter.xml", true));
$filter = new filter(get_template_path("dep-filter.xml", TRUE));
}
$filter->setObjectStorage(array(''));
// Build headpage
$headpage = new listing(get_template_path("dep-list.xml", true));
$headpage = new listing(get_template_path("dep-list.xml", TRUE));
$headpage->registerElementFilter("depLabel", "departmentManagement::filterDepLabel");
$headpage->setFilter($filter);
$this->setFilter($filter);
parent::__construct($config, $ui, "departments", $headpage);
$this->registerAction("open","openEntry");
$this->registerAction("new_domain","newEntry");
$this->registerAction("new_country","newEntry");
$this->registerAction("new_locality","newEntry");
$this->registerAction("new_dcObject","newEntry");
$this->registerAction("new_organization","newEntry");
$this->registerAction("new_organizationalUnit","newEntry");
$this->registerAction("performRecMove","performRecMove");
$this->registerAction("tagDepartment","tagDepartment");
$this->registerAction("open", "openEntry");
$this->registerAction("new_domain", "newEntry");
$this->registerAction("new_country", "newEntry");
$this->registerAction("new_locality", "newEntry");
$this->registerAction("new_dcObject", "newEntry");
$this->registerAction("new_organization", "newEntry");
$this->registerAction("new_organizationalUnit", "newEntry");