From 89fecaa47a0f5e1a575d51cc1160f37a936d6a3d Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 6 Sep 2005 12:26:07 +0000 Subject: [PATCH] Some fixes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1312 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/FAI/class_faiManagement.inc | 118 +++++++++++++----- plugins/admin/FAI/class_faiPartitionTable.inc | 83 ++++++++---- 2 files changed, 147 insertions(+), 54 deletions(-) diff --git a/plugins/admin/FAI/class_faiManagement.inc b/plugins/admin/FAI/class_faiManagement.inc index 901b44baf..800964b6c 100644 --- a/plugins/admin/FAI/class_faiManagement.inc +++ b/plugins/admin/FAI/class_faiManagement.inc @@ -51,10 +51,9 @@ class faiManagement extends plugin */ function faiManagement ($config, $ui) { - /* #WT ??? Whats That */ $this->ui = $ui; - /* Set current dn to "", wherefore ? */ + /* Set current dn to "", */ $this->dn = ""; /* Assign config */ @@ -115,18 +114,91 @@ class faiManagement extends plugin }elseif(preg_match("/^entry_edit_.*/",$key)){ $s_entry = preg_replace("/^entry_edit_/","",$key); $s_entry = preg_replace("/_.*$/","",$s_entry); - $s_action = "edit"; + }elseif(preg_match("/^entry_delete_.*/",$key)){ + $s_entry = preg_replace("/^entry_delete_/","",$key); + $s_entry = preg_replace("/_.*$/","",$s_entry); + $s_action = "delete"; } - + + } + + /* Confirm dialog + * Delte object + */ + if ($s_action=="delete"){ + + /* Get 'dn' from posted termlinst */ + $this->dn= $this->objects[$s_entry]['dn']; + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + $acl= get_permissions ($this->dn, $this->ui->subtreeACL); + $this->acl= get_module_permission($acl, "FAIclass", $this->dn); + if (chkacl($this->acl, "delete") == ""){ + + /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so nobody will edit it during deletion */ + add_lock ($this->dn, $this->ui->dn); + $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn)); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } else { + + /* Obviously the user isn't allowed to delete. Show message and + clean session. */ + print_red (_("You are not allowed to delete this component!")); + } + } + + /* Deltetion was confirmed, so delete this entry + */ + if (isset($_POST['delete_terminal_confirm'])){ + + /* Some nice guy may send this as POST, so we've to check + for the permissions again. */ + if (chkacl($this->acl, "delete") == ""){ + + /* Find out more about the object type */ + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->dn); + $attrs = $ldap->fetch(); + + $type = $this->get_type($attrs); + + $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn); + $this->dialog->set_acl(array($this->acl)); + + $this->dialog->by_object[$type[1]]->remove_from_parent (); + unset ($this->dialog); + gosa_log ("System object'".$this->dn."' has been removed"); + $this->dialog= NULL; + + /* Terminal list has changed, reload it. */ + $this->reload (); + } else { + + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + print_red (_("You are not allowed to delete this component!")); + gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ". + "deletion."); + } + + /* Remove lock file after successfull deletion */ + del_lock ($this->dn); } + /* Edit Entry */ if($s_action == "edit"){ $entry = $this->objects[$s_entry]; switch($entry['type']){ case "FAIpartitionTable" : $this->dn = $entry['dn']; - $this->dialog= new tabsPartition($this->config, + $this->dialog= new tabsPartition($this->config, $this->config->data['TABS']['PARTITIONTABS'],$this->dn); $this->is_dialog = true; ;break; @@ -167,8 +239,6 @@ class faiManagement extends plugin $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']); $_SESSION['faifilter']= $faifilter; - $this->reload(); - /* Edit dialog was canceled * Remove dialog an show management dialog */ @@ -245,6 +315,7 @@ class faiManagement extends plugin ""; + $this->reload(); /* Create list with objects */ $divlist = new divlist("faiManagement"); @@ -258,7 +329,8 @@ class faiManagement extends plugin array("string" => _("Obtions"), "attach" => "style='border:none'" ))); - $action = ""; + $action = ""; + $action .= ""; /* Attach objects */ foreach($this->objects as $key => $value){ @@ -331,7 +403,7 @@ class faiManagement extends plugin $field1 = array("string" => $img , "attach" => "style='height:26px;width=20px;'"); $field2 = array("string" => $value['cn'].$desc , "attach" => ""); $field3 = array("string" => $info, "attach" => ""); - $field4 = array("string" => sprintf($action,$key) , "attach" => "style='border-right:none;'"); + $field4 = array("string" => preg_replace("/%KEY%/",$key,$action) , "attach" => "style='border-right:none;'"); $divlist->AddEntry(array($field1,$field2,$field3,$field4)); } @@ -375,6 +447,8 @@ class faiManagement extends plugin /* Array to save objects */ $objects = array(); + + $this->objects=array(); $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", FALSE, $base, array("cn","description","objectClass"),TRUE); @@ -419,26 +493,6 @@ class faiManagement extends plugin reset ($this->objects); } - function remove_from_parent() - { - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - $ldap->recursive_remove(); - - /* Optionally execute a command after we're done */ - $this->postremove(); - - /* Delete references to object groups */ - $ldap->cd ($this->config->current['BASE']); - $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn")); - while ($ldap->fetch()){ - $og= new ogroup($this->config, $ldap->getDN()); - unset($og->member[$this->dn]); - $og->save (); - } - - } - function remove_lock() { if (isset($this->dn)){ @@ -446,6 +500,12 @@ class faiManagement extends plugin } } + function get_type($array){ + if(in_array("FAIpartitionTable",$array['objectClass'])){ + return(array("tabsPartition","faiPartitionTable","PARTITIONTABS")); + } + } + } ?> diff --git a/plugins/admin/FAI/class_faiPartitionTable.inc b/plugins/admin/FAI/class_faiPartitionTable.inc index 6a45e892b..8d657ca60 100644 --- a/plugins/admin/FAI/class_faiPartitionTable.inc +++ b/plugins/admin/FAI/class_faiPartitionTable.inc @@ -8,24 +8,25 @@ class faiPartitionTable extends plugin var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("cn","description"); - var $objectclasses= array("top","FAIclass","FAIpartitionTable"); - - var $cn = ""; - var $description = ""; - var $disks = array(); - var $is_dialog = false; - var $dialog = NULL; + var $ignore_account = TRUE; + var $attributes = array("cn","description"); + var $objectclasses = array("top","FAIclass","FAIpartitionTable"); + + /* Specific attributes */ + var $cn = ""; // The class name for this object + var $description = ""; // The description for this set of partitions + var $disks = array(); // All defined Disks + var $is_dialog = false; // specifies which buttons will be shown to save or abort + var $dialog = NULL; // a dialog, e.g. new disk dialog + function faiPartitionTable ($config, $dn= NULL) { + /* Load Attributes */ plugin::plugin ($config, $dn); - $this->partitions = array(); - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap taht belong to this entry - * First read disks from ldap ... and then the partition definitions for the disks + * Else we must read all objects from ldap which belong to this entry. + * First read disks from ldap ... and then the partition definitions for the disks. */ if($dn != "new"){ $this->dn =$dn; @@ -62,7 +63,8 @@ class faiPartitionTable extends plugin $partition[$key] = $val[0]; } } - + /* Append fetched partitions + */ $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; } } @@ -84,17 +86,25 @@ class faiPartitionTable extends plugin $this->is_dialog = true; } + /* Edit disk. + * Open dialog which allows us to edit the selected entry + */ if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){ $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this->disks[$_POST['disks']]); $this->is_dialog = true; } + /* Edit aborted, close dialog, without saving anything + */ if(isset($_POST['CancelDisk'])){ unset($this->dialog); $this->dialog = NULL; $this->is_dialog=false; } + /* Dialog saved + * Save given data from Dialog, if no error is occured + */ if(isset($_POST['SaveDisk'])){ $this->dialog->save_object(); if(count($this->dialog->check())){ @@ -110,11 +120,15 @@ class faiPartitionTable extends plugin } } + /* Display dialog if one is defined + */ if(isset($this->dialog)){ $this->dialog->save_object(); return($this->dialog->execute()); } + /* Assign all attributes to smarty engine + */ foreach($this->attributes as $attrs){ $smarty->assign($attrs,$this->$attrs); if($this->$attrs){ @@ -123,13 +137,7 @@ class faiPartitionTable extends plugin $smarty->assign($attrs."CHK"," disabled "); } } - - $disks = array(); - foreach($this->partitions as $part){ - $disks[$part['cn']] = $part['cn']." [".$part['description']."]"; - } - - + $disks = $this->getDisks(); $smarty->assign("disks" ,$disks); $smarty->assign("diskKeys",array_flip($disks)); @@ -138,6 +146,9 @@ class faiPartitionTable extends plugin } function getDisks(){ + /* Return all available disks for this partition table + * Return in listBox friendly array + */ $a_return = array(); foreach($this->disks as $key => $disk){ $cnt = count( $disk['partitions']); @@ -150,13 +161,22 @@ class faiPartitionTable extends plugin return($a_return); } + + /* Delete me, and all my subtrees + */ function remove_from_parent() { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->rmdir_recursive($this->dn); + $this->handle_post_events("remove"); + /* This cannot be removed... */ } - /* Save data to object */ + /* Save data to object + */ function save_object() { plugin::save_object(); @@ -172,6 +192,9 @@ class faiPartitionTable extends plugin function check() { $message= array(); + if(empty($this->description)){ + $message[]=_("Please enter a valid description."); + } return ($message); } @@ -181,7 +204,13 @@ class faiPartitionTable extends plugin function save() { plugin::save(); - + /* Save current settings. + * 1 : We must save the partition table, with its description and cn + * 2 : Append Disk with cn and description. + * 3 : Save partitions for each disk + */ + + /* remove old entry */ $ldap = $this->config->get_ldap_link(); $ldap->cat($this->dn); if($ldap->count()){ @@ -189,12 +218,16 @@ class faiPartitionTable extends plugin $ldap->rmdir_recursive($this->dn); show_ldap_error($ldap->get_error()); } + + /* Add partition table to ldap + */ $ldap->cd($this->dn); $ldap->create_missing_trees($this->dn); $ldap->cd($this->dn); $ldap->add($this->attrs); show_ldap_error($ldap->get_error()); + /* Append all disks to ldap */ foreach($this->disks as $cn=>$disk){ $disk_cn = "cn=".$cn.",".$this->dn; $disk_attrs['cn'] = $disk['cn']; @@ -205,8 +238,9 @@ class faiPartitionTable extends plugin $ldap->create_missing_trees($disk_cn); $ldap->cd($disk_cn); $ldap->add($disk_attrs); - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error()); + /* Add all partitions */ foreach($disk['partitions'] as $key => $partition){ $partition_attrs = array(); foreach($partition as $key => $value){ @@ -229,7 +263,6 @@ class faiPartitionTable extends plugin } $this->handle_post_events("add"); } - } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -- 2.30.2