1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 require "tabsPartition.inc";
22 require "tabsVariable.inc";
23 require "tabsHook.inc";
24 require "tabsTemplate.inc";
25 require "tabsScript.inc";
26 require "tabsProfile.inc";
27 require "tabsPackage.inc";
29 class faiManagement extends plugin
30 {
31 /* Definitions */
32 var $plHeadline = "FAI";
33 var $plDescription = "Fully Automatic Installation - management";
35 /* CLI vars */
36 var $cli_summary = "Handling of FAI entries";
37 var $cli_description = "This plugin represents a management tool\n
38 which allows us to manage all needed attributes for fully automatic installations (FAI)";
39 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
41 /* Headpage attributes */
42 var $lock_type = ""; // should be branch/freeze
43 var $lock_name = "";
44 var $lock_dn = "";
46 /* attribute list for save action */
47 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
48 var $objectclasses= array(); // ObjectClasses which the attributes are related to
49 var $dialog = array(); // This object contains every dialog we have currently opened
51 var $objects = array(); // This array contains all available objects shown in divlist
52 var $is_dialog = false;
54 var $dispNewBranch= false;
55 var $dispNewFreeze= false;
56 var $DivListFai;
57 var $CopyPasteHandler = NULL;
59 /* construction/reconstruction
60 */
61 function faiManagement ($config, $ui)
62 {
63 /* Set defaults */
64 $this->dn = "";
65 $this->config = $config;
66 $this->ui = $ui;
68 /* Creat dialog object */
69 $this->DivListFai = new divListFai($this->config,$this);
70 $this->DivListFai->AvailableBranches = $this->getBranches();
72 /* Copy & Paste handler */
73 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
74 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
75 }
76 }
78 function execute()
79 {
80 /* Call parent execute */
81 plugin::execute();
83 /* Get new list of available branches */
84 $this->DivListFai->AvailableBranches = $this->getBranches();
86 /* Initialise vars and smarty */
87 $smarty = get_smarty();
88 $smarty->assign("BranchName","");
90 $display = "";
91 $s_action = "";
92 $s_entry = "";
94 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
95 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
98 /****************
99 Handle posts
100 ****************/
102 /* Check ImageButton posts
103 * Create new tab ich new_xx is posted
104 */
105 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
106 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
107 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
108 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
109 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
110 "/edit_continue/"=>"select_class_name_finished");
112 foreach($_POST as $name => $value){
113 foreach($posts as $reg => $act ){
114 if(preg_match($reg,$name)){
115 $s_action = $act;
116 }
117 }
118 if(preg_match("/^entry_edit_.*/",$name)){
119 $s_entry = preg_replace("/^entry_edit_/","",$name);
120 $s_entry = preg_replace("/_.*$/","",$s_entry);
121 $s_action = "edit";
122 }elseif(preg_match("/^entry_delete_.*/",$name)){
123 $s_entry = preg_replace("/^entry_delete_/","",$name);
124 $s_entry = preg_replace("/_.*$/","",$s_entry);
125 $s_action = "delete";
126 }
128 /* Check for Copy & Paste actions */
129 foreach(array( "editPaste" => "editPaste",
130 "copy" => "copy",
131 "cut" => "cut") as $act => $action){
132 if (preg_match("/".$act.".*/", $name)){
133 $s_action= $action;
134 $s_entry= preg_replace("/".$act."_/i", "", $name);
135 $s_entry = preg_replace("/_.*$/","",$s_entry);
136 break;
137 }
138 }
139 }
141 if(isset($_GET['edit_entry'])){
142 $s_entry = $_GET['edit_entry'];
143 $s_action = "edit";
144 }
146 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
147 $this->dispNewBranch = false;
148 $this->dispNewFreeze = false;
149 }
151 /* Display the copy & paste dialog, if it is currently open */
152 $ret = $this->copyPasteHandling($s_action,$s_entry);
153 if($ret){
154 return($ret);
155 }
157 /****************
158 Delete confirme dialog
159 ****************/
161 if ($s_action=="delete"){
163 /* Get 'dn' from posted termlinst */
164 $this->dn= $this->objects[$s_entry]['dn'];
166 /* Load permissions for selected 'dn' and check if
167 we're allowed to remove this 'dn' */
168 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
169 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
170 if (chkacl($this->acl, "delete") == ""){
172 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
173 if (($user= get_lock($this->dn)) != ""){
174 return(gen_locked_message ($user, $this->dn));
175 }
177 /* Lock the current entry, so nobody will edit it during deletion */
178 add_lock ($this->dn, $this->ui->dn);
179 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
180 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
181 } else {
183 /* Obviously the user isn't allowed to delete. Show message and
184 clean session. */
185 print_red (_("You are not allowed to delete this component!"));
186 }
187 }
190 /****************
191 Delete aborted
192 ****************/
194 /* Delete canceled? */
195 if (isset($_POST['delete_cancel'])){
196 del_lock ($this->dn);
197 }
200 /****************
201 Delete confirmed
202 ****************/
204 /* Deltetion was confirmed, so delete this entry
205 */
206 if (isset($_POST['delete_terminal_confirm'])){
208 /* Some nice guy may send this as POST, so we've to check
209 for the permissions again. */
210 if (chkacl($this->acl, "delete") == ""){
212 /* Find out more about the object type */
213 $ldap = $this->config->get_ldap_link();
214 $ldap->cat($this->dn, array('objectClass'));
215 $attrs = $ldap->fetch();
216 $type = $this->get_type($attrs);
217 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
218 $this->dialog->set_acl(array($this->acl));
220 $this->dialog->by_object[$type[1]]->remove_from_parent ();
221 unset ($this->dialog);
222 gosa_log ("FAI class '".$this->dn."' has been removed");
223 $this->dialog= NULL;
224 $this->DivListFai->AvailableBranches = $this->getBranches();
225 } else {
227 /* Normally this shouldn't be reached, send some extra
228 logs to notify the administrator */
229 print_red (_("You are not allowed to delete this component!"));
230 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
231 "deletion.");
232 }
234 /* Remove lock file after successfull deletion */
235 del_lock ($this->dn);
236 }
239 /****************
240 Edit entry
241 ****************/
243 if(($s_action == "edit") && (!isset($this->dialog->config))){
244 $entry = $this->objects[$s_entry];
245 $a_setup = $this->get_type($entry);
246 $this->dn = $entry['dn'];
248 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
249 if (($user= get_lock($this->dn)) != ""){
250 return(gen_locked_message ($user, $this->dn));
251 }
252 add_lock ($this->dn, $this->ui->dn);
254 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
255 $this->is_dialog = true;
257 if($entry['FAIstate'] == "freeze"){
258 $this->dialog->set_acl(array("*none*")) ;
259 }
260 $_SESSION['objectinfo'] = $this->dn;
261 }
264 /* Branch handling
265 09.01.2006
266 */
268 /****************
269 Remove branch
270 ****************/
272 /* Remove branch
273 */
274 if($s_action == "remove_branch"){
275 $base= $this->DivListFai->selectedBranch;
277 /* Load permissions for selected 'dn' and check if
278 we're allowed to remove this 'dn' */
279 $acl= get_permissions ($this->DivListFai->selectedBase, $this->ui->subtreeACL);
280 $this->acl= get_module_permission($acl, "FAIclass", $base);
281 if (chkacl($this->acl, "delete") == ""){
282 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
283 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
284 } else {
285 print_red (_("You are not allowed to delete this release!"));
286 }
287 }
290 /****************
291 Remove branch confirmed
292 ****************/
294 if(isset($_POST['delete_branch_confirm'])){
295 $bb = $this->DivListFai->selectedBranch;
296 if(!isset($ldap)){
297 $ldap = $this->config->get_ldap_link();
298 }
300 $br = $this->DivListFai->AvailableBranches;
302 if(isset($br[$bb])){
303 $name = $br[$bb];
304 $ldap->cd($bb);
305 $ldap->recursive_remove();
306 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
307 $ldap->recursive_remove();
308 $this->DivListFai->selectedBranch = "main";
309 $this->DivListFai->AvailableBranches = $this->getBranches();
311 /* Post remove */
312 $this->lock_name = $name;
313 $this->lock_dn = $bb;
314 $this->postremove();
315 }
316 }
319 /****************
320 Create a new branch "insert Name"
321 ****************/
323 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
324 $_SESSION['LASTPOST'] = $_POST;
326 if($this->dispNewBranch){
327 $type = "branch";
328 }else{
329 $type = "freeze";
330 }
332 /* Check branch name */
333 $name = $_POST['BranchName'];
334 $is_ok = true;
335 $smarty->assign("BranchName",$name);
336 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
338 /* Check used characters */
339 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
340 if($type == "branch"){
341 print_red(_("Specified branch name is invalid."));
342 }else{
343 print_red(_("Specified freeze name is invalid."));
344 }
345 $is_ok = false;
346 }
348 /* Check if this name is already in use */
349 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
350 print_red(_("This name is already in use."));
351 $is_ok = false;
352 }
354 if($is_ok){
355 $_SESSION['LASTPOST']['base'] = $base;
356 $_SESSION['LASTPOST']['type'] = $type;
357 $smarty->assign("iframe", true);
358 $smarty->assign("plugID", $_GET['plug']);
359 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
360 return($display);
361 }
362 }
365 /****************
366 Create a new branch
367 ****************/
369 if(isset($_GET['PerformBranch'])){
370 /* Create it know */
371 $this->dispNewBranch = false;
372 $this->dispNewFreeze = false;
373 $base = $_SESSION['LASTPOST']['base'];
374 $_POST = $_SESSION['LASTPOST'];
375 $name = $_POST['BranchName'];
377 $type = $_SESSION['LASTPOST']['type'];
378 $ldap = $this->config->get_ldap_link();
380 $baseToUse = $base;
381 if($this->DivListFai->selectedBranch != "main" ){
382 $baseToUse = $this->DivListFai->selectedBranch;
383 }
385 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
387 $CurrentReleases = $this->DivListFai->AvailableBranches;
388 $NewReleaseName = $name;
389 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
390 if($this->DivListFai->selectedBranch != "main"){
391 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
392 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
393 }else{
394 $NewReleaseName = $name;
395 }
396 }
398 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
399 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
401 /* Print header to have styles included */
402 echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
403 echo "<body style='background-image:none;margin:3px;color:black'>";
405 /* Duplicate applications
406 */
407 $ldap->cd ($appdst);
408 $ldap->recursive_remove();
409 $ldap->cd ($this->config->current['BASE']);
410 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
412 /* Duplicate fai objects
413 */
414 $ldap->cd ("ou=".$name.",".$baseToUse);
415 $ldap->recursive_remove();
416 $ldap->cd ($this->config->current['BASE']);
417 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
419 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
420 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
421 </form></div>";
423 /* Print footer to have valid html */
424 echo "</body></html>";
426 $this->dispNewFreeze = false;
428 /* Postcreate */
430 /* Assign possible attributes */
431 $this->lock_type = $type;
432 $this->lock_name = $name;
433 $this->lock_dn = $baseToUse;
434 $this->postcreate();
435 $this->DivListFai->AvailableBranches = $this->getBranches();
436 exit();
437 }
440 /****************
441 Display dialog to enter new Branch name
442 ****************/
444 if(($s_action == "branch_branch")||($this->dispNewBranch)){
445 $this->dispNewBranch=true;
446 $smarty->assign("iframe",false);
447 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
448 return($display);
449 }
452 /****************
453 Display dialog to enter new Freeze name
454 ****************/
456 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
457 $this->dispNewFreeze = true;
458 $smarty->assign("iframe",false);
459 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
460 return($display);
461 }
464 /****************
465 Create a new object
466 ****************/
468 $types = array( "new_partition" => "FAIpartitionTable",
469 "new_script" => "FAIscript",
470 "new_hook" => "FAIhook",
471 "new_variable" => "FAIvariable",
472 "new_template" => "FAItemplate",
473 "new_package" => "FAIpackageList");
475 if(isset($types[$s_action])){
476 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
477 }
479 /* New Profile */
480 if($s_action == "new_profile"){
481 $this->dn = "new" ;
482 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
484 $this->dialog = new $a_setup[0]($this->config,
485 $this->config->data['TABS'][$a_setup[2]],$this->dn);
486 $this->is_dialog = true;
487 }
490 /****************
491 Get from ask class name dialog
492 ****************/
494 if($s_action == "select_class_name_finished"){
495 $this->dialog->save_object();
496 if(count($this->dialog->check())!=0){
497 foreach($this->dialog->check() as $msg){
498 print_red($msg);
499 }
500 }else{
501 $this->dn = "new" ;
502 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
503 $name = $this->dialog->save();
505 $this->dialog = new $a_setup[0]($this->config,
506 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
507 $this->dialog->by_object[$a_setup[1]]->cn = $name;
508 $this->is_dialog = true;
509 }
510 }
513 /****************
514 Cancel dialogs
515 ****************/
517 if(isset($_POST['edit_cancel'])){
518 unset($this->dialog);
519 $this->dialog=NULL;
520 $this->is_dialog = false;
521 unset($_SESSION['objectinfo']);
522 del_lock ($this->dn);
523 }
526 /****************
527 Save sub dialogs
528 ****************/
530 /* This check if the given tab could be saved
531 * If it was possible to save it, remove dialog object.
532 * If it wasn't possible, show errors and keep dialog.
533 */
534 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
535 $this->dialog->save_object();
536 if(count($this->dialog->check())!=0){
537 foreach($this->dialog->check() as $msg){
538 print_red($msg);
539 }
540 }else{
541 del_lock ($this->dn);
542 $this->dialog->save();
543 unset($this->dialog);
544 $this->dialog=NULL;
545 $this->is_dialog=false;
546 unset($_SESSION['objectinfo']);
547 }
548 }
551 /****************
552 Display currently open dialog
553 ****************/
555 /* If dialog is set, but $this->is_dialog==false, then
556 * only the "abort" button is shown, this are dialogs that must not be saved.
557 * If is_dialog == true, we are currently editing tab objects.
558 * Here we need both, save and cancel
559 */
561 if(($this->dialog != NULL) && (isset($this->dialog->config))){
562 $display .= $this->dialog->execute();
563 /* Don't show buttons if tab dialog requests this */
564 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
566 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
567 $display.= "<p style=\"text-align:right\">\n";
568 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
569 $display.= " \n";
570 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
571 $display.= "</p>";
572 }elseif(!isset($this->dialog->current)){
573 $display.= "<p style=\"text-align:right\">\n";
574 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
575 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
576 $display.= "</p>";
577 }
578 return($display);
579 }
582 /****************
583 Dialog display
584 ****************/
586 /* Display dialog with system list */
587 $this->DivListFai->parent = $this;
588 $this->DivListFai->execute();
589 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
590 $this->reload();
591 $this->DivListFai->setEntries($this->objects);
592 return($this->DivListFai->Draw());
593 }
596 /* Get available branches for current base */
597 function getBranches($base = false,$prefix = "")
598 {
599 $ret = array("main"=>"/");
600 $ldap = $this->config->get_ldap_link();
601 if(!$base){
602 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
603 }
604 $ldap->ls("(objectClass=FAIbranch)",$base);
605 while($attrs = $ldap->fetch()){
606 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
607 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
608 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
609 }
610 }
612 return ($ret);
613 }
616 /* Perform copy & paste requests
617 If copy&paste is in progress this returns a dialog to fix required attributes
618 */
619 function copyPasteHandling($s_action,$s_entry)
620 {
622 /* Only perform copy/paste if it is enabled */
623 if($this->CopyPasteHandler){
625 /* Prepare current object to be pasted */
626 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
628 $this->CopyPasteHandler->save_object();
629 $this->CopyPasteHandler->SetVar("base", $this->DivListFai->selectedBase);
631 if($this->CopyPasteHandler->copyCurrent){
632 $this->CopyPasteHandler->SetVar("copy_paste_mode", TRUE);
633 }
634 if($this->CopyPasteHandler->cutCurrent){
635 $this->CopyPasteHandler->SetVar("cut_paste_mode", TRUE);
636 }
638 $release = "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
639 if($_SESSION['faifilter']['branch']!="main"){
640 $release = $_SESSION['faifilter']['branch'];
641 }
642 $this->CopyPasteHandler->SetVar("release", $release);
644 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
645 us to solve all attribute mismatches for this object.
646 If nothing is returned, copy & paste was succesfully or aborted */
647 if(($ret= $this->CopyPasteHandler->execute())){
648 return ($ret);
649 }
651 /* Use the last dn to search for it's ID in the newly generated list. */
652 $dn= $this->CopyPasteHandler->lastdn;
654 /* Get new list */
655 $this->reload();
656 foreach($this->objects as $id => $entry){
657 if($entry['dn'] == $dn){
658 $s_entry= $id;
659 break;
660 }
661 }
662 }
664 /* Copy selected object
665 Create a new empty object and the current selected object.
666 Send both to copy&paste class*/
667 if($s_action == "copy"){
668 $this->CopyPasteHandler->Clear();
670 $dn= $this->objects[$s_entry]['dn'];
671 $acl= get_permissions ($dn, $this->ui->subtreeACL);
673 $ldap = $this->config->get_ldap_link();
674 $ldap->cat($dn);
675 $attr = $ldap->fetch();
676 $tmp = $this->get_type($attr);
678 if(!count($tmp) == 3 ) return;
680 $tabs = $tmp[0];
681 $class = $tmp[1];
682 $data = $tmp[2];
684 $obj = new $tabs($this->config, $this->config->data['TABS'][$data], $dn);
685 $objNew = new $tabs($this->config, $this->config->data['TABS'][$data], "new");
686 $obj-> set_acl($acl);
687 $objNew-> set_acl($acl);
688 $this->CopyPasteHandler->Copy($obj,$objNew);
689 }
691 /* Cut selected object.
692 Open user object and send it to the copy & paste handler */
693 if($s_action == "cut"){
694 $this->CopyPasteHandler->Clear();
695 $dn= $this->objects[$s_entry]['dn'];
697 $ldap = $this->config->get_ldap_link();
698 $ldap->cat($dn);
699 $attr = $ldap->fetch();
700 $tmp = $this->get_type($attr);
702 if(!count($tmp) == 3 ) return;
704 $tabs = $tmp[0];
705 $class = $tmp[1];
706 $data = $tmp[2];
707 $obj= new $tabs($this->config, $this->config->data['TABS'][$data], $dn);
708 $this->CopyPasteHandler->Cut($obj);
709 }
710 }
711 }
715 /* reload list of objects */
716 function reload()
717 {
718 /* Create a new list of FAI object
719 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
720 */
721 $ObjectTypes = array(
722 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions"),
723 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages"),
724 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts"),
725 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables"),
726 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks"),
727 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles"),
728 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates"));
730 /* Set base for all searches */
731 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
732 if($this->DivListFai->selectedBranch != "main"){
733 $br = $this->DivListFai->AvailableBranches;
734 if(isset($br[$this->DivListFai->selectedBranch])){
735 $base = $this->DivListFai->selectedBranch;
736 }else{
737 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
738 }
739 }
741 $Regex = $this->DivListFai->Regex;
742 $str = "";
743 $objects = array();
744 $this->objects = array();
746 /* Walk through possible sub departments and fetch all FAI objects */
747 foreach($ObjectTypes as $type => $obj){
749 /* Skip all unchecked types */
750 if(! $this->DivListFai->$obj['CHKBOX']){
751 continue;
752 }
754 /* Fetch objects from fai sub department */
755 $res= get_list("(&(objectClass=".$type.")(cn=$Regex))", $this->ui->subtreeACL, $obj['OU'].$base,
756 array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT);
758 /* Walk through objects */
759 foreach($res as $object){
761 /* Prepare object */
762 unset($object['objectClass']['count']);
763 if(!isset($object['description'][0])){
764 $object['description'][0]="";
765 }
767 /* Clean up object informations */
768 $obj['cn'] = $object['cn'][0];
769 $obj['dn'] = $object['dn'];
770 $obj['description'] = $object['description'][0];
771 $obj['objectClass'] = $object['objectClass'];
773 /* Append type to this string, to be able to check if the selected
774 * entry is of type 'freeze' or 'branch'
775 */
776 if(isset($object['FAIstate'])){
777 $obj['FAIstate'] = $object['FAIstate'][0];
778 $str.="|".$obj['FAIstate'];
779 }else{
780 $obj['FAIstate'] ="";
781 }
782 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
783 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
784 }
785 }
787 /* Tell class what we have currently opened
788 'main' has type '' */
789 if(preg_match("/freeze/",$str)){
790 $this->lock_type = "freeze";
791 }elseif(preg_match("/branch/",$str)){
792 $this->lock_type = "branch";
793 }else{
794 $this->lock_type = "";
795 }
797 ksort($this->objects);
798 reset ($this->objects);
800 /* use numeric index, thats a bit more secure */
801 $tmp0 = array();
802 foreach($this->objects as $obj){
803 $tmp0[]= $obj;
804 }
805 $this->objects = array();
806 $this->objects = $tmp0;
807 }
809 function remove_lock()
810 {
811 if (isset($this->dn)){
812 del_lock ($this->dn);
813 }
814 }
816 function get_type($array){
817 if(in_array("FAIpartitionTable",$array['objectClass'])){
818 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
819 }
820 if(in_array("FAIscript",$array['objectClass'])){
821 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
822 }
823 if(in_array("FAItemplate",$array['objectClass'])){
824 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
825 }
826 if(in_array("FAIhook",$array['objectClass'])){
827 return(array("tabsHook","faiHook","FAIHOOKTABS"));
828 }
829 if(in_array("FAIvariable",$array['objectClass'])){
830 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
831 }
832 if(in_array("FAIprofile",$array['objectClass'])){
833 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
834 }
836 if(in_array("FAIpackageList",$array['objectClass'])){
837 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
838 }
839 }
841 function CheckNewBranchName($name,$base)
842 {
843 $f = $this->DivListFai->selectedBranch;
844 if(empty($name)){
845 return(false);
846 }elseif(in_array($name,$this->getBranches($f))) {
847 return(false);
848 }elseif(empty($name)){
849 return(false);
850 }elseif(is_department_name_reserved($name,$base)){
851 return(false);
852 }
853 return(true);
854 }
856 function save_object()
857 {
858 $this->DivListFai->save_object();
859 }
861 }
862 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
863 ?>