diff --git a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc
index 2975fe0c072e775c4b5a5458488982ee4985dfee..0c63bf53617c2b2e1e475eee21044d765655c28d 100644 (file)
var $partitions = array();
var $is_edit = false;
var $old_cn = "";
- var $status = "new";
- var $deletePartitions = array();
var $fstabkey = "device";
var $disklabel = "msdos";
var $FAIstate = "";
// Set default attributes
$this->parent = $parent;
$this->FAIdiskType = $type;
- $this->status = "new";
// If disk is not empty, then we are going to edit
// an existing disk, load disk info now.
$this->lvmDevices = $disk['FAIlvmDevice'];
}
- // Get disk status
- $this->status = $disk['status'];
-
// Load default attributes
$this->DISKcn = $disk['cn'];
$this->DISKdescription = $disk['description'];
$this->old_cn = $disk['cn'];
// Load partition info
- foreach($disk['partitions'] as $name => $values){
+ foreach($disk['partitions'] as $values){
- // Do not load removed partitions
- if($values['status'] == "delete"){
- unset($disk['partitions'][$name]);
- $this->deletePartitions[]=$values;
- }else{
+ $name = $values['FAIpartitionNr'];
- /* If status is not new, set to edit mode.
- * New means that this partition currently wasn't saved to ldap.
- */
- if($disk['partitions'][$name]['status']!="new"){
- $disk['partitions'][$name]['status']="edited";
- }
-
- // Load partition attributes
- $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
- $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
- foreach($this->UsedAttrs as $attr){
- if(!isset($values[$attr])){
- $disk['partitions'][$name][$attr]="";
- }
- }
- if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
- $disk['partitions'][$name]['FAIfsType']=
- preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
+ // Load partition attributes
+ $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
+ $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
+ foreach($this->UsedAttrs as $attr){
+ if(!isset($values[$attr])){
+ $disk['partitions'][$name][$attr]="";
}
}
+
+ if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
+ $disk['partitions'][$name]['FAIfsType']=
+ preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
+ }
}
$this->partitions = $disk['partitions'];
/* Load FAIdiskOptions.
- * Some options are disk related and some are used for partitions.
+ * Some options are disk related and others are used for partitions.
* - fstabkey -> disk
* - disklabel -> disk
* - bootable -> partition
// Load bootable flag for partitions
if (preg_match("/^bootable:/", $option)){
- $bootable = split(",", trim(preg_replace("/^bootable:/","",$option),","));
+ $bootable = explode(",", trim(preg_replace("/^bootable:/","",$option),","));
foreach($bootable as $bootflag){
if(isset($this->partitions[$bootflag])){
$this->partitions[$bootflag]['bootable'] = TRUE;
// Load resize flag for partitions
if (preg_match("/^resize:/", $option)){
- $resize = split(",", trim(preg_replace("/^resize:/","",$option),","));
+ $resize = explode(",", trim(preg_replace("/^resize:/","",$option),","));
foreach($resize as $id){
if(isset($this->partitions[$id])){
$this->partitions[$id]['resize'] = TRUE;
// Load preserve_always flag for partitions
if (preg_match("/^preserve_always:/", $option)){
- $preserve = split(",", trim(preg_replace("/^preserve_always:/","",$option),","));
+ $preserve = explode(",", trim(preg_replace("/^preserve_always:/","",$option),","));
foreach($preserve as $presflag){
if(isset($this->partitions[$presflag])){
$this->partitions[$presflag]['preserve'] = TRUE;
// Load preserve_reinstall flag for partitions
if (preg_match("/^preserve_reinstall:/", $option)){
- $preserve = split(",", trim(preg_replace("/^preserve_reinstall:/","",$option),","));
+ $preserve = explode(",", trim(preg_replace("/^preserve_reinstall:/","",$option),","));
foreach($preserve as $presflag){
if(isset($this->partitions[$bootflag])){
$this->partitions[$presflag]['preserve'] = TRUE;
$this->fstabkey= "device";
}
}
+
+ // 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('200px','*'));
+ $this->diskList->setHeader(array("Name",_("Description"),_("Type"),_("Mount point"),_("Options")));
+ $this->diskList->setDefaultSortColumn(1);
+ $this->diskList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
}
// Remove partition from lvm compilation.
if(isset($_POST['delLvmPartition']) && isset($_POST['physicalPartition'])){
- $names = $_POST['physicalPartition'];
+ $names = get_post('physicalPartition');
foreach($names as $name){
if(isset($this->lvmDevices[$name])){
unset($this->lvmDevices[$name]);
}
}
- /* Check all Posts if there is something usefull for us,
- * For example : Delete is posted as Delete_1
- * The number specifies the index we want to delete
- */
- foreach($_POST as $name => $value){
- if((preg_match("/RemovePartition_/",$name)) &&
- $this->acl_is_removeable() &&
- !preg_match("/freeze/i",$this->FAIstate)){
- $tmp = split("_",$name);
- $this->removePartition($tmp[1]);
- break;
- }
- if(preg_match("/^EditPartition_/",$name)){
- $id = preg_replace("/^EditPartition_/","",$name);
- $id = preg_replace("/_.*$/","",$id);
+ // Get list actions
+ $this->diskList->save_object();
+ $action = $this->diskList->getAction();
+ if($action['action'] == 'edit'){
+ $id = $this->diskList->getKey($action['targets'][0]);
if(isset($this->partitions[$id])){
- $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
- break;
+ $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
}
- }
}
-
- /* Act on _GET edit request
- */
- if(isset($_GET['act']) && $_GET['act'] == "editPart" && isset($_GET['id'])){
- $id = $_GET['id'];
- if(isset($this->partitions[$id])){
- $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
- }
+ if($action['action'] == 'delete'){
+ $id = $this->diskList->getKey($action['targets'][0]);
+ if(isset($this->partitions[$id])){
+ $this->removePartition($id);
+ }
}
/* Create a new partition for this disk.
if($this->dialog instanceOf plugin && isset($_POST['PartitionSave'])){
$this->dialog->save_object();
+ // Validate new partition
$new_partition = $this->dialog->save();
$msgs = $this->dialog->check();
$msgs = array_merge($msgs,$this->check_disks($new_partition));
// Assign checkbox related values.
foreach($this->attributes as $attrs){
- $smarty->assign($attrs,$this->$attrs);
+ $smarty->assign($attrs,set_post($this->$attrs));
if($this->$attrs){
$smarty->assign($attrs."CHK"," ");
}else{
$smarty->assign("fstabkeys", array("device" => _("Device"), "label" => _("Label"), "uuid" => _("UUID")));
$smarty->assign("disklabels", array("msdos" => "MSDOS", "gpt" => "GPT"));
$smarty->assign("fstabkey", $this->fstabkey);
- $smarty->assign("disklabel", $this->disklabel);
+ $smarty->assign("disklabel", set_post($this->disklabel));
$smarty->assign("FAIdiskType", $this->FAIdiskType);
$smarty->assign("plist", $this->getPartitionList());
$smarty->assign("physicalPartitionList", $this->getAvailablePartitions());
- foreach($this->attributes as $attr){
- $smarty->assign($attr,$this->$attr);
- }
-
// Assign partitions
$tmp = $this->plInfo();
$sacl = "";
return($display);
}
+
+ /* Creates a human readable list, that contains all physical
+ * devices that are used by the volume group.
+ * This list will then be displayed in a html select box.
+ * (lvm)
+ */
function getPartitionList()
{
- $divlist = new divSelectBox("RaidList");
-
/* Create a list of all available disks and partitions.
* This list will then be used to display detailed info.
*/
}
- /* Returns a list of available partitions that are useable in this
- * lvm disk setup.
+ /* Returns a list of available partitions that are useable in
+ * lvm disk setups.
*/
function getAvailablePartitions()
{
- $array = array();
+ $may = $used = array();
foreach($this->parent->disks as $disk){
- // We can't add ourselves to the available partitions
- if($disk['cn'] == $this->old_cn) continue;
+ // Skip ourselves
+ if($disk['cn'] == $this->DISKcn) continue;
+
+ // Add partition from lvm combinations
+ if($disk['FAIdiskType'] == "lvm"){
+ $used = array_merge($used,$disk['FAIlvmDevice']);
+ }
- // Add partitions to the list.
foreach($disk['partitions'] as $key => $part){
- $name = $part['cn'];
- if(!isset($this->lvmDevices[$name])){
- $array[$name] = $name;
+
+ // Add disks of raid arrays, to the used list.
+ if($disk['FAIdiskType'] == "raid"){
+ foreach(explode(",",$part['FAIpartitionSize']) as $rDevice){
+ $used[] = preg_replace("/:.*$/i","",$rDevice);
+ }
+ }
+
+ // Collect all available partitions
+ if($disk['FAIdiskType'] == "disk" || $disk['FAIdiskType'] == "raid"){
+ $name = $part['cn'];
+ if(!isset($this->lvmDevices[$name])){
+ $may[] = $name;
+ }
}
}
}
- return($array);
+ // Check which of the available disks are unused.
+ $ret = array();
+ foreach($may as $val){
+ if(!in_array_strict($val,$used)){
+ $ret[$val] = $val;
+ }
+ }
+ return($ret);
}
/* Remove the selected partition and shift the following partitions
* to fill the gap.
* Additionally update the partition numbers correspondingly.
+ * (Checks if the partition is in use, too)
*/
function removePartition($id)
{
$list = array();
foreach($this->parent->disks as $dname => $disk){
if($disk['FAIdiskType'] != "disk"){
- 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;
}
}
msg_dialog::display(_("Error"),
sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"),
$used), ERROR_DIALOG);
-
}else{
- foreach($this->partitions as $key => $part){
- if($id == $key){
- $start = true;
- }
- if($start){
- if($this->partitions[$key]['status'] == "edited"){
- $this->deletePartitions[$key]= $this->partitions[$key];
- $this->deletePartitions[$key]['FAIpartitionNr']=$key;
- unset($this->partitions[$key]);
- }else{
- unset($this->partitions[$key]);
- }
- if(isset($this->partitions[($key+1)])){
- if(isset($this->deletePartitions[$key])){
- unset($this->deletePartitions[$key]);
- }
- $this->partitions[$key] = $this->partitions[($key+1)];
- $this->partitions[$key]['FAIpartitionNr'] = $key;
- $this->partitions[$key]['status'] = "new";
- }
- }
- }
- $tmp= array();
- foreach($this->partitions as $part){
- $tmp[count($tmp)+1]=$part;
- }
- $this->partitions = $tmp;
+ unset($this->partitions[$id]);
}
}
+
+ function get_free_partition_number()
+ {
+ $used = array();
+ foreach($this->partitions as $key => $part){
+ $used[$key] = $part['FAIpartitionNr'];
+ }
+ $id = 1;
+ while(in_array_strict($id,$used) && $id < 16 ){
+ $id++;
+ }
+ return($id);
+ }
+
+
/* Add or update a partition
*/
function updatePartition($part)
{
if(!isset($part['FAIpartitionNr']) || $part['FAIpartitionNr'] == "undefined"){
- $part['FAIpartitionNr'] = count($this->partitions) + 1;
+ $part['FAIpartitionNr'] = $this->get_free_partition_number();
}
/* Update the disk cn -
- * Do NOT touch the partition 'cn' in case of lvm devices.
+ * Do NOT touch the partition 'cn' in case of lvm or raid devices.
*/
if($this->FAIdiskType == "disk"){
$part['cn'] = $this->DISKcn.$part['FAIpartitionNr'];
}
- /* Check if we've to update lvm compilations.
+ /* Check if we've to update partition names of lvm compilations.
*/
if($this->FAIdiskType == "lvm"){
if(isset($this->partitions[$part['FAIpartitionNr']])){
}
}
- /* Check if we've to update lvm compilations.
+ /* Set raid names to md#
*/
if($this->FAIdiskType == "raid"){
$part['cn'] = 'md'.$part['FAIpartitionNr'];
}
+ /* This method generates the partition listing with all necessary info,
+ * depending on the disk type.
+ */
function generateParts()
{
-
- $divlist = new divSelectBox("DiskEntries");
+ $data = $lData = array();
foreach($this->partitions as $key => $part){
+
+ $cn = $part['cn'];
+ $desc = $part['description'];
+ $number = $part['FAIpartitionNr'];
+ $size = $part['FAIpartitionSize'];
+ $type = $part['FAIpartitionType'];
- $cn =array(
- "string" => "<a href='?plug=".$_GET['plug']."&act=editPart&id={$key}'>".$part['cn']."</a>",
- "attach" => "style='width:160px;'");
-
- $desc =array(
- "string" => "<a href='?plug=".$_GET['plug']."&act=editPart&id={$key}'>".
- $part['description']."</a>",
- "attach" => "style='width:200px;'");
-
- $number =array(
- "string" => $part['FAIpartitionNr'],
- "attach" => "style='width:20px;'");
- $size =array(
- "string" => $part['FAIpartitionSize'],
- "attach" => "style='width:100px;'");
- $type =array(
- "string" => $part['FAIpartitionType'],
- "attach" => "style='width:80px;'");
-
+ // Remove encryption info from the mount point.
$mnt = $part['FAImountPoint'];
if(preg_match("/:encrypt/", $mnt)){
$mnt = preg_replace("/:encrypt/","",$mnt);
}
- $mntp =array("string" => $mnt);
+ // create human readable strings out of the flags.
$opt = "";
if(isset($part['encrypted']) && $part['encrypted']){
$opt.= " "._("encrypted").", ";
}
if(isset($part['bootable']) && $part['bootable']){
- $opt.= " "._("bootable").", ";
+ $opt.= " "._("boot able").", ";
}
if(isset($part['preserve']) && $part['preserve']){
$opt.= " "._("preserve").": ".$part['preserveType'].", ";
- }
- $opt =array(
- "string" => "<i>".preg_replace('/, $/',"",$opt)."</i>");
-
- if(!preg_match("/freeze/", $this->FAIstate)){
- $action =array(
- "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
- "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
- "attach" => "style='width:40px; border-right: 0px;'");
- }else{
- $action =array(
- "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
- "attach" => "style='width:40px; border-right: 0px;'");
- }
+ }
-
+ // Combine options to a single table col.
+ $opt = "<i>".preg_replace('/, $/',"",$opt)." </i>";
- if($this->FAIdiskType == "lvm"){
- $fields = array($cn,$desc,$mntp,$opt,$size, $action);
+ // Build up info table, depending on the disk type.
+ $data[$key]=$key;
+ if($this->FAIdiskType == "lvm"){
+ $lData[$key]=array('data' => array($cn,$desc,"",$mnt,$opt,$size));
}elseif($this->FAIdiskType == "raid"){
-
- $raid_str = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
- $raid = array("string" => $raid_str);
-
- $fields = array($cn,$desc,$raid,$mntp,$opt,$action);
+ $raid = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
+ $lData[$key]=array('data' => array($cn,$desc,$raid,$mnt,$opt));
}else{
- $fields = array($number,$desc,$type,$mntp,$opt,$size,$action);
+ $lData[$key]=array('data' => array("",$desc,$type,$mnt,$opt,$size));
}
- $divlist->AddEntry($fields);
}
- return($divlist->DrawList());
+ $this->diskList->setListData($data,$lData);
+ $acl = "rwcdm";
+ if(preg_match("/freeze/", $this->FAIstate)) $acl = "r";
+ $this->diskList->setAcl($acl);;
+ $this->diskList->update();
+ return($this->diskList->render());
}
$tmp = array();
$tmp['cn'] = $this->DISKcn;
- /* Attach partitions */
+ /* Attach partitions.
+ * And prepare names and numbers.
+ */
foreach($this->partitions as $key=>$val) {
$this->partitions[$key]['FAIpartitionNr']=$key;
-
if($this->FAIdiskType == "disk"){
$this->partitions[$key]['cn'] = $this->DISKcn.$key;
}elseif($this->FAIdiskType == "lvm"){
}
}
- /* Attach deleted */
- foreach($this->deletePartitions as $key=>$val) {
- $this->partitions[$key."-delete"]=$val;
- $this->partitions[$key."-delete"]['status']="delete";
- }
-
$tmp['description'] = $this->DISKdescription;
$tmp['partitions'] = $this->partitions;
- $tmp['status'] = $this->status;
$tmp['FAIdiskType'] = $this->FAIdiskType;
+ // Add lvm devices if available.
$tmp['FAIlvmDevice'] = array();
foreach($this->lvmDevices as $dev){
$tmp['FAIlvmDevice'][] = $dev;
$preserve_always = "";
$preserve_reinstall = "";
+ /* Assemble boot, resize and preserve flags
+ */
foreach($tmp['partitions'] as $id => $part){
if(isset($part['bootable']) && $part['bootable']){
$bootable .= $id.",";
$preserve_reinstall .= $id.",";
}
}
- $tmp['partitions'][$id]['status'] = $part['status'];
// Unset non valid attributes
foreach(array("bootable","encrypted","preserve","preserveType","resize","FAIdiskType") as $attr){
}
}
+ /* Assembe disk flags
+ */
if(!empty($bootable)){
$tmp['FAIdiskOption'][] = "bootable:".trim($bootable,",");
}
$tmp['FAIdiskOption'][] = "preserve_reinstall:".trim($preserve_reinstall,",");
}
- $tmp['status'] = $this->status;
return($tmp);
}
// Save posted disk label and fstab key
if (isset($_POST['disklabel']) && preg_match("/^(msdos|gpt)$/", $_POST['disklabel'])){
- $this->disklabel= $_POST['disklabel'];
+ $this->disklabel= get_post('disklabel');
}
if (isset($_POST['fstabkey']) && preg_match("/^(device|label|uuid)$/", $_POST['fstabkey'])){
- $this->fstabkey= $_POST['fstabkey'];
+ $this->fstabkey= get_post('fstabkey');
}
}
}
if(preg_match("/[^a-z0-9_\-]/i",$d)){
$message[] = msgPool::invalid(_("Name"),$d,"/[a-z0-9_\-]/i");
}
+
return ($message);
}
"FAIpartitionFlags" => _("Partition flags"))
));
}
-
}