1 <?php
3 class faiDiskEntry extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes = array("DISKcn","DISKdescription");
8 var $UsedAttrs = array("cn","description","FAIpartitionType",
9 "FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
10 "FAIfsTuneOptions", "FAIfsCreateOptions", "FAImountOptions",
11 "FAIfsOptions","FAIpartitionFlags","FAIdiskOption");
13 var $objectclasses= array();
15 var $DISKcn = "";
16 var $DISKdescription = "";
17 var $DISKFAIdiskOptions = "";
19 var $partitions = array();
20 var $is_edit = false;
21 var $old_cn = "";
22 var $status = "new";
23 var $deletePartitions = array();
24 var $fstabkey = "device";
25 var $disklabel = "msdos";
26 var $FAIstate = "";
27 var $FAIdiskType = "disk";
29 var $lvmDevices = array();
31 function faiDiskEntry (&$config, $dn= NULL,$parent,$disk,$type)
32 {
33 plugin::plugin ($config, $dn);
35 // Set default attributes
36 $this->parent = $parent;
37 $this->FAIdiskType = $type;
38 $this->status = "new";
40 // If disk is not empty, then we are going to edit
41 // an existing disk, load disk info now.
42 if($disk){
44 // Get devices used in volume base disks.
45 if(isset($disk['FAIlvmDevice'])){
46 $this->lvmDevices = $disk['FAIlvmDevice'];
47 }
49 // Get disk status
50 $this->status = $disk['status'];
52 // Load default attributes
53 $this->DISKcn = $disk['cn'];
54 $this->DISKdescription = $disk['description'];
55 $this->is_edit = true;
56 $this->old_cn = $disk['cn'];
58 // Load partition info
59 foreach($disk['partitions'] as $values){
61 $name = $values['FAIpartitionNr'];
63 // Do not load removed partitions
64 if($values['status'] == "delete"){
65 unset($disk['partitions'][$name]);
66 $this->deletePartitions[]=$values;
67 }else{
69 /* If the partition status is not 'new', then set it to 'edit'.
70 * New means that this partition wasn't saved to ldap, yet.
71 */
72 if($disk['partitions'][$name]['status']!="new"){
73 $disk['partitions'][$name]['status']="edited";
74 }
76 // Load partition attributes
77 $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
78 $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
79 foreach($this->UsedAttrs as $attr){
80 if(!isset($values[$attr])){
81 $disk['partitions'][$name][$attr]="";
82 }
83 }
85 if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
86 $disk['partitions'][$name]['FAIfsType']=
87 preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
88 }
89 }
90 }
92 $this->partitions = $disk['partitions'];
94 /* Load FAIdiskOptions.
95 * Some options are disk related and others are used for partitions.
96 * - fstabkey -> disk
97 * - disklabel -> disk
98 * - bootable -> partition
99 * - preserve -> partition
100 * - resize -> partition
101 */
102 if (isset($disk['FAIdiskOption'])){
103 foreach($disk['FAIdiskOption'] as $option) {
105 // Get fstab key
106 if (preg_match("/fstabkey:(device|label|uuid)/", $option)){
107 $this->fstabkey= preg_replace("/^.*fstabkey:(device|label|uuid).*$/", "$1", $option);
108 continue;
109 }
111 // Get disk label
112 if (preg_match("/disklabel:(msdos|gpt)/", $option)){
113 $this->disklabel= preg_replace("/^.*disklabel:(msdos|gpt).*$/", "$1", $option);
114 continue;
115 }
117 // Load bootable flag for partitions
118 if (preg_match("/^bootable:/", $option)){
119 $bootable = split(",", trim(preg_replace("/^bootable:/","",$option),","));
120 foreach($bootable as $bootflag){
121 if(isset($this->partitions[$bootflag])){
122 $this->partitions[$bootflag]['bootable'] = TRUE;
123 }
124 }
125 continue;
126 }
128 // Load resize flag for partitions
129 if (preg_match("/^resize:/", $option)){
130 $resize = split(",", trim(preg_replace("/^resize:/","",$option),","));
131 foreach($resize as $id){
132 if(isset($this->partitions[$id])){
133 $this->partitions[$id]['resize'] = TRUE;
134 }
135 }
136 continue;
137 }
139 // Load preserve_always flag for partitions
140 if (preg_match("/^preserve_always:/", $option)){
141 $preserve = split(",", trim(preg_replace("/^preserve_always:/","",$option),","));
142 foreach($preserve as $presflag){
143 if(isset($this->partitions[$presflag])){
144 $this->partitions[$presflag]['preserve'] = TRUE;
145 $this->partitions[$presflag]['preserveType'] = 'always';
146 }
147 }
148 continue;
149 }
151 // Load preserve_reinstall flag for partitions
152 if (preg_match("/^preserve_reinstall:/", $option)){
153 $preserve = split(",", trim(preg_replace("/^preserve_reinstall:/","",$option),","));
154 foreach($preserve as $presflag){
155 if(isset($this->partitions[$bootflag])){
156 $this->partitions[$presflag]['preserve'] = TRUE;
157 $this->partitions[$presflag]['preserveType'] = 'reinstall';
158 }
159 }
160 continue;
161 }
162 }
163 } else {
164 $this->fstabkey= "device";
165 }
166 }
167 }
170 function execute()
171 {
172 /* Call parent execute */
173 plugin::execute();
175 // Fill templating stuff
176 $smarty = get_smarty();
177 $s_action = "";
178 $s_entry = "";
179 $display = "";
181 // Add partition to lvm compilation.
182 if(isset($_POST['addLvmPartition']) && isset($_POST['lvmPartitionAdd'])){
183 $name = get_post('lvmPartitionAdd');
184 $this->lvmDevices[$name] = $name;
185 }
187 // Remove partition from lvm compilation.
188 if(isset($_POST['delLvmPartition']) && isset($_POST['physicalPartition'])){
189 $names = $_POST['physicalPartition'];
190 foreach($names as $name){
191 if(isset($this->lvmDevices[$name])){
192 unset($this->lvmDevices[$name]);
193 }
194 }
195 }
197 /* Check all Posts if there is something usefull for us,
198 * For example : Delete is posted as Delete_1
199 * The number specifies the index we want to delete
200 */
201 foreach($_POST as $name => $value){
202 if((preg_match("/RemovePartition_/",$name)) &&
203 $this->acl_is_removeable() &&
204 !preg_match("/freeze/i",$this->FAIstate)){
205 $tmp = split("_",$name);
206 $this->removePartition($tmp[1]);
207 break;
208 }
209 if(preg_match("/^EditPartition_/",$name)){
210 $id = preg_replace("/^EditPartition_/","",$name);
211 $id = preg_replace("/_.*$/","",$id);
212 if(isset($this->partitions[$id])){
213 $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
214 break;
215 }
216 }
217 }
219 /* Act on _GET edit request
220 */
221 if(isset($_GET['act']) && $_GET['act'] == "editPart" && isset($_GET['id'])){
222 $id = $_GET['id'];
223 if(isset($this->partitions[$id])){
224 $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
225 }
226 }
228 /* Create a new partition for this disk.
229 */
230 if(isset($_POST['AddPartition']) && !preg_match("/freeze/i",$this->FAIstate)){
231 $this->dialog = new faiPartition($this->config, array(), $this,$this->FAIdiskType);
232 }
234 /* Handle partition dialogs.
235 */
236 if($this->dialog instanceOf plugin && isset($_POST['PartitionCancel'])){
237 $this->dialog = null;
238 }
239 if($this->dialog instanceOf plugin && isset($_POST['PartitionSave'])){
240 $this->dialog->save_object();
242 // Validate new partition
243 $new_partition = $this->dialog->save();
244 $msgs = $this->dialog->check();
245 $msgs = array_merge($msgs,$this->check_disks($new_partition));
247 if(!count($msgs)){
248 $this->updatePartition($new_partition);
249 $this->dialog = null;
250 }else{
251 msg_dialog::displayChecks($msgs);
252 }
253 }
254 if($this->dialog instanceOf plugin){
255 $this->dialog->save_object();
256 return($this->dialog->execute());
257 }
259 // Assign checkbox related values.
260 foreach($this->attributes as $attrs){
261 $smarty->assign($attrs,$this->$attrs);
262 if($this->$attrs){
263 $smarty->assign($attrs."CHK"," ");
264 }else{
265 $smarty->assign($attrs."CHK"," disabled ");
266 }
267 }
269 // Assign disk info to smarty.
270 $smarty->assign("setup", $this->generateParts());
271 $smarty->assign("sub_object_is_createable",$this->acl_is_createable());
272 $smarty->assign("freeze",preg_match("/freeze/i",$this->FAIstate));
273 $smarty->assign("fstabkeys", array("device" => _("Device"), "label" => _("Label"), "uuid" => _("UUID")));
274 $smarty->assign("disklabels", array("msdos" => "MSDOS", "gpt" => "GPT"));
275 $smarty->assign("fstabkey", $this->fstabkey);
276 $smarty->assign("disklabel", $this->disklabel);
277 $smarty->assign("FAIdiskType", $this->FAIdiskType);
278 $smarty->assign("plist", $this->getPartitionList());
279 $smarty->assign("physicalPartitionList", $this->getAvailablePartitions());
281 foreach($this->attributes as $attr){
282 $smarty->assign($attr,$this->$attr);
283 }
285 // Assign partitions
286 $tmp = $this->plInfo();
287 $sacl = "";
288 foreach($tmp['plProvidedAcls'] as $name => $translated){
289 $acl = $this->getacl($name, preg_match("/freeze/i",$this->FAIstate));
290 $smarty->assign($name."ACL",$acl);
291 }
293 $display.= $smarty->fetch(get_template_path('faiDiskEntry.tpl', TRUE));
294 return($display);
295 }
298 /* Creates a human readable list, that contains all physical
299 * devices that are used by the volume group.
300 * This list will then be displayed in a html select box.
301 * (lvm)
302 */
303 function getPartitionList()
304 {
305 $divlist = new divSelectBox("RaidList");
307 /* Create a list of all available disks and partitions.
308 * This list will then be used to display detailed info.
309 */
310 $disks = $this->parent->disks;
311 foreach($disks as $dname => $disk){
313 // Skip currently edited disk
314 if($disk['cn'] == $this->old_cn) continue;
316 // Add disk
317 $objs[$dname] = $disk;
319 // Add disk partitions
320 foreach($disk['partitions'] as $id => $part){
321 $part['parentDisk'] = $disk;
322 $objs[$part['cn']] = $part;
323 }
324 }
326 // Attach current disk setup to the details list.
327 $data = $this->save();
328 $objs[$data['cn']] = $data;
329 foreach($data['partitions'] as $part){
330 $part['parentDisk'] = $data;
331 $objs[$part['cn']] = $part;
332 }
334 // Walk through physical partition combinations and build up
335 // user friendly list with partition details.
336 $list = array();
337 foreach($this->lvmDevices as $device){
339 // We've a html select box here, add spaces for better readability
340 $str = $device;
341 $str = preg_replace("/ /"," ",str_pad($str,20," "));
343 // Add disk/partition details.
344 if(isset($objs[$device])){
345 if(isset($objs[$device]['FAIpartitionSize'])){
346 if($objs[$device]['parentDisk']['FAIdiskType'] == "raid"){
347 $str .= _("Disks").": ";
348 $str .= preg_replace("/(:spare|:missing)/i","",$objs[$device]['FAIpartitionSize']);
349 }else{
350 $str .= _("Size").": ";
351 $str .= $objs[$device]['FAIpartitionSize'];
352 }
353 }
354 }
355 $list[$device] = $str;
356 }
357 return($list);
358 }
361 /* Returns a list of available partitions that are useable in
362 * lvm disk setups.
363 */
364 function getAvailablePartitions()
365 {
367 $may = $used = array();
368 foreach($this->parent->disks as $disk){
370 // Skip ourselves
371 if($disk['cn'] == $this->DISKcn) continue;
372 if($disk['status'] == "delete") continue;
374 // Add partition from lvm combinations
375 if($disk['FAIdiskType'] == "lvm"){
376 $used = array_merge($used,$disk['FAIlvmDevice']);
377 }
379 foreach($disk['partitions'] as $key => $part){
381 if($part['status'] == "delete") continue;
383 // Add disks of raid arrays, to the used list.
384 if($disk['FAIdiskType'] == "raid"){
385 foreach(split(",",$part['FAIpartitionSize']) as $rDevice){
386 $used[] = preg_replace("/:.*$/i","",$rDevice);
387 }
388 }
390 // Collect all available disks
391 if($disk['FAIdiskType'] == "disk"){
392 $name = $part['cn'];
393 if(!isset($this->lvmDevices[$name])){
394 $may[] = $name;
395 }
396 }
397 }
398 }
400 // Check which of the available disks are unused.
401 $ret = array();
402 foreach($may as $val){
403 if(!in_array($val,$used)){
404 $ret[$val] = $val;
405 }
406 }
407 return($ret);
408 }
411 /* Remove the selected partition and shift the following partitions
412 * to fill the gap.
413 * Additionally update the partition numbers correspondingly.
414 * (Checks if the partition is in use, too)
415 */
416 function removePartition($id)
417 {
418 $start = false;
420 /* Create a list of all partitions that are used in
421 * lvm or raid compilations.
422 */
423 $list = array();
424 foreach($this->parent->disks as $dname => $disk){
425 if($disk['FAIdiskType'] != "disk"){
426 if($disk['status'] == "delete") continue;
427 if($disk['FAIdiskType'] == "lvm"){
428 foreach($disk['FAIlvmDevice'] as $partname){
429 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
430 }
431 }
432 foreach($disk['partitions'] as $partkey => $part){
433 if($part['status'] == "delete") continue;
434 if($disk['FAIdiskType'] == "raid"){
435 foreach(split(",",$part['FAIpartitionSize']) as $partname){
436 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
437 }
438 }
439 }
440 }
441 }
443 /* Now that we've a list of all partition references, lets check if
444 * one of the partitions we are going to remove is still in use.
445 */
446 if(isset($list[$this->partitions[$id]['cn']])){
447 $used = array();
448 foreach($list[$this->partitions[$id]['cn']] as $disk){
449 $used[$disk['cn']] = $disk['cn'];
450 }
451 $used = implode(",",$used);
452 msg_dialog::display(_("Error"),
453 sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"),
454 $used), ERROR_DIALOG);
456 }else{
457 foreach($this->partitions as $key => $part){
458 if($id == $key){
459 $start = true;
460 }
461 if($start){
462 if($this->partitions[$key]['status'] == "edited"){
463 $this->deletePartitions[$key]= $this->partitions[$key];
464 $this->deletePartitions[$key]['FAIpartitionNr']=$key;
465 unset($this->partitions[$key]);
466 }else{
467 unset($this->partitions[$key]);
468 }
469 if(isset($this->partitions[($key+1)])){
470 if(isset($this->deletePartitions[$key])){
471 unset($this->deletePartitions[$key]);
472 }
473 $this->partitions[$key] = $this->partitions[($key+1)];
474 $this->partitions[$key]['FAIpartitionNr'] = $key;
475 $this->partitions[$key]['status'] = "new";
476 }
477 }
478 }
479 $tmp= array();
480 foreach($this->partitions as $part){
481 $tmp[count($tmp)+1]=$part;
482 }
483 $this->partitions = $tmp;
484 }
485 }
488 function get_free_partition_number()
489 {
490 $used = array();
491 foreach($this->partitions as $key => $part){
492 if($part['status'] != "delete"){
493 $used[] = $part['FAIpartitionNr'];
494 }
495 }
496 $id = 1;
497 while(in_array($id,$used) && $id < 16 ){
498 $id++;
499 }
500 return($id);
501 }
505 /* Add or update a partition
506 */
507 function updatePartition($part)
508 {
509 if(!isset($part['FAIpartitionNr']) || $part['FAIpartitionNr'] == "undefined"){
510 $part['FAIpartitionNr'] = $this->get_free_partition_number();
511 }
513 /* Update the disk cn -
514 * Do NOT touch the partition 'cn' in case of lvm or raid devices.
515 */
516 if($this->FAIdiskType == "disk"){
517 $part['cn'] = $this->DISKcn.$part['FAIpartitionNr'];
518 }
520 /* Check if we've to update partition names of lvm compilations.
521 */
522 if($this->FAIdiskType == "lvm"){
523 if(isset($this->partitions[$part['FAIpartitionNr']])){
524 $old_cn = $this->partitions[$part['FAIpartitionNr']]['cn'];
525 $new_cn = $part['cn'];
526 if(isset($this->lvmDevices[$old_cn])){
527 unset($this->lvmDevices[$old_cn]);
528 $this->lvmDevices[$new_cn] = $new_cn;
529 }
530 }
531 }
533 /* Set raid names to md#
534 */
535 if($this->FAIdiskType == "raid"){
536 $part['cn'] = 'md'.$part['FAIpartitionNr'];
537 }
539 $this->partitions[$part['FAIpartitionNr']] = $part;
540 }
543 /* This method generates the partition listing with all necessary info,
544 * depending on the disk type.
545 * The list is of type divSelectBox.
546 */
547 function generateParts()
548 {
549 $divlist = new divSelectBox("DiskEntries");
550 foreach($this->partitions as $key => $part){
552 if($part['status'] != "delete"){
554 // Create default table cols
555 $cn =array(
556 "string" => "<a href='?plug=".$_GET['plug']."&act=editPart&id={$key}'>".$part['cn']."</a>",
557 "attach" => "style='width:160px;'");
558 $desc =array(
559 "string" => "<a href='?plug=".$_GET['plug']."&act=editPart&id={$key}'>".
560 $part['description']."</a>",
561 "attach" => "style='width:200px;'");
562 $number =array(
563 "string" => $part['FAIpartitionNr'],
564 "attach" => "style='width:20px;'");
565 $size =array(
566 "string" => $part['FAIpartitionSize'],
567 "attach" => "style='width:100px;'");
568 $type =array(
569 "string" => $part['FAIpartitionType'],
570 "attach" => "style='width:80px;'");
572 // Remove encryption info from the mount point.
573 $mnt = $part['FAImountPoint'];
574 if(preg_match("/:encrypt/", $mnt)){
575 $mnt = preg_replace("/:encrypt/","",$mnt);
576 }
577 $mntp =array("string" => $mnt);
579 // create human readable strings out of the flags.
580 $opt = "";
581 if(isset($part['encrypted']) && $part['encrypted']){
582 $opt.= " "._("encrypted").", ";
583 }
584 if(isset($part['bootable']) && $part['bootable']){
585 $opt.= " "._("bootable").", ";
586 }
587 if(isset($part['preserve']) && $part['preserve']){
588 $opt.= " "._("preserve").": ".$part['preserveType'].", ";
589 }
591 // Combine options to a single table col.
592 $opt =array(
593 "string" => "<i>".preg_replace('/, $/',"",$opt)."</i>");
595 // Depending on the FAIstatus (freeze?) we will display different options.
596 // We can't remove freezed branches -> Hide remove button.
597 if(!preg_match("/freeze/", $this->FAIstate)){
598 $action =array(
599 "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
600 "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
601 "attach" => "style='width:40px; border-right: 0px;'");
602 }else{
603 $action =array(
604 "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
605 "attach" => "style='width:40px; border-right: 0px;'");
606 }
608 // Build up info table, depending on the disk type.
609 if($this->FAIdiskType == "lvm"){
610 $fields = array($cn,$desc,$mntp,$opt,$size, $action);
611 }elseif($this->FAIdiskType == "raid"){
612 $raid_str = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
613 $raid = array("string" => $raid_str);
614 $fields = array($cn,$desc,$raid,$mntp,$opt,$action);
615 }else{
616 $fields = array($number,$desc,$type,$mntp,$opt,$size,$action);
617 }
618 $divlist->AddEntry($fields);
619 }
620 }
621 return($divlist->DrawList());
622 }
625 function save()
626 {
627 $tmp = array();
628 $tmp['cn'] = $this->DISKcn;
630 /* Attach partitions.
631 * And prepare names and numbers.
632 */
633 foreach($this->partitions as $key=>$val) {
634 if($val['status'] == "delete") continue;
635 $this->partitions[$key]['FAIpartitionNr']=$key;
636 if($this->FAIdiskType == "disk"){
637 $this->partitions[$key]['cn'] = $this->DISKcn.$key;
638 }elseif($this->FAIdiskType == "lvm"){
639 $this->partitions[$key]['FAIpartitionType'] = 'lvm';
640 }
641 }
643 $tmp['description'] = $this->DISKdescription;
644 $tmp['partitions'] = $this->partitions;
645 $tmp['status'] = $this->status;
646 $tmp['FAIdiskType'] = $this->FAIdiskType;
648 // Add lvm devices if available.
649 $tmp['FAIlvmDevice'] = array();
650 foreach($this->lvmDevices as $dev){
651 $tmp['FAIlvmDevice'][] = $dev;
652 }
654 /* Assemble flags */
655 $tmp['FAIdiskOption'] = array("fstabkey:".$this->fstabkey, "disklabel:".$this->disklabel);
657 /* If hdd name has changed, tell partitionTable to rename it */
658 if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){
659 $tmp['rename']['from'] = $this->old_cn;
660 $tmp['rename']['to'] = $this->DISKcn;
661 }
663 // Build up disk options
664 $bootable = "";
665 $resize = "";
666 $preserve_always = "";
667 $preserve_reinstall = "";
669 /* Assemble boot, resize and preserve flags
670 */
671 foreach($tmp['partitions'] as $id => $part){
672 if(isset($part['bootable']) && $part['bootable']){
673 $bootable .= $id.",";
674 }
675 if(isset($part['resize']) && $part['resize']){
676 $resize .= $id.",";
677 }
678 if(isset($part['preserve']) && $part['preserve']){
679 if($part['preserveType'] == "always"){
680 $preserve_always .= $id.",";
681 }else{
682 $preserve_reinstall .= $id.",";
683 }
684 }
685 $tmp['partitions'][$id]['status'] = $part['status'];
687 // Unset non valid attributes
688 foreach(array("bootable","encrypted","preserve","preserveType","resize","FAIdiskType") as $attr){
689 if(isset($tmp['partitions'][$id][$attr])){
690 unset($tmp['partitions'][$id][$attr]);
691 }
692 }
693 }
695 /* Assembe disk flags
696 */
697 if(!empty($bootable)){
698 $tmp['FAIdiskOption'][] = "bootable:".trim($bootable,",");
699 }
700 if(!empty($resize)){
701 $tmp['FAIdiskOption'][] = "resize:".trim($resize,",");
702 }
703 if(!empty($preserve_always)){
704 $tmp['FAIdiskOption'][] = "preserve_always:".trim($preserve_always,",");
705 }
706 if(!empty($preserve_reinstall)){
707 $tmp['FAIdiskOption'][] = "preserve_reinstall:".trim($preserve_reinstall,",");
708 }
710 /* Attach deleted.
711 */
712 foreach($this->deletePartitions as $val) {
713 $key = $val['FAIpartitionNr'];
714 $this->partitions[$key."-delete"]=$val;
715 $this->partitions[$key."-delete"]['status']="delete";
716 }
718 $tmp['status'] = $this->status;
719 return($tmp);
720 }
723 /* Save data to object */
724 function save_object()
725 {
726 if((isset($_POST['TableEntryFrameSubmitted'])) && !preg_match("/freeze/", $this->FAIstate) ){
727 plugin::save_object();
729 // Save posted disk label and fstab key
730 if (isset($_POST['disklabel']) && preg_match("/^(msdos|gpt)$/", $_POST['disklabel'])){
731 $this->disklabel= $_POST['disklabel'];
732 }
733 if (isset($_POST['fstabkey']) && preg_match("/^(device|label|uuid)$/", $_POST['fstabkey'])){
734 $this->fstabkey= $_POST['fstabkey'];
735 }
736 }
737 }
740 /* Check supplied data */
741 function check()
742 {
743 /* Call common method to give check the hook */
744 $message= plugin::check();
746 /* Check for an empty disk name */
747 $d = trim($this->DISKcn);
748 if($d == "" ){
749 $message[] = msgPool::required(_("Name"));
750 }
751 if(preg_match("/[^a-z0-9_\-]/i",$d)){
752 $message[] = msgPool::invalid(_("Name"),$d,"/[a-z0-9_\-]/i");
753 }
755 return ($message);
756 }
759 /* Checks the disk combinations.
760 *
761 */
762 function check_disks($disk_to_add = array())
763 {
764 $msgs = array();
766 /* Check 'disk' combinations.
767 * - There can be four primary partitions.
768 * - If there is at least one 'logical' partition, then there can be only
769 * three 'primary' partitions.
770 */
771 if($this->FAIdiskType == "disk"){
773 $types = array('logical' => array(), 'primary' => array());
774 $types[$disk_to_add['FAIpartitionType']][$disk_to_add['FAIpartitionNr']] = 1;
775 foreach($this->partitions as $key => $part){
776 $types[$part['FAIpartitionType']][$part['FAIpartitionNr']] = 1;
777 }
779 // There can only be four primary partitions per disk - without any logical partition.
780 if(count($types['logical']) == 0){
781 if(count($types['primary']) > 4){
782 $msgs[] = _("You have more than four primary partition table entries in your configuration, please check your configuration twice.");
783 }
784 }else{
785 if(count($types['primary']) > 3){
786 $msgs[] = _("You cannot have more than three primary partition while using logical partitions, please check your configuration twice.");
787 }
788 }
789 }
791 return($msgs);
792 }
795 /* Return plugin informations for acl handling */
796 static function plInfo()
797 {
798 return (array(
799 "plShortName" => _("Partition table entry"),
800 "plDescription" => _("FAI partition table entry"),
801 "plSelfModify" => FALSE,
802 "plDepends" => array(),
803 "plPriority" => 27,
804 "plSection" => array("administration"),
805 "plCategory" => array("fai"),
806 "plProvidedAcls" => array(
807 "DISKcn" => _("Name"),
808 "DISKdescription" => _("Description"),
809 "DISKFAIdiskOption" => _("Disk options"),
810 "FAIpartitionType" => _("Partition type"),
811 "FAIpartitionNr" => _("Partition no."),
812 "FAIfsType" => _("File system type"),
813 "FAImountPoint" => _("Mount point"),
814 "FAIpartitionSize" => _("Partition size"),
815 "FAImountOptions" => _("Mount options"),
816 "FAIfsOptions" => _("File system options"),
817 "FAIpartitionFlags" => _("Partition flags"))
818 ));
819 }
821 }
823 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
824 ?>