X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Ffai%2Fclass_faiPartitionTable.inc;h=96b4adc2201e1acf5a6b0ddc52b01fd1c30a531c;hb=bf9fd071bad641f7fce6d3e3ed61f866841ec183;hp=77b2e76e83075ce9da883a78eb31e6cc7e1d5739;hpb=2304649c2c57b79131339b8bd6fa6359a87de877;p=gosa.git diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index 77b2e76e8..96b4adc22 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -19,11 +19,21 @@ class faiPartitionTable extends plugin var $is_dialog = false; // specifies which buttons will be shown to save or abort var $dialog = NULL; // a dialog, e.g. new disk dialog + var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; + var $cut_paste_mode = false; + + var $CopyPasteVars = array("disks"); + function faiPartitionTable ($config, $dn= NULL) { /* Load Attributes */ plugin::plugin ($config, $dn); + $this->acl ="#all#"; + /* If "dn==new" we try to create a new entry * 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. @@ -31,6 +41,19 @@ class faiPartitionTable extends plugin if($dn != "new"){ $this->dn =$dn; + /* Set acls + */ + $ui = get_userinfo(); + $acl = get_permissions ($this->dn, $ui->subtreeACL); + $acli = get_module_permission($acl, "FAIclass", $this->dn); + $this->acl=$acli; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + /* Read all disks from ldap taht are defined fot this partition table */ $ldap = $this->config->get_ldap_link(); @@ -94,6 +117,8 @@ class faiPartitionTable extends plugin $usedDiskNames[]= $key; } $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); + $this->dialog->acl = $this->acl; + $this->dialog->FAIstate = $this->FAIstate; $this->is_dialog = true; } @@ -116,7 +141,16 @@ class faiPartitionTable extends plugin } } $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); - $_SESSION['objectinfo'] = $this->disks[$Udisk]['dn']; + $this->dialog->acl = $this->acl; + $this->dialog->FAIstate = $this->FAIstate; + + /* Set object info string, which will be displayed in plugin info line */ + if(isset($this->disks[$Udisk]['dn'])){ + $_SESSION['objectinfo'] = $this->disks[$Udisk]['dn']; + }else{ + $_SESSION['objectinfo'] = ""; + } + $this->is_dialog = true; } @@ -127,40 +161,46 @@ class faiPartitionTable extends plugin $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())){ - foreach($this->dialog->check() as $msg){ - print_red($msg); - } - }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']]); + + if($this->FAIstate != "freeze"){ + $this->dialog->save_object(); + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msg){ + print_red($msg); } - - foreach($disk['partitions'] as $key => $val){ - if($disk['partitions'][$key]['status']!="delete"){ - $disk['partitions'][$key]['status']= "new"; + }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"; + $disk['cn']= $disk['rename']['to']; } - $disk['status']="new"; - $disk['cn']= $disk['rename']['to']; + $this->disks[$disk['cn']]=$disk; + unset($this->dialog); + $this->dialog = NULL; + $this->is_dialog=false; + ksort($this->disks); } - - $this->disks[$disk['cn']]=$disk; - unset($this->dialog); + }else{ $this->dialog = NULL; $this->is_dialog=false; - ksort($this->disks); } } @@ -168,22 +208,23 @@ class faiPartitionTable extends plugin * Assign delete status for all its partitions */ if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){ - - foreach($_POST['disks'] as $disk) { - if($this->disks[$disk]['status']=="edited"){ - $this->disks[$disk."-delete"]=$this->disks[$disk]; - unset($this->disks[$disk]); - $disk = $disk."-delete"; - $this->disks[$disk]['status']="delete"; - foreach($this->disks[$disk]['partitions'] as $name => $value ){ - if($value['status']=="edited"){ - $this->disks[$disk]['partitions'][$name]['status']="delete"; - }else{ - unset($this->disks[$disk]['partitions'][$name]); + if($this->FAIstate != "freeze"){ + foreach($_POST['disks'] as $disk) { + if($this->disks[$disk]['status']=="edited"){ + $this->disks[$disk."-delete"]=$this->disks[$disk]; + unset($this->disks[$disk]); + $disk = $disk."-delete"; + $this->disks[$disk]['status']="delete"; + foreach($this->disks[$disk]['partitions'] as $name => $value ){ + if($value['status']=="edited"){ + $this->disks[$disk]['partitions'][$name]['status']="delete"; + }else{ + unset($this->disks[$disk]['partitions'][$name]); + } } + }else{ + unset($this->disks[$disk]); } - }else{ - unset($this->disks[$disk]); } } } @@ -205,10 +246,13 @@ class faiPartitionTable extends plugin $smarty->assign($attrs."CHK"," disabled "); } } - + + foreach($this->attributes as $attr){ + $smarty->assign($attr."ACL",chkacl($this->acl,$attr)); + } + $disks = $this->getDisks(); $smarty->assign("disks" ,$disks); - $smarty->assign("diskKeys",array_flip($disks)); $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE)); return($display); } @@ -262,6 +306,7 @@ class faiPartitionTable extends plugin */ function save_object() { + if($this->FAIstate == "freeze") return; plugin::save_object(); foreach($this->attributes as $attrs){ if(isset($_POST[$attrs])){ @@ -274,8 +319,22 @@ class faiPartitionTable extends plugin /* Check supplied data */ function check() { + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && ($this->copy_paste_mode || $this->cut_paste_mode) ){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=disk,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ - $message= array(); + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a new fai partition table named '%s' in '%s' there is already one defined with the given name."),$this->cn,$r); + } + } return ($message); } @@ -291,6 +350,11 @@ class faiPartitionTable extends plugin * 3 : Save partitions for each disk */ + /* Copy & Paste : Ensure that FAIstate is copied too */ + if($this->copy_paste_mode && preg_match("/freeze/",$this->FAIstate)){ + $this->attrs['FAIstate'] = $this->FAIstate; + } + $ldap = $this->config->get_ldap_link(); if($this->new){ @@ -298,17 +362,17 @@ class faiPartitionTable extends plugin $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); $ldap->cd($this->dn); $ldap->add($this->attrs); - show_ldap_error($ldap->get_error()); }else{ /* Add partition table to ldap */ $ldap->cd($this->dn); $this->cleanup(); -$ldap->modify ($this->attrs); - - show_ldap_error($ldap->get_error()); + $ldap->modify ($this->attrs); } + show_ldap_error($ldap->get_error(), _("Saving FAI partition table base failed")); + /* Do object tagging */ + $this->handle_object_tagging(); /* Sort entries, because we must delete entries with status="delete" first */ $order = array(); @@ -330,24 +394,37 @@ $ldap->modify ($this->attrs); $disk_attrs['description'] = $disk['description']; $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk"); + /* We currently use the copy & paste method */ + if($this->copy_paste_mode){ + $disk['status'] = "new"; + } + if($disk['status']=="new"){ - $ldap->cat($disk_dn); + $ldap->cat($disk_dn,array("objectClass")); if($ldap->count()){ $disk['status']="edited"; } } - + + /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for disks */ + $ldap->cat($disk_dn,array("objectClass")); + $attrs = $ldap->fetch(); + if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ + $disk_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; + } + if($disk['status'] == "delete"){ $ldap->cd($disk_dn); $ldap->rmdir_recursive($disk_dn); + show_ldap_error($ldap->get_error(), _("Removing FAI partition table failed")); }elseif($disk['status']== "edited"){ if(empty($disk_attrs['description'])){ $disk_attrs['description']=array(); } $ldap->cd($disk_dn); $this->cleanup(); -$ldap->modify ($disk_attrs); - + $ldap->modify ($disk_attrs); + show_ldap_error($ldap->get_error(), _("Saving FAI partition table failed")); }elseif($disk['status']== "new"){ if(empty($disk_attrs['description'])){ unset($disk_attrs['description']); @@ -356,67 +433,137 @@ $ldap->modify ($disk_attrs); $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $disk_dn)); $ldap->cd($disk_dn); $ldap->add($disk_attrs); + show_ldap_error($ldap->get_error(), _("Saving FAI partition table failed")); }else{ print_red("unknown status while saving disks"); } - show_ldap_error($ldap->get_error()); - if($disk['status']!="delete") - /* Add all partitions */ - foreach($disk['partitions'] as $key => $partition){ - $partition_attrs = array(); + $this->handle_object_tagging($disk_dn, $this->gosaUnitTag); - foreach($partition as $key => $value){ - if(!empty($value)){ - $partition_attrs[$key]=$value; - }else{ - unset($partition_attrs[$key]); + /* Collect all opperations. Delete first than add new entries .*/ + $Todo['delete'] = array(); + $Todo['rest'] = array(); + + /* Skip partition handling if current disk is marked as deleted */ + if($disk['status']!="delete"){ + + /* Add all partitions */ + foreach($disk['partitions'] as $key => $partition){ + + /* Create attribute array */ + $partition_attrs = array(); + foreach($partition as $key => $value){ + if(!empty($value)){ + $partition_attrs[$key]=$value; + }else{ + unset($partition_attrs[$key]); + } } - } - $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; - $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); - $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; - - unset($partition_attrs['status']); - unset($partition_attrs['old_cn']); - - if($partition['status']=="new"){ - $ldap->cat($partition_dn); - if($ldap->count()){ - $partition['status']="edited"; + /* Create partition dn and add necessary attributes */ + $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; + $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); + $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; + + /* Unset status attributes */ + unset($partition_attrs['status']); + unset($partition_attrs['old_cn']); + + /* We currently use the copy & paste method */ + if($this->copy_paste_mode){ + $partition['status']="new"; + } + + /* Check if this partition is realy new .. */ + if($partition['status']=="new"){ + $ldap->cat($partition_dn,array("objectClass")); + if($ldap->count()){ + $partition['status']="edited"; + } + } + + /* Set mount point top swap if it is emtpy */ + if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ + $partition_attrs['FAImountPoint']="swap"; } - } - if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ - $partition_attrs['FAImountPoint']="swap"; + /* Collect all operations */ + if(($partition['status'] == "delete")&&($disk['status']!="new")){ + $Todo['delete'][$partition_dn] = $partition_attrs; + }elseif($partition['status'] == "new"){ + $Todo['rest'][$partition_dn] = $partition_attrs; + }elseif($partition['status'] == "edited"){ + $Todo['rest'][$partition_dn] = $partition_attrs; + } } + } - if(($partition['status'] == "delete")&&($disk['status']!="new")){ + /* First of all, delete old entries */ + foreach($Todo['delete'] as $partition_dn => $attrs){ $ldap->cd($partition_dn); $ldap->rmdir_recursive($partition_dn); - }elseif($partition['status'] == "new"){ - if(empty($partition_attrs['description'])){ - unset($partition_attrs['description']); + show_ldap_error($ldap->get_error(), _("Removing FAI partition table entry failed")); + } + + /* Add/edit entries */ + foreach($Todo['rest'] as $partition_dn => $partition_attrs){ + + /* Check if entry exists */ + $ldap->cat($partition_dn); + if($ldap->count()){ + + /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */ + $attrs = $ldap->fetch(); + if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ + $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; } - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn)); - $ldap->cd($partition_dn); - $ldap->add($partition_attrs); - }elseif($partition['status'] == "edited"){ if(empty($partition_attrs['description'])){ $partition_attrs['description']=array(); } $ldap->cd($partition_dn); $this->cleanup(); -$ldap->modify ($partition_attrs); + $ldap->modify ($partition_attrs); + show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); + }else{ + + if(empty($partition_attrs['description'])){ + unset($partition_attrs['description']); + } - } - show_ldap_error($ldap->get_error()); + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn)); + $ldap->cd($partition_dn); + $ldap->add($partition_attrs); + show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); + } } + $this->handle_object_tagging($partition_dn, $this->gosaUnitTag); } $this->handle_post_events("add"); } + + + /* return copy & paste dialog + */ + function getCopyDialog() + { + /* Ask for cn */ + $smarty = get_smarty(); + $smarty->assign("cn" ,$this->cn); + $str = $smarty->fetch(get_template_path("paste_fai_object.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + /* Get posted cn */ + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: