diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc
index 1d78d57219a9e839694d7e617708b2dd12808847..59a1cc5d390304dffc56cebd1ee777b891aaefd1 100644 (file)
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 = "";
+
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.
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();
$ldap->cd ($this->dn);
$ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*"));
while($object = $ldap->fetch()){
+
+ /* Skip objects, that are tagged as removed */
+ if(isset($object['FAIstate'][0])){
+ if(preg_match("/removed$/",$object['FAIstate'][0])){
+ continue;
+ }
+ }
+
$this->disks[$object['cn'][0]]['status'] = "edited";
$this->disks[$object['cn'][0]]['dn'] = $object['dn'];
$this->disks[$object['cn'][0]]['cn'] = $object['cn'][0];
$ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))",array("*"));
while($partition = $ldap->fetch()){
+ /* Skip objects, that are tagged as removed */
+ if(isset($partition['FAIstate'][0])){
+ if(preg_match("/removed$/",$partition['FAIstate'][0])){
+ continue;
+ }
+ }
+
/* remove count ... from ldap result
*/
foreach($partition as $key=>$val){
function execute()
{
+ /* Call parent execute */
+ plugin::execute();
+
/* Fill templating stuff */
$smarty= get_smarty();
$display= "";
$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;
}
/* Edit disk.
* Open dialog which allows us to edit the selected entry
*/
- $_SESSION['objectinfo'] = $this->dn;
+
+ if($this->dn != "new"){
+ $_SESSION['objectinfo']= $this->dn;
+ }
+
if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){
$usedDiskNames =array();
+
+ $Udisk = $_POST['disks'][0];
+
foreach($this->disks as $key=>$disk){
- if($key != $_POST['disks']){
+ if($key != $Udisk){
$usedDiskNames[]= $key;
}
}
- $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$_POST['disks']]);
- $_SESSION['objectinfo'] = $this->disks[$_POST['disks']]['dn'];
+ $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
+ $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;
}
$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);
}
}
* Assign delete status for all its partitions
*/
if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){
- $disk = $_POST['disks'];
- 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";
+ 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]['partitions'][$name]);
+ unset($this->disks[$disk]);
}
}
- }else{
- unset($this->disks[$disk]);
}
}
$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);
}
}
}
if(!empty($disk['description'])){
- $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+ if($cnt == 1){
+ $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
+ }else{
+ $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+ }
}else{
- $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+ if($cnt == 1){
+ $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
+ }else{
+ $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+ }
}
}
}
{
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->dn);
- $ldap->rmdir_recursive($this->dn);
- $this->handle_post_events("remove");
-
- /* This cannot be removed... */
+
+ $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+ if($_SESSION['faifilter']['branch'] == "main"){
+ $use_dn = $this->dn;
+ }
+
+ prepare_to_save_FAI_object($use_dn,array(),true);
+
+ foreach($this->disks as $disk){
+
+ $disk_dn = "cn=".$disk['cn'].",".$this->dn;
+ $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $disk_dn);
+ if($_SESSION['faifilter']['branch'] == "main"){
+ $use_dn = $disk_dn;
+ }
+ prepare_to_save_FAI_object($use_dn,array(),true);
+
+ foreach($disk['partitions'] as $key => $partition){
+
+ $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;
+ $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $partition_dn);
+ if($_SESSION['faifilter']['branch'] == "main"){
+ $use_dn = $disk_dn;
+ }
+ prepare_to_save_FAI_object($use_dn,array(),true);
+ }
+ }
}
*/
function save_object()
{
+ if($this->FAIstate == "freeze") return;
plugin::save_object();
foreach($this->attributes as $attrs){
if(isset($_POST[$attrs])){
/* Check supplied data */
function check()
{
+ /* Call common method to give check the hook */
+ $message= plugin::check();
- $message= array();
return ($message);
}
$ldap = $this->config->get_ldap_link();
- if($this->new){
- $ldap->cd($this->config->current['BASE']);
- $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);
- $ldap->modify($this->attrs);
- show_ldap_error($ldap->get_error());
- }
+ prepare_to_save_FAI_object($this->dn,$this->attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/partition table with dn '%s' failed."),$this->dn));
+ /* Do object tagging */
+ $this->handle_object_tagging();
/* Sort entries, because we must delete entries with status="delete" first */
$order = array();
$disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk");
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);
- }elseif($disk['status']== "edited"){
- if(empty($disk_attrs['description'])){
- $disk_attrs['description']=array();
- }
- $ldap->cd($disk_dn);
- $ldap->modify($disk_attrs);
- }elseif($disk['status']== "new"){
- if(empty($disk_attrs['description'])){
- unset($disk_attrs['description']);
- }
- $ldap->cd($this->config->current['BASE']);
- $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $disk_dn));
- $ldap->cd($disk_dn);
- $ldap->add($disk_attrs);
- }else{
- print_red("unknown status while saving disks");
+ prepare_to_save_FAI_object($disk_dn,array(),true);
+ $this->handle_post_events("remove");
+ }elseif($disk['status'] == "edited"){
+ prepare_to_save_FAI_object($disk_dn,$disk_attrs);
+ $this->handle_post_events("modify");
+ }elseif($disk['status']=="new"){
+ prepare_to_save_FAI_object($disk_dn,$disk_attrs);
+ $this->handle_post_events("add");
}
- show_ldap_error($ldap->get_error());
+ $this->handle_object_tagging($disk_dn, $this->gosaUnitTag);
+
if($disk['status']!="delete")
/* Add all partitions */
foreach($disk['partitions'] as $key => $partition){
unset($partition_attrs['old_cn']);
if($partition['status']=="new"){
- $ldap->cat($partition_dn);
+ $ldap->cat($partition_dn,array("objectClass"));
if($ldap->count()){
$partition['status']="edited";
}
$partition_attrs['FAImountPoint']="swap";
}
- if(($partition['status'] == "delete")&&($disk['status']!="new")){
- $ldap->cd($partition_dn);
- $ldap->rmdir_recursive($partition_dn);
- }elseif($partition['status'] == "new"){
- if(empty($partition_attrs['description'])){
- unset($partition_attrs['description']);
- }
- $ldap->cd($this->config->current['BASE']);
- $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn));
- $ldap->cd($partition_dn);
- $ldap->add($partition_attrs);
+ /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */
+ $ldap->cat($partition_dn,array("objectClass"));
+ $attrs = $ldap->fetch();
+ if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){
+ $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag";
+ }
+
+ if($partition['status'] == "delete"){
+ prepare_to_save_FAI_object($partition_dn,array(),true);
+ $this->handle_post_events("remove");
}elseif($partition['status'] == "edited"){
- if(empty($partition_attrs['description'])){
- $partition_attrs['description']=array();
- }
- $ldap->cd($partition_dn);
- $ldap->modify($partition_attrs);
- }
- show_ldap_error($ldap->get_error());
+ prepare_to_save_FAI_object($partition_dn,$partition_attrs);
+ $this->handle_post_events("modify");
+ }elseif($partition['status']=="new"){
+ prepare_to_save_FAI_object($partition_dn,$partition_attrs);
+ $this->handle_post_events("add");
+ }
+
+ $this->handle_object_tagging($partition_dn, $this->gosaUnitTag);
}
}
$this->handle_post_events("add");
}
+
+
+ /* Return plugin informations for acl handling */
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Partition table"),
+ "plDescription" => _("FAI partition table"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "plSection" => array("administration"),
+ "plCategory" => array("fai"),
+ "plProvidedAcls" => array(
+ "cn" => _("Name"),
+ "FAIpartitionType" => _("Partition type"),
+ "FAIpartitionNr" => _("Partition no."),
+ "FAIfsType" => _("File system type"),
+ "FAImountPoint" => _("Mount point"),
+ "FAIpartitionSize" => _("Partition size"),
+ "FAImountOptions" => _("Mount options"),
+ "FAIfsOptions" => _("File system options"),
+ "FAIpartitionFlags" => _("Partition flags"))
+ ));
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: