From 80a92a3efa5e3bf5752a0810100cb53937fdc24d Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 5 Oct 2005 05:03:39 +0000 Subject: [PATCH] Fixed Already exists errormsg, for fai objects git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1471 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_faiHook.inc | 7 ++++ plugins/admin/fai/class_faiHookEntry.inc | 40 +++++++++++++++++++ plugins/admin/fai/class_faiPartitionTable.inc | 17 +++++++- plugins/admin/fai/class_faiScript.inc | 7 ++++ plugins/admin/fai/class_faiScriptEntry.inc | 2 +- plugins/admin/fai/class_faiTemplate.inc | 14 ++++++- plugins/admin/fai/class_faiVariable.inc | 9 ++++- plugins/admin/fai/faiHookEntry.tpl | 31 +++++++++----- 8 files changed, 113 insertions(+), 14 deletions(-) diff --git a/plugins/admin/fai/class_faiHook.inc b/plugins/admin/fai/class_faiHook.inc index 6d8e21a34..83551a24a 100644 --- a/plugins/admin/fai/class_faiHook.inc +++ b/plugins/admin/fai/class_faiHook.inc @@ -270,6 +270,13 @@ class faiHook extends plugin $tmp['objectClass'] = $this->subClasses; $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn); + if($ldap->count()){ + $obj['status']="modify"; + } + } if($obj['status'] == "delete"){ $ldap->cd($sub_dn); diff --git a/plugins/admin/fai/class_faiHookEntry.inc b/plugins/admin/fai/class_faiHookEntry.inc index 3621552b0..5dd08ab68 100644 --- a/plugins/admin/fai/class_faiHookEntry.inc +++ b/plugins/admin/fai/class_faiHookEntry.inc @@ -35,6 +35,34 @@ class faiHookEntry extends plugin $this->Object_status = "new"; $this->orig_cn = false; } + + if(isset($this->Object_FAIscript)){ + $ds= ldap_connect($this->config->current['SERVER']); + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); + if(function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") { + ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1); + ldap_set_rebind_proc($ds, array(&$this, "rebind")); + } + + if(isset($this->config->current['TLS']) && $this->config->current['TLS'] == "true"){ + ldap_start_tls($ds); + } + + $r = ldap_bind($ds); + $sr= @ldap_read($ds, $this->dn, "FAIscript=*", array("FAIscript")); + if ($sr) { + $ei=ldap_first_entry($ds, $sr); + if ($ei) { + if ($info = ldap_get_values_len($ds, $ei, "FAIscript")){ + $this->Object_FAIscript = base64_decode($info[0]); + } + } + } + + /* close conncetion */ + ldap_unbind($ds); + } + } function execute() @@ -42,6 +70,18 @@ class faiHookEntry extends plugin /* Fill templating stuff */ $smarty = get_smarty(); $display = ""; + + if(isset($_POST['ImportUpload'])){ + if(($_FILES['ImportFile']['error']!=0)){ + print_red(_("Please select a valid file.")); + }else + if(($_FILES['ImportFile']['size']==0)){ + print_red(_("Selected file is empty.")); + }else{ + $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name'])); + $this->Object_FAIscript = $str; + } + } foreach($this->attributes as $attrs){ $smarty->assign($attrs,stripslashes($this->$attrs)); diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index e00bacd6e..8cedb0f16 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -313,6 +313,13 @@ class faiPartitionTable extends plugin $disk_attrs['cn'] = $disk['cn']; $disk_attrs['description'] = $disk['description']; $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk"); + + if($disk['status']=="new"){ + $ldap->cat($disk_dn); + if($ldap->count()){ + $disk['status']="edited"; + } + } if($disk['status'] == "delete"){ $ldap->cd($disk_dn); @@ -355,7 +362,15 @@ class faiPartitionTable extends plugin unset($partition_attrs['status']); unset($partition_attrs['old_cn']); - + + if($partition['status']=="new"){ + $ldap->cat($partition_dn); + if($ldap->count()){ + $partition['status']="edited"; + } + } + + if(($partition['status'] == "delete")&&($disk['status']!="new")){ $ldap->cd($partition_dn); $ldap->rmdir_recursive($partition_dn); diff --git a/plugins/admin/fai/class_faiScript.inc b/plugins/admin/fai/class_faiScript.inc index e3ee13884..9b4b17815 100644 --- a/plugins/admin/fai/class_faiScript.inc +++ b/plugins/admin/fai/class_faiScript.inc @@ -260,6 +260,13 @@ class faiScript extends plugin $tmp['objectClass'] = $this->subClasses; $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn); + if($ldap->count()){ + $obj['status']="modify"; + } + } if($obj['status'] == "delete"){ $ldap->cd($sub_dn); diff --git a/plugins/admin/fai/class_faiScriptEntry.inc b/plugins/admin/fai/class_faiScriptEntry.inc index ebaf792f4..4d337ca4b 100644 --- a/plugins/admin/fai/class_faiScriptEntry.inc +++ b/plugins/admin/fai/class_faiScriptEntry.inc @@ -50,7 +50,7 @@ class faiScriptEntry extends plugin if(($_FILES['ImportFile']['size']==0)){ print_red(_("Selected file is empty.")); }else{ - $str = file_get_contents($_FILES['ImportFile']['tmp_name']); + $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name'])); $this->Object_FAIscript = $str; } } diff --git a/plugins/admin/fai/class_faiTemplate.inc b/plugins/admin/fai/class_faiTemplate.inc index 6792e36a2..b33788bd5 100644 --- a/plugins/admin/fai/class_faiTemplate.inc +++ b/plugins/admin/fai/class_faiTemplate.inc @@ -159,7 +159,11 @@ class faiTemplate extends plugin $a_return=array(); foreach($this->SubObjects as $obj){ if($obj['status'] != "delete"){ - $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; + if((isset($obj['description']))&&(!empty($obj['description']))){ + $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; + }else{ + $a_return[$obj['cn']]= $obj['cn']; + } } } return($a_return); @@ -240,6 +244,7 @@ class faiTemplate extends plugin } foreach($Objects as $name => $obj){ + foreach($this->sub64coded as $codeIt){ $obj[$codeIt]=base64_encode($obj[$codeIt]); } @@ -255,6 +260,13 @@ class faiTemplate extends plugin $sub_dn = "cn=".$obj['cn'].",".$this->dn; + if($obj['status']=="new"){ + $ldap->cat($sub_dn); + if($ldap->count()){ + $obj['status']="modify"; + } + } + if($obj['status'] == "delete"){ $ldap->cd($sub_dn); $ldap->rmdir_recursive($sub_dn); diff --git a/plugins/admin/fai/class_faiVariable.inc b/plugins/admin/fai/class_faiVariable.inc index e90e7e9b2..ae7d76f63 100644 --- a/plugins/admin/fai/class_faiVariable.inc +++ b/plugins/admin/fai/class_faiVariable.inc @@ -160,7 +160,7 @@ class faiVariable extends plugin foreach($this->SubObjects as $obj){ if($obj['status'] != "delete"){ - if((isset($obj['description']))&&(!empty($obj['description']))){ + if((isset($obj['description']))&&(!empty($obj['description']))&&(!preg_match("/\[\*\]/",$obj['description']))){ if (preg_match("/\[\*\]/", $obj['description'])){ $a_return[$obj['cn']]= $obj['cn']." [".preg_replace("/\s*\[\*\]\s*/", "", $obj['description'])."]"; } else { @@ -269,6 +269,13 @@ class faiVariable extends plugin $tmp['objectClass'] = $this->subClasses; $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn); + if($ldap->count()){ + $obj['status']="modify"; + } + } if($obj['status'] == "delete"){ $ldap->cd($sub_dn); diff --git a/plugins/admin/fai/faiHookEntry.tpl b/plugins/admin/fai/faiHookEntry.tpl index d2a4f0ea0..78fe9d369 100644 --- a/plugins/admin/fai/faiHookEntry.tpl +++ b/plugins/admin/fai/faiHookEntry.tpl @@ -28,16 +28,6 @@

 {t}Hook attributes{/t}

- - - -
- - - -
+ + +

 

+

  + +

+ + + + +
+ +
+
+
+   + +
+

 


-- 2.30.2