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 /* Load permissions for selected 'dn' and check if
148 we're allowed to remove this 'dn' */
149 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
150 if(preg_match("/d/",$acl)){
152 /* Get 'dn' from posted termlinst */
153 $this->dn= $this->objects[$s_entry]['dn'];
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. */
193 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
194 if(preg_match("/d/",$acl)){
196 /* Find out more about the object type */
197 $ldap = $this->config->get_ldap_link();
198 $ldap->cat($this->dn, array('objectClass'));
199 $attrs = $ldap->fetch();
200 $type = $this->get_type($attrs);
201 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
202 $this->dialog->set_acl_base($this->dn);
203 $this->dialog->by_object[$type[1]]->remove_from_parent ();
204 unset ($this->dialog);
205 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
206 $this->dialog= NULL;
207 $to_del = clean_up_releases($this->dn);
208 save_release_changes_now();
210 foreach($to_del as $dn){
211 $ldap->rmdir_recursive($dn);
212 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
213 }
215 } else {
217 /* Normally this shouldn't be reached, send some extra
218 logs to notify the administrator */
219 print_red (_("You are not allowed to delete this component!"));
220 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
221 "deletion.");
222 }
224 /* Remove lock file after successfull deletion */
225 del_lock ($this->dn);
226 }
229 /****************
230 Edit entry
231 ****************/
233 if(($s_action == "edit") && (!isset($this->dialog->config))){
234 $entry = $this->objects[$s_entry];
235 $a_setup = $this->get_type($entry);
236 $this->dn = $entry['dn'];
238 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
239 if (($user= get_lock($this->dn)) != ""){
240 return(gen_locked_message ($user, $this->dn));
241 }
242 add_lock ($this->dn, $this->ui->dn);
244 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
245 $this->dialog->set_acl_base($this->dn);
246 $this->is_dialog = true;
248 if($entry['FAIstate'] == "freeze"){
249 #$this->dialog->set_acl(array("*none*")) ;
250 echo "Dawn it is freezed.";
251 }
252 $_SESSION['objectinfo'] = $this->dn;
253 }
256 /* Branch handling
257 09.01.2006
258 */
260 /****************
261 Remove branch
262 ****************/
264 /* Remove branch
265 */
266 if($s_action == "remove_branch"){
267 $base= $this->DivListFai->selectedBranch;
269 /* Load permissions for selected 'dn' and check if
270 we're allowed to remove this 'dn' */
271 $this->set_acl_base($base);
272 if($this->acl_is_removeable()){
274 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
275 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
276 } else {
277 print_red (_("You are not allowed to delete this release!"));
278 }
279 }
282 /****************
283 Remove branch confirmed
284 ****************/
286 if(isset($_POST['delete_branch_confirm'])){
287 $bb = $this->DivListFai->selectedBranch;
288 if(!isset($ldap)){
289 $ldap = $this->config->get_ldap_link();
290 }
292 $br = $this->getBranches();
294 if(isset($br[$bb]) && $this->acl_is_removeable()){
295 $name = $br[$bb];
296 $ldap->cd($bb);
297 $ldap->recursive_remove();
298 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
299 $ldap->recursive_remove();
300 $this->DivListFai->selectedBranch = "main";
302 /* Post remove */
303 $this->lock_name = $name;
304 $this->lock_dn = $bb;
305 $this->postremove();
306 }
307 }
310 /****************
311 Create a new branch "insert Name"
312 ****************/
314 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
315 $_SESSION['LASTPOST'] = $_POST;
317 if($this->dispNewBranch){
318 $type = "branch";
319 }else{
320 $type = "freeze";
321 }
323 /* Check branch name */
324 $name = $_POST['BranchName'];
325 $is_ok = true;
326 $smarty->assign("BranchName",$name);
327 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
329 /* Check used characters */
330 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
331 if($type == "branch"){
332 print_red(_("Specified branch name is invalid."));
333 }else{
334 print_red(_("Specified freeze name is invalid."));
335 }
336 $is_ok = false;
337 }
339 /* Check if this name is already in use */
340 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
341 print_red(_("This name is already in use."));
342 $is_ok = false;
343 }
345 if($is_ok){
346 $_SESSION['LASTPOST']['base'] = $base;
347 $_SESSION['LASTPOST']['type'] = $type;
348 $smarty->assign("iframe", true);
349 $smarty->assign("plugID", $_GET['plug']);
350 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
351 return($display);
352 }
353 }
356 /****************
357 Create a new branch
358 ****************/
360 if(isset($_GET['PerformBranch'])){
362 if(!$this->acl_is_createable()){
363 print_red(_("You are not allowed to create a new branch."));
364 }else{
366 /* Create it know */
367 $this->dispNewBranch = false;
368 $this->dispNewFreeze = false;
369 $base = $_SESSION['LASTPOST']['base'];
370 $_POST = $_SESSION['LASTPOST'];
371 $name = $_POST['BranchName'];
373 $type = $_SESSION['LASTPOST']['type'];
374 $ldap = $this->config->get_ldap_link();
376 $baseToUse = $base;
377 if($this->DivListFai->selectedBranch != "main" ){
378 $baseToUse = $this->DivListFai->selectedBranch;
379 }
381 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
383 $CurrentReleases = $this->getBranches();
384 $NewReleaseName = $name;
385 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
386 if($this->DivListFai->selectedBranch != "main"){
387 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
388 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
389 }else{
390 $NewReleaseName = $name;
391 }
392 }
394 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
395 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
397 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
398 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
400 /* Print header to have styles included */
401 echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
402 echo "<body style='background-image:none;margin:3px;color:black'>";
404 /* Duplicate applications
405 */
406 $ldap->cat($appsrc,array("dn")) ;
407 if($ldap->count()){
408 $ldap->cd ($appdst);
409 $ldap->recursive_remove();
410 $ldap->cd ($this->config->current['BASE']);
411 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
412 }
414 /* Duplicate mime types
415 */
416 $ldap->cat($mimesrc,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($mimesrc,$mimedst,$NewReleaseName,$type,true);
422 }
424 $attr = array();
425 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
426 $attr['ou'] = $name;
427 $attr['FAIstate'] = $type;
428 $ldap->cd($this->config->current['BASE']);
429 $ldap->cd("ou=".$name.",".$baseToUse);
430 $ldap->cat("ou=".$name.",".$baseToUse);
431 if($ldap->count()){
432 $ldap->modify($attr);
433 }else{
434 $ldap->add($attr);
435 }
437 /* Duplicate fai objects
438 */
439 // $ldap->cd ("ou=".$name.",".$baseToUse);
440 // $ldap->recursive_remove();
441 // $ldap->cd ($this->config->current['BASE']);
442 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
444 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
445 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
446 </form></div>";
448 /* Print footer to have valid html */
449 echo "</body></html>";
451 $this->dispNewFreeze = false;
453 /* Postcreate */
455 /* Assign possible attributes */
456 $this->lock_type = $type;
457 $this->lock_name = $name;
458 $this->lock_dn = $baseToUse;
459 $this->postcreate();
460 exit();
461 }
462 }
464 /****************
465 Display dialog to enter new Branch name
466 ****************/
468 if(($s_action == "branch_branch")||($this->dispNewBranch)){
469 $this->dispNewBranch=true;
470 $smarty->assign("iframe",false);
471 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
472 return($display);
473 }
476 /****************
477 Display dialog to enter new Freeze name
478 ****************/
480 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
481 $this->dispNewFreeze = true;
482 $smarty->assign("iframe",false);
483 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
484 return($display);
485 }
488 /****************
489 Create a new object
490 ****************/
492 $types = array( "new_partition" => "FAIpartitionTable",
493 "new_script" => "FAIscript",
494 "new_hook" => "FAIhook",
495 "new_variable" => "FAIvariable",
496 "new_template" => "FAItemplate",
497 "new_package" => "FAIpackageList");
499 if(isset($types[$s_action])){
500 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
501 if(preg_match("/c/",$acl)){
502 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
503 }else{
504 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
505 }
506 }
508 /* New Profile */
509 if($s_action == "new_profile"){
510 $this->dn = "new" ;
512 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
513 if(preg_match("/c/",$acl)){
514 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
515 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
516 $this->is_dialog = false;
517 }else{
518 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
519 }
520 }
523 /****************
524 Get from ask class name dialog
525 ****************/
527 if($s_action == "select_class_name_finished"){
528 $this->dialog->save_object();
529 if(count($this->dialog->check())!=0){
530 foreach($this->dialog->check() as $msg){
531 print_red($msg);
532 }
533 }else{
534 $this->dn = "new" ;
535 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
536 $name = $this->dialog->save();
538 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
539 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
540 $this->dialog->by_object[$a_setup[1]]->cn = $name;
541 $this->is_dialog = true;
542 }
543 }
546 /****************
547 Cancel dialogs
548 ****************/
550 if(isset($_POST['edit_cancel'])){
551 unset($this->dialog);
552 $this->dialog=NULL;
553 $this->is_dialog = false;
554 unset($_SESSION['objectinfo']);
555 del_lock ($this->dn);
556 }
559 /****************
560 Save sub dialogs
561 ****************/
563 /* This check if the given tab could be saved
564 * If it was possible to save it, remove dialog object.
565 * If it wasn't possible, show errors and keep dialog.
566 */
567 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
568 $this->dialog->save_object();
569 $msgs= $this->dialog->check();
570 if(count($msgs)!=0){
571 foreach($msgs as $msg){
572 print_red($msg);
573 }
574 }else{
575 $this->dialog->save();
576 save_release_changes_now();
577 if (!isset($_POST['edit_apply'])){
578 del_lock ($this->dn);
579 unset($this->dialog);
580 $this->dialog=NULL;
581 $this->is_dialog=false;
582 unset($_SESSION['objectinfo']);
583 }
584 }
585 }
588 /****************
589 Display currently open dialog
590 ****************/
592 /* If dialog is set, but $this->is_dialog==false, then
593 * only the "abort" button is shown, this are dialogs that must not be saved.
594 * If is_dialog == true, we are currently editing tab objects.
595 * Here we need both, save and cancel
596 */
598 if(($this->dialog != NULL) && (isset($this->dialog->config))){
599 $display .= $this->dialog->execute();
600 /* Don't show buttons if tab dialog requests this */
602 if(isset($this->dialog->current)){
604 $obj = $this->dialog->by_object[$this->dialog->current];
606 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
608 $display.= "<p style=\"text-align:right\">\n";
609 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
610 $display.= " \n";
611 if ($this->dn != "new"){
612 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
613 $display.= " \n";
614 }
615 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
616 $display.= "</p>";
617 }elseif(!isset($this->dialog->current)){
618 $display.= "<p style=\"text-align:right\">\n";
619 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
620 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
621 $display.= "</p>";
622 }
623 }else{
624 $display.= "<p style=\"text-align:right\">\n";
625 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
626 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
627 $display.= "</p>";
629 }
630 return($display);
631 }
634 /****************
635 Dialog display
636 ****************/
638 /* Check if there is a snapshot dialog open */
639 $base = $this->DivListFai->selectedBase;
640 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
641 return($str);
642 }
644 /* Display dialog with system list */
645 $this->DivListFai->parent = $this;
646 $this->DivListFai->execute();
647 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
648 $this->reload();
649 $this->DivListFai->setEntries($this->objects);
650 return($this->DivListFai->Draw());
651 }
654 /* Return departments, that will be included within snapshot detection */
655 function get_used_snapshot_bases()
656 {
657 $tmp = array();
658 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
659 foreach($types as $type){
660 if($this->DivListFai->selectedBranch == "main"){
661 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
662 }else{
663 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
664 }
665 }
666 return($tmp);
667 }
670 /* Get available branches for current base */
671 function getBranches($base = false,$prefix = "")
672 {
673 $ret = array("main"=>"/");
674 $ldap = $this->config->get_ldap_link();
675 if(!$base){
676 $base= $_SESSION['CurrentMainBase'];
677 }
678 $tmp = get_all_releases_from_base($base,true);
679 foreach($tmp as $dn => $name){
680 $ret[$dn]=$name;
681 }
682 return ($ret);
683 }
687 /* reload list of objects */
688 function reload()
689 {
690 /* Variable initialisation */
691 $str = "";
692 $Regex = $this->DivListFai->Regex;
693 $this->objects = array();
695 /* Get base */
696 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
697 if($this->DivListFai->selectedBranch != "main"){
698 $br = $this->getBranches();
699 if(isset($br[$this->DivListFai->selectedBranch])){
700 $base = $this->DivListFai->selectedBranch;
701 }else{
702 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
703 }
704 }
706 $this->lock_type = get_release_tag(get_release_dn($base));
708 /* Create a new list of FAI object
709 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
710 */
711 $ObjectTypes = array(
712 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
713 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
714 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
715 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
716 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
717 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
718 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
720 $filter = "";
721 foreach($ObjectTypes as $key => $data){
722 if($this->DivListFai->$data['CHKBOX']){
723 $filter.= "(objectClass=".$key.")";
724 }
725 }
726 $filter = "(&(|".$filter.")(cn=$Regex))";
728 /* Get resolved release dependencies */
729 $tmp = get_all_objects_for_given_base($base,$filter);
731 /* Ge listed ldap objects */
732 $ldap = $this->config->get_ldap_link();
733 $ldap->cd($this->config->current['BASE']);
734 foreach($tmp as $entry){
736 /* Get some more informations about the object */
737 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
738 $object = $ldap->fetch();
740 /* Walk through possible types */
741 foreach($ObjectTypes as $type => $rest){
743 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
745 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
747 /* Prepare object */
748 unset($object['objectClass']['count']);
749 if(!isset($object['description'][0])){
750 $object['description'][0]="";
751 }
753 /* Clean up object informations */
754 $obj = array();
755 $obj['cn'] = $object['cn'][0];
756 $obj['dn'] = $object['dn'];
757 $obj['acl'] = $acl;
758 $obj['description'] = $object['description'][0];
759 $obj['objectClass'] = $object['objectClass'];
761 /* Append type to this string, to be able to check if the selected
762 * entry is of type 'freeze' or 'branch'
763 */
764 if(!isset($object['FAIstate'])){
765 $obj['FAIstate'] = $this->lock_type;
766 }else{
767 $obj['FAIstate'] = $object['FAIstate'][0];
768 }
770 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
771 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
772 }
773 }
774 }
776 ksort($this->objects);
777 reset ($this->objects);
779 /* use numeric index, thats a bit more secure */
780 $tmp0 = array();
781 foreach($this->objects as $obj){
782 $tmp0[]= $obj;
783 }
784 $this->objects = array();
785 $this->objects = $tmp0;
786 }
788 function remove_lock()
789 {
790 if (isset($this->dn)){
791 del_lock ($this->dn);
792 }
793 }
795 function get_type($array){
796 if(in_array("FAIpartitionTable",$array['objectClass'])){
797 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
798 }
799 if(in_array("FAIscript",$array['objectClass'])){
800 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
801 }
802 if(in_array("FAItemplate",$array['objectClass'])){
803 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
804 }
805 if(in_array("FAIhook",$array['objectClass'])){
806 return(array("tabsHook","faiHook","FAIHOOKTABS"));
807 }
808 if(in_array("FAIvariable",$array['objectClass'])){
809 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
810 }
811 if(in_array("FAIprofile",$array['objectClass'])){
812 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
813 }
815 if(in_array("FAIpackageList",$array['objectClass'])){
816 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
817 }
818 }
820 function CheckNewBranchName($name,$base)
821 {
822 $f = $this->DivListFai->selectedBranch;
823 if($name == ""){
824 return(false);
825 }elseif(in_array($name,$this->getBranches($f))) {
826 return(false);
827 }elseif(is_department_name_reserved($name,$base)){
828 return(false);
829 }
830 return(true);
831 }
833 function save_object()
834 {
835 $this->DivListFai->save_object();
836 }
839 /* Return plugin informations for acl handling */
840 function plInfo()
841 {
842 return (array(
843 "plShortName" => _("FAI releases"),
844 "plDescription" => _("FAI release management"),
845 "plSelfModify" => FALSE,
846 "plDepends" => array(),
847 "plPriority" => 0,
848 "plSection" => array("administration"),
849 "plCategory" => array("fai"=> array("description" => _("FAI"),
850 "objectClass" => "FAIclass")),
851 "plProvidedAcls"=> array()));
852 }
853 }
854 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
855 ?>