From b1b5bc3d6f87b8f8bed2112098b9a3029b5ea176 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 10 Jan 2006 16:17:27 +0000 Subject: [PATCH] Some changes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2437 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_faiManagement.inc | 82 +++++++++++++++-------- plugins/admin/fai/tabsHook.inc | 9 +-- plugins/admin/fai/tabsPackage.inc | 8 +-- plugins/admin/fai/tabsPartition.inc | 10 +-- plugins/admin/fai/tabsProfile.inc | 9 ++- plugins/admin/fai/tabsScript.inc | 7 +- plugins/admin/fai/tabsTemplate.inc | 9 ++- plugins/admin/fai/tabsVariable.inc | 9 ++- 8 files changed, 78 insertions(+), 65 deletions(-) diff --git a/plugins/admin/fai/class_faiManagement.inc b/plugins/admin/fai/class_faiManagement.inc index 8ee09f1ff..42438f6dd 100644 --- a/plugins/admin/fai/class_faiManagement.inc +++ b/plugins/admin/fai/class_faiManagement.inc @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + require "tabsPartition.inc"; require "tabsVariable.inc"; require "tabsHook.inc"; @@ -363,27 +364,44 @@ class faiManagement extends plugin } if($s_action == "freeze_branch"){ - $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($base); - - $attrs = $ldap->fetch($ldap->cat ($base)); + $this->dispNewFreeze = true; + $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); + return($display); + } - if(!in_array("FAIbranch",$attrs)){ - $attrs['objectClass'][] = "FAIbranch"; - } - - if((!isset($attrs['FAIstate']))||($attrs['FAIstate'] != "frozen")){ - $attrs['FAIstate']= "frozen"; - } - - print "Freeze "; + if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){ + /* Check branch name */ + $name = $_POST['BranchName']; + $is_ok = true; + $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; + /* Check used characters */ + if(preg_match("/[^0-9a-z]/i",$name)){ + print_red(_("Specified branch name is invalid.")); + $is_ok = false; + } + + /* Check if this name is already in use */ + if(!$this->CheckNewBranchName($_POST['BranchName'])){ + print_red(_("This name is already in use.")); + $this->is_ok = false; + } + + if($is_ok){ + /* Create it know */ + $ldap = $this->config->get_ldap_link(); - - + $ldap->cd ("ou=".$name.",".$base); + $ldap->recursive_remove(); + + $ldap->cd ($this->config->current['BASE']); + $ldap->copy_FAI_resource_recursive($base,"ou=".$name.",".$base,"freeze",true); + + $this->dispNewFreeze = false; + } } + /* ENDE Branch handling */ @@ -447,7 +465,6 @@ class faiManagement extends plugin } } - /* Search is set */ if(isset($_GET['search'])){ $faifilter['regex']=$_GET['search']."*"; @@ -695,14 +712,16 @@ class faiManagement extends plugin $desc= ""; } - if($value['FAIstate'] == "branch"){ + if($value['FAIstate'] == "freeze"){ $acti = ""; + $edi = "%NAME%"; }else{ $acti = $action; + $edi = $editlink; } $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'"); - $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$editlink) , "attach" => "style=''"); + $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''"); $field3 = array("string" => $info, "attach" => "style='width:200px;'"); $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'"); $divlist->AddEntry(array($field1,$field2,$field3,$field4)); @@ -737,7 +756,7 @@ class faiManagement extends plugin return ($display); } - function getBranches() + function getBranches($base = false,$prefix = "") { $ret = array("main"=>_("main")); $ldap = $this->config->get_ldap_link(); @@ -745,14 +764,19 @@ class faiManagement extends plugin $ldap->cd($this->config->current['BASE']); $faifilter = $_SESSION['faifilter']; - $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; + + + if(!$base){ + $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; + } $ldap->cd($base); - $ldap->search("(objectClass=FAIbranch)",array("*")); + $ldap->ls("(objectClass=FAIbranch)",$base); while($attrs = $ldap->fetch()){ - if(isset($attrs['ou'])){ - $ou = $attrs['ou'][0]; - $ret[$ou]=$ou; + + if((isset($attrs['ou']))&&($attrs['dn']!=$base)){ + $ret[$attrs['dn']]= $prefix.$attrs['ou'][0]; + $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix."/".$attrs['ou'][0])); } } return($ret); @@ -771,7 +795,7 @@ class faiManagement extends plugin $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; if($faifilter['branch'] !="main"){ - $base = "ou=".$faifilter['branch'].",".$base; + $base = $faifilter['branch']; } $regex = $faifilter['regex']; @@ -899,8 +923,10 @@ class faiManagement extends plugin } } - function checknewbranchname($name){ - + function CheckNewBranchName($name){ + if(in_array($name,$this->getBranches())) { + return(false); + } return(true); } diff --git a/plugins/admin/fai/tabsHook.inc b/plugins/admin/fai/tabsHook.inc index a44816fe3..cae153ef2 100644 --- a/plugins/admin/fai/tabsHook.inc +++ b/plugins/admin/fai/tabsHook.inc @@ -19,15 +19,12 @@ class tabsHook extends tabs { $baseobject= $this->by_object['faiHook']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=hooks,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=hooks,".$_SESSION['faifilter']['branch']; } - $new_dn= 'cn='.$baseobject->cn.",ou=hooks,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - - print $new_dn; - if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ diff --git a/plugins/admin/fai/tabsPackage.inc b/plugins/admin/fai/tabsPackage.inc index f0c16646e..1ac6ab563 100644 --- a/plugins/admin/fai/tabsPackage.inc +++ b/plugins/admin/fai/tabsPackage.inc @@ -19,13 +19,11 @@ class tabsPackage extends tabs { $baseobject= $this->by_object['faiPackage']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=packages,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=packages,".$_SESSION['faifilter']['branch']; } - - $new_dn= 'cn='.$baseobject->cn.",ou=packages,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - + if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ diff --git a/plugins/admin/fai/tabsPartition.inc b/plugins/admin/fai/tabsPartition.inc index 2308dcec8..c8c622210 100644 --- a/plugins/admin/fai/tabsPartition.inc +++ b/plugins/admin/fai/tabsPartition.inc @@ -19,16 +19,12 @@ class tabsPartition extends tabs { $baseobject= $this->by_object['faiPartitionTable']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=disk,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=disk,".$_SESSION['faifilter']['branch']; } - // cn=FAIBASE,ou=disk,".$branch."ou=fai,ou=configs,ou=systems,dc=gonicus,dc=de - $new_dn= 'cn='.$baseobject->cn.",ou=disk,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - - // Old .. $new_dn= 'ou='.$baseobject->ou.','.$baseobject->base; - if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ diff --git a/plugins/admin/fai/tabsProfile.inc b/plugins/admin/fai/tabsProfile.inc index f40addaf3..599f6772c 100644 --- a/plugins/admin/fai/tabsProfile.inc +++ b/plugins/admin/fai/tabsProfile.inc @@ -19,13 +19,12 @@ class tabsProfile extends tabs { $baseobject= $this->by_object['faiProfile']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=profiles,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=profiles,".$_SESSION['faifilter']['branch']; } - - $new_dn= 'cn='.$baseobject->cn.",ou=profiles,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - + if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ diff --git a/plugins/admin/fai/tabsScript.inc b/plugins/admin/fai/tabsScript.inc index 60d70673e..f85bde587 100644 --- a/plugins/admin/fai/tabsScript.inc +++ b/plugins/admin/fai/tabsScript.inc @@ -19,12 +19,11 @@ class tabsScript extends tabs { $baseobject= $this->by_object['faiScript']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=scripts,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=scripts,".$_SESSION['faifilter']['branch']; } - - $new_dn= 'cn='.$baseobject->cn.",ou=scripts,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; if ($this->dn != $new_dn && $this->dn != "new"){ diff --git a/plugins/admin/fai/tabsTemplate.inc b/plugins/admin/fai/tabsTemplate.inc index 98be6054e..1363b09bc 100644 --- a/plugins/admin/fai/tabsTemplate.inc +++ b/plugins/admin/fai/tabsTemplate.inc @@ -19,13 +19,12 @@ class tabsTemplate extends tabs { $baseobject= $this->by_object['faiTemplate']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=templates,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=templates,".$_SESSION['faifilter']['branch']; } - - $new_dn= 'cn='.$baseobject->cn.",ou=templates,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - + if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ diff --git a/plugins/admin/fai/tabsVariable.inc b/plugins/admin/fai/tabsVariable.inc index cf4f2b910..b526884df 100644 --- a/plugins/admin/fai/tabsVariable.inc +++ b/plugins/admin/fai/tabsVariable.inc @@ -19,13 +19,12 @@ class tabsVariable extends tabs { $baseobject= $this->by_object['faiVariable']; - $branch = ""; + $new_dn= 'cn='.$baseobject->cn.",ou=variables,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + if($_SESSION['faifilter']['branch']!="main"){ - $branch = "ou=".$_SESSION['faifilter']['branch'].","; + $new_dn ='cn='.$baseobject->cn.",ou=variables,".$_SESSION['faifilter']['branch']; } - - $new_dn= 'cn='.$baseobject->cn.",ou=variables,".$branch."ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; - + if ($this->dn != $new_dn && $this->dn != "new"){ /* if( new_dn is subtree of this->dn ) */ -- 2.30.2