diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
index 878c4833ac63626843e0c9d607c9ab6ef2ce1b2f..9534a765e1afef84ca18981a5b89c3b45e717139 100644 (file)
{
/* attribute list for save action */
var $ignore_account = TRUE;
- var $attributes = array("cn","description");
+ var $attributes = array("cn","description", "FAIpartitionMethod");
var $objectclasses = array("top","FAIclass","FAIpartitionTable");
var $subAttributes = array("cn","description");
- var $subPartAttributes = array("cn","FAIpartitionNr","FAIpartitionSize","FAImountPoint","FAIfsType","FAIpartitionType","FAImountOptions","FAIfsOptions","FAIpartitionFlags","description");
+ var $subPartAttributes = array("cn","FAIpartitionNr","FAIpartitionSize","FAImountPoint","FAIfsType","FAIpartitionType","FAImountOptions","FAIfsOptions","FAIpartitionFlags","description","FAIfsCreateOptions","FAIfsTuneOptions","FAIfsOptions","FAIpartitionFlags","FAIlvmDevice");
var $sub64coded = array();
var $subBinary = array();
/* 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 $cn = ""; // The class name for this object
+ var $description = ""; // The description for this set of partitions
+ var $FAIpartitionMethod = ""; // "setup-storage" or not assigned
+ var $disks = array(); // All defined Disks
+ var $is_dialog = false; // specifies which buttons will be shown to save or abort
- var $FAIstate = "";
+ var $FAIstate = "";
var $ui;
var $view_logged = FALSE;
foreach($res as $obj){
/* Skip not relevant objects */
- if(!preg_match("/".normalizePreg($this->dn)."$/i",$obj['dn'])) continue;
-
+ 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'])){
+ $objects['FAIdiskType'] = "old";
+ } else {
+ $objects['FAIdiskType'] = $obj['FAIdiskType'];
+ }
+ $objects['FAIdiskOption'] = $obj['FAIdiskOption'];
+
+ // Transform potential lvm information
+ if (isset($obj['FAIlvmDevice'])){
+ $objects['FAIlvmDevice'] = $obj['FAIlvmDevice'];
+ }
+
$objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$this->disks[$objects['cn']] = $objects;
foreach($res as $obj){
/* Skip not relevant objects */
- if(!preg_match("/".normalizePreg($disk['dn'])."$/i",$obj['dn'])) continue;
+ if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
$objects = array();
$objects['status'] = "edited";
function acl_base_for_current_object($dn)
{
- if($dn == "new"){
+ if($dn == "new" || $dn == ""){
if($this->dn == "new"){
- $dn = session::get('CurrentMainBase');
+ $dn= $this->parent->parent->acl_base;
}else{
$dn = $this->dn;
}
* This code adds a new HDD to the disks
* A new Dialog will be opened
*/
- if(isset($_POST['AddDisk']) && !preg_match("/freeze/i",$this->FAIstate)){
+ if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) &&
+ !preg_match("/freeze/i",$this->FAIstate)){
$usedDiskNames =array();
foreach($this->disks as $key=>$disk){
$usedDiskNames[]= $key;
}
- $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames);
+ if ($this->FAIpartitionMethod == "setup-storage") {
+ if(isset($_POST['AddDisk'])) $type = "disk";
+ if(isset($_POST['AddRaid'])) $type = "raid";
+ if(isset($_POST['AddAddVolgroup'])) $type = "lvm";
+ $this->dialog = new faiDiskEntry($this->config,$this->dn,$this, array(),$type);
+ } else {
+ $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this);
+ }
+
$this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
$this->dialog->set_acl_category("fai");
$this->dialog->FAIstate = $this->FAIstate;
+
+
$this->is_dialog = true;
}
*/
if($this->dn != "new"){
- session::set('objectinfo',$this->dn);
+ set_object_info($this->dn);
+ }
+
+ /* Edit entries via GET */
+ $Udisk = null;
+ if(isset($_GET['act']) && isset($_GET['id'])){
+ if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
+ $Udisk= $_GET['id'];
+ }
}
- if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){
+ /* New Listhandling */
+ foreach($_POST as $name => $value){
+ if(preg_match("/^edit_/",$name)){
+ $entry = preg_replace("/^edit_/","",$name);
+ $Udisk = base64_decode(preg_replace("/_.*/","",$entry));
+ break;
+ }
+ if(preg_match("/^delete_/",$name)){
+ $entry = preg_replace("/^delete_/","",$name);
+ $disk = base64_decode(preg_replace("/_.*/","",$entry));
+
+ if (!preg_match("/freeze/i", $this->FAIstate)){
+ if(isset($this->disks[$disk])){
+
+ /* Check for references */
+ $ignore = false;
+ $name = "";
+ foreach($this->disks as $dtest) {
+ // Is raid?
+ $device= null;
+ $name = $dtest['cn'];
+
+ if ($disk == "raid"){
+ $device = "md";
+ } else {
+ $device = $disk;
+
+ // Used by raid?
+ if (isset($this->disks[$name]['partitions'])){
+ foreach ($this->disks[$name]['partitions'] as $partition) {
+ if (preg_match("/${disk}\.?[0-9]+/", $partition['FAIpartitionSize'])){
+ $ignore = true;
+ break 2;
+ }
+ }
+ }
+ }
+
+ // Used by volgroup?
+ if (isset($this->disks[$name]["FAIlvmDevice"])){
+ foreach ($this->disks[$name]["FAIlvmDevice"] as $vg_element) {
+ if (preg_match("/^${device}\.?[0-9]+$/", $vg_element)){
+ $ignore = true;
+ break 2;
+ }
+ }
+ }
+ }
+
+ if ($ignore) {
+ msg_dialog::display(_("Error"), sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), $name), ERROR_DIALOG);
+ } else {
+ 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]);
+ }
+ }
+
+ }
+ }
+ break;
+ }
+ }
+
+ if($Udisk){
$usedDiskNames =array();
- $Udisk = $_POST['disks'][0];
if(isset($this->disks[$Udisk])){
foreach($this->disks as $key=>$disk){
/* Set object info string, which will be displayed in plugin info line */
if(isset($this->disks[$Udisk]['dn'])){
- session::set('objectinfo',$this->disks[$Udisk]['dn']);
+ set_object_info($this->disks[$Udisk]['dn']);
$dn = $this->disks[$Udisk]['dn'];
}else{
- session::set('objectinfo',"");
+ set_object_info("");
$dn = "new";
}
- $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
- $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
- $this->dialog->set_acl_category("fai");
- $this->dialog->FAIstate = $this->FAIstate;
-
- $this->is_dialog = true;
+ if(isset($this->disks[$Udisk]['FAIdiskType'])){
+ switch($this->disks[$Udisk]['FAIdiskType']){
+ case 'raid':
+ case 'lvm':
+ case 'disk':
+ $this->dialog = new faiDiskEntry(
+ $this->config,$this->dn,$this,$this->disks[$Udisk],
+ $this->disks[$Udisk]['FAIdiskType']);
+ break;
+ case 'old':
+ $this->dialog = new faiPartitionTableEntry(
+ $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
+ break;
+ }
+ }else{
+ $this->dialog = new faiPartitionTableEntry(
+ $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]);
+ }
+ if($this->dialog){
+ $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
+ $this->dialog->set_acl_category("fai");
+ $this->dialog->FAIstate = $this->FAIstate;
+ $this->is_dialog = true;
+ }
}
}
}
}
- /* Delete selected disk drive from list
- * Assign delete status for all its partitions
- */
- if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){
- if (!preg_match("/freeze/i", $this->FAIstate)){
- foreach($_POST['disks'] as $disk) {
-
- if(isset($this->disks[$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]);
- }
- }
- }
- }
- }
-
/* Display dialog if one is defined
*/
if(is_object($this->dialog)){
foreach($tmp['plProvidedAcls'] as $name => $translated){
$smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
}
- $disks = $this->getDisks();
- $smarty->assign("disks" ,$disks);
- $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
- return($display);
- }
- function getDisks(){
- /* Return all available disks for this partition table
- * Return in listBox friendly array
- */
- $a_return = array();
+ /* Assign mode */
+ if ($this->FAIpartitionMethod == ""){
+ $smarty->assign("mode", "");
+ $smarty->assign("storage_mode", "disabled");
+ } else {
+ $smarty->assign("mode", "checked");
+ $smarty->assign("storage_mode", "");
+ }
+ if (!count($this->disks)) {
+ $smarty->assign("lockmode", "");
+ } else {
+ $smarty->assign("lockmode", "disabled");
+ }
+ if (isset($this->disks['raid'])){
+ $smarty->assign("addraid", "disabled");
+ } else {
+ $smarty->assign("addraid", "");
+ }
+
+ /* Divlist containing disks */
+ $divlist = new divSelectBox("FAItemplates");
+ $divlist->setHeight(400);
foreach($this->disks as $key => $disk){
+ $act = "";
$dn = "new";
if(isset($obj['dn'])){
$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)){
+ $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 ++;
}
}
- if(!empty($disk['description'])){
- 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{
- if($cnt == 1){
- $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
- }else{
- $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition(s)"), $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;'")));
}
}
}
- return($a_return);
+ $smarty->assign("Entry_divlist",$divlist->DrawList());
+
+ $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
+ return($display);
}
+
/* Delete me, and all my subtrees
*/
function remove_from_parent()
$ldap->cd ($this->dn);
$release = $this->parent->parent->fai_release;
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $this->dn);
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
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){
$disk_dn = "cn=".$disk['cn'].",".$this->dn;
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i",$release, $disk_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);
foreach($disk['partitions'] as $key => $partition){
$partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $partition_dn);
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $partition_dn);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
}
}
$this->$attrs = $_POST[$attrs];
}
}
+ if(isset($_POST['faiPartitionTable'])){
+ if(!count($this->disks)){
+ if(isset($_POST['mode'])){
+ $this->FAIpartitionMethod = "setup-storage";
+ }else{
+ $this->FAIpartitionMethod = "";
+ }
+ }
+ }
}
*/
if($this->is_new){
$release = $this->parent->parent->fai_release;
- $new_dn= 'cn='.$this->cn.",".get_ou('faipartitionou').get_ou('faiou').$release;
+ $new_dn= 'cn='.$this->cn.",".get_ou('faiPartitionRDN').get_ou('faiBaseRDN').$release;
$res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
if(isset($res[$this->cn])){
$message[] = msgPool::duplicated(_("Name"));
foreach($order as $cn=>$disk){
$disk_dn = "cn=".$disk['cn'].",".$this->dn;
$disk_attrs['cn'] = $disk['cn'];
- $disk_attrs['description'] = $disk['description'];
+ $disk_attrs['description'] = $disk['description'];
+
+ if(isset($disk['FAIdiskType'])){
+ $disk_attrs['FAIdiskType'] = $disk['FAIdiskType'];
+ }
+ if(isset($disk['FAIdiskOption'])){
+ $disk_attrs['FAIdiskOption'] = $disk['FAIdiskOption'];
+ }
+ if(isset($disk['FAIlvmDevice'])){
+ $disk_attrs['FAIlvmDevice'] = $disk['FAIlvmDevice'];
+ }
if(empty($disk_attrs['description']) && $disk['status'] == "edited"){
$disk_attrs['description'] = array();
}
if($disk['status']!="delete")
+
/* Add all partitions */
foreach($disk['partitions'] as $key => $partition){
$partition_attrs = array();
function PrepareForCopyPaste($source)
{
plugin::PrepareForCopyPaste($source);
- /* Get FAIstate
- */
- if(isset($source['FAIstate'][0])){
- $this->FAIstate = $source['FAIstate'][0];
- }
- /* Read all disks from ldap taht are defined fot this partition table
+ /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($source['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];
- if(isset($object['description'][0])){
- $this->disks[$object['cn'][0]]['description'] = $object['description'][0];
- }else{
- $this->disks[$object['cn'][0]]['description'] = "";
- }
- $this->disks[$object['cn'][0]]['partitions'] = array();
+ $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
+ foreach($res as $obj){
+
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
+
+ $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();
}
- /* read all partitions for each disk
+ /* read all partitions for each disk
*/
foreach($this->disks as $name => $disk){
- $ldap->cd ($disk['dn']);
- $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;
- }
- }
+ $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
+ foreach($res as $obj){
- /* remove count ... from ldap result
- */
- foreach($partition as $key=>$val){
- if((is_numeric($key))||($key=="count")||($key=="dn")){
- unset($partition[$key]);
- }else{
- $partition[$key] = $val[0];
- }
- }
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
- /* Append fetched partitions
- */
- $partition['status']="edited";
- $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition;
- }
+ $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);
}