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 $smarty->assign("BranchName","");
97 $s_action = "";
98 $s_entry = "";
99 /* filter management
100 * Filter will be changed if POST['regex'] or $_GET['search'] isset
101 * New Filter will be stored in session and is used to generate list contents
102 */
103 $faifilter = $_SESSION['faifilter'];
105 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
106 $faifilter['branch'] = $_POST['select_branch'];
107 }
109 /* Filter is posted by apply button
110 * Check every single chkbox
111 */
112 if(isset($_POST['regex'])){
113 $faifilter['regex'] = $_POST['regex']."*";
114 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
115 if(isset($_POST[$attrs])){
116 $faifilter[$attrs] = true;
117 }else{
118 $faifilter[$attrs] = false;
119 }
120 }
121 }
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 $faifilter['branch'] = "main";
160 $s_action="back";
161 }elseif(preg_match("/dep_home.*/i",$key)){
162 $faifilter['branch'] = "main";
163 $s_action="home";
164 }elseif(preg_match("/dep_root.*/i",$key)){
165 $faifilter['branch'] = "main";
166 $s_action="root";
167 }
169 }
171 if($s_action=="root"){
172 $faifilter['base']=($this->config->current['BASE']);
173 }
175 if($s_action=="home"){
176 $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
177 $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
178 }
180 if($s_action=="back"){
181 $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']);
182 $base_back = convert_department_dn($base_back);
184 if(isset($this->config->departments[trim($base_back)])){
185 $faifilter['base']= $this->config->departments[trim($base_back)];
186 }else{
187 $faifilter['base']= $this->config->departments["/"];
188 }
189 }
191 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
192 $s_action="open";
193 $s_entry = base64_decode($_GET['dep_id']);
194 $faifilter['base']= $this->config->departments[trim($s_entry)];
195 }
197 if(isset($_GET['edit_entry'])){
198 $s_entry = $_GET['edit_entry'];
199 $s_action = "edit";
200 }
202 /* Confirm dialog
203 * Delte object
204 */
205 if ($s_action=="delete"){
207 /* Get 'dn' from posted termlinst */
208 $this->dn= $this->objects[$s_entry]['dn'];
210 /* Load permissions for selected 'dn' and check if
211 we're allowed to remove this 'dn' */
212 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
213 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
214 if (chkacl($this->acl, "delete") == ""){
216 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
217 if (($user= get_lock($this->dn)) != ""){
218 return(gen_locked_message ($user, $this->dn));
219 }
221 /* Lock the current entry, so nobody will edit it during deletion */
222 add_lock ($this->dn, $this->ui->dn);
223 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
224 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
225 } else {
227 /* Obviously the user isn't allowed to delete. Show message and
228 clean session. */
229 print_red (_("You are not allowed to delete this component!"));
230 }
231 }
233 /* Delete canceled? */
234 if (isset($_POST['delete_cancel'])){
235 del_lock ($this->dn);
236 }
239 /* Deltetion was confirmed, so delete this entry
240 */
241 if (isset($_POST['delete_terminal_confirm'])){
243 /* Some nice guy may send this as POST, so we've to check
244 for the permissions again. */
245 if (chkacl($this->acl, "delete") == ""){
247 /* Find out more about the object type */
248 $ldap = $this->config->get_ldap_link();
249 $ldap->cat($this->dn);
250 $attrs = $ldap->fetch();
252 $type = $this->get_type($attrs);
254 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
255 $this->dialog->set_acl(array($this->acl));
257 $this->dialog->by_object[$type[1]]->remove_from_parent ();
258 unset ($this->dialog);
259 gosa_log ("FAI class '".$this->dn."' has been removed");
260 $this->dialog= NULL;
262 /* Terminal list has changed, reload it. */
263 $this->reload ();
264 } else {
266 /* Normally this shouldn't be reached, send some extra
267 logs to notify the administrator */
268 print_red (_("You are not allowed to delete this component!"));
269 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
270 "deletion.");
271 }
273 /* Remove lock file after successfull deletion */
274 del_lock ($this->dn);
275 }
277 /* Edit Entry */
278 if($s_action == "edit"){
279 $entry = $this->objects[$s_entry];
281 $a_setup = ($this->get_type($entry));
283 $this->dn = $entry['dn'];
284 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
285 if (($user= get_lock($this->dn)) != ""){
286 return(gen_locked_message ($user, $this->dn));
287 }
288 add_lock ($this->dn, $this->ui->dn);
290 $this->dialog= new $a_setup[0]($this->config,
291 $this->config->data['TABS'][$a_setup[2]],$this->dn);
292 $this->is_dialog = true;
293 $_SESSION['objectinfo'] = $this->dn;
294 }
297 /* Branch handling
298 09.01.2006
299 */
301 /* Create new branch */
302 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
304 /* Check branch name */
305 $name = $_POST['BranchName'];
306 $is_ok = true;
308 $smarty->assign("BranchName",$name);
309 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
311 /* Check used characters */
312 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
313 print_red(_("Specified branch name is invalid."));
314 $is_ok = false;
315 }
317 /* Check if this name is already in use */
318 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
319 print_red(_("This name is already in use."));
320 $is_ok = false;
321 }
323 if($is_ok){
324 /* Create it know */
325 $ldap = $this->config->get_ldap_link();
327 $baseToUse = $base;
328 if($_SESSION['faifilter']['branch']!="main"){
329 $baseToUse = $_SESSION['faifilter']['branch'];
330 }
332 $ldap->cd ("ou=".$name.",".$baseToUse);
333 $ldap->recursive_remove();
335 $ldap->cd ($this->config->current['BASE']);
336 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
338 $this->dispNewBranch = false;
339 }
340 }
342 /* Abort creating new branch */
343 if(isset($_POST['CancelBranchName'])){
344 $this->dispNewBranch = false;
345 $this->dispNewFreeze = false;
346 }
348 /* Open dialog to insert new branch name */
349 if(($s_action == "branch_branch")||($this->dispNewBranch)){
350 $this->dispNewBranch=true;
351 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
352 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
353 return($display);
354 }
356 /* Remove branch */
357 if($s_action == "remove_branch"){
358 $base= $faifilter['branch'];
359 /* Load permissions for selected 'dn' and check if
360 we're allowed to remove this 'dn' */
361 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
362 $this->acl= get_module_permission($acl, "fai", $base);
363 if (chkacl($this->acl, "delete") == ""){
364 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
365 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
366 } else {
367 print_red (_("You are not allowed to delete this user!"));
368 }
369 }
371 /* Delete this entry */
372 if(isset($_POST['delete_branch_confirm'])){
373 $bb = $faifilter['branch'];
374 if(!isset($ldap)){
375 $ldap = $this->config->get_ldap_link();
376 }
378 $br = $this->getBranches();
380 if(isset($br[$bb])){
381 $ldap->cd($bb);
382 $ldap->recursive_remove();
383 $faifilter['branch'] = "main";
384 }
385 }
388 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
389 /* Check branch name */
390 $name = $_POST['BranchName'];
391 $is_ok = true;
393 $smarty->assign("BranchName",$name);
395 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
397 /* Check used characters */
398 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
399 print_red(_("Specified branch name is invalid."));
400 $is_ok = false;
401 }
403 /* Check if this name is already in use */
404 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
405 print_red(_("This name is already in use."));
406 $is_ok = false;
407 }
409 if($is_ok){
410 /* Create it know */
411 $ldap = $this->config->get_ldap_link();
413 $baseToUse = $base;
414 if($_SESSION['faifilter']['branch']!="main"){
415 $baseToUse = $_SESSION['faifilter']['branch'];
416 }
418 $ldap->cd ("ou=".$name.",".$baseToUse);
419 $ldap->recursive_remove();
421 $ldap->cd ($this->config->current['BASE']);
422 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
424 $this->dispNewFreeze = false;
425 }
426 }
428 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
429 $this->dispNewFreeze = true;
430 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
431 return($display);
432 }
434 /* ENDE Branch handling
435 */
437 /* Dialog handling */
438 if($s_action == "new_partition"){
439 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
440 }
442 /* Dialog handling */
443 if($s_action == "new_script"){
444 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
445 }
447 /* Dialog handling */
448 if($s_action == "new_hook"){
449 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
450 }
452 /* Dialog handling */
453 if($s_action == "new_variable"){
454 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
455 }
457 /* Dialog handling */
458 if($s_action == "new_template"){
459 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
460 }
462 /* Dialog handling */
463 if($s_action == "new_package"){
464 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
465 }
467 /* New Profile */
468 if($s_action == "new_profile"){
469 $this->dn = "new" ;
470 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
472 $this->dialog = new $a_setup[0]($this->config,
473 $this->config->data['TABS'][$a_setup[2]],$this->dn);
474 $this->is_dialog = true;
476 }
478 if($s_action == "select_class_name_finished"){
479 $this->dialog->save_object();
480 if(count($this->dialog->check())!=0){
481 foreach($this->dialog->check() as $msg){
482 print_red($msg);
483 }
484 }else{
485 $this->dn = "new" ;
486 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
487 $name = $this->dialog->save();
489 $this->dialog = new $a_setup[0]($this->config,
490 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
491 $this->dialog->by_object[$a_setup[1]]->cn = $name;
492 $this->is_dialog = true;
493 }
494 }
496 /* Search is set */
497 if(isset($_GET['search'])){
498 $faifilter['regex']=$_GET['search']."*";
499 }
501 /* Department select */
502 if((isset($_POST['base']))&&($s_action=="")){
503 $faifilter['base']=$_POST['base'];
504 }
507 $br = $this->getBranches();
508 if(!isset($br[$faifilter['branch']])){
509 $faifilter['branch'] = "main";
510 }
512 $smarty->assign("select_branch",$faifilter['branch']);
514 /* remove double asterisks and save new filter */
515 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
516 $_SESSION['faifilter']= $faifilter;
518 /* Edit dialog was canceled
519 * Remove dialog an show management dialog
520 */
521 if(isset($_POST['edit_cancel'])){
522 unset($this->dialog);
523 $this->dialog=NULL;
524 $this->is_dialog = false;
525 unset($_SESSION['objectinfo']);
526 del_lock ($this->dn);
527 }
529 /* This check if the given tab could be saved
530 * If it was possible to save it, remove dialog object.
531 * If it wasn't possible, show errors and keep dialog.
532 */
533 if(isset($_POST['edit_finish'])){
534 $this->dialog->save_object();
535 if(count($this->dialog->check())!=0){
536 foreach($this->dialog->check() as $msg){
537 print_red($msg);
538 }
539 }else{
540 del_lock ($this->dn);
541 $this->dialog->save();
542 unset($this->dialog);
543 $this->dialog=NULL;
544 $this->is_dialog=false;
545 unset($_SESSION['objectinfo']);
546 }
547 }
549 /* If dialog is set, but $this->is_dialog==false, then
550 * only the "abort" button is shown, this are dialogs that must not be saved.
551 * If is_dialog == true, we are currently editing tab objects.
552 * Here we need both, save and cancel
553 */
555 if($this->dialog != NULL){
556 $display .= $this->dialog->execute();
557 /* Don't show buttons if tab dialog requests this */
558 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
560 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
561 $display.= "<p style=\"text-align:right\">\n";
562 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
563 $display.= " \n";
564 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
565 $display.= "</p>";
566 }elseif(!isset($this->dialog->current)){
567 $display.= "<p style=\"text-align:right\">\n";
568 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
569 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
570 $display.= "</p>";
571 }
572 return($display);
573 }
575 /* Show Management template
576 * The following code will only be reached if no dialog (tabs or dialogs)
577 * are currently opened.
578 * Assign all reguired vars to template engine
579 */
581 /* Prepare departments */
582 $options= "";
583 foreach ($this->config->idepartments as $key => $value){
584 if ($faifilter['base'] == $key){
585 $options.= "<option selected='selected' value='$key'>$value</option>";
586 } else {
587 $options.= "<option value='$key'>$value</option>";
588 }
589 }
591 /* Create listhead, it will be shown on top of the divlist.
592 * It provides general navigation and object creation
593 */
594 $faihead =
595 "<div style='background:#F0F0F9;padding:5px;'> ".
597 "<input class='center' type='image' src='images/list_up.png' align='middle'
598 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
600 "<input class='center' type='image' src='images/list_root.png' align='middle'
601 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
603 "<input class='center' type='image' src='images/list_home.png' align='middle'
604 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
606 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
608 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
609 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
611 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
613 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
614 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
616 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
617 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
619 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
620 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
622 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
623 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
625 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
626 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
628 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
629 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
631 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
633 _("Current base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
634 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
636 "</div>";
638 $this->reload();
640 /* Create list with objects */
641 $divlist = new divlist("faiManagement");
642 $divlist->SetEntriesPerPage(0);
643 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
645 $divlist->SetHeader(array(
646 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
647 array("string" => _("Name of FAI class"), "attach" => "style=''"),
648 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
649 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
652 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
653 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
655 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
656 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
658 foreach($this->departments as $key => $val) {
659 if(!isset($this->config->departments[trim($key)])){
660 $this->config->departments[trim($key)]="";
661 }
663 $non_empty="";
664 $keys= str_replace("/","\/",$key);
665 foreach($this->config->departments as $keyd=>$vald ){
666 if(preg_match("/".$keys."\/.*/",$keyd)){
667 $non_empty="full";
668 }
669 }
672 $title = $this->config->departments[$key];
673 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
674 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
675 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
676 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
678 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
680 }
682 /* Attach objects */
683 foreach($this->objects as $key => $value){
684 $info= "";
685 $img = "";
686 $type = $value['type'];
687 $abort=false;
689 switch($type) {
690 case "FAIpartitionTable" :
691 if(!$faifilter['ShowPartitions']){
692 $abort = true;
693 }
694 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
695 $info = _("Partition table");
696 break;
697 case "FAIpackageList" :
698 if(!$faifilter['ShowPackages']){
699 $abort = true;
700 }
701 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
702 $info = _("Package list");
703 break;
704 case "FAIscript" :
705 if(!$faifilter['ShowScripts']){
706 $abort = true;
707 }
708 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
709 $info = _("Scripts");
710 break;
711 case "FAIvariable" :
712 if(!$faifilter['ShowVariables']){
713 $abort = true;
714 }
715 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
716 $info = _("Variables");
717 break;
718 case "FAIhook" :
719 if(!$faifilter['ShowHooks']){
720 $abort = true;
721 }
722 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
723 $info = _("Hooks");
724 break;
725 case "FAIprofile" :
726 if(!$faifilter['ShowProfiles']){
727 $abort = true;
728 }
729 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
730 $info = _("Profile");
731 break;
732 case "FAItemplate" :
733 if(!$faifilter['ShowTemplates']){
734 $abort = true;
735 }
736 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
737 $info = _("Templates");
738 break;
739 default :
740 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
742 }
744 if(!$abort) {
745 if((isset($value['description']))&&(!empty($value['description']))){
746 $desc= " [".$value['description']."]";
747 }else{
748 $desc= "";
749 }
751 if($value['FAIstate'] == "freeze"){
752 $acti = "";
753 $edi = "%NAME%";
754 }else{
755 $acti = $action;
756 $edi = $editlink;
757 }
759 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
760 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
761 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
762 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
763 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
765 }
766 }
768 foreach($faifilter as $attrs => $value){
769 if($value){
770 $smarty->assign($attrs."CHK", " checked ");
771 }else{
772 $smarty->assign($attrs."CHK", " ");
773 }
774 }
776 /* Assign all reguired vars to template engine */
778 $smarty->assign("branchKeys",array_flip($this->getBranches()));
779 $smarty->assign("branches",$this->getBranches());
781 $smarty->assign("faihead" , $faihead);
782 $smarty->assign("failist" , $divlist->DrawList());
783 $smarty->assign("regex" , $faifilter['regex']);
784 $smarty->assign("infoimage" , get_template_path('images/info.png'));
785 $smarty->assign("branchimage" , get_template_path('images/action.png'));
786 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
787 $smarty->assign("alphabet" , generate_alphabet());
788 $smarty->assign("apply" , apply_filter());
789 $smarty->assign("search_image" , get_template_path('images/search.png'));
790 $smarty->assign("hint", print_sizelimit_warning());
792 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
793 return ($display);
794 }
796 function getBranches($base = false,$prefix = "")
797 {
798 $ret = array("main"=>_("main"));
799 $ldap = $this->config->get_ldap_link();
801 $ldap->cd($this->config->current['BASE']);
803 $faifilter = $_SESSION['faifilter'];
806 if(!$base){
807 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
808 }
809 $ldap->cd($base);
810 $ldap->ls("(objectClass=FAIbranch)",$base);
812 while($attrs = $ldap->fetch()){
814 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
815 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
816 $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix.$attrs['ou'][0]."/"));
817 }
818 }
819 return($ret);
820 }
822 function reload()
823 {
824 /* Create a new list of FAI object
825 * Object list depends on faifilter['regex']
826 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
827 */
828 $faifilter= get_global('faifilter');
829 // Added for dirlist function...
831 /* Set base for all searches */
832 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
834 if($faifilter['branch'] !="main"){
835 $base = $faifilter['branch'];
836 }
838 $regex = $faifilter['regex'];
840 /* Array to save objects */
841 $objects = array();
843 $this->objects=array();
845 /* NEW LIST MANAGMENT
846 * We also need to search for the departments
847 * So we are able to navigate like in konquerer
848 */
849 $base2 = $faifilter['base'];
851 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
852 TRUE, $base2, array("ou", "description"), TRUE);
854 $this->departments= array();
855 $tmp = array();
856 foreach ($res3 as $value){
857 $tmp[strtolower($value['dn']).$value['dn']]=$value;
858 }
859 ksort($tmp);
860 foreach($tmp as $value){
861 if(isset($value["description"][0])){
862 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
863 }else{
864 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
865 }
866 }
868 /* END NEW LIST MANAGMENT
869 */
872 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
873 FALSE, $base, array("cn","description","objectClass"),TRUE);
875 foreach($res as $objecttypes){
876 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
877 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
878 foreach($res2 as $object){
879 $type= "";
880 unset($object['objectClass']['count']);
881 if(!isset($object['description'][0])){
882 $object['description'][0]="";
883 }
885 /* Clean up object informations */
886 $obj['cn'] = $object['cn'][0];
887 $obj['dn'] = $object['dn'];
888 $obj['description'] = $object['description'][0];
889 $obj['objectClass'] = $object['objectClass'];
891 if(isset($object['FAIstate'])){
892 $obj['FAIstate'] = $object['FAIstate'][0];
893 }else{
894 $obj['FAIstate'] ="";
895 }
897 if(in_array("FAIpartitionTable",$obj['objectClass'])){
898 $type = "FAIpartitionTable";
899 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
900 $type = "FAIpackageList";
901 }elseif(in_array("FAIscript",$obj['objectClass'])){
902 $type = "FAIscript";
903 }elseif(in_array("FAIvariable",$obj['objectClass'])){
904 $type = "FAIvariable";
905 }elseif(in_array("FAIhook",$obj['objectClass'])){
906 $type = "FAIhook";
907 }elseif(in_array("FAIprofile",$obj['objectClass'])){
908 $obj['FAIclass'] = $object['FAIclass'][0];
909 $type = "FAIprofile";
910 }elseif(in_array("FAItemplate",$obj['objectClass'])){
911 $type = "FAItemplate";
912 }
913 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
914 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
916 }
917 }
918 ksort($this->objects);
919 reset ($this->objects);
921 /* use numeric index, thats a bit more secure */
922 $tmp0 = array();
923 foreach($this->objects as $obj){
924 $tmp0[]= $obj;
925 }
926 $this->objects = array();
927 $this->objects = $tmp0;
929 }
931 function remove_lock()
932 {
933 if (isset($this->dn)){
934 del_lock ($this->dn);
935 }
936 }
938 function get_type($array){
939 if(in_array("FAIpartitionTable",$array['objectClass'])){
940 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
941 }
942 if(in_array("FAIscript",$array['objectClass'])){
943 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
944 }
945 if(in_array("FAItemplate",$array['objectClass'])){
946 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
947 }
948 if(in_array("FAIhook",$array['objectClass'])){
949 return(array("tabsHook","faiHook","FAIHOOKTABS"));
950 }
951 if(in_array("FAIvariable",$array['objectClass'])){
952 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
953 }
954 if(in_array("FAIprofile",$array['objectClass'])){
955 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
956 }
958 if(in_array("FAIpackageList",$array['objectClass'])){
959 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
960 }
961 }
963 function CheckNewBranchName($name,$base){
964 $f = $_SESSION['faifilter']['branch'];
966 if($f == "main"){
967 $f = $_SESSION['faifilter']['base'];
968 }
970 if(in_array($name,$this->getBranches($f))) {
971 return(false);
972 }
974 if(empty($name)){
975 return(false);
976 }
977 return(true);
978 }
980 }
981 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
982 ?>