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 $baseToUse = $base;
324 if($_SESSION['faifilter']['branch']!="main"){
325 $baseToUse = $_SESSION['faifilter']['branch'];
326 }
328 $ldap->cd ("ou=".$name.",".$baseToUse);
329 $ldap->recursive_remove();
331 $ldap->cd ($this->config->current['BASE']);
332 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
334 $this->dispNewBranch = false;
335 }
336 }
338 /* Abort creating new branch */
339 if(isset($_POST['CancelBranchName'])){
340 $this->dispNewBranch = false;
341 }
343 /* Open dialog to insert new branch name */
344 if(($s_action == "branch_branch")||($this->dispNewBranch)){
345 $this->dispNewBranch=true;
346 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
347 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
348 return($display);
349 }
351 /* Remove branch */
352 if($s_action == "remove_branch"){
353 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
354 /* Load permissions for selected 'dn' and check if
355 we're allowed to remove this 'dn' */
356 $acl= get_permissions ($base, $this->ui->subtreeACL);
357 $this->acl= get_module_permission($acl, "fai", $base);
358 if (chkacl($this->acl, "delete") == ""){
359 $smarty->assign("warning", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $base));
360 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
361 } else {
362 print_red (_("You are not allowed to delete this user!"));
363 }
364 }
366 /* Delete this entry */
367 if(isset($_POST['delete_branch_confirm'])){
368 print "branch removed ";
369 }
371 if($s_action == "freeze_branch"){
372 $this->dispNewFreeze = true;
373 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
374 return($display);
375 }
377 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
378 /* Check branch name */
379 $name = $_POST['BranchName'];
380 $is_ok = true;
382 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
384 /* Check used characters */
385 if(preg_match("/[^0-9a-z]/i",$name)){
386 print_red(_("Specified branch name is invalid."));
387 $is_ok = false;
388 }
390 /* Check if this name is already in use */
391 if(!$this->CheckNewBranchName($_POST['BranchName'])){
392 print_red(_("This name is already in use."));
393 $this->is_ok = false;
394 }
396 if($is_ok){
397 /* Create it know */
398 $ldap = $this->config->get_ldap_link();
400 $baseToUse = $base;
401 if($_SESSION['faifilter']['branch']!="main"){
402 $baseToUse = $_SESSION['faifilter']['branch'];
403 }
405 $ldap->cd ("ou=".$name.",".$baseToUse);
406 $ldap->recursive_remove();
408 $ldap->cd ($this->config->current['BASE']);
409 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
411 $this->dispNewFreeze = false;
412 }
413 }
416 /* ENDE Branch handling
417 */
419 /* Dialog handling */
420 if($s_action == "new_partition"){
421 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
422 }
424 /* Dialog handling */
425 if($s_action == "new_script"){
426 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
427 }
429 /* Dialog handling */
430 if($s_action == "new_hook"){
431 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
432 }
434 /* Dialog handling */
435 if($s_action == "new_variable"){
436 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
437 }
439 /* Dialog handling */
440 if($s_action == "new_template"){
441 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
442 }
444 /* Dialog handling */
445 if($s_action == "new_package"){
446 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
447 }
449 /* New Profile */
450 if($s_action == "new_profile"){
451 $this->dn = "new" ;
452 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
454 $this->dialog = new $a_setup[0]($this->config,
455 $this->config->data['TABS'][$a_setup[2]],$this->dn);
456 $this->is_dialog = true;
458 }
460 if($s_action == "select_class_name_finished"){
461 $this->dialog->save_object();
462 if(count($this->dialog->check())!=0){
463 foreach($this->dialog->check() as $msg){
464 print_red($msg);
465 }
466 }else{
467 $this->dn = "new" ;
468 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
469 $name = $this->dialog->save();
471 $this->dialog = new $a_setup[0]($this->config,
472 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
473 $this->dialog->by_object[$a_setup[1]]->cn = $name;
474 $this->is_dialog = true;
475 }
476 }
478 /* Search is set */
479 if(isset($_GET['search'])){
480 $faifilter['regex']=$_GET['search']."*";
481 }
483 /* Department select */
484 if((isset($_POST['base']))&&($s_action=="")){
485 $faifilter['base']=$_POST['base'];
486 }
488 /* remove double asterisks and save new filter */
489 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
490 $_SESSION['faifilter']= $faifilter;
492 /* Edit dialog was canceled
493 * Remove dialog an show management dialog
494 */
495 if(isset($_POST['edit_cancel'])){
496 unset($this->dialog);
497 $this->dialog=NULL;
498 $this->is_dialog = false;
499 unset($_SESSION['objectinfo']);
500 del_lock ($this->dn);
501 }
503 /* This check if the given tab could be saved
504 * If it was possible to save it, remove dialog object.
505 * If it wasn't possible, show errors and keep dialog.
506 */
507 if(isset($_POST['edit_finish'])){
508 $this->dialog->save_object();
509 if(count($this->dialog->check())!=0){
510 foreach($this->dialog->check() as $msg){
511 print_red($msg);
512 }
513 }else{
514 del_lock ($this->dn);
515 $this->dialog->save();
516 unset($this->dialog);
517 $this->dialog=NULL;
518 $this->is_dialog=false;
519 unset($_SESSION['objectinfo']);
520 }
521 }
523 /* If dialog is set, but $this->is_dialog==false, then
524 * only the "abort" button is shown, this are dialogs that must not be saved.
525 * If is_dialog == true, we are currently editing tab objects.
526 * Here we need both, save and cancel
527 */
529 if($this->dialog != NULL){
530 $display .= $this->dialog->execute();
531 /* Don't show buttons if tab dialog requests this */
532 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
534 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
535 $display.= "<p style=\"text-align:right\">\n";
536 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
537 $display.= " \n";
538 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
539 $display.= "</p>";
540 }elseif(!isset($this->dialog->current)){
541 $display.= "<p style=\"text-align:right\">\n";
542 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
543 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
544 $display.= "</p>";
545 }
546 return($display);
547 }
549 /* Show Management template
550 * The following code will only be reached if no dialog (tabs or dialogs)
551 * are currently opened.
552 * Assign all reguired vars to template engine
553 */
555 /* Prepare departments */
556 $options= "";
557 foreach ($this->config->idepartments as $key => $value){
558 if ($faifilter['base'] == $key){
559 $options.= "<option selected='selected' value='$key'>$value</option>";
560 } else {
561 $options.= "<option value='$key'>$value</option>";
562 }
563 }
565 /* Create listhead, it will be shown on top of the divlist.
566 * It provides general navigation and object creation
567 */
568 $faihead =
569 "<div style='background:#F0F0F9;padding:5px;'> ".
571 "<input class='center' type='image' src='images/list_up.png' align='middle'
572 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
574 "<input class='center' type='image' src='images/list_root.png' align='middle'
575 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
577 "<input class='center' type='image' src='images/list_home.png' align='middle'
578 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
580 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
582 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
583 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
585 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
587 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
588 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
590 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
591 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
593 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
594 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
596 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
597 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
599 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
600 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
602 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
603 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
605 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
607 _("Current base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
608 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
610 "</div>";
612 $this->reload();
614 /* Create list with objects */
615 $divlist = new divlist("faiManagement");
616 $divlist->SetEntriesPerPage(0);
617 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
619 $divlist->SetHeader(array(
620 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
621 array("string" => _("Name of FAI class"), "attach" => "style=''"),
622 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
623 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
626 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
627 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
629 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
630 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
632 foreach($this->departments as $key => $val) {
633 if(!isset($this->config->departments[trim($key)])){
634 $this->config->departments[trim($key)]="";
635 }
637 $non_empty="";
638 $keys= str_replace("/","\/",$key);
639 foreach($this->config->departments as $keyd=>$vald ){
640 if(preg_match("/".$keys."\/.*/",$keyd)){
641 $non_empty="full";
642 }
643 }
646 $title = $this->config->departments[$key];
647 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
648 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
649 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
650 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
652 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
654 }
656 /* Attach objects */
657 foreach($this->objects as $key => $value){
658 $info= "";
659 $img = "";
660 $type = $value['type'];
661 $abort=false;
663 switch($type) {
664 case "FAIpartitionTable" :
665 if(!$faifilter['ShowPartitions']){
666 $abort = true;
667 }
668 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
669 $info = _("Partition table");
670 break;
671 case "FAIpackageList" :
672 if(!$faifilter['ShowPackages']){
673 $abort = true;
674 }
675 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
676 $info = _("Package list");
677 break;
678 case "FAIscript" :
679 if(!$faifilter['ShowScripts']){
680 $abort = true;
681 }
682 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
683 $info = _("Scripts");
684 break;
685 case "FAIvariable" :
686 if(!$faifilter['ShowVariables']){
687 $abort = true;
688 }
689 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
690 $info = _("Variables");
691 break;
692 case "FAIhook" :
693 if(!$faifilter['ShowHooks']){
694 $abort = true;
695 }
696 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
697 $info = _("Hooks");
698 break;
699 case "FAIprofile" :
700 if(!$faifilter['ShowProfiles']){
701 $abort = true;
702 }
703 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
704 $info = _("Profile");
705 break;
706 case "FAItemplate" :
707 if(!$faifilter['ShowTemplates']){
708 $abort = true;
709 }
710 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
711 $info = _("Templates");
712 break;
713 default :
714 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
716 }
718 if(!$abort) {
719 if((isset($value['description']))&&(!empty($value['description']))){
720 $desc= " [".$value['description']."]";
721 }else{
722 $desc= "";
723 }
725 if($value['FAIstate'] == "freeze"){
726 $acti = "";
727 $edi = "%NAME%";
728 }else{
729 $acti = $action;
730 $edi = $editlink;
731 }
733 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
734 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
735 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
736 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
737 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
739 }
740 }
742 foreach($faifilter as $attrs => $value){
743 if($value){
744 $smarty->assign($attrs."CHK", " checked ");
745 }else{
746 $smarty->assign($attrs."CHK", " ");
747 }
748 }
750 /* Assign all reguired vars to template engine */
752 $smarty->assign("branchKeys",array_flip($this->getBranches()));
753 $smarty->assign("branches",$this->getBranches());
755 $smarty->assign("faihead" , $faihead);
756 $smarty->assign("failist" , $divlist->DrawList());
757 $smarty->assign("regex" , $faifilter['regex']);
758 $smarty->assign("infoimage" , get_template_path('images/info.png'));
759 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
760 $smarty->assign("alphabet" , generate_alphabet());
761 $smarty->assign("apply" , apply_filter());
762 $smarty->assign("search_image" , get_template_path('images/search.png'));
763 $smarty->assign("hint", print_sizelimit_warning());
765 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
766 return ($display);
767 }
769 function getBranches($base = false,$prefix = "")
770 {
771 $ret = array("main"=>_("main"));
772 $ldap = $this->config->get_ldap_link();
774 $ldap->cd($this->config->current['BASE']);
776 $faifilter = $_SESSION['faifilter'];
779 if(!$base){
780 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
781 }
782 $ldap->cd($base);
783 $ldap->ls("(objectClass=FAIbranch)",$base);
785 while($attrs = $ldap->fetch()){
787 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
788 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
789 $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix.$attrs['ou'][0]."/"));
790 }
791 }
792 return($ret);
793 }
795 function reload()
796 {
797 /* Create a new list of FAI object
798 * Object list depends on faifilter['regex']
799 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
800 */
801 $faifilter= get_global('faifilter');
802 // Added for dirlist function...
804 /* Set base for all searches */
805 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
807 if($faifilter['branch'] !="main"){
808 $base = $faifilter['branch'];
809 }
811 $regex = $faifilter['regex'];
813 /* Array to save objects */
814 $objects = array();
816 $this->objects=array();
818 /* NEW LIST MANAGMENT
819 * We also need to search for the departments
820 * So we are able to navigate like in konquerer
821 */
822 $base2 = $faifilter['base'];
824 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
825 TRUE, $base2, array("ou", "description"), TRUE);
827 $this->departments= array();
828 $tmp = array();
829 foreach ($res3 as $value){
830 $tmp[strtolower($value['dn']).$value['dn']]=$value;
831 }
832 ksort($tmp);
833 foreach($tmp as $value){
834 if(isset($value["description"][0])){
835 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
836 }else{
837 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
838 }
839 }
841 /* END NEW LIST MANAGMENT
842 */
845 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
846 FALSE, $base, array("cn","description","objectClass"),TRUE);
848 foreach($res as $objecttypes){
849 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
850 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
851 foreach($res2 as $object){
852 $type= "";
853 unset($object['objectClass']['count']);
854 if(!isset($object['description'][0])){
855 $object['description'][0]="";
856 }
858 /* Clean up object informations */
859 $obj['cn'] = $object['cn'][0];
860 $obj['dn'] = $object['dn'];
861 $obj['description'] = $object['description'][0];
862 $obj['objectClass'] = $object['objectClass'];
864 if(isset($object['FAIstate'])){
865 $obj['FAIstate'] = $object['FAIstate'][0];
866 }else{
867 $obj['FAIstate'] ="";
868 }
870 if(in_array("FAIpartitionTable",$obj['objectClass'])){
871 $type = "FAIpartitionTable";
872 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
873 $type = "FAIpackageList";
874 }elseif(in_array("FAIscript",$obj['objectClass'])){
875 $type = "FAIscript";
876 }elseif(in_array("FAIvariable",$obj['objectClass'])){
877 $type = "FAIvariable";
878 }elseif(in_array("FAIhook",$obj['objectClass'])){
879 $type = "FAIhook";
880 }elseif(in_array("FAIprofile",$obj['objectClass'])){
881 $obj['FAIclass'] = $object['FAIclass'][0];
882 $type = "FAIprofile";
883 }elseif(in_array("FAItemplate",$obj['objectClass'])){
884 $type = "FAItemplate";
885 }
886 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
887 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
889 }
890 }
891 ksort($this->objects);
892 reset ($this->objects);
894 /* use numeric index, thats a bit more secure */
895 $tmp0 = array();
896 foreach($this->objects as $obj){
897 $tmp0[]= $obj;
898 }
899 $this->objects = array();
900 $this->objects = $tmp0;
902 }
904 function remove_lock()
905 {
906 if (isset($this->dn)){
907 del_lock ($this->dn);
908 }
909 }
911 function get_type($array){
912 if(in_array("FAIpartitionTable",$array['objectClass'])){
913 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
914 }
915 if(in_array("FAIscript",$array['objectClass'])){
916 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
917 }
918 if(in_array("FAItemplate",$array['objectClass'])){
919 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
920 }
921 if(in_array("FAIhook",$array['objectClass'])){
922 return(array("tabsHook","faiHook","FAIHOOKTABS"));
923 }
924 if(in_array("FAIvariable",$array['objectClass'])){
925 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
926 }
927 if(in_array("FAIprofile",$array['objectClass'])){
928 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
929 }
931 if(in_array("FAIpackageList",$array['objectClass'])){
932 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
933 }
934 }
936 function CheckNewBranchName($name){
937 if(in_array($name,$this->getBranches())) {
938 return(false);
939 }
940 return(true);
941 }
943 }
944 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
945 ?>