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 */
20 require "tabsPartition.inc";
21 require "tabsVariable.inc";
22 require "tabsHook.inc";
23 require "tabsTemplate.inc";
24 require "tabsScript.inc";
25 require "tabsProfile.inc";
26 require "tabsPackage.inc";
28 class faiManagement extends plugin
29 {
30 /* Definitions */
31 var $plHeadline = "FAI";
32 var $plDescription = "Fully Automatic Installation - management";
34 /* CLI vars */
35 var $cli_summary = "Handling of FAI entries";
36 var $cli_description = "This plugin represents a management tool\n
37 which allows us to manage all needed attributes for fully automatic installations (FAI)";
38 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
40 /* Headpage attributes */
41 var $departments= array();
42 var $deptabs= NULL;
44 /* attribute list for save action */
45 var $attributes = array(); // Attributes Managed by this plugin, none,
46 // because this is only an overview over all objects already defined in FAI.
47 var $objectclasses = array(); // ObjectClasses which the attributes are related to
48 var $dialog = array(); // This object contains every dialog we have currently opened
50 var $objects = array(); // This array contains all available objects shown in divlist
51 var $is_dialog = false;
53 var $dispNewBranch= false;
54 var $dispNewFreeze= false;
56 /* construction/reconstruction
57 * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last
58 * selected department and filter options
59 * If it is not defined already we create a new fresh faifilter.
60 */
61 function faiManagement ($config, $ui)
62 {
63 $this->ui = $ui;
65 /* Set current dn to "", */
66 $this->dn = "";
68 /* Assign config */
69 $this->config = $config;
71 /* Get global filter config */
72 if (!is_global("faifilter")){
73 $base = get_base_from_people($ui->dn);
74 $faifilter= array("base" => $base,
75 "regex" => "*","branch" => "main");
76 $faifilter['ShowProfiles'] = true;
77 $faifilter['ShowTemplates'] = true;
78 $faifilter['ShowScripts'] = true;
79 $faifilter['ShowHooks'] = true;
80 $faifilter['ShowVariables'] = true;
81 $faifilter['ShowPackages'] = true;
82 $faifilter['ShowPartitions']=true;
83 register_global("faifilter", $faifilter);
84 }
85 }
87 function execute()
88 {
90 /* Call parent execute */
91 plugin::execute();
93 $display = "";
94 $smarty = get_smarty();
95 $s_action = "";
96 $s_entry = "";
97 /* filter management
98 * Filter will be changed if POST['regex'] or $_GET['search'] isset
99 * New Filter will be stored in session and is used to generate list contents
100 */
101 $faifilter = $_SESSION['faifilter'];
103 /* Filter is posted by apply button
104 * Check every single chkbox
105 */
106 if(isset($_POST['regex'])){
107 $faifilter['regex'] = $_POST['regex']."*";
108 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
109 if(isset($_POST[$attrs])){
110 $faifilter[$attrs] = true;
111 }else{
112 $faifilter[$attrs] = false;
113 }
114 }
115 }
117 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
118 $faifilter['branch'] = $_POST['select_branch'];
119 }
121 $smarty->assign("select_branch",$_SESSION['faifilter']['branch']);
123 /* Check ImageButton posts
124 * Create new tab ich new_xx is posted
125 */
126 foreach($_POST as $key => $val){
127 if(preg_match("/remove_branch/",$key)){
128 $s_action = "remove_branch";
129 }elseif(preg_match("/branch_branch/",$key)){
130 $s_action = "branch_branch";
131 }elseif(preg_match("/freeze_branch/",$key)){
132 $s_action = "freeze_branch";
133 }elseif(preg_match("/create_partition/i",$key)){
134 $s_action = "new_partition";
135 }elseif(preg_match("/create_script/i",$key)){
136 $s_action = "new_script";
137 }elseif(preg_match("/create_hook/i",$key)){
138 $s_action = "new_hook";
139 }elseif(preg_match("/create_variable/i",$key)){
140 $s_action = "new_variable";
141 }elseif(preg_match("/create_template/i",$key)){
142 $s_action = "new_template";
143 }elseif(preg_match("/create_package/i",$key)){
144 $s_action = "new_package";
145 }elseif(preg_match("/create_profile/i",$key)){
146 $s_action = "new_profile";
147 }elseif(preg_match("/edit_continue/",$key)){
148 $s_action = "select_class_name_finished";
149 }elseif(preg_match("/^entry_edit_.*/",$key)){
150 $s_entry = preg_replace("/^entry_edit_/","",$key);
151 $s_entry = preg_replace("/_.*$/","",$s_entry);
152 $s_action = "edit";
153 }elseif(preg_match("/^entry_delete_.*/",$key)){
154 $s_entry = preg_replace("/^entry_delete_/","",$key);
155 $s_entry = preg_replace("/_.*$/","",$s_entry);
156 $s_action = "delete";
157 }elseif(preg_match("/dep_back.*/i",$key)){
158 $s_action="back";
159 }elseif(preg_match("/dep_home.*/i",$key)){
160 $s_action="home";
161 }elseif(preg_match("/dep_root.*/i",$key)){
162 $s_action="root";
163 }
165 }
167 if($s_action=="root"){
168 $faifilter['base']=($this->config->current['BASE']);
169 }
171 if($s_action=="home"){
172 $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
173 $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
174 }
176 if($s_action=="back"){
177 $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']);
178 $base_back = convert_department_dn($base_back);
180 if(isset($this->config->departments[trim($base_back)])){
181 $faifilter['base']= $this->config->departments[trim($base_back)];
182 }else{
183 $faifilter['base']= $this->config->departments["/"];
184 }
185 }
187 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
188 $s_action="open";
189 $s_entry = base64_decode($_GET['dep_id']);
190 $faifilter['base']= $this->config->departments[trim($s_entry)];
191 }
193 if(isset($_GET['edit_entry'])){
194 $s_entry = $_GET['edit_entry'];
195 $s_action = "edit";
196 }
198 /* Confirm dialog
199 * Delte object
200 */
201 if ($s_action=="delete"){
203 /* Get 'dn' from posted termlinst */
204 $this->dn= $this->objects[$s_entry]['dn'];
206 /* Load permissions for selected 'dn' and check if
207 we're allowed to remove this 'dn' */
208 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
209 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
210 if (chkacl($this->acl, "delete") == ""){
212 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
213 if (($user= get_lock($this->dn)) != ""){
214 return(gen_locked_message ($user, $this->dn));
215 }
217 /* Lock the current entry, so nobody will edit it during deletion */
218 add_lock ($this->dn, $this->ui->dn);
219 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
220 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
221 } else {
223 /* Obviously the user isn't allowed to delete. Show message and
224 clean session. */
225 print_red (_("You are not allowed to delete this component!"));
226 }
227 }
229 /* Delete canceled? */
230 if (isset($_POST['delete_cancel'])){
231 del_lock ($this->dn);
232 }
235 /* Deltetion was confirmed, so delete this entry
236 */
237 if (isset($_POST['delete_terminal_confirm'])){
239 /* Some nice guy may send this as POST, so we've to check
240 for the permissions again. */
241 if (chkacl($this->acl, "delete") == ""){
243 /* Find out more about the object type */
244 $ldap = $this->config->get_ldap_link();
245 $ldap->cat($this->dn);
246 $attrs = $ldap->fetch();
248 $type = $this->get_type($attrs);
250 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
251 $this->dialog->set_acl(array($this->acl));
253 $this->dialog->by_object[$type[1]]->remove_from_parent ();
254 unset ($this->dialog);
255 gosa_log ("FAI class '".$this->dn."' has been removed");
256 $this->dialog= NULL;
258 /* Terminal list has changed, reload it. */
259 $this->reload ();
260 } else {
262 /* Normally this shouldn't be reached, send some extra
263 logs to notify the administrator */
264 print_red (_("You are not allowed to delete this component!"));
265 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
266 "deletion.");
267 }
269 /* Remove lock file after successfull deletion */
270 del_lock ($this->dn);
271 }
273 /* Edit Entry */
274 if($s_action == "edit"){
275 $entry = $this->objects[$s_entry];
277 $a_setup = ($this->get_type($entry));
279 $this->dn = $entry['dn'];
280 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
281 if (($user= get_lock($this->dn)) != ""){
282 return(gen_locked_message ($user, $this->dn));
283 }
284 add_lock ($this->dn, $this->ui->dn);
286 $this->dialog= new $a_setup[0]($this->config,
287 $this->config->data['TABS'][$a_setup[2]],$this->dn);
288 $this->is_dialog = true;
289 $_SESSION['objectinfo'] = $this->dn;
290 }
293 /* Branch handling
294 09.01.2006
295 */
297 /* Create new branch */
298 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
300 /* Check branch name */
301 $name = $_POST['BranchName'];
302 $is_ok = true;
304 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
306 /* Check used characters */
307 if(preg_match("/[^0-9a-z]/i",$name)){
308 print_red(_("Specified branch name is invalid."));
309 $is_ok = false;
310 }
312 /* Check if this name is already in use */
313 if(!$this->CheckNewBranchName($_POST['BranchName'])){
314 print_red(_("This name is already in use."));
315 $this->is_ok = false;
316 }
318 if($is_ok){
319 /* Create it know */
320 $ldap = $this->config->get_ldap_link();
322 $ldap->cd ("ou=".$name.",".$base);
323 $ldap->recursive_remove();
325 $ldap->cd ($this->config->current['BASE']);
326 $ldap->copy_FAI_resource_recursive($base,"ou=".$name.",".$base,"branch",true);
328 $this->dispNewBranch = false;
329 }
330 }
332 /* Abort creating new branch */
333 if(isset($_POST['CancelBranchName'])){
334 $this->dispNewBranch = false;
335 }
337 /* Open dialog to insert new branch name */
338 if(($s_action == "branch_branch")||($this->dispNewBranch)){
339 $this->dispNewBranch=true;
340 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
341 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
342 return($display);
343 }
345 /* Remove branch */
346 if($s_action == "remove_branch"){
347 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
348 /* Load permissions for selected 'dn' and check if
349 we're allowed to remove this 'dn' */
350 $acl= get_permissions ($base, $this->ui->subtreeACL);
351 $this->acl= get_module_permission($acl, "fai", $base);
352 if (chkacl($this->acl, "delete") == ""){
353 $smarty->assign("warning", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $base));
354 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
355 } else {
356 print_red (_("You are not allowed to delete this user!"));
357 }
358 }
360 /* Delete this entry */
361 if(isset($_POST['delete_branch_confirm'])){
362 print "branch removed ";
363 }
365 if($s_action == "freeze_branch"){
366 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
367 $ldap = $this->config->get_ldap_link();
368 $ldap->cd ($base);
370 $attrs = $ldap->fetch($ldap->cat ($base));
372 if(!in_array("FAIbranch",$attrs)){
373 $attrs['objectClass'][] = "FAIbranch";
374 }
376 if((!isset($attrs['FAIstate']))||($attrs['FAIstate'] != "frozen")){
377 $attrs['FAIstate']= "frozen";
378 }
380 print "Freeze ";
386 }
388 /* ENDE Branch handling
389 */
391 /* Dialog handling */
392 if($s_action == "new_partition"){
393 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
394 }
396 /* Dialog handling */
397 if($s_action == "new_script"){
398 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
399 }
401 /* Dialog handling */
402 if($s_action == "new_hook"){
403 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
404 }
406 /* Dialog handling */
407 if($s_action == "new_variable"){
408 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
409 }
411 /* Dialog handling */
412 if($s_action == "new_template"){
413 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
414 }
416 /* Dialog handling */
417 if($s_action == "new_package"){
418 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
419 }
421 /* New Profile */
422 if($s_action == "new_profile"){
423 $this->dn = "new" ;
424 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
426 $this->dialog = new $a_setup[0]($this->config,
427 $this->config->data['TABS'][$a_setup[2]],$this->dn);
428 $this->is_dialog = true;
430 }
432 if($s_action == "select_class_name_finished"){
433 $this->dialog->save_object();
434 if(count($this->dialog->check())!=0){
435 foreach($this->dialog->check() as $msg){
436 print_red($msg);
437 }
438 }else{
439 $this->dn = "new" ;
440 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
441 $name = $this->dialog->save();
443 $this->dialog = new $a_setup[0]($this->config,
444 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
445 $this->dialog->by_object[$a_setup[1]]->cn = $name;
446 $this->is_dialog = true;
447 }
448 }
451 /* Search is set */
452 if(isset($_GET['search'])){
453 $faifilter['regex']=$_GET['search']."*";
454 }
456 /* Department select */
457 if((isset($_POST['base']))&&($s_action=="")){
458 $faifilter['base']=$_POST['base'];
459 }
461 /* remove double asterisks and save new filter */
462 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
463 $_SESSION['faifilter']= $faifilter;
465 /* Edit dialog was canceled
466 * Remove dialog an show management dialog
467 */
468 if(isset($_POST['edit_cancel'])){
469 unset($this->dialog);
470 $this->dialog=NULL;
471 $this->is_dialog = false;
472 unset($_SESSION['objectinfo']);
473 del_lock ($this->dn);
474 }
476 /* This check if the given tab could be saved
477 * If it was possible to save it, remove dialog object.
478 * If it wasn't possible, show errors and keep dialog.
479 */
480 if(isset($_POST['edit_finish'])){
481 $this->dialog->save_object();
482 if(count($this->dialog->check())!=0){
483 foreach($this->dialog->check() as $msg){
484 print_red($msg);
485 }
486 }else{
487 del_lock ($this->dn);
488 $this->dialog->save();
489 unset($this->dialog);
490 $this->dialog=NULL;
491 $this->is_dialog=false;
492 unset($_SESSION['objectinfo']);
493 }
494 }
496 /* If dialog is set, but $this->is_dialog==false, then
497 * only the "abort" button is shown, this are dialogs that must not be saved.
498 * If is_dialog == true, we are currently editing tab objects.
499 * Here we need both, save and cancel
500 */
502 if($this->dialog != NULL){
503 $display .= $this->dialog->execute();
504 /* Don't show buttons if tab dialog requests this */
505 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
507 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
508 $display.= "<p style=\"text-align:right\">\n";
509 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
510 $display.= " \n";
511 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
512 $display.= "</p>";
513 }elseif(!isset($this->dialog->current)){
514 $display.= "<p style=\"text-align:right\">\n";
515 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
516 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
517 $display.= "</p>";
518 }
519 return($display);
520 }
522 /* Show Management template
523 * The following code will only be reached if no dialog (tabs or dialogs)
524 * are currently opened.
525 * Assign all reguired vars to template engine
526 */
528 /* Prepare departments */
529 $options= "";
530 foreach ($this->config->idepartments as $key => $value){
531 if ($faifilter['base'] == $key){
532 $options.= "<option selected='selected' value='$key'>$value</option>";
533 } else {
534 $options.= "<option value='$key'>$value</option>";
535 }
536 }
538 /* Create listhead, it will be shown on top of the divlist.
539 * It provides general navigation and object creation
540 */
541 $faihead =
542 "<div style='background:#F0F0F9;padding:5px;'> ".
544 "<input class='center' type='image' src='images/list_up.png' align='middle'
545 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
547 "<input class='center' type='image' src='images/list_root.png' align='middle'
548 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
550 "<input class='center' type='image' src='images/list_home.png' align='middle'
551 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
553 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
555 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
556 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
558 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
560 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
561 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
563 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
564 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
566 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
567 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
569 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
570 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
572 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
573 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
575 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
576 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
578 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
580 _("Current base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
581 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
583 "</div>";
585 $this->reload();
587 /* Create list with objects */
588 $divlist = new divlist("faiManagement");
589 $divlist->SetEntriesPerPage(0);
590 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
592 $divlist->SetHeader(array(
593 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
594 array("string" => _("Name of FAI class"), "attach" => "style=''"),
595 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
596 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
599 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
600 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
602 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
603 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
605 foreach($this->departments as $key => $val) {
606 if(!isset($this->config->departments[trim($key)])){
607 $this->config->departments[trim($key)]="";
608 }
610 $non_empty="";
611 $keys= str_replace("/","\/",$key);
612 foreach($this->config->departments as $keyd=>$vald ){
613 if(preg_match("/".$keys."\/.*/",$keyd)){
614 $non_empty="full";
615 }
616 }
619 $title = $this->config->departments[$key];
620 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
621 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
622 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
623 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
625 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
627 }
629 /* Attach objects */
630 foreach($this->objects as $key => $value){
631 $info= "";
632 $img = "";
633 $type = $value['type'];
634 $abort=false;
636 switch($type) {
637 case "FAIpartitionTable" :
638 if(!$faifilter['ShowPartitions']){
639 $abort = true;
640 }
641 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
642 $info = _("Partition table");
643 break;
644 case "FAIpackageList" :
645 if(!$faifilter['ShowPackages']){
646 $abort = true;
647 }
648 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
649 $info = _("Package list");
650 break;
651 case "FAIscript" :
652 if(!$faifilter['ShowScripts']){
653 $abort = true;
654 }
655 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
656 $info = _("Scripts");
657 break;
658 case "FAIvariable" :
659 if(!$faifilter['ShowVariables']){
660 $abort = true;
661 }
662 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
663 $info = _("Variables");
664 break;
665 case "FAIhook" :
666 if(!$faifilter['ShowHooks']){
667 $abort = true;
668 }
669 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
670 $info = _("Hooks");
671 break;
672 case "FAIprofile" :
673 if(!$faifilter['ShowProfiles']){
674 $abort = true;
675 }
676 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
677 $info = _("Profile");
678 break;
679 case "FAItemplate" :
680 if(!$faifilter['ShowTemplates']){
681 $abort = true;
682 }
683 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
684 $info = _("Templates");
685 break;
686 default :
687 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
689 }
691 if(!$abort) {
692 if((isset($value['description']))&&(!empty($value['description']))){
693 $desc= " [".$value['description']."]";
694 }else{
695 $desc= "";
696 }
698 if($value['FAIstate'] == "branch"){
699 $acti = "";
700 }else{
701 $acti = $action;
702 }
704 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
705 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$editlink) , "attach" => "style=''");
706 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
707 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
708 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
710 }
711 }
713 foreach($faifilter as $attrs => $value){
714 if($value){
715 $smarty->assign($attrs."CHK", " checked ");
716 }else{
717 $smarty->assign($attrs."CHK", " ");
718 }
719 }
721 /* Assign all reguired vars to template engine */
723 $smarty->assign("branchKeys",array_flip($this->getBranches()));
724 $smarty->assign("branches",$this->getBranches());
726 $smarty->assign("faihead" , $faihead);
727 $smarty->assign("failist" , $divlist->DrawList());
728 $smarty->assign("regex" , $faifilter['regex']);
729 $smarty->assign("infoimage" , get_template_path('images/info.png'));
730 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
731 $smarty->assign("alphabet" , generate_alphabet());
732 $smarty->assign("apply" , apply_filter());
733 $smarty->assign("search_image" , get_template_path('images/search.png'));
734 $smarty->assign("hint", print_sizelimit_warning());
736 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
737 return ($display);
738 }
740 function getBranches()
741 {
742 $ret = array("main"=>_("main"));
743 $ldap = $this->config->get_ldap_link();
745 $ldap->cd($this->config->current['BASE']);
747 $faifilter = $_SESSION['faifilter'];
748 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
749 $ldap->cd($base);
750 $ldap->search("(objectClass=FAIbranch)",array("*"));
752 while($attrs = $ldap->fetch()){
753 if(isset($attrs['ou'])){
754 $ou = $attrs['ou'][0];
755 $ret[$ou]=$ou;
756 }
757 }
758 return($ret);
759 }
761 function reload()
762 {
763 /* Create a new list of FAI object
764 * Object list depends on faifilter['regex']
765 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
766 */
767 $faifilter= get_global('faifilter');
768 // Added for dirlist function...
770 /* Set base for all searches */
771 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
773 if($faifilter['branch'] !="main"){
774 $base = "ou=".$faifilter['branch'].",".$base;
775 }
777 $regex = $faifilter['regex'];
779 /* Array to save objects */
780 $objects = array();
782 $this->objects=array();
784 /* NEW LIST MANAGMENT
785 * We also need to search for the departments
786 * So we are able to navigate like in konquerer
787 */
788 $base2 = $faifilter['base'];
790 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
791 TRUE, $base2, array("ou", "description"), TRUE);
793 $this->departments= array();
794 $tmp = array();
795 foreach ($res3 as $value){
796 $tmp[strtolower($value['dn']).$value['dn']]=$value;
797 }
798 ksort($tmp);
799 foreach($tmp as $value){
800 if(isset($value["description"][0])){
801 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
802 }else{
803 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
804 }
805 }
807 /* END NEW LIST MANAGMENT
808 */
811 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
812 FALSE, $base, array("cn","description","objectClass"),TRUE);
814 foreach($res as $objecttypes){
815 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
816 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
817 foreach($res2 as $object){
818 $type= "";
819 unset($object['objectClass']['count']);
820 if(!isset($object['description'][0])){
821 $object['description'][0]="";
822 }
824 /* Clean up object informations */
825 $obj['cn'] = $object['cn'][0];
826 $obj['dn'] = $object['dn'];
827 $obj['description'] = $object['description'][0];
828 $obj['objectClass'] = $object['objectClass'];
830 if(isset($object['FAIstate'])){
831 $obj['FAIstate'] = $object['FAIstate'][0];
832 }else{
833 $obj['FAIstate'] ="";
834 }
836 if(in_array("FAIpartitionTable",$obj['objectClass'])){
837 $type = "FAIpartitionTable";
838 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
839 $type = "FAIpackageList";
840 }elseif(in_array("FAIscript",$obj['objectClass'])){
841 $type = "FAIscript";
842 }elseif(in_array("FAIvariable",$obj['objectClass'])){
843 $type = "FAIvariable";
844 }elseif(in_array("FAIhook",$obj['objectClass'])){
845 $type = "FAIhook";
846 }elseif(in_array("FAIprofile",$obj['objectClass'])){
847 $obj['FAIclass'] = $object['FAIclass'][0];
848 $type = "FAIprofile";
849 }elseif(in_array("FAItemplate",$obj['objectClass'])){
850 $type = "FAItemplate";
851 }
852 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
853 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
855 }
856 }
857 ksort($this->objects);
858 reset ($this->objects);
860 /* use numeric index, thats a bit more secure */
861 $tmp0 = array();
862 foreach($this->objects as $obj){
863 $tmp0[]= $obj;
864 }
865 $this->objects = array();
866 $this->objects = $tmp0;
868 }
870 function remove_lock()
871 {
872 if (isset($this->dn)){
873 del_lock ($this->dn);
874 }
875 }
877 function get_type($array){
878 if(in_array("FAIpartitionTable",$array['objectClass'])){
879 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
880 }
881 if(in_array("FAIscript",$array['objectClass'])){
882 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
883 }
884 if(in_array("FAItemplate",$array['objectClass'])){
885 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
886 }
887 if(in_array("FAIhook",$array['objectClass'])){
888 return(array("tabsHook","faiHook","FAIHOOKTABS"));
889 }
890 if(in_array("FAIvariable",$array['objectClass'])){
891 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
892 }
893 if(in_array("FAIprofile",$array['objectClass'])){
894 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
895 }
897 if(in_array("FAIpackageList",$array['objectClass'])){
898 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
899 }
900 }
902 function checknewbranchname($name){
904 return(true);
905 }
907 }
908 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
909 ?>