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 $departments= array();
43 var $deptabs= NULL;
45 /* attribute list for save action */
46 var $attributes = array(); // Attributes Managed by this plugin, none,
47 // because this is only an overview over all objects already defined in FAI.
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;
57 /* construction/reconstruction
58 * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last
59 * selected department and filter options
60 * If it is not defined already we create a new fresh faifilter.
61 */
62 function faiManagement ($config, $ui)
63 {
64 $this->ui = $ui;
66 /* Set current dn to "", */
67 $this->dn = "";
69 /* Assign config */
70 $this->config = $config;
72 /* Get global filter config */
73 if (!is_global("faifilter")){
74 $base = get_base_from_people($ui->dn);
75 $faifilter= array("base" => $base,
76 "regex" => "*","branch" => "main");
77 $faifilter['ShowProfiles'] = true;
78 $faifilter['ShowTemplates'] = true;
79 $faifilter['ShowScripts'] = true;
80 $faifilter['ShowHooks'] = true;
81 $faifilter['ShowVariables'] = true;
82 $faifilter['ShowPackages'] = true;
83 $faifilter['ShowPartitions']=true;
84 register_global("faifilter", $faifilter);
85 }
86 }
88 function execute()
89 {
91 /* Call parent execute */
92 plugin::execute();
94 $display = "";
95 $smarty = get_smarty();
96 $s_action = "";
97 $s_entry = "";
98 /* filter management
99 * Filter will be changed if POST['regex'] or $_GET['search'] isset
100 * New Filter will be stored in session and is used to generate list contents
101 */
102 $faifilter = $_SESSION['faifilter'];
104 /* Filter is posted by apply button
105 * Check every single chkbox
106 */
107 if(isset($_POST['regex'])){
108 $faifilter['regex'] = $_POST['regex']."*";
109 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
110 if(isset($_POST[$attrs])){
111 $faifilter[$attrs] = true;
112 }else{
113 $faifilter[$attrs] = false;
114 }
115 }
116 }
118 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
119 $faifilter['branch'] = $_POST['select_branch'];
120 }
122 $smarty->assign("select_branch",$_SESSION['faifilter']['branch']);
124 /* Check ImageButton posts
125 * Create new tab ich new_xx is posted
126 */
127 foreach($_POST as $key => $val){
128 if(preg_match("/remove_branch/",$key)){
129 $s_action = "remove_branch";
130 }elseif(preg_match("/branch_branch/",$key)){
131 $s_action = "branch_branch";
132 }elseif(preg_match("/freeze_branch/",$key)){
133 $s_action = "freeze_branch";
134 }elseif(preg_match("/create_partition/i",$key)){
135 $s_action = "new_partition";
136 }elseif(preg_match("/create_script/i",$key)){
137 $s_action = "new_script";
138 }elseif(preg_match("/create_hook/i",$key)){
139 $s_action = "new_hook";
140 }elseif(preg_match("/create_variable/i",$key)){
141 $s_action = "new_variable";
142 }elseif(preg_match("/create_template/i",$key)){
143 $s_action = "new_template";
144 }elseif(preg_match("/create_package/i",$key)){
145 $s_action = "new_package";
146 }elseif(preg_match("/create_profile/i",$key)){
147 $s_action = "new_profile";
148 }elseif(preg_match("/edit_continue/",$key)){
149 $s_action = "select_class_name_finished";
150 }elseif(preg_match("/^entry_edit_.*/",$key)){
151 $s_entry = preg_replace("/^entry_edit_/","",$key);
152 $s_entry = preg_replace("/_.*$/","",$s_entry);
153 $s_action = "edit";
154 }elseif(preg_match("/^entry_delete_.*/",$key)){
155 $s_entry = preg_replace("/^entry_delete_/","",$key);
156 $s_entry = preg_replace("/_.*$/","",$s_entry);
157 $s_action = "delete";
158 }elseif(preg_match("/dep_back.*/i",$key)){
159 $s_action="back";
160 }elseif(preg_match("/dep_home.*/i",$key)){
161 $s_action="home";
162 }elseif(preg_match("/dep_root.*/i",$key)){
163 $s_action="root";
164 }
166 }
168 if($s_action=="root"){
169 $faifilter['base']=($this->config->current['BASE']);
170 }
172 if($s_action=="home"){
173 $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
174 $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
175 }
177 if($s_action=="back"){
178 $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']);
179 $base_back = convert_department_dn($base_back);
181 if(isset($this->config->departments[trim($base_back)])){
182 $faifilter['base']= $this->config->departments[trim($base_back)];
183 }else{
184 $faifilter['base']= $this->config->departments["/"];
185 }
186 }
188 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
189 $s_action="open";
190 $s_entry = base64_decode($_GET['dep_id']);
191 $faifilter['base']= $this->config->departments[trim($s_entry)];
192 }
194 if(isset($_GET['edit_entry'])){
195 $s_entry = $_GET['edit_entry'];
196 $s_action = "edit";
197 }
199 /* Confirm dialog
200 * Delte object
201 */
202 if ($s_action=="delete"){
204 /* Get 'dn' from posted termlinst */
205 $this->dn= $this->objects[$s_entry]['dn'];
207 /* Load permissions for selected 'dn' and check if
208 we're allowed to remove this 'dn' */
209 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
210 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
211 if (chkacl($this->acl, "delete") == ""){
213 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
214 if (($user= get_lock($this->dn)) != ""){
215 return(gen_locked_message ($user, $this->dn));
216 }
218 /* Lock the current entry, so nobody will edit it during deletion */
219 add_lock ($this->dn, $this->ui->dn);
220 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
221 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
222 } else {
224 /* Obviously the user isn't allowed to delete. Show message and
225 clean session. */
226 print_red (_("You are not allowed to delete this component!"));
227 }
228 }
230 /* Delete canceled? */
231 if (isset($_POST['delete_cancel'])){
232 del_lock ($this->dn);
233 }
236 /* Deltetion was confirmed, so delete this entry
237 */
238 if (isset($_POST['delete_terminal_confirm'])){
240 /* Some nice guy may send this as POST, so we've to check
241 for the permissions again. */
242 if (chkacl($this->acl, "delete") == ""){
244 /* Find out more about the object type */
245 $ldap = $this->config->get_ldap_link();
246 $ldap->cat($this->dn);
247 $attrs = $ldap->fetch();
249 $type = $this->get_type($attrs);
251 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
252 $this->dialog->set_acl(array($this->acl));
254 $this->dialog->by_object[$type[1]]->remove_from_parent ();
255 unset ($this->dialog);
256 gosa_log ("FAI class '".$this->dn."' has been removed");
257 $this->dialog= NULL;
259 /* Terminal list has changed, reload it. */
260 $this->reload ();
261 } else {
263 /* Normally this shouldn't be reached, send some extra
264 logs to notify the administrator */
265 print_red (_("You are not allowed to delete this component!"));
266 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
267 "deletion.");
268 }
270 /* Remove lock file after successfull deletion */
271 del_lock ($this->dn);
272 }
274 /* Edit Entry */
275 if($s_action == "edit"){
276 $entry = $this->objects[$s_entry];
278 $a_setup = ($this->get_type($entry));
280 $this->dn = $entry['dn'];
281 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
282 if (($user= get_lock($this->dn)) != ""){
283 return(gen_locked_message ($user, $this->dn));
284 }
285 add_lock ($this->dn, $this->ui->dn);
287 $this->dialog= new $a_setup[0]($this->config,
288 $this->config->data['TABS'][$a_setup[2]],$this->dn);
289 $this->is_dialog = true;
290 $_SESSION['objectinfo'] = $this->dn;
291 }
294 /* Branch handling
295 09.01.2006
296 */
298 /* Create new branch */
299 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
301 /* Check branch name */
302 $name = $_POST['BranchName'];
303 $is_ok = true;
305 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
307 /* Check used characters */
308 if(preg_match("/[^0-9a-z]/i",$name)){
309 print_red(_("Specified branch name is invalid."));
310 $is_ok = false;
311 }
313 /* Check if this name is already in use */
314 if(!$this->CheckNewBranchName($_POST['BranchName'])){
315 print_red(_("This name is already in use."));
316 $this->is_ok = false;
317 }
319 if($is_ok){
320 /* Create it know */
321 $ldap = $this->config->get_ldap_link();
323 $ldap->cd ("ou=".$name.",".$base);
324 $ldap->recursive_remove();
326 $ldap->cd ($this->config->current['BASE']);
327 $ldap->copy_FAI_resource_recursive($base,"ou=".$name.",".$base,"branch",true);
329 $this->dispNewBranch = false;
330 }
331 }
333 /* Abort creating new branch */
334 if(isset($_POST['CancelBranchName'])){
335 $this->dispNewBranch = false;
336 }
338 /* Open dialog to insert new branch name */
339 if(($s_action == "branch_branch")||($this->dispNewBranch)){
340 $this->dispNewBranch=true;
341 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
342 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
343 return($display);
344 }
346 /* Remove branch */
347 if($s_action == "remove_branch"){
348 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
349 /* Load permissions for selected 'dn' and check if
350 we're allowed to remove this 'dn' */
351 $acl= get_permissions ($base, $this->ui->subtreeACL);
352 $this->acl= get_module_permission($acl, "fai", $base);
353 if (chkacl($this->acl, "delete") == ""){
354 $smarty->assign("warning", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $base));
355 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
356 } else {
357 print_red (_("You are not allowed to delete this user!"));
358 }
359 }
361 /* Delete this entry */
362 if(isset($_POST['delete_branch_confirm'])){
363 print "branch removed ";
364 }
366 if($s_action == "freeze_branch"){
367 $this->dispNewFreeze = true;
368 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
369 return($display);
370 }
372 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
373 /* Check branch name */
374 $name = $_POST['BranchName'];
375 $is_ok = true;
377 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
379 /* Check used characters */
380 if(preg_match("/[^0-9a-z]/i",$name)){
381 print_red(_("Specified branch name is invalid."));
382 $is_ok = false;
383 }
385 /* Check if this name is already in use */
386 if(!$this->CheckNewBranchName($_POST['BranchName'])){
387 print_red(_("This name is already in use."));
388 $this->is_ok = false;
389 }
391 if($is_ok){
392 /* Create it know */
393 $ldap = $this->config->get_ldap_link();
395 $ldap->cd ("ou=".$name.",".$base);
396 $ldap->recursive_remove();
398 $ldap->cd ($this->config->current['BASE']);
399 $ldap->copy_FAI_resource_recursive($base,"ou=".$name.",".$base,"freeze",true);
401 $this->dispNewFreeze = false;
402 }
403 }
406 /* ENDE Branch handling
407 */
409 /* Dialog handling */
410 if($s_action == "new_partition"){
411 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
412 }
414 /* Dialog handling */
415 if($s_action == "new_script"){
416 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
417 }
419 /* Dialog handling */
420 if($s_action == "new_hook"){
421 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
422 }
424 /* Dialog handling */
425 if($s_action == "new_variable"){
426 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
427 }
429 /* Dialog handling */
430 if($s_action == "new_template"){
431 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
432 }
434 /* Dialog handling */
435 if($s_action == "new_package"){
436 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
437 }
439 /* New Profile */
440 if($s_action == "new_profile"){
441 $this->dn = "new" ;
442 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
444 $this->dialog = new $a_setup[0]($this->config,
445 $this->config->data['TABS'][$a_setup[2]],$this->dn);
446 $this->is_dialog = true;
448 }
450 if($s_action == "select_class_name_finished"){
451 $this->dialog->save_object();
452 if(count($this->dialog->check())!=0){
453 foreach($this->dialog->check() as $msg){
454 print_red($msg);
455 }
456 }else{
457 $this->dn = "new" ;
458 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
459 $name = $this->dialog->save();
461 $this->dialog = new $a_setup[0]($this->config,
462 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
463 $this->dialog->by_object[$a_setup[1]]->cn = $name;
464 $this->is_dialog = true;
465 }
466 }
468 /* Search is set */
469 if(isset($_GET['search'])){
470 $faifilter['regex']=$_GET['search']."*";
471 }
473 /* Department select */
474 if((isset($_POST['base']))&&($s_action=="")){
475 $faifilter['base']=$_POST['base'];
476 }
478 /* remove double asterisks and save new filter */
479 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
480 $_SESSION['faifilter']= $faifilter;
482 /* Edit dialog was canceled
483 * Remove dialog an show management dialog
484 */
485 if(isset($_POST['edit_cancel'])){
486 unset($this->dialog);
487 $this->dialog=NULL;
488 $this->is_dialog = false;
489 unset($_SESSION['objectinfo']);
490 del_lock ($this->dn);
491 }
493 /* This check if the given tab could be saved
494 * If it was possible to save it, remove dialog object.
495 * If it wasn't possible, show errors and keep dialog.
496 */
497 if(isset($_POST['edit_finish'])){
498 $this->dialog->save_object();
499 if(count($this->dialog->check())!=0){
500 foreach($this->dialog->check() as $msg){
501 print_red($msg);
502 }
503 }else{
504 del_lock ($this->dn);
505 $this->dialog->save();
506 unset($this->dialog);
507 $this->dialog=NULL;
508 $this->is_dialog=false;
509 unset($_SESSION['objectinfo']);
510 }
511 }
513 /* If dialog is set, but $this->is_dialog==false, then
514 * only the "abort" button is shown, this are dialogs that must not be saved.
515 * If is_dialog == true, we are currently editing tab objects.
516 * Here we need both, save and cancel
517 */
519 if($this->dialog != NULL){
520 $display .= $this->dialog->execute();
521 /* Don't show buttons if tab dialog requests this */
522 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
524 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
525 $display.= "<p style=\"text-align:right\">\n";
526 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
527 $display.= " \n";
528 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
529 $display.= "</p>";
530 }elseif(!isset($this->dialog->current)){
531 $display.= "<p style=\"text-align:right\">\n";
532 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
533 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
534 $display.= "</p>";
535 }
536 return($display);
537 }
539 /* Show Management template
540 * The following code will only be reached if no dialog (tabs or dialogs)
541 * are currently opened.
542 * Assign all reguired vars to template engine
543 */
545 /* Prepare departments */
546 $options= "";
547 foreach ($this->config->idepartments as $key => $value){
548 if ($faifilter['base'] == $key){
549 $options.= "<option selected='selected' value='$key'>$value</option>";
550 } else {
551 $options.= "<option value='$key'>$value</option>";
552 }
553 }
555 /* Create listhead, it will be shown on top of the divlist.
556 * It provides general navigation and object creation
557 */
558 $faihead =
559 "<div style='background:#F0F0F9;padding:5px;'> ".
561 "<input class='center' type='image' src='images/list_up.png' align='middle'
562 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
564 "<input class='center' type='image' src='images/list_root.png' align='middle'
565 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
567 "<input class='center' type='image' src='images/list_home.png' align='middle'
568 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
570 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
572 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
573 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
575 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
577 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
578 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
580 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
581 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
583 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
584 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
586 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
587 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
589 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
590 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
592 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
593 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
595 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
597 _("Current base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
598 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
600 "</div>";
602 $this->reload();
604 /* Create list with objects */
605 $divlist = new divlist("faiManagement");
606 $divlist->SetEntriesPerPage(0);
607 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
609 $divlist->SetHeader(array(
610 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
611 array("string" => _("Name of FAI class"), "attach" => "style=''"),
612 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
613 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
616 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
617 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
619 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
620 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
622 foreach($this->departments as $key => $val) {
623 if(!isset($this->config->departments[trim($key)])){
624 $this->config->departments[trim($key)]="";
625 }
627 $non_empty="";
628 $keys= str_replace("/","\/",$key);
629 foreach($this->config->departments as $keyd=>$vald ){
630 if(preg_match("/".$keys."\/.*/",$keyd)){
631 $non_empty="full";
632 }
633 }
636 $title = $this->config->departments[$key];
637 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
638 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
639 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
640 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
642 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
644 }
646 /* Attach objects */
647 foreach($this->objects as $key => $value){
648 $info= "";
649 $img = "";
650 $type = $value['type'];
651 $abort=false;
653 switch($type) {
654 case "FAIpartitionTable" :
655 if(!$faifilter['ShowPartitions']){
656 $abort = true;
657 }
658 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
659 $info = _("Partition table");
660 break;
661 case "FAIpackageList" :
662 if(!$faifilter['ShowPackages']){
663 $abort = true;
664 }
665 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
666 $info = _("Package list");
667 break;
668 case "FAIscript" :
669 if(!$faifilter['ShowScripts']){
670 $abort = true;
671 }
672 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
673 $info = _("Scripts");
674 break;
675 case "FAIvariable" :
676 if(!$faifilter['ShowVariables']){
677 $abort = true;
678 }
679 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
680 $info = _("Variables");
681 break;
682 case "FAIhook" :
683 if(!$faifilter['ShowHooks']){
684 $abort = true;
685 }
686 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
687 $info = _("Hooks");
688 break;
689 case "FAIprofile" :
690 if(!$faifilter['ShowProfiles']){
691 $abort = true;
692 }
693 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
694 $info = _("Profile");
695 break;
696 case "FAItemplate" :
697 if(!$faifilter['ShowTemplates']){
698 $abort = true;
699 }
700 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
701 $info = _("Templates");
702 break;
703 default :
704 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
706 }
708 if(!$abort) {
709 if((isset($value['description']))&&(!empty($value['description']))){
710 $desc= " [".$value['description']."]";
711 }else{
712 $desc= "";
713 }
715 if($value['FAIstate'] == "freeze"){
716 $acti = "";
717 $edi = "%NAME%";
718 }else{
719 $acti = $action;
720 $edi = $editlink;
721 }
723 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
724 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
725 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
726 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
727 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
729 }
730 }
732 foreach($faifilter as $attrs => $value){
733 if($value){
734 $smarty->assign($attrs."CHK", " checked ");
735 }else{
736 $smarty->assign($attrs."CHK", " ");
737 }
738 }
740 /* Assign all reguired vars to template engine */
742 $smarty->assign("branchKeys",array_flip($this->getBranches()));
743 $smarty->assign("branches",$this->getBranches());
745 $smarty->assign("faihead" , $faihead);
746 $smarty->assign("failist" , $divlist->DrawList());
747 $smarty->assign("regex" , $faifilter['regex']);
748 $smarty->assign("infoimage" , get_template_path('images/info.png'));
749 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
750 $smarty->assign("alphabet" , generate_alphabet());
751 $smarty->assign("apply" , apply_filter());
752 $smarty->assign("search_image" , get_template_path('images/search.png'));
753 $smarty->assign("hint", print_sizelimit_warning());
755 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
756 return ($display);
757 }
759 function getBranches($base = false,$prefix = "")
760 {
761 $ret = array("main"=>_("main"));
762 $ldap = $this->config->get_ldap_link();
764 $ldap->cd($this->config->current['BASE']);
766 $faifilter = $_SESSION['faifilter'];
769 if(!$base){
770 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
771 }
772 $ldap->cd($base);
773 $ldap->ls("(objectClass=FAIbranch)",$base);
775 while($attrs = $ldap->fetch()){
777 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
778 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
779 $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix."/".$attrs['ou'][0]));
780 }
781 }
782 return($ret);
783 }
785 function reload()
786 {
787 /* Create a new list of FAI object
788 * Object list depends on faifilter['regex']
789 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
790 */
791 $faifilter= get_global('faifilter');
792 // Added for dirlist function...
794 /* Set base for all searches */
795 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
797 if($faifilter['branch'] !="main"){
798 $base = $faifilter['branch'];
799 }
801 $regex = $faifilter['regex'];
803 /* Array to save objects */
804 $objects = array();
806 $this->objects=array();
808 /* NEW LIST MANAGMENT
809 * We also need to search for the departments
810 * So we are able to navigate like in konquerer
811 */
812 $base2 = $faifilter['base'];
814 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
815 TRUE, $base2, array("ou", "description"), TRUE);
817 $this->departments= array();
818 $tmp = array();
819 foreach ($res3 as $value){
820 $tmp[strtolower($value['dn']).$value['dn']]=$value;
821 }
822 ksort($tmp);
823 foreach($tmp as $value){
824 if(isset($value["description"][0])){
825 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
826 }else{
827 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
828 }
829 }
831 /* END NEW LIST MANAGMENT
832 */
835 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
836 FALSE, $base, array("cn","description","objectClass"),TRUE);
838 foreach($res as $objecttypes){
839 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
840 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
841 foreach($res2 as $object){
842 $type= "";
843 unset($object['objectClass']['count']);
844 if(!isset($object['description'][0])){
845 $object['description'][0]="";
846 }
848 /* Clean up object informations */
849 $obj['cn'] = $object['cn'][0];
850 $obj['dn'] = $object['dn'];
851 $obj['description'] = $object['description'][0];
852 $obj['objectClass'] = $object['objectClass'];
854 if(isset($object['FAIstate'])){
855 $obj['FAIstate'] = $object['FAIstate'][0];
856 }else{
857 $obj['FAIstate'] ="";
858 }
860 if(in_array("FAIpartitionTable",$obj['objectClass'])){
861 $type = "FAIpartitionTable";
862 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
863 $type = "FAIpackageList";
864 }elseif(in_array("FAIscript",$obj['objectClass'])){
865 $type = "FAIscript";
866 }elseif(in_array("FAIvariable",$obj['objectClass'])){
867 $type = "FAIvariable";
868 }elseif(in_array("FAIhook",$obj['objectClass'])){
869 $type = "FAIhook";
870 }elseif(in_array("FAIprofile",$obj['objectClass'])){
871 $obj['FAIclass'] = $object['FAIclass'][0];
872 $type = "FAIprofile";
873 }elseif(in_array("FAItemplate",$obj['objectClass'])){
874 $type = "FAItemplate";
875 }
876 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
877 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
879 }
880 }
881 ksort($this->objects);
882 reset ($this->objects);
884 /* use numeric index, thats a bit more secure */
885 $tmp0 = array();
886 foreach($this->objects as $obj){
887 $tmp0[]= $obj;
888 }
889 $this->objects = array();
890 $this->objects = $tmp0;
892 }
894 function remove_lock()
895 {
896 if (isset($this->dn)){
897 del_lock ($this->dn);
898 }
899 }
901 function get_type($array){
902 if(in_array("FAIpartitionTable",$array['objectClass'])){
903 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
904 }
905 if(in_array("FAIscript",$array['objectClass'])){
906 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
907 }
908 if(in_array("FAItemplate",$array['objectClass'])){
909 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
910 }
911 if(in_array("FAIhook",$array['objectClass'])){
912 return(array("tabsHook","faiHook","FAIHOOKTABS"));
913 }
914 if(in_array("FAIvariable",$array['objectClass'])){
915 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
916 }
917 if(in_array("FAIprofile",$array['objectClass'])){
918 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
919 }
921 if(in_array("FAIpackageList",$array['objectClass'])){
922 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
923 }
924 }
926 function CheckNewBranchName($name){
927 if(in_array($name,$this->getBranches())) {
928 return(false);
929 }
930 return(true);
931 }
933 }
934 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
935 ?>