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 "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
404 echo "<body style='background-image:none;margin:3px;color:black'>";
406 /* Duplicate applications
407 */
408 $ldap->cat($appsrc,array("dn")) ;
409 if($ldap->count()){
410 $ldap->cd ($appdst);
411 $ldap->recursive_remove();
412 $ldap->cd ($this->config->current['BASE']);
413 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
414 }
416 /* Duplicate mime types
417 */
418 $ldap->cat($mimesrc,array("dn")) ;
419 if($ldap->count()){
420 $ldap->cd ($appdst);
421 $ldap->recursive_remove();
422 $ldap->cd ($this->config->current['BASE']);
423 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
424 }
426 $attr = array();
427 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
428 $attr['ou'] = $name;
429 $attr['FAIstate'] = $type;
430 $ldap->cd($this->config->current['BASE']);
431 $ldap->cd("ou=".$name.",".$baseToUse);
432 $ldap->cat("ou=".$name.",".$baseToUse);
433 if($ldap->count()){
434 $ldap->modify($attr);
435 }else{
436 $ldap->add($attr);
437 }
439 /* Duplicate fai objects
440 */
441 // $ldap->cd ("ou=".$name.",".$baseToUse);
442 // $ldap->recursive_remove();
443 // $ldap->cd ($this->config->current['BASE']);
444 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
446 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
447 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
448 </form></div>";
450 /* Print footer to have valid html */
451 echo "</body></html>";
453 $this->dispNewFreeze = false;
455 /* Postcreate */
457 /* Assign possible attributes */
458 $this->lock_type = $type;
459 $this->lock_name = $name;
460 $this->lock_dn = $baseToUse;
461 $this->postcreate();
462 exit();
463 }
464 }
466 /****************
467 Display dialog to enter new Branch name
468 ****************/
470 if(($s_action == "branch_branch")||($this->dispNewBranch)){
471 $this->dispNewBranch=true;
472 $smarty->assign("iframe",false);
473 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
474 return($display);
475 }
478 /****************
479 Display dialog to enter new Freeze name
480 ****************/
482 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
483 $this->dispNewFreeze = true;
484 $smarty->assign("iframe",false);
485 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
486 return($display);
487 }
490 /****************
491 Create a new object
492 ****************/
494 $types = array( "new_partition" => "FAIpartitionTable",
495 "new_script" => "FAIscript",
496 "new_hook" => "FAIhook",
497 "new_variable" => "FAIvariable",
498 "new_template" => "FAItemplate",
499 "new_package" => "FAIpackageList");
501 if(isset($types[$s_action])){
502 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
503 if(preg_match("/c/",$acl)){
504 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
505 }else{
506 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
507 }
508 }
510 /* New Profile */
511 if($s_action == "new_profile"){
512 $this->dn = "new" ;
514 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
515 if(preg_match("/c/",$acl)){
516 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
517 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
518 $this->is_dialog = false;
519 }else{
520 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
521 }
522 }
525 /****************
526 Get from ask class name dialog
527 ****************/
529 if($s_action == "select_class_name_finished"){
530 $this->dialog->save_object();
531 if(count($this->dialog->check())!=0){
532 foreach($this->dialog->check() as $msg){
533 print_red($msg);
534 }
535 }else{
536 $this->dn = "new" ;
537 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
538 $name = $this->dialog->save();
540 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
541 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
542 $this->dialog->by_object[$a_setup[1]]->cn = $name;
543 $this->is_dialog = true;
544 }
545 }
548 /****************
549 Cancel dialogs
550 ****************/
552 if(isset($_POST['edit_cancel'])){
553 unset($this->dialog);
554 $this->dialog=NULL;
555 $this->is_dialog = false;
556 unset($_SESSION['objectinfo']);
557 del_lock ($this->dn);
558 }
561 /****************
562 Save sub dialogs
563 ****************/
565 /* This check if the given tab could be saved
566 * If it was possible to save it, remove dialog object.
567 * If it wasn't possible, show errors and keep dialog.
568 */
569 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
570 $this->dialog->save_object();
571 $msgs= $this->dialog->check();
572 if(count($msgs)!=0){
573 foreach($msgs as $msg){
574 print_red($msg);
575 }
576 }else{
577 $this->dialog->save();
578 save_release_changes_now();
579 if (!isset($_POST['edit_apply'])){
580 del_lock ($this->dn);
581 unset($this->dialog);
582 $this->dialog=NULL;
583 $this->is_dialog=false;
584 unset($_SESSION['objectinfo']);
585 }
586 }
587 }
590 /****************
591 Display currently open dialog
592 ****************/
594 /* If dialog is set, but $this->is_dialog==false, then
595 * only the "abort" button is shown, this are dialogs that must not be saved.
596 * If is_dialog == true, we are currently editing tab objects.
597 * Here we need both, save and cancel
598 */
600 if(($this->dialog != NULL) && (isset($this->dialog->config))){
601 $display .= $this->dialog->execute();
602 /* Don't show buttons if tab dialog requests this */
604 if(isset($this->dialog->current)){
606 $obj = $this->dialog->by_object[$this->dialog->current];
608 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
610 $display.= "<p style=\"text-align:right\">\n";
611 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
612 $display.= " \n";
613 if ($this->dn != "new"){
614 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
615 $display.= " \n";
616 }
617 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
618 $display.= "</p>";
619 }elseif(!isset($this->dialog->current)){
620 $display.= "<p style=\"text-align:right\">\n";
621 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
622 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
623 $display.= "</p>";
624 }
625 }else{
626 $display.= "<p style=\"text-align:right\">\n";
627 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
628 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
629 $display.= "</p>";
631 }
632 return($display);
633 }
636 /****************
637 Dialog display
638 ****************/
640 /* Check if there is a snapshot dialog open */
641 $base = $this->DivListFai->selectedBase;
642 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
643 return($str);
644 }
646 /* Display dialog with system list */
647 $this->DivListFai->parent = $this;
648 $this->DivListFai->execute();
649 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
650 $this->reload();
651 $this->DivListFai->setEntries($this->objects);
652 return($this->DivListFai->Draw());
653 }
656 /* Return departments, that will be included within snapshot detection */
657 function get_used_snapshot_bases()
658 {
659 $tmp = array();
660 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
661 foreach($types as $type){
662 if($this->DivListFai->selectedBranch == "main"){
663 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
664 }else{
665 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
666 }
667 }
668 return($tmp);
669 }
672 /* Get available branches for current base */
673 function getBranches($base = false,$prefix = "")
674 {
675 $ret = array("main"=>"/");
676 $ldap = $this->config->get_ldap_link();
677 if(!$base){
678 $base= $_SESSION['CurrentMainBase'];
679 }
680 $tmp = get_all_releases_from_base($base,true);
681 foreach($tmp as $dn => $name){
682 $ret[$dn]=$name;
683 }
684 return ($ret);
685 }
689 /* reload list of objects */
690 function reload()
691 {
692 /* Variable initialisation */
693 $str = "";
694 $Regex = $this->DivListFai->Regex;
695 $this->objects = array();
697 /* Get base */
698 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
699 if($this->DivListFai->selectedBranch != "main"){
700 $br = $this->getBranches();
701 if(isset($br[$this->DivListFai->selectedBranch])){
702 $base = $this->DivListFai->selectedBranch;
703 }else{
704 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
705 }
706 }
708 $this->lock_type = get_release_tag(get_release_dn($base));
710 /* Create a new list of FAI object
711 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
712 */
713 $ObjectTypes = array(
714 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
715 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
716 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
717 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
718 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
719 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
720 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
722 $filter = "";
723 foreach($ObjectTypes as $key => $data){
724 if($this->DivListFai->$data['CHKBOX']){
725 $filter.= "(objectClass=".$key.")";
726 }
727 }
728 $filter = "(&(|".$filter.")(cn=$Regex))";
730 /* Get resolved release dependencies */
731 $tmp = get_all_objects_for_given_base($base,$filter);
733 /* Ge listed ldap objects */
734 $ldap = $this->config->get_ldap_link();
735 $ldap->cd($this->config->current['BASE']);
736 foreach($tmp as $entry){
738 /* Get some more informations about the object */
739 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
740 $object = $ldap->fetch();
742 /* Walk through possible types */
743 foreach($ObjectTypes as $type => $rest){
745 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
747 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
749 /* Prepare object */
750 unset($object['objectClass']['count']);
751 if(!isset($object['description'][0])){
752 $object['description'][0]="";
753 }
755 /* Clean up object informations */
756 $obj = array();
757 $obj['cn'] = $object['cn'][0];
758 $obj['dn'] = $object['dn'];
759 $obj['acl'] = $acl;
760 $obj['description'] = $object['description'][0];
761 $obj['objectClass'] = $object['objectClass'];
763 /* Append type to this string, to be able to check if the selected
764 * entry is of type 'freeze' or 'branch'
765 */
766 if(!isset($object['FAIstate'])){
767 $obj['FAIstate'] = $this->lock_type;
768 }else{
769 $obj['FAIstate'] = $object['FAIstate'][0];
770 }
772 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
773 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
774 }
775 }
776 }
778 ksort($this->objects);
779 reset ($this->objects);
781 /* use numeric index, thats a bit more secure */
782 $tmp0 = array();
783 foreach($this->objects as $obj){
784 $tmp0[]= $obj;
785 }
786 $this->objects = array();
787 $this->objects = $tmp0;
788 }
790 function remove_lock()
791 {
792 if (isset($this->dn)){
793 del_lock ($this->dn);
794 }
795 }
797 function get_type($array){
798 if(in_array("FAIpartitionTable",$array['objectClass'])){
799 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
800 }
801 if(in_array("FAIscript",$array['objectClass'])){
802 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
803 }
804 if(in_array("FAItemplate",$array['objectClass'])){
805 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
806 }
807 if(in_array("FAIhook",$array['objectClass'])){
808 return(array("tabsHook","faiHook","FAIHOOKTABS"));
809 }
810 if(in_array("FAIvariable",$array['objectClass'])){
811 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
812 }
813 if(in_array("FAIprofile",$array['objectClass'])){
814 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
815 }
817 if(in_array("FAIpackageList",$array['objectClass'])){
818 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
819 }
820 }
822 function CheckNewBranchName($name,$base)
823 {
824 $f = $this->DivListFai->selectedBranch;
825 if($name == ""){
826 return(false);
827 }elseif(in_array($name,$this->getBranches($f))) {
828 return(false);
829 }elseif(is_department_name_reserved($name,$base)){
830 return(false);
831 }
832 return(true);
833 }
835 function save_object()
836 {
837 $this->DivListFai->save_object();
838 }
841 /* Return plugin informations for acl handling */
842 function plInfo()
843 {
844 return (array(
845 "plShortName" => _("FAI releases"),
846 "plDescription" => _("FAI release management"),
847 "plSelfModify" => FALSE,
848 "plDepends" => array(),
849 "plPriority" => 0,
850 "plSection" => array("administration"),
851 "plCategory" => array("fai"=> array("description" => _("FAI"),
852 "objectClass" => "FAIclass")),
853 "plProvidedAcls"=> array()));
854 }
855 }
856 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
857 ?>