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 } else {
265 /* Normally this shouldn't be reached, send some extra
266 logs to notify the administrator */
267 print_red (_("You are not allowed to delete this component!"));
268 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
269 "deletion.");
270 }
272 /* Remove lock file after successfull deletion */
273 del_lock ($this->dn);
274 }
276 /* Edit Entry */
277 if($s_action == "edit"){
278 $entry = $this->objects[$s_entry];
280 $a_setup = ($this->get_type($entry));
282 $this->dn = $entry['dn'];
283 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
284 if (($user= get_lock($this->dn)) != ""){
285 return(gen_locked_message ($user, $this->dn));
286 }
287 add_lock ($this->dn, $this->ui->dn);
289 $this->dialog= new $a_setup[0]($this->config,
290 $this->config->data['TABS'][$a_setup[2]],$this->dn);
291 $this->is_dialog = true;
292 $_SESSION['objectinfo'] = $this->dn;
293 }
296 /* Branch handling
297 09.01.2006
298 */
300 /* Create new branch */
301 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
303 /* Check branch name */
304 $name = $_POST['BranchName'];
305 $is_ok = true;
307 $smarty->assign("BranchName",$name);
308 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
310 /* Check used characters */
311 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
312 print_red(_("Specified branch name is invalid."));
313 $is_ok = false;
314 }
316 /* Check if this name is already in use */
317 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
318 print_red(_("This name is already in use."));
319 $is_ok = false;
320 }
322 if($is_ok){
323 /* Create it know */
324 $ldap = $this->config->get_ldap_link();
326 $baseToUse = $base;
327 if($_SESSION['faifilter']['branch']!="main"){
328 $baseToUse = $_SESSION['faifilter']['branch'];
329 }
331 $ldap->cd($this->config->current['BASE']);
332 $ldap->create_missing_trees($baseToUse);
333 $ldap->cd ("ou=".$name.",".$baseToUse);
334 $ldap->recursive_remove();
336 $ldap->cd ($this->config->current['BASE']);
337 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
339 $this->dispNewBranch = false;
340 }
341 }
343 /* Abort creating new branch */
344 if(isset($_POST['CancelBranchName'])){
345 $this->dispNewBranch = false;
346 $this->dispNewFreeze = false;
347 }
349 /* Open dialog to insert new branch name */
350 if(($s_action == "branch_branch")||($this->dispNewBranch)){
351 $this->dispNewBranch=true;
352 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
353 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
354 return($display);
355 }
357 /* Remove branch */
358 if($s_action == "remove_branch"){
359 $base= $faifilter['branch'];
360 /* Load permissions for selected 'dn' and check if
361 we're allowed to remove this 'dn' */
362 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
363 $this->acl= get_module_permission($acl, "fai", $base);
364 if (chkacl($this->acl, "delete") == ""){
365 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
366 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
367 } else {
368 print_red (_("You are not allowed to delete this user!"));
369 }
370 }
372 /* Delete this entry */
373 if(isset($_POST['delete_branch_confirm'])){
374 $bb = $faifilter['branch'];
375 if(!isset($ldap)){
376 $ldap = $this->config->get_ldap_link();
377 }
379 $br = $this->getBranches();
381 if(isset($br[$bb])){
382 $ldap->cd($bb);
383 $ldap->recursive_remove();
384 $faifilter['branch'] = "main";
385 }
386 }
389 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
390 /* Check branch name */
391 $name = $_POST['BranchName'];
392 $is_ok = true;
394 $smarty->assign("BranchName",$name);
396 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
398 /* Check used characters */
399 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
400 print_red(_("Specified branch name is invalid."));
401 $is_ok = false;
402 }
404 /* Check if this name is already in use */
405 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
406 print_red(_("This name is already in use."));
407 $is_ok = false;
408 }
410 if($is_ok){
411 /* Create it know */
412 $ldap = $this->config->get_ldap_link();
414 $baseToUse = $base;
415 if($_SESSION['faifilter']['branch']!="main"){
416 $baseToUse = $_SESSION['faifilter']['branch'];
417 }
419 $ldap->cd ("ou=".$name.",".$baseToUse);
420 $ldap->recursive_remove();
422 $ldap->cd ($this->config->current['BASE']);
423 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
425 $this->dispNewFreeze = false;
426 }
427 }
429 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
430 $this->dispNewFreeze = true;
431 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
432 return($display);
433 }
435 /* ENDE Branch handling
436 */
438 /* Dialog handling */
439 if($s_action == "new_partition"){
440 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
441 }
443 /* Dialog handling */
444 if($s_action == "new_script"){
445 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
446 }
448 /* Dialog handling */
449 if($s_action == "new_hook"){
450 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
451 }
453 /* Dialog handling */
454 if($s_action == "new_variable"){
455 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
456 }
458 /* Dialog handling */
459 if($s_action == "new_template"){
460 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
461 }
463 /* Dialog handling */
464 if($s_action == "new_package"){
465 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
466 }
468 /* New Profile */
469 if($s_action == "new_profile"){
470 $this->dn = "new" ;
471 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
473 $this->dialog = new $a_setup[0]($this->config,
474 $this->config->data['TABS'][$a_setup[2]],$this->dn);
475 $this->is_dialog = true;
477 }
479 if($s_action == "select_class_name_finished"){
480 $this->dialog->save_object();
481 if(count($this->dialog->check())!=0){
482 foreach($this->dialog->check() as $msg){
483 print_red($msg);
484 }
485 }else{
486 $this->dn = "new" ;
487 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
488 $name = $this->dialog->save();
490 $this->dialog = new $a_setup[0]($this->config,
491 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
492 $this->dialog->by_object[$a_setup[1]]->cn = $name;
493 $this->is_dialog = true;
494 }
495 }
497 /* Search is set */
498 if(isset($_GET['search'])){
499 $faifilter['regex']=$_GET['search']."*";
500 }
502 /* Department select */
503 if((isset($_POST['base']))&&($s_action=="")){
504 $faifilter['base']=$_POST['base'];
505 }
507 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
509 $br = $this->getBranches($base);
510 if(!isset($br[$faifilter['branch']])){
511 $faifilter['branch'] = "main";
512 }
514 $smarty->assign("select_branch",$faifilter['branch']);
516 /* remove double asterisks and save new filter */
517 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
518 $_SESSION['faifilter']= $faifilter;
520 /* Edit dialog was canceled
521 * Remove dialog an show management dialog
522 */
523 if(isset($_POST['edit_cancel'])){
524 unset($this->dialog);
525 $this->dialog=NULL;
526 $this->is_dialog = false;
527 unset($_SESSION['objectinfo']);
528 del_lock ($this->dn);
529 }
531 /* This check if the given tab could be saved
532 * If it was possible to save it, remove dialog object.
533 * If it wasn't possible, show errors and keep dialog.
534 */
535 if(isset($_POST['edit_finish'])){
536 $this->dialog->save_object();
537 if(count($this->dialog->check())!=0){
538 foreach($this->dialog->check() as $msg){
539 print_red($msg);
540 }
541 }else{
542 del_lock ($this->dn);
543 $this->dialog->save();
544 unset($this->dialog);
545 $this->dialog=NULL;
546 $this->is_dialog=false;
547 unset($_SESSION['objectinfo']);
548 }
549 }
551 /* If dialog is set, but $this->is_dialog==false, then
552 * only the "abort" button is shown, this are dialogs that must not be saved.
553 * If is_dialog == true, we are currently editing tab objects.
554 * Here we need both, save and cancel
555 */
557 if($this->dialog != NULL){
558 $display .= $this->dialog->execute();
559 /* Don't show buttons if tab dialog requests this */
560 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
562 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
563 $display.= "<p style=\"text-align:right\">\n";
564 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
565 $display.= " \n";
566 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
567 $display.= "</p>";
568 }elseif(!isset($this->dialog->current)){
569 $display.= "<p style=\"text-align:right\">\n";
570 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
571 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
572 $display.= "</p>";
573 }
574 return($display);
575 }
577 /* Show Management template
578 * The following code will only be reached if no dialog (tabs or dialogs)
579 * are currently opened.
580 * Assign all reguired vars to template engine
581 */
583 /* Prepare departments */
584 $options= "";
585 foreach ($this->config->idepartments as $key => $value){
586 if ($faifilter['base'] == $key){
587 $options.= "<option selected='selected' value='$key'>$value</option>";
588 } else {
589 $options.= "<option value='$key'>$value</option>";
590 }
591 }
593 /* Create listhead, it will be shown on top of the divlist.
594 * It provides general navigation and object creation
595 */
596 $faihead =
597 "<div style='background:#F0F0F9;padding:5px;'> ".
599 "<input class='center' type='image' src='images/list_up.png' align='middle'
600 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
602 "<input class='center' type='image' src='images/list_root.png' align='middle'
603 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
605 "<input class='center' type='image' src='images/list_home.png' align='middle'
606 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
608 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
610 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
611 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
613 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
615 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
616 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
618 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
619 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
621 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
622 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
624 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
625 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
627 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
628 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
630 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
631 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
633 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
635 _("Current base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
636 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
638 "</div>";
640 $this->reload();
642 /* Create list with objects */
643 $divlist = new divlist("faiManagement");
644 $divlist->SetEntriesPerPage(0);
645 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
647 $divlist->SetHeader(array(
648 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
649 array("string" => _("Name of FAI class"), "attach" => "style=''"),
650 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
651 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
654 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
655 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
657 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
658 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
660 foreach($this->departments as $key => $val) {
661 if(!isset($this->config->departments[trim($key)])){
662 $this->config->departments[trim($key)]="";
663 }
665 $non_empty="";
666 $keys= str_replace("/","\/",$key);
667 foreach($this->config->departments as $keyd=>$vald ){
668 if(preg_match("/".$keys."\/.*/",$keyd)){
669 $non_empty="full";
670 }
671 }
674 $title = $this->config->departments[$key];
675 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
676 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
677 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
678 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
680 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
682 }
684 /* Attach objects */
685 foreach($this->objects as $key => $value){
686 $info= "";
687 $img = "";
688 $type = $value['type'];
689 $abort=false;
691 switch($type) {
692 case "FAIpartitionTable" :
693 if(!$faifilter['ShowPartitions']){
694 $abort = true;
695 }
696 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
697 $info = _("Partition table");
698 break;
699 case "FAIpackageList" :
700 if(!$faifilter['ShowPackages']){
701 $abort = true;
702 }
703 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
704 $info = _("Package list");
705 break;
706 case "FAIscript" :
707 if(!$faifilter['ShowScripts']){
708 $abort = true;
709 }
710 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
711 $info = _("Scripts");
712 break;
713 case "FAIvariable" :
714 if(!$faifilter['ShowVariables']){
715 $abort = true;
716 }
717 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
718 $info = _("Variables");
719 break;
720 case "FAIhook" :
721 if(!$faifilter['ShowHooks']){
722 $abort = true;
723 }
724 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
725 $info = _("Hooks");
726 break;
727 case "FAIprofile" :
728 if(!$faifilter['ShowProfiles']){
729 $abort = true;
730 }
731 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
732 $info = _("Profile");
733 break;
734 case "FAItemplate" :
735 if(!$faifilter['ShowTemplates']){
736 $abort = true;
737 }
738 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
739 $info = _("Templates");
740 break;
741 default :
742 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
744 }
746 if(!$abort) {
747 if((isset($value['description']))&&(!empty($value['description']))){
748 $desc= " [".$value['description']."]";
749 }else{
750 $desc= "";
751 }
753 if($value['FAIstate'] == "freeze"){
754 $acti = "";
755 $edi = "%NAME%";
756 }else{
757 $acti = $action;
758 $edi = $editlink;
759 }
761 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
762 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
763 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
764 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
765 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
767 }
768 }
770 foreach($faifilter as $attrs => $value){
771 if($value){
772 $smarty->assign($attrs."CHK", " checked ");
773 }else{
774 $smarty->assign($attrs."CHK", " ");
775 }
776 }
778 /* Assign all reguired vars to template engine */
780 $branches = $this->getBranches();
781 asort($branches);
782 $smarty->assign("branchKeys",array_flip($branches));
783 $smarty->assign("branches",$branches);
785 $smarty->assign("faihead" , $faihead);
786 $smarty->assign("failist" , $divlist->DrawList());
787 $smarty->assign("regex" , $faifilter['regex']);
788 $smarty->assign("infoimage" , get_template_path('images/info.png'));
789 $smarty->assign("branchimage" , get_template_path('images/action.png'));
790 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
791 $smarty->assign("alphabet" , generate_alphabet());
792 $smarty->assign("apply" , apply_filter());
793 $smarty->assign("search_image" , get_template_path('images/search.png'));
794 $smarty->assign("hint", print_sizelimit_warning());
796 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
797 return ($display);
798 }
800 function getBranches($base = false,$prefix = "")
801 {
802 $ret = array("main"=>_("main"));
803 $ldap = $this->config->get_ldap_link();
805 $ldap->cd($this->config->current['BASE']);
807 $faifilter = $_SESSION['faifilter'];
810 if(!$base){
811 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
812 }
813 $ldap->cd($base);
814 $ldap->ls("(objectClass=FAIbranch)",$base);
816 while($attrs = $ldap->fetch()){
818 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
819 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
820 $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix.$attrs['ou'][0]."/"));
821 }
822 }
823 return($ret);
824 }
826 function reload()
827 {
828 /* Create a new list of FAI object
829 * Object list depends on faifilter['regex']
830 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
831 */
832 $faifilter= get_global('faifilter');
833 // Added for dirlist function...
835 /* Set base for all searches */
836 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
838 if($faifilter['branch'] !="main"){
839 $base = $faifilter['branch'];
840 }
842 $regex = $faifilter['regex'];
844 /* Array to save objects */
845 $objects = array();
847 $this->objects=array();
849 /* NEW LIST MANAGMENT
850 * We also need to search for the departments
851 * So we are able to navigate like in konquerer
852 */
853 $base2 = $faifilter['base'];
855 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
856 TRUE, $base2, array("ou", "description"), TRUE);
858 $this->departments= array();
859 $tmp = array();
860 foreach ($res3 as $value){
861 $tmp[strtolower($value['dn']).$value['dn']]=$value;
862 }
863 ksort($tmp);
864 foreach($tmp as $value){
865 if(isset($value["description"][0])){
866 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
867 }else{
868 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
869 }
870 }
872 /* END NEW LIST MANAGMENT
873 */
876 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
877 FALSE, $base, array("cn","description","objectClass"),TRUE);
879 foreach($res as $objecttypes){
880 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
881 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
882 foreach($res2 as $object){
883 $type= "";
884 unset($object['objectClass']['count']);
885 if(!isset($object['description'][0])){
886 $object['description'][0]="";
887 }
889 /* Clean up object informations */
890 $obj['cn'] = $object['cn'][0];
891 $obj['dn'] = $object['dn'];
892 $obj['description'] = $object['description'][0];
893 $obj['objectClass'] = $object['objectClass'];
895 if(isset($object['FAIstate'])){
896 $obj['FAIstate'] = $object['FAIstate'][0];
897 }else{
898 $obj['FAIstate'] ="";
899 }
901 if(in_array("FAIpartitionTable",$obj['objectClass'])){
902 $type = "FAIpartitionTable";
903 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
904 $type = "FAIpackageList";
905 }elseif(in_array("FAIscript",$obj['objectClass'])){
906 $type = "FAIscript";
907 }elseif(in_array("FAIvariable",$obj['objectClass'])){
908 $type = "FAIvariable";
909 }elseif(in_array("FAIhook",$obj['objectClass'])){
910 $type = "FAIhook";
911 }elseif(in_array("FAIprofile",$obj['objectClass'])){
912 $obj['FAIclass'] = $object['FAIclass'][0];
913 $type = "FAIprofile";
914 }elseif(in_array("FAItemplate",$obj['objectClass'])){
915 $type = "FAItemplate";
916 }
917 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
918 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
920 }
921 }
922 ksort($this->objects);
923 reset ($this->objects);
925 /* use numeric index, thats a bit more secure */
926 $tmp0 = array();
927 foreach($this->objects as $obj){
928 $tmp0[]= $obj;
929 }
930 $this->objects = array();
931 $this->objects = $tmp0;
933 }
935 function remove_lock()
936 {
937 if (isset($this->dn)){
938 del_lock ($this->dn);
939 }
940 }
942 function get_type($array){
943 if(in_array("FAIpartitionTable",$array['objectClass'])){
944 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
945 }
946 if(in_array("FAIscript",$array['objectClass'])){
947 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
948 }
949 if(in_array("FAItemplate",$array['objectClass'])){
950 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
951 }
952 if(in_array("FAIhook",$array['objectClass'])){
953 return(array("tabsHook","faiHook","FAIHOOKTABS"));
954 }
955 if(in_array("FAIvariable",$array['objectClass'])){
956 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
957 }
958 if(in_array("FAIprofile",$array['objectClass'])){
959 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
960 }
962 if(in_array("FAIpackageList",$array['objectClass'])){
963 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
964 }
965 }
967 function CheckNewBranchName($name,$base){
968 $f = $_SESSION['faifilter']['branch'];
970 if($f == "main"){
971 $f = $_SESSION['faifilter']['base'];
972 }
974 if(in_array($name,$this->getBranches($f))) {
975 return(false);
976 }
978 if(empty($name)){
979 return(false);
980 }
981 return(true);
982 }
984 }
985 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
986 ?>