From 78ff273400c1bfc84cfea5ce4f338349602fe8f2 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 23 May 2006 04:32:19 +0000 Subject: [PATCH 1/1] Added function that checks if a department name is allowed in specified base git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3492 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/functions.inc | 24 +++++++++++++++++++ .../departments/class_departmentGeneric.inc | 14 +++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/functions.inc b/include/functions.inc index 0cb50d54b..45ae25876 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -1976,5 +1976,29 @@ function get_MicroTimeDiff($start , $stop) } +/* Check if the given department name is valid */ +function is_department_name_reserved($name,$base) +{ + $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook", + preg_replace("/ou=(.*),/","\\1",get_people_ou()), + preg_replace("/ou=(.*),/","\\1",get_groups_ou())); + + $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disks","packages","variables","profiles"); + + /* Check if name is one of the reserved names */ + if(in_array_ics($name,$reservedName)) { + return(true); + } + + /* Check all follow combinations if name is in array && parent base == array_key, return false*/ + foreach($follwedNames as $key => $names){ + if((in_array_ics($name,$names)) && (preg_match($key,$base))){ + return(true); + } + } + return(false); +} + + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index df8c51e78..64d631deb 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -236,17 +236,9 @@ class department extends plugin $message[]= _("Required field 'Description' is not set."); } - /* Validate and modify - or: spaghetti rules! */ - $SkipNames = array( "incoming","apps","systems","fai","config", - preg_replace("/ou=(.*),/","\\1",get_people_ou()), - preg_replace("/ou=(.*),/","\\1",get_groups_ou()) - ); - foreach($SkipNames as $name){ - if ($this->ou == $name){ - $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$name); - } - } - + if(is_department_name_reserved($this->ou,$this->base)){ + $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$this->ou); + } if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){ $message[]= _("The field 'Name' contains invalid characters."); -- 2.30.2