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";
30 class faiManagement extends plugin
31 {
32 /* Definitions */
33 var $plHeadline = "FAI";
34 var $plDescription = "Fully Automatic Installation - management";
36 /* CLI vars */
37 var $cli_summary = "Handling of FAI entries";
38 var $cli_description = "This plugin represents a management tool\n
39 which allows us to manage all needed attributes for fully automatic installations (FAI)";
40 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
42 /* Headpage attributes */
43 var $lock_type = ""; // should be branch/freeze
44 var $lock_name = "";
45 var $lock_dn = "";
47 /* attribute list for save action */
48 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
49 var $objectclasses= array(); // ObjectClasses which the attributes are related to
50 var $dialog = array(); // This object contains every dialog we have currently opened
52 var $objects = array(); // This array contains all available objects shown in divlist
53 var $is_dialog = false;
55 var $dispNewBranch= false;
56 var $dispNewFreeze= false;
58 var $DivListFai;
60 /* construction/reconstruction
61 */
62 function faiManagement ($config, $ui)
63 {
64 /* Set defaults */
65 $this->dn = "";
66 $this->config = $config;
67 $this->ui = $ui;
69 /* Creat dialog object */
70 $this->DivListFai = new divListFai($this->config,$this);
71 }
73 function execute()
74 {
75 /* Call parent execute */
76 plugin::execute();
78 /* Initialise vars and smarty */
79 $smarty = get_smarty();
80 $smarty->assign("BranchName","");
82 $display = "";
83 $s_action = "";
84 $s_entry = "";
86 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
87 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
90 /****************
91 Handle posts
92 ****************/
94 /* Check ImageButton posts
95 * Create new tab ich new_xx is posted
96 */
97 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
98 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
99 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
100 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
101 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
102 "/edit_continue/"=>"select_class_name_finished");
104 foreach($_POST as $name => $value){
105 foreach($posts as $reg => $act ){
106 if(preg_match($reg,$name)){
107 $s_action = $act;
108 }
109 }
110 if(preg_match("/^entry_edit_.*/",$name)){
111 $s_entry = preg_replace("/^entry_edit_/","",$name);
112 $s_entry = preg_replace("/_.*$/","",$s_entry);
113 $s_action = "edit";
114 }elseif(preg_match("/^entry_delete_.*/",$name)){
115 $s_entry = preg_replace("/^entry_delete_/","",$name);
116 $s_entry = preg_replace("/_.*$/","",$s_entry);
117 $s_action = "delete";
118 }
119 }
121 if(isset($_GET['edit_entry'])){
122 $s_entry = $_GET['edit_entry'];
123 $s_action = "edit";
124 }
126 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
127 $this->dispNewBranch = false;
128 $this->dispNewFreeze = false;
129 }
132 $type_acl_mapping = array(
133 "FAIpartitionTable" => "faiPartitionTable",
134 "FAIpackageList" => "faiPackage",
135 "FAIscript" => "faiScript",
136 "FAIvariable" => "faiVariable",
137 "FAIhook" => "faiHook",
138 "FAIprofile" => "faiProfile",
139 "FAItemplate" => "faiTemplate");
141 /****************
142 Delete confirme dialog
143 ****************/
145 if ($s_action=="delete"){
147 /* Get 'dn' from posted termlinst */
148 $this->dn= $this->objects[$s_entry]['dn'];
150 /* Load permissions for selected 'dn' and check if
151 we're allowed to remove this 'dn' */
152 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
153 if(preg_match("/d/",$acl)){
155 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
156 if (($user= get_lock($this->dn)) != ""){
157 return(gen_locked_message ($user, $this->dn));
158 }
160 /* Lock the current entry, so nobody will edit it during deletion */
161 add_lock ($this->dn, $this->ui->dn);
162 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
163 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
164 } else {
166 /* Obviously the user isn't allowed to delete. Show message and
167 clean session. */
168 print_red (_("You are not allowed to delete this component!"));
169 }
170 }
173 /****************
174 Delete aborted
175 ****************/
177 /* Delete canceled? */
178 if (isset($_POST['delete_cancel'])){
179 del_lock ($this->dn);
180 }
183 /****************
184 Delete confirmed
185 ****************/
187 /* Deltetion was confirmed, so delete this entry
188 */
189 if (isset($_POST['delete_terminal_confirm'])){
191 /* Some nice guy may send this as POST, so we've to check
192 for the permissions again. */
194 /* Find out more about the object type */
195 $ldap = $this->config->get_ldap_link();
196 $ldap->cat($this->dn, array('objectClass'));
197 $attrs = $ldap->fetch();
198 $type = $this->get_type($attrs);
200 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
201 if(preg_match("/d/",$acl)){
203 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
204 $this->dialog->set_acl_base($this->dn);
205 $this->dialog->by_object[$type[1]]->remove_from_parent ();
206 unset ($this->dialog);
207 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
208 $this->dialog= NULL;
209 $to_del = clean_up_releases($this->dn);
210 save_release_changes_now();
212 foreach($to_del as $dn){
213 $ldap->rmdir_recursive($dn);
214 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
215 }
217 } else {
219 /* Normally this shouldn't be reached, send some extra
220 logs to notify the administrator */
221 print_red (_("You are not allowed to delete this component!"));
222 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
223 "deletion.");
224 }
226 /* Remove lock file after successfull deletion */
227 del_lock ($this->dn);
228 }
231 /****************
232 Edit entry
233 ****************/
235 if(($s_action == "edit") && (!isset($this->dialog->config))){
236 $entry = $this->objects[$s_entry];
237 $a_setup = $this->get_type($entry);
238 $this->dn = $entry['dn'];
240 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
241 if (($user= get_lock($this->dn)) != ""){
242 return(gen_locked_message ($user, $this->dn));
243 }
244 add_lock ($this->dn, $this->ui->dn);
246 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
247 $this->dialog->set_acl_base($this->dn);
248 $this->is_dialog = true;
250 if($entry['FAIstate'] == "freeze"){
251 #$this->dialog->set_acl(array("*none*")) ;
252 echo "Dawn it is freezed.";
253 }
254 $_SESSION['objectinfo'] = $this->dn;
255 }
258 /* Branch handling
259 09.01.2006
260 */
262 /****************
263 Remove branch
264 ****************/
266 /* Remove branch
267 */
268 if($s_action == "remove_branch"){
269 $base= $this->DivListFai->selectedBranch;
271 /* Load permissions for selected 'dn' and check if
272 we're allowed to remove this 'dn' */
273 $this->set_acl_base($base);
274 if($this->acl_is_removeable()){
276 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
277 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
278 } else {
279 print_red (_("You are not allowed to delete this release!"));
280 }
281 }
284 /****************
285 Remove branch confirmed
286 ****************/
288 if(isset($_POST['delete_branch_confirm'])){
289 $bb = $this->DivListFai->selectedBranch;
290 if(!isset($ldap)){
291 $ldap = $this->config->get_ldap_link();
292 }
294 $br = $this->getBranches();
296 if(isset($br[$bb]) && $this->acl_is_removeable()){
297 $name = $br[$bb];
298 $ldap->cd($bb);
299 $ldap->recursive_remove();
300 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
301 $ldap->recursive_remove();
302 $this->DivListFai->selectedBranch = "main";
304 /* Post remove */
305 $this->lock_name = $name;
306 $this->lock_dn = $bb;
307 $this->postremove();
308 }
309 }
312 /****************
313 Create a new branch "insert Name"
314 ****************/
316 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
317 $_SESSION['LASTPOST'] = $_POST;
319 if($this->dispNewBranch){
320 $type = "branch";
321 }else{
322 $type = "freeze";
323 }
325 /* Check branch name */
326 $name = $_POST['BranchName'];
327 $is_ok = true;
328 $smarty->assign("BranchName",$name);
329 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
331 /* Check used characters */
332 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
333 if($type == "branch"){
334 print_red(_("Specified branch name is invalid."));
335 }else{
336 print_red(_("Specified freeze name is invalid."));
337 }
338 $is_ok = false;
339 }
341 /* Check if this name is already in use */
342 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
343 print_red(_("This name is already in use."));
344 $is_ok = false;
345 }
347 if($is_ok){
348 $_SESSION['LASTPOST']['base'] = $base;
349 $_SESSION['LASTPOST']['type'] = $type;
350 $smarty->assign("iframe", true);
351 $smarty->assign("plugID", $_GET['plug']);
352 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
353 return($display);
354 }
355 }
358 /****************
359 Create a new branch
360 ****************/
362 if(isset($_GET['PerformBranch'])){
364 if(!$this->acl_is_createable()){
365 print_red(_("You are not allowed to create a new branch."));
366 }else{
368 /* Create it know */
369 $this->dispNewBranch = false;
370 $this->dispNewFreeze = false;
371 $base = $_SESSION['LASTPOST']['base'];
372 $_POST = $_SESSION['LASTPOST'];
373 $name = $_POST['BranchName'];
375 $type = $_SESSION['LASTPOST']['type'];
376 $ldap = $this->config->get_ldap_link();
378 $baseToUse = $base;
379 if($this->DivListFai->selectedBranch != "main" ){
380 $baseToUse = $this->DivListFai->selectedBranch;
381 }
383 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
385 $CurrentReleases = $this->getBranches();
386 $NewReleaseName = $name;
387 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
388 if($this->DivListFai->selectedBranch != "main"){
389 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
390 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
391 }else{
392 $NewReleaseName = $name;
393 }
394 }
396 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
397 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
399 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
400 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
402 /* Print header to have styles included */
403 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
404 <html>
405 <head>
406 <title></title>
407 <style type="text/css">@import url("themes/default/style.css");</style>
408 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
409 </head>
410 <body style="background: none;margin:3px;color:black">
411 ';
414 /* Duplicate applications
415 */
416 $ldap->cat($appsrc,array("dn")) ;
417 if($ldap->count()){
418 $ldap->cd ($appdst);
419 $ldap->recursive_remove();
420 $ldap->cd ($this->config->current['BASE']);
421 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
422 }
424 /* Duplicate mime types
425 */
426 $ldap->cat($mimesrc,array("dn")) ;
427 if($ldap->count()){
428 $ldap->cd ($appdst);
429 $ldap->recursive_remove();
430 $ldap->cd ($this->config->current['BASE']);
431 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
432 }
434 $attr = array();
435 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
436 $attr['ou'] = $name;
437 $attr['FAIstate'] = $type;
438 $ldap->cd($this->config->current['BASE']);
439 $ldap->cd("ou=".$name.",".$baseToUse);
440 $ldap->cat("ou=".$name.",".$baseToUse);
441 if($ldap->count()){
442 $ldap->modify($attr);
443 }else{
444 $ldap->add($attr);
445 }
447 /* Duplicate fai objects
448 */
449 // $ldap->cd ("ou=".$name.",".$baseToUse);
450 // $ldap->recursive_remove();
451 // $ldap->cd ($this->config->current['BASE']);
452 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
454 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
455 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
456 </form></div>";
458 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
460 /* Print footer to have valid html */
461 echo "</body></html>";
463 $this->dispNewFreeze = false;
465 /* Postcreate */
467 /* Assign possible attributes */
468 $this->lock_type = $type;
469 $this->lock_name = $name;
470 $this->lock_dn = $baseToUse;
471 $this->postcreate();
472 exit();
473 }
474 }
476 /****************
477 Display dialog to enter new Branch name
478 ****************/
480 if(($s_action == "branch_branch")||($this->dispNewBranch)){
481 $this->dispNewBranch=true;
482 $smarty->assign("iframe",false);
483 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
484 return($display);
485 }
488 /****************
489 Display dialog to enter new Freeze name
490 ****************/
492 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
493 $this->dispNewFreeze = true;
494 $smarty->assign("iframe",false);
495 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
496 return($display);
497 }
500 /****************
501 Create a new object
502 ****************/
504 $types = array( "new_partition" => "FAIpartitionTable",
505 "new_script" => "FAIscript",
506 "new_hook" => "FAIhook",
507 "new_variable" => "FAIvariable",
508 "new_template" => "FAItemplate",
509 "new_package" => "FAIpackageList");
511 if(isset($types[$s_action])){
512 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
513 if(preg_match("/c/",$acl)){
514 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
515 }else{
516 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
517 }
518 }
520 /* New Profile */
521 if($s_action == "new_profile"){
522 $this->dn = "new" ;
524 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
525 if(preg_match("/c/",$acl)){
526 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
527 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
528 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
530 $this->is_dialog = false;
531 }else{
532 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
533 }
534 }
537 /****************
538 Get from ask class name dialog
539 ****************/
541 if($s_action == "select_class_name_finished"){
542 $this->dialog->save_object();
543 if(count($this->dialog->check())!=0){
544 foreach($this->dialog->check() as $msg){
545 print_red($msg);
546 }
547 }else{
548 $this->dn = "new" ;
549 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
550 $name = $this->dialog->save();
552 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
553 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
554 $this->dialog->by_object[$a_setup[1]]->cn = $name;
555 $this->is_dialog = true;
556 }
557 }
560 /****************
561 Cancel dialogs
562 ****************/
564 if(isset($_POST['edit_cancel'])){
565 unset($this->dialog);
566 $this->dialog=NULL;
567 $this->is_dialog = false;
568 unset($_SESSION['objectinfo']);
569 del_lock ($this->dn);
570 }
573 /****************
574 Save sub dialogs
575 ****************/
577 /* This check if the given tab could be saved
578 * If it was possible to save it, remove dialog object.
579 * If it wasn't possible, show errors and keep dialog.
580 */
581 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
582 $this->dialog->save_object();
583 $msgs= $this->dialog->check();
584 if(count($msgs)!=0){
585 foreach($msgs as $msg){
586 print_red($msg);
587 }
588 }else{
589 $this->dialog->save();
590 save_release_changes_now();
591 if (!isset($_POST['edit_apply'])){
592 del_lock ($this->dn);
593 unset($this->dialog);
594 $this->dialog=NULL;
595 $this->is_dialog=false;
596 unset($_SESSION['objectinfo']);
597 }
598 }
599 }
602 /****************
603 Display currently open dialog
604 ****************/
606 /* If dialog is set, but $this->is_dialog==false, then
607 * only the "abort" button is shown, this are dialogs that must not be saved.
608 * If is_dialog == true, we are currently editing tab objects.
609 * Here we need both, save and cancel
610 */
612 if(($this->dialog != NULL) && (isset($this->dialog->config))){
613 $display .= $this->dialog->execute();
614 /* Don't show buttons if tab dialog requests this */
616 if(isset($this->dialog->current)){
618 $obj = $this->dialog->by_object[$this->dialog->current];
620 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
622 $display.= "<p style=\"text-align:right\">\n";
623 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
624 $display.= " \n";
625 if ($this->dn != "new"){
626 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
627 $display.= " \n";
628 }
629 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
630 $display.= "</p>";
631 }elseif(!isset($this->dialog->current)){
632 $display.= "<p style=\"text-align:right\">\n";
633 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
634 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
635 $display.= "</p>";
636 }
637 }else{
638 $display.= "<p style=\"text-align:right\">\n";
639 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
640 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
641 $display.= "</p>";
643 }
644 return($display);
645 }
648 /****************
649 Dialog display
650 ****************/
652 /* Check if there is a snapshot dialog open */
653 $base = $this->DivListFai->selectedBase;
654 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
655 return($str);
656 }
658 /* Display dialog with system list */
659 $this->DivListFai->parent = $this;
660 $this->DivListFai->execute();
661 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
662 $this->reload();
663 $this->DivListFai->setEntries($this->objects);
664 return($this->DivListFai->Draw());
665 }
668 /* Return departments, that will be included within snapshot detection */
669 function get_used_snapshot_bases()
670 {
671 $tmp = array();
672 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
673 foreach($types as $type){
674 if($this->DivListFai->selectedBranch == "main"){
675 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
676 }else{
677 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
678 }
679 }
680 return($tmp);
681 }
684 /* Get available branches for current base */
685 function getBranches($base = false,$prefix = "")
686 {
687 $ret = array("main"=>"/");
688 $ldap = $this->config->get_ldap_link();
689 if(!$base){
690 $base= $_SESSION['CurrentMainBase'];
691 }
692 $tmp = get_all_releases_from_base($base,true);
693 foreach($tmp as $dn => $name){
694 $ret[$dn]=$name;
695 }
696 return ($ret);
697 }
701 /* reload list of objects */
702 function reload()
703 {
704 /* Variable initialisation */
705 $str = "";
706 $Regex = $this->DivListFai->Regex;
707 $this->objects = array();
709 /* Get base */
710 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
711 if($this->DivListFai->selectedBranch != "main"){
712 $br = $this->getBranches();
713 if(isset($br[$this->DivListFai->selectedBranch])){
714 $base = $this->DivListFai->selectedBranch;
715 }else{
716 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
717 }
718 }
720 $this->lock_type = get_release_tag(get_release_dn($base));
722 /* Create a new list of FAI object
723 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
724 */
725 $ObjectTypes = array(
726 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
727 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
728 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
729 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
730 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
731 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
732 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
734 $filter = "";
735 foreach($ObjectTypes as $key => $data){
736 if($this->DivListFai->$data['CHKBOX']){
737 $filter.= "(objectClass=".$key.")";
738 }
739 }
740 $filter = "(&(|".$filter.")(cn=$Regex))";
742 /* Get resolved release dependencies */
743 $tmp = get_all_objects_for_given_base($base,$filter);
745 /* Ge listed ldap objects */
746 $ldap = $this->config->get_ldap_link();
747 $ldap->cd($this->config->current['BASE']);
748 foreach($tmp as $entry){
750 /* Get some more informations about the object */
751 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
752 $object = $ldap->fetch();
754 /* Walk through possible types */
755 foreach($ObjectTypes as $type => $rest){
757 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
759 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
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 = array();
769 $obj['cn'] = $object['cn'][0];
770 $obj['dn'] = $object['dn'];
771 $obj['acl'] = $acl;
772 $obj['description'] = $object['description'][0];
773 $obj['objectClass'] = $object['objectClass'];
775 /* Append type to this string, to be able to check if the selected
776 * entry is of type 'freeze' or 'branch'
777 */
778 if(!isset($object['FAIstate'])){
779 $obj['FAIstate'] = $this->lock_type;
780 }else{
781 $obj['FAIstate'] = $object['FAIstate'][0];
782 }
784 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
785 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
786 }
787 }
788 }
790 ksort($this->objects);
791 reset ($this->objects);
793 /* use numeric index, thats a bit more secure */
794 $tmp0 = array();
795 foreach($this->objects as $obj){
796 $tmp0[]= $obj;
797 }
798 $this->objects = array();
799 $this->objects = $tmp0;
800 }
802 function remove_lock()
803 {
804 if (isset($this->dn)){
805 del_lock ($this->dn);
806 }
807 }
809 function get_type($array){
810 if(in_array("FAIpartitionTable",$array['objectClass'])){
811 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
812 }
813 if(in_array("FAIscript",$array['objectClass'])){
814 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
815 }
816 if(in_array("FAItemplate",$array['objectClass'])){
817 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
818 }
819 if(in_array("FAIhook",$array['objectClass'])){
820 return(array("tabsHook","faiHook","FAIHOOKTABS"));
821 }
822 if(in_array("FAIvariable",$array['objectClass'])){
823 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
824 }
825 if(in_array("FAIprofile",$array['objectClass'])){
826 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
827 }
829 if(in_array("FAIpackageList",$array['objectClass'])){
830 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
831 }
832 }
834 function CheckNewBranchName($name,$base)
835 {
836 $f = $this->DivListFai->selectedBranch;
837 if($name == ""){
838 return(false);
839 }elseif(in_array($name,$this->getBranches($f))) {
840 return(false);
841 }elseif(is_department_name_reserved($name,$base)){
842 return(false);
843 }
844 return(true);
845 }
847 function save_object()
848 {
849 $this->DivListFai->save_object();
850 }
853 /* Return plugin informations for acl handling */
854 function plInfo()
855 {
856 return (array(
857 "plShortName" => _("FAI releases"),
858 "plDescription" => _("FAI release management"),
859 "plSelfModify" => FALSE,
860 "plDepends" => array(),
861 "plPriority" => 0,
862 "plSection" => array("administration"),
863 "plCategory" => array("fai"=> array("description" => _("FAI"),
864 "objectClass" => "FAIclass")),
865 "plProvidedAcls"=> array()));
866 }
867 }
868 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
869 ?>