1 <?php
3 class faiPartitionTable extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array("cn","description", "FAIpartitionMethod");
8 var $objectclasses = array("top","FAIclass","FAIpartitionTable");
10 var $subAttributes = array("cn","description");
11 var $subPartAttributes = array("cn","FAIpartitionNr","FAIpartitionSize","FAImountPoint","FAIfsType","FAIpartitionType","FAImountOptions","FAIfsOptions","FAIpartitionFlags","description","FAIfsCreateOptions","FAIfsTuneOptions","FAIfsOptions","FAIpartitionFlags","FAIlvmDevice");
13 var $sub64coded = array();
14 var $subBinary = array();
16 /* Specific attributes */
17 var $cn = ""; // The class name for this object
18 var $description = ""; // The description for this set of partitions
19 var $FAIpartitionMethod = ""; // "setup-storage" or not assigned
20 var $disks = array(); // All defined Disks
21 var $is_dialog = false; // specifies which buttons will be shown to save or abort
23 var $FAIstate = "";
24 var $ui;
26 var $view_logged = FALSE;
28 function faiPartitionTable (&$config, $dn= NULL)
29 {
30 /* Load Attributes */
31 plugin::plugin ($config, $dn);
33 /* If "dn==new" we try to create a new entry
34 * Else we must read all objects from ldap which belong to this entry.
35 */
36 $this->ui = get_userinfo();
37 if($dn != "new"){
38 $this->dn =$dn;
40 /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
41 */
42 $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
43 foreach($res as $obj){
45 /* Skip not relevant objects */
46 if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
47 $objects = array();
48 $objects['description'] = "";
50 // Transform disk type into image later...
51 if (!isset($obj['FAIdiskType'])){
52 $objects['FAIdiskType'] = "old";
53 } else {
54 $objects['FAIdiskType'] = $obj['FAIdiskType'];
55 }
57 // Get disk options, without 'count' index.
58 $objects['FAIdiskOption'] = array();
59 if (isset($obj['FAIdiskOption'])){
60 for($i=0;$i<$obj['FAIdiskOption']['count'];$i++){
61 $objects['FAIdiskOption'][] = $obj['FAIdiskOption'][$i];
62 }
63 }
65 // Transform potential lvm information
66 if (isset($obj['FAIlvmDevice'])){
67 for($i=0;$i<$obj['FAIlvmDevice']['count'];$i++){
68 $name = $obj['FAIlvmDevice'][$i];
69 $objects['FAIlvmDevice'][$name] = $name;
70 }
71 }
73 $objects['dn'] = $obj['dn'];
74 $objects = $this->get_object_attributes($objects,$this->subAttributes);
75 $this->disks[$objects['cn']] = $objects;
76 $this->disks[$objects['cn']]['partitions'] = array();
77 }
79 /* read all partitions for each disk
80 */
81 foreach($this->disks as $name => $disk){
82 $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
83 foreach($res as $obj){
85 /* Skip not relevant objects */
86 if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
88 $objects = array();
89 $objects['dn'] = $obj['dn'];
90 $objects = $this->get_object_attributes($objects,$this->subPartAttributes);
91 unset($objects['dn']);;
92 $this->disks[$name]['partitions'][$objects['FAIpartitionNr']] = $objects;
93 }
94 }
95 }
97 /* Keep track of disk changes, by comparing the initial and resulting
98 * disk setup.
99 */
100 $this->initial_disks = $this->disks;
102 $this->is_new = FALSE;
103 if($this->dn == "new"){
104 $this->is_new =TRUE;
105 }
106 ksort($this->disks);
107 }
110 function acl_base_for_current_object($dn)
111 {
112 if($dn == "new" || $dn == ""){
113 if($this->dn == "new"){
114 $dn= $this->parent->parent->acl_base;
115 }else{
116 $dn = $this->dn;
117 }
118 }
119 return($dn);
120 }
123 function execute()
124 {
125 /* Call parent execute */
126 plugin::execute();
128 if($this->is_account && !$this->view_logged){
129 $this->view_logged = TRUE;
130 new log("view","fai/".get_class($this),$this->dn);
131 }
133 /* Fill templating stuff */
134 $smarty= get_smarty();
135 $display= "";
137 /* Add Disk to this Partitionset
138 * This code adds a new HDD to the disks
139 * A new Dialog will be opened
140 */
141 if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) &&
142 !preg_match("/freeze/i",$this->FAIstate)){
143 $usedDiskNames =array();
144 foreach($this->disks as $key=>$disk){
145 $usedDiskNames[]= $key;
146 }
147 if ($this->FAIpartitionMethod == "setup-storage") {
148 if(isset($_POST['AddDisk'])) $type = "disk";
149 if(isset($_POST['AddRaid'])) $type = "raid";
150 if(isset($_POST['AddVolgroup'])) $type = "lvm";
151 $this->dialog = new faiDiskEntry($this->config,$this->dn,$this, array(),$type);
152 } else {
153 $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this);
154 }
156 $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
157 $this->dialog->set_acl_category("fai");
158 $this->dialog->FAIstate = $this->FAIstate;
161 $this->is_dialog = true;
162 }
164 /* Edit disk.
165 * Open dialog which allows us to edit the selected entry
166 */
168 if($this->dn != "new"){
169 set_object_info($this->dn);
170 }
172 /* Edit entries via GET */
173 $s_action = "";
174 $s_entry = "";
175 if(isset($_GET['act']) && isset($_GET['id'])){
176 if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
177 $s_entry= $_GET['id'];
178 $s_action= "edit";
179 }
180 }
182 /* New Listhandling */
183 foreach($_POST as $name => $value){
184 if(preg_match("/^edit_/",$name)){
185 $s_entry = preg_replace("/^edit_/","",$name);
186 $s_entry = postDecode($s_entry);
187 $s_action = "edit";
188 break;
189 }
190 if (!preg_match("/freeze/i", $this->FAIstate) && preg_match("/^delete_[^_]*_/",$name)){
191 $s_entry = preg_replace("/^delete_/","",$name);
192 $s_entry = postDecode($s_entry);
193 $s_action = "remove";
194 break;
195 }
196 }
199 /* Disk remove was requested.
200 * Now check if the disk is still in use, in this case
201 * display a warning message and abort the removal.
202 * If the disk is not used anymore, then remove it.
203 */
204 if($s_action == "remove"){
205 if(isset($this->disks[$s_entry])){
207 /* Create a list of all partitions that are used in
208 * lvm or raid compilations.
209 */
210 $list = array();
211 foreach($this->disks as $dname => $disk){
212 if($disk['FAIdiskType'] != "disk" && $dname != $s_entry){
213 if($disk['FAIdiskType'] == "lvm"){
214 foreach($disk['FAIlvmDevice'] as $partname){
215 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
216 }
217 }
218 foreach($disk['partitions'] as $partkey => $part){
219 if($disk['FAIdiskType'] == "raid"){
220 foreach(explode(",",$part['FAIpartitionSize']) as $partname){
221 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
222 }
223 }
224 }
225 }
226 }
228 /* Now that we've a list of all partition references, lets check if
229 * one of the partitions we are going to remove is still in use.
230 */
231 $used = array();
232 foreach($this->disks[$s_entry]['partitions'] as $part){
233 if(isset($list[$part['cn']])){
234 foreach($list[$part['cn']] as $disk){
235 $used[$disk['cn']] = $disk['cn'];
236 }
237 }
238 }
240 /* Skip removal while disk is in use.
241 */
242 if(count($used)){
243 $used = implode(",",$used);
244 msg_dialog::display(_("Error"),
245 sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"),
246 $used), ERROR_DIALOG);
247 }else{
249 /* Everything is ok, we can remove the disk now.
250 */
251 unset($this->disks[$s_entry]);
252 }
253 }
254 }
258 if($s_action == "edit"){
260 /* Set object info string, which will be displayed in plugin info line */
261 if(isset($this->disks[$s_entry]['dn'])){
262 set_object_info($this->disks[$s_entry]['dn']);
263 $dn = $this->disks[$s_entry]['dn'];
264 }else{
265 set_object_info("");
266 $dn = "new";
267 }
269 $type ="old";
270 if(isset($this->disks[$s_entry]['FAIdiskType'])){
271 $type = $this->disks[$s_entry]['FAIdiskType'];
272 }
273 if(in_array($type,array('raid','lvm','disk'))){
274 $this->dialog = new faiDiskEntry(
275 $this->config,$this->dn,$this,$this->disks[$s_entry],
276 $this->disks[$s_entry]['FAIdiskType']);
278 }else{
279 $this->dialog = new faiPartitionTableEntry(
280 $this->config,$this->dn,$this,$this->disks[$s_entry]);
281 }
282 if($this->dialog){
283 $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
284 $this->dialog->set_acl_category("fai");
285 $this->dialog->FAIstate = $this->FAIstate;
286 $this->is_dialog = true;
287 }
288 }
290 /* Edit aborted, close dialog, without saving anything
291 */
292 if(isset($_POST['CancelDisk'])){
293 unset($this->dialog);
294 $this->dialog = FALSE;
295 $this->is_dialog=false;
296 }
298 /* Dialog saved
299 * Save given data from Dialog, if no error is occurred
300 */
301 if(isset($_POST['SaveDisk'])){
303 if (!preg_match("/freeze/i", $this->FAIstate)){
304 $this->dialog->save_object();
305 if(count($this->dialog->check())){
306 foreach($this->dialog->check() as $msg){
307 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
308 }
309 }else{
310 $disk = $this->dialog->save();
311 if(isset($disk['rename'])){
312 unset($this->disks[$disk['rename']['from']]);
313 $disk['cn']= $disk['rename']['to'];
314 }
316 $this->disks[$disk['cn']]=$disk;
317 unset($this->dialog);
318 $this->dialog = FALSE;
319 $this->is_dialog=false;
320 ksort($this->disks);
321 }
322 }else{
323 $this->dialog = FALSE;
324 $this->is_dialog=false;
325 }
326 }
328 /* Display dialog if one is defined
329 */
330 if(is_object($this->dialog)){
331 $this->dialog->save_object();
332 return($this->dialog->execute());
333 }
335 /* Assign all attributes to smarty engine
336 */
337 foreach($this->attributes as $attrs){
338 $smarty->assign($attrs,$this->$attrs);
339 if($this->$attrs){
340 $smarty->assign($attrs."CHK"," ");
341 }else{
342 $smarty->assign($attrs."CHK"," disabled ");
343 }
344 }
346 $dn = $this->acl_base_for_current_object($this->dn);
347 $smarty->assign("sub_object_is_addable",
348 preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
349 !preg_match("/freeze/",$this->FAIstate));
350 $smarty->assign("sub_object_is_removeable",
351 preg_match("/d/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
352 !preg_match("/freeze/",$this->FAIstate));
354 $tmp = $this->plInfo();
355 foreach($tmp['plProvidedAcls'] as $name => $translated){
356 $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
357 }
359 /* Assign mode */
360 if ($this->FAIpartitionMethod == ""){
361 $smarty->assign("mode", "");
362 $smarty->assign("storage_mode", "disabled");
363 } else {
364 $smarty->assign("mode", "checked");
365 $smarty->assign("storage_mode", "");
366 }
367 if (!count($this->disks)) {
368 $smarty->assign("lockmode", "");
369 } else {
370 $smarty->assign("lockmode", "disabled");
371 }
372 if (isset($this->disks['raid'])){
373 $smarty->assign("addraid", "disabled");
374 } else {
375 $smarty->assign("addraid", "");
376 }
378 /* Divlist containing disks */
379 $divlist = new divSelectBox("FAItemplates");
380 $divlist->setHeight(400);
381 foreach($this->disks as $key => $disk){
382 $act = "";
384 $dn = "new";
385 if(isset($obj['dn'])){
386 $dn = $obj['dn'];
387 }
388 $dn = $this->acl_base_for_current_object($dn);
389 $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
390 if(preg_match("/(r|w)/",$acl)) {
392 $act .= image('images/lists/edit.png','edit_%s',msgPool::editButton());
393 if(preg_match("/d/",$acl) && !preg_match("/freeze/", $this->FAIstate)){
394 $act .= image('images/lists/trash.png','delete_%s',msgPool::delButton());
395 }
397 $cnt= count($disk['partitions']);
399 $edit_link = "<a href='?plug=".$_GET['plug']."&act=edit&id=".$key."'>".$key."</a>";
400 $types= array(
401 "old" => "plugins/fai/images/fai_partitionTable.png",
402 "disk" => "plugins/fai/images/fai_partitionTable.png",
403 "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
404 $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
405 $divlist->AddEntry(array(
406 array("string"=> image($type), "attach"=>"style='width:16px'"),
407 array("string"=> $edit_link, "attach"=>"style='width:100px'"),
408 array("string"=> $disk['description']),
409 array("string"=> $cnt, "attach"=>"style='width:16px'"),
410 array("string"=>str_replace("%s",postEncode($key),$act),
411 "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
412 }
413 }
414 $smarty->assign("Entry_divlist",$divlist->DrawList());
416 $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
417 return($display);
418 }
421 function getUsedDiskNames()
422 {
423 $ret = array();
424 foreach($this->disks as $disk){
425 $ret[] = $disk['cn'];
426 }
427 return($ret);
428 }
431 /* Delete me, and all my subtrees
432 */
433 function remove_from_parent()
434 {
435 $ldap = $this->config->get_ldap_link();
436 $ldap->cd ($this->dn);
438 $release = $this->parent->parent->fai_release;
439 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
441 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
442 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
443 foreach($this->initial_disks as $disk){
444 $disk_dn = "cn=".$disk['cn'].",".$this->dn;
445 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i",$release, $disk_dn);
446 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
447 foreach($disk['partitions'] as $key => $partition){
448 $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;
449 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $partition_dn);
450 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
451 }
452 }
453 }
456 /* Save data to object
457 */
458 function save_object()
459 {
460 if(isset($_POST['FAIpartitionTablePosted'])){
461 if (preg_match("/freeze/", $this->FAIstate)) return;
462 plugin::save_object();
463 # foreach($this->attributes as $attrs){
464 # if(isset($_POST[$attrs])){
465 # $this->$attrs = $_POST[$attrs];
466 # }
467 # }
468 if(!count($this->disks)){
469 if(isset($_POST['mode'])){
470 $this->FAIpartitionMethod = "setup-storage";
471 }else{
472 $this->FAIpartitionMethod = "";
473 }
474 }
475 }
476 }
479 /* Check supplied data */
480 function check()
481 {
482 /* Call common method to give check the hook */
483 $message= plugin::check();
485 /* Ensure that we do not overwrite an allready existing entry
486 */
487 if($this->is_new){
488 $release = $this->parent->parent->fai_release;
489 $new_dn= 'cn='.$this->cn.",".get_ou('faiPartitionRDN').get_ou('faiBaseRDN').$release;
490 $res = faiManagement::check_class_name("FAIpartitionTable",$this->cn,$new_dn);
491 if(isset($res[$this->cn])){
492 $message[] = msgPool::duplicated(_("Name"));
493 }
494 }
495 return ($message);
496 }
499 /* Save to LDAP */
500 function save()
501 {
502 plugin::save();
504 /* Save current settings.
505 * 1 : We must save the partition table, with its description and cn
506 * 2 : Append Disk with cn and description.
507 * 3 : Save partitions for each disk
508 */
510 $ldap = $this->config->get_ldap_link();
512 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
514 if($this->initially_was_account){
515 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
516 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Saving disk: ");
517 }else{
518 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
519 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$this->dn , "Adding disk: ");
520 }
522 // Prepare disks to be saved - The 'status' attribute is added here.
523 $this->prepareDiskToBeSave();
525 /* Sort entries, because we must delete entries with status="delete" first */
526 $order = array();
527 foreach($this->disks as $key => $disk){
528 if($disk['status'] == "delete"){
529 $order[$key] = $disk;
530 }
531 }
532 foreach($this->disks as $key => $disk){
533 if($disk['status'] != "delete"){
534 $order[$key] = $disk;
535 }
536 }
539 /* Append all disks to ldap */
540 foreach($order as $cn=>$disk){
542 $disk_dn = "cn=".$disk['cn'].",".$this->dn;
543 $short_dn = "cn=".$disk['cn'].",...";
544 $disk_attrs['cn'] = $disk['cn'];
545 $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk");
548 if($disk['status']=="new"){
549 $ldap->cat($disk_dn,array("objectClass"));
550 if($ldap->count()){
551 $disk['status']="edited";
552 }
553 }
555 foreach(array("description","FAIdiskType","FAIdiskOption","FAIlvmDevice") as $attr){
556 if($disk['status'] == "new"){
557 if(isset($disk_attrs[$attr])) unset($disk_attrs[$attr]);
558 if(isset($disk[$attr]) && !empty($disk[$attr])){
559 if(is_array($disk[$attr])){
560 $disk_attrs[$attr] = array_values($disk[$attr]);
561 }else{
562 $disk_attrs[$attr] = $disk[$attr];
563 }
564 }
565 }else{
566 if(isset($disk[$attr]) && !empty($disk[$attr])){
567 if(is_array($disk[$attr])){
568 $disk_attrs[$attr] = array_values($disk[$attr]);
569 }else{
570 $disk_attrs[$attr] = $disk[$attr];
571 }
572 }else{
573 $disk_attrs[$attr] = array();
574 }
575 }
576 }
579 /* Tag object */
580 $this->tag_attrs($disk_attrs, $disk_dn, $this->gosaUnitTag);
582 if($disk['status'] == "delete"){
583 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing disk: ");
584 FAI::prepare_to_save_FAI_object($disk_dn,array(),true);
585 $this->handle_post_events("remove");
586 unset($this->disks[$cn]);
587 }elseif($disk['status'] == "edited"){
588 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating disk: ");
589 FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
590 $this->handle_post_events("modify");
591 }elseif($disk['status']=="new"){
592 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding disk: ");
593 FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs);
594 $this->handle_post_events("add");
595 }
597 if($disk['status']!="delete")
599 /* Add all partitions */
600 foreach($disk['partitions'] as $pkey => $partition){
601 $partition_attrs = array();
603 foreach($partition as $key => $value){
604 if(!empty($value)){
605 $partition_attrs[$key]=$value;
606 }else{
607 unset($partition_attrs[$key]);
608 }
609 }
611 $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;
612 $short_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",...";
614 $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
616 unset($partition_attrs['status']);
617 unset($partition_attrs['old_cn']);
619 if($partition['status']=="new"){
620 $ldap->cat($partition_dn,array("objectClass"));
621 if($ldap->count()){
622 $partition['status']="edited";
623 }
624 }
626 if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){
627 $partition_attrs['FAImountPoint']="swap";
628 }
630 /* Tag object */
631 $this->tag_attrs($partition_attrs, $partition_dn, $this->gosaUnitTag);
634 if($partition['status'] == "delete"){
635 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Removing partition: ");
636 FAI::prepare_to_save_FAI_object($partition_dn,array(),true);
637 $this->handle_post_events("remove");
638 unset($this->disks[$cn]['partitions'][$pkey]);
639 }elseif($partition['status'] == "edited"){
640 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Updating partition: ");
641 FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
642 $this->handle_post_events("modify");
643 }elseif($partition['status']=="new"){
644 @DEBUG (DEBUG_FAI, __LINE__, __FUNCTION__, __FILE__,$short_dn , "Adding partition: ");
645 FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs);
646 $this->handle_post_events("add");
647 }
649 // We do not need the status flag any longer
650 if(isset($this->disks[$cn]['partitions'][$pkey]['status'])){
651 unset($this->disks[$cn]['partitions'][$pkey]['status']);
652 }
653 }
654 // We do not need the status flag any longer
655 if(isset($this->disks[$cn]['status'])){
656 unset($this->disks[$cn]['status']);
657 }
658 }
659 $this->initial_disks = $this->disks;
660 $this->handle_post_events("add");
661 }
664 function prepareDiskToBeSave()
665 {
666 foreach($this->disks as $id => $disk){
668 /* Correct FAIpartitionNr.
669 * If we've only primary partition then set the partition numbers from
670 * 1 to 4, else set the primary from 1 to 3 and logical >= 5
671 *
672 */
673 if(!isset($disk['partitions'])){
674 $disk['partitions'] = array();
675 }
676 $newSetup = array();
678 if($disk['FAIdiskType'] == "disk"){
679 $primary = $logical = array();
680 foreach($disk['partitions'] as $partid => $part){
681 if($part['FAIpartitionType'] == "primary"){
682 $primary[$partid] = $part;
683 }elseif($part['FAIpartitionType'] == "logical"){
684 $logical[$partid] = $part;
685 }else{
686 trigger_error("Fatal: unknown disk type? ".$part['FAIpartitionType']);
687 }
688 }
689 $cnt = 1;
690 foreach($primary as $part){
691 $part['FAIpartitionNr'] = $cnt;
692 $part['cn'] = $disk['cn'].$cnt;
693 $newSetup[$cnt] = $part;
694 $cnt ++;
695 }
696 $cnt = 5;
697 foreach($logical as $part){
698 $part['FAIpartitionNr'] = $cnt;
699 $part['cn'] = $disk['cn'].$cnt;
700 $newSetup[$cnt] = $part;
701 $cnt ++;
702 }
703 $this->disks[$disk['cn']]['partitions'] = $newSetup;
704 }
705 }
708 # FAIpartitionNr have to be used as index for this->disks
709 # else the next operation will fail.
712 /* Check if there are disks to be removed, edited or added.
713 * We compare the initial disk setup with the current setup and
714 * and add a status flag, which will then be used to perform the
715 * correct action - add, edited, remove.
716 */
717 foreach($this->disks as $key => $disk){
719 // - A complete NEW disk
720 if(!isset($this->initial_disks[$disk['cn']])){
721 $this->disks[$key]['status'] = "new";
722 foreach($disk['partitions'] as $pkey => $part){
723 $this->disks[$disk['cn']]['partitions'][$pkey]['status'] = "new";
724 }
725 }else{
727 // - Disk was "EDITED"
728 $this->disks[$key]['status'] = "edited";
729 foreach($disk['partitions'] as $pkey => $part){
731 // - Check whether partition is "NEW" or "EDITED"
732 if(!isset($this->initial_disks[$key]['partitions'][$pkey])){
733 $this->disks[$key]['partitions'][$pkey]['status'] = "new";
734 }else{
735 $this->disks[$key]['partitions'][$pkey]['status'] = "edited";
736 }
737 }
738 }
739 }
741 /* Check which partitions havbe to be removed.
742 * (They intially existed, but are now gone.)
743 */
744 foreach($this->initial_disks as $ikey => $idisk){
746 // - Complete disk was REMOVED.
747 if(!isset($this->disks[$idisk['cn']])){
748 $this->disks[$idisk['cn']] = $idisk;
749 $this->disks[$idisk['cn']]['status'] = "delete";
750 foreach($idisk['partitions'] as $pkey=>$part){
751 $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
752 $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
753 }
754 }else{
755 foreach($idisk['partitions'] as $pkey=>$part){
756 if(!isset($this->disks[$idisk['cn']]['partitions'][$pkey])){
757 $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
758 $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
759 }
760 }
761 }
762 }
763 }
766 function PrepareForCopyPaste($source)
767 {
768 plugin::PrepareForCopyPaste($source);
770 /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
771 */
773 /* To be sure to copy disks and partitions correctly, just create a
774 * new PartitionTable object and use the 'disks' attribute
775 * from this it. This is much easier and less code.
776 */
777 $obj = new faiPartitionTable($this->config, $source['dn']);
778 $this->disks = $obj->disks;
779 }
782 /* Return plugin informations for acl handling */
783 static function plInfo()
784 {
785 return (array(
786 "plShortName" => _("Partition table"),
787 "plDescription" => _("FAI partition table"),
788 "plSelfModify" => FALSE,
789 "plDepends" => array(),
790 "plPriority" => 26,
791 "plSection" => array("administration"),
792 "plCategory" => array("fai"),
793 "plProvidedAcls" => array(
794 "cn" => _("Name")." ("._("Read only").")",
795 "description" => _("Description"))
796 ));
797 }
800 /*! \brief Used for copy & paste.
801 Returns a HTML input mask, which allows to change the cn of this entry.
802 @param Array Array containing current status && a HTML template.
803 */
804 function getCopyDialog()
805 {
806 $vars = array("cn");
807 $smarty = get_smarty();
808 $smarty->assign("cn", htmlentities($this->cn));
809 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
810 $ret = array();
811 $ret['string'] = $str;
812 $ret['status'] = "";
813 return($ret);
814 }
817 /*! \brief Used for copy & paste.
818 Some entries must be renamed to avaoid duplicate entries.
819 */
820 function saveCopyDialog()
821 {
822 if(isset($_POST['cn'])){
823 $this->cn = get_post('cn');
824 }
825 }
827 /* Reload some attributes */
828 function get_object_attributes($object,$attributes)
829 {
830 $ldap = $this->config->get_ldap_link();
831 $ldap->cd($this->config->current['BASE']);
832 $ldap->cat($object['dn'],$attributes);
833 $tmp = $ldap->fetch();
835 foreach($attributes as $attrs){
836 if(isset($tmp[$attrs][0])){
837 $var = $tmp[$attrs][0];
839 /* Check if we must decode some attributes */
840 if(in_array_ics($attrs,$this->sub64coded)){
841 $var = postDecode($var);
842 }
844 /* check if this is a binary entry */
845 if(in_array_ics($attrs,$this->subBinary)){
846 $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
847 }
849 /* Fix slashes */
850 $var = addslashes($var);
851 $object[$attrs] = $var;
852 }
853 }
854 return($object);
855 }
857 }
859 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
860 ?>