diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
index 4f3c269aa214ae452a51a27464217b276671c6db..6f3630e6e54c2b8768198af0294f2bce6530a997 100644 (file)
if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
$objects = array();
$objects['description'] = "";
- $objects['status'] = "edited";
// Transform disk type into image later...
if (!isset($obj['FAIdiskType'])){
} else {
$objects['FAIdiskType'] = $obj['FAIdiskType'];
}
- $objects['FAIdiskOption'] = $obj['FAIdiskOption'];
+
+ // Get disk options, without 'count' index.
+ $objects['FAIdiskOption'] = array();
+ if (isset($obj['FAIdiskOption'])){
+ for($i=0;$i<$obj['FAIdiskOption']['count'];$i++){
+ $objects['FAIdiskOption'][] = $obj['FAIdiskOption'][$i];
+ }
+ }
// Transform potential lvm information
if (isset($obj['FAIlvmDevice'])){
if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
$objects = array();
- $objects['status'] = "edited";
$objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subPartAttributes);
unset($objects['dn']);;
}
}
+ /* Keep track of disk changes, by comparing the initial and resulting
+ * disk setup.
+ */
+ $this->initial_disks = $this->disks;
+
$this->is_new = FALSE;
if($this->dn == "new"){
$this->is_new =TRUE;
}
ksort($this->disks);
+
+ // Prepare lists
+ $this->diskList = new sortableListing();
+ $this->diskList->setDeleteable(true);
+ $this->diskList->setEditable(true);
+ $this->diskList->setWidth("100%");
+ $this->diskList->setHeight("400px");
+ $this->diskList->setColspecs(array('20px','*','*','40px'));
+ $this->diskList->setHeader(array(("?"),_("Name"),_("Description"),"#"));
+ $this->diskList->setDefaultSortColumn(1);
+
}
}
}
- /* New Listhandling */
- foreach($_POST as $name => $value){
- if(preg_match("/^edit_[^_]*_/",$name)){
- $s_entry = preg_replace("/^edit_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
- $s_action = "edit";
- break;
- }
- if (!preg_match("/freeze/i", $this->FAIstate) && preg_match("/^delete_[^_]*_/",$name)){
- $s_entry = preg_replace("/^delete_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
- $s_action = "remove";
- break;
- }
+ $this->diskList->save_object();
+ $action = $this->diskList->getAction();
+ if($action['action'] == 'edit'){
+ $s_entry = $this->diskList->getKey($action['targets'][0]);
+ $s_action ="edit";
+ }
+ if($action['action'] == 'delete'){
+ $s_entry = $this->diskList->getKey($action['targets'][0]);
+ $s_action ="remove";
}
-
/* Disk remove was requested.
* Now check if the disk is still in use, in this case
$list = array();
foreach($this->disks as $dname => $disk){
if($disk['FAIdiskType'] != "disk" && $dname != $s_entry){
- if($disk['status'] == "delete") continue;
if($disk['FAIdiskType'] == "lvm"){
foreach($disk['FAIlvmDevice'] as $partname){
$list[preg_replace("/:.*$/","",$partname)][] = $disk;
}
}
foreach($disk['partitions'] as $partkey => $part){
- if($part['status'] == "delete") continue;
if($disk['FAIdiskType'] == "raid"){
- foreach(split(",",$part['FAIpartitionSize']) as $partname){
+ foreach(explode(",",$part['FAIpartitionSize']) as $partname){
$list[preg_replace("/:.*$/","",$partname)][] = $disk;
}
}
/* Everything is ok, we can remove the disk now.
*/
- if($this->disks[$s_entry]['status']=="edited"){
- $this->disks[$s_entry."-delete"]=$this->disks[$s_entry];
- unset($this->disks[$s_entry]);
- $s_entry = $s_entry."-delete";
- $this->disks[$s_entry]['status']="delete";
- foreach($this->disks[$s_entry]['partitions'] as $name => $value ){
- if($value['status']=="edited"){
- $this->disks[$s_entry]['partitions'][$name]['status']="delete";
- }else{
- unset($this->disks[$s_entry]['partitions'][$name]);
- }
- }
- }else{
- unset($this->disks[$s_entry]);
- }
+ unset($this->disks[$s_entry]);
}
}
}
}else{
$disk = $this->dialog->save();
if(isset($disk['rename'])){
- if($this->disks[$disk['rename']['from']]['status']=="edited"){
- $this->disks[$disk['rename']['from']]['status']="delete";
- }else{
- unset($this->disks[$disk['rename']['from']]);
- }
-
- foreach($disk['partitions'] as $key => $val){
- if($disk['partitions'][$key]['status']!="delete"){
- $disk['partitions'][$key]['status']= "new";
- }
- }
-
- $disk['status']="new";
+ unset($this->disks[$disk['rename']['from']]);
$disk['cn']= $disk['rename']['to'];
}
$smarty->assign("addraid", "");
}
- /* Divlist containing disks */
- $divlist = new divSelectBox("FAItemplates");
- $divlist->setHeight(400);
+ $dn = $this->acl_base_for_current_object($this->dn);
+ $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
+ $this->diskList->setAcl($acl);
+ $data = $lData = array();
foreach($this->disks as $key => $disk){
$act = "";
$dn = $this->acl_base_for_current_object($dn);
$acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
if(preg_match("/(r|w)/",$acl)) {
- if($disk['status'] != "delete"){
-
- $act .= "<input type='image' src='images/lists/edit.png' name='edit_%s' title='"._("edit")."' alt='"._("edit")."'>";
- if(preg_match("/d/",$acl) && !preg_match("/freeze/", $this->FAIstate)){
- $act .="<input type='image' src='images/lists/trash.png' name='delete_%s' title='"._("delete")."' alt='"._("delete")."'>";
- }
-
- $cnt=0;
- foreach($disk['partitions'] as $val){
- if($val['status']!="delete"){
- $cnt ++;
- }
- }
-
- $edit_link = "<a href='?plug=".$_GET['plug']."&act=edit&id=".$key."'>".$key."</a>";
- $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
- "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
- $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
- $divlist->AddEntry(array(
- array("string"=> "<img border='0' src='".$type."'>", "attach"=>"style='width:16px'"),
- array("string"=> $edit_link, "attach"=>"style='width:100px'"),
- array("string"=> $disk['description']),
- array("string"=> $cnt, "attach"=>"style='width:16px'"),
- array("string"=>str_replace("%s",base64_encode($key),$act),
- "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
- }
+ $cnt= count($disk['partitions']);
+ $types= array(
+ "old" => "plugins/fai/images/fai_partitionTable.png",
+ "disk" => "plugins/fai/images/fai_partitionTable.png",
+ "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
+ $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
+ $data[$key] = $key;
+ $lData[$key] = array('data' => array(image($type),$key,$disk['description'],$cnt));
}
}
- $smarty->assign("Entry_divlist",$divlist->DrawList());
+ $this->diskList->setListData($data,$lData);
+ $this->diskList->update();
+ $smarty->assign("Entry_listing",$this->diskList->render());
$display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
return($display);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
- foreach($this->disks as $disk){
+ foreach($this->initial_disks as $disk){
$disk_dn = "cn=".$disk['cn'].",".$this->dn;
$use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i",$release, $disk_dn);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
if(isset($_POST['FAIpartitionTablePosted'])){
if (preg_match("/freeze/", $this->FAIstate)) return;
plugin::save_object();
- foreach($this->attributes as $attrs){
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
- }
- }
+# foreach($this->attributes as $attrs){
+# if(isset($_POST[$attrs])){
+# $this->$attrs = $_POST[$attrs];
+# }
+# }
if(!count($this->disks)){
if(isset($_POST['mode'])){
$this->FAIpartitionMethod = "setup-storage";
*/
if($this->is_new){
$release = $this->parent->parent->fai_release;
- $new_dn= 'cn='.$this->cn.",".get_ou('faiPartitionRDN').get_ou('faiBaseRDN').$release;
+ $new_dn= 'cn='.$this->cn.",".get_ou("faiPartitionTable", "faiPartitionRDN").get_ou('faiBaseRDN').$release;
$res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
if(isset($res[$this->cn])){
$message[] = msgPool::duplicated(_("Name"));
/* Save to LDAP */
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.
if($this->initially_was_account){
new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Saving disk: ");
}else{
new log("create","fai/".get_class($this),$this->dn,$this->attributes);
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Adding disk: ");
}
+ // Prepare disks to be saved - The 'status' attribute is added here.
+ $this->prepareDiskToBeSave();
+
/* Sort entries, because we must delete entries with status="delete" first */
$order = array();
foreach($this->disks as $key => $disk){
}
}
+
/* Append all disks to ldap */
foreach($order as $cn=>$disk){
+
$disk_dn = "cn=".$disk['cn'].",".$this->dn;
+ $short_dn = "cn=".$disk['cn'].",...";
$disk_attrs['cn'] = $disk['cn'];
$disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk");
if($disk['status'] == "new"){
if(isset($disk_attrs[$attr])) unset($disk_attrs[$attr]);
if(isset($disk[$attr]) && !empty($disk[$attr])){
- $disk_attrs[$attr] = $disk[$attr];
+ if(is_array($disk[$attr])){
+ $disk_attrs[$attr] = array_values($disk[$attr]);
+ }else{
+ $disk_attrs[$attr] = $disk[$attr];
+ }
}
}else{
if(isset($disk[$attr]) && !empty($disk[$attr])){
$this->tag_attrs($disk_attrs, $disk_dn, $this->gosaUnitTag);
if($disk['status'] == "delete"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing disk: ");
FAI::prepare_to_save_FAI_object($disk_dn,array(),true);
$this->handle_post_events("remove");
+ unset($this->disks[$cn]);
}elseif($disk['status'] == "edited"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating disk: ");
FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
$this->handle_post_events("modify");
}elseif($disk['status']=="new"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding disk: ");
FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
$this->handle_post_events("add");
}
if($disk['status']!="delete")
/* Add all partitions */
- foreach($disk['partitions'] as $key => $partition){
+ foreach($disk['partitions'] as $pkey => $partition){
$partition_attrs = array();
foreach($partition as $key => $value){
}
}
- $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;
+ $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;
+ $short_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",...";
+
$partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
unset($partition_attrs['status']);
/* Tag object */
$this->tag_attrs($partition_attrs, $partition_dn, $this->gosaUnitTag);
+
if($partition['status'] == "delete"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing partition: ");
FAI::prepare_to_save_FAI_object($partition_dn,array(),true);
$this->handle_post_events("remove");
+ unset($this->disks[$cn]['partitions'][$pkey]);
}elseif($partition['status'] == "edited"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating partition: ");
FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
$this->handle_post_events("modify");
}elseif($partition['status']=="new"){
+ @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding partition: ");
FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
$this->handle_post_events("add");
}
+
+ // We do not need the status flag any longer
+ if(isset($this->disks[$cn]['partitions'][$pkey]['status'])){
+ unset($this->disks[$cn]['partitions'][$pkey]['status']);
+ }
+ }
+ // We do not need the status flag any longer
+ if(isset($this->disks[$cn]['status'])){
+ unset($this->disks[$cn]['status']);
}
}
+ $this->initial_disks = $this->disks;
$this->handle_post_events("add");
}
- function PrepareForCopyPaste($source)
+ function prepareDiskToBeSave()
{
- plugin::PrepareForCopyPaste($source);
+ foreach($this->disks as $id => $disk){
+
+ /* Correct FAIpartitionNr.
+ * If we've only primary partition then set the partition numbers from
+ * 1 to 4, else set the primary from 1 to 3 and logical >= 5
+ *
+ */
+ if(!isset($disk['partitions'])){
+ $disk['partitions'] = array();
+ }
+ $newSetup = array();
+
+ if($disk['FAIdiskType'] == "disk"){
+ $primary = $logical = array();
+ foreach($disk['partitions'] as $partid => $part){
+ if($part['FAIpartitionType'] == "primary"){
+ $primary[$partid] = $part;
+ }elseif($part['FAIpartitionType'] == "logical"){
+ $logical[$partid] = $part;
+ }else{
+ trigger_error("Fatal: unknown disk type? ".$part['FAIpartitionType']);
+ }
+ }
+ $cnt = 1;
+ foreach($primary as $part){
+ $part['FAIpartitionNr'] = $cnt;
+ $part['cn'] = $disk['cn'].$cnt;
+ $newSetup[$cnt] = $part;
+ $cnt ++;
+ }
+ $cnt = 5;
+ foreach($logical as $part){
+ $part['FAIpartitionNr'] = $cnt;
+ $part['cn'] = $disk['cn'].$cnt;
+ $newSetup[$cnt] = $part;
+ $cnt ++;
+ }
+ $this->disks[$disk['cn']]['partitions'] = $newSetup;
+ }
+ }
- /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
+
+ # FAIpartitionNr have to be used as index for this->disks
+ # else the next operation will fail.
+
+
+ /* Check if there are disks to be removed, edited or added.
+ * We compare the initial disk setup with the current setup and
+ * and add a status flag, which will then be used to perform the
+ * correct action - add, edited, remove.
*/
- $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
- foreach($res as $obj){
+ foreach($this->disks as $key => $disk){
- /* Skip not relevant objects */
- if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
+ // - A complete NEW disk
+ if(!isset($this->initial_disks[$disk['cn']])){
+ $this->disks[$key]['status'] = "new";
+ foreach($disk['partitions'] as $pkey => $part){
+ $this->disks[$disk['cn']]['partitions'][$pkey]['status'] = "new";
+ }
+ }else{
+
+ // - Disk was "EDITED"
+ $this->disks[$key]['status'] = "edited";
+ foreach($disk['partitions'] as $pkey => $part){
- $objects = array();
- $objects['description'] = "";
- $objects['status'] = "edited";
- $objects['dn'] = $obj['dn'];
- $objects = $this->get_object_attributes($objects,$this->subAttributes);
- $this->disks[$objects['cn']] = $objects;
- $this->disks[$objects['cn']]['partitions'] = array();
+ // - Check whether partition is "NEW" or "EDITED"
+ if(!isset($this->initial_disks[$key]['partitions'][$pkey])){
+ $this->disks[$key]['partitions'][$pkey]['status'] = "new";
+ }else{
+ $this->disks[$key]['partitions'][$pkey]['status'] = "edited";
+ }
+ }
+ }
}
+
+ /* Check which partitions havbe to be removed.
+ * (They intially existed, but are now gone.)
+ */
+ foreach($this->initial_disks as $ikey => $idisk){
+
+ // - Complete disk was REMOVED.
+ if(!isset($this->disks[$idisk['cn']])){
+ $this->disks[$idisk['cn']] = $idisk;
+ $this->disks[$idisk['cn']]['status'] = "delete";
+ foreach($idisk['partitions'] as $pkey=>$part){
+ $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
+ $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
+ }
+ }else{
+ foreach($idisk['partitions'] as $pkey=>$part){
+ if(!isset($this->disks[$idisk['cn']]['partitions'][$pkey])){
+ $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
+ $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
+ }
+ }
+ }
+ }
+ }
+
- /* read all partitions for each disk
- */
- foreach($this->disks as $name => $disk){
- $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
- foreach($res as $obj){
+ function PrepareForCopyPaste($source)
+ {
+ plugin::PrepareForCopyPaste($source);
- /* Skip not relevant objects */
- if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
+ /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
+ */
- $objects = array();
- $objects['status'] = "edited";
- $objects['dn'] = $obj['dn'];
- $objects = $this->get_object_attributes($objects,$this->subPartAttributes);
- unset($objects['dn']);;
- $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
- }
- }
- ksort($this->disks);
+ /* To be sure to copy disks and partitions correctly, just create a
+ * new PartitionTable object and use the 'disks' attribute
+ * from this it. This is much easier and less code.
+ */
+ $obj = new faiPartitionTable($this->config, $source['dn']);
+ $this->disks = $obj->disks;
}
"plPriority" => 26,
"plSection" => array("administration"),
"plCategory" => array("fai"),
+ "plProperties" =>
+ array(
+ array(
+ "name" => "faiPartitionRDN",
+ "type" => "rdn",
+ "default" => "ou=disk,",
+ "description" => "The 'faiPartitionRDN' statement defines the location where new fai-partitions will be created. The default is 'ou=disk,'.",
+ "check" => "gosaProperty::isRdn",
+ "migrate" => "",
+ "group" => "plugin",
+ "mandatory" => FALSE)),
+
"plProvidedAcls" => array(
"cn" => _("Name")." ("._("Read only").")",
"description" => _("Description"))