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;
44 var $lock_type = ""; // should be branch/freeze
45 var $lock_name = "";
46 var $lock_dn = "";
48 /* attribute list for save action */
49 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin, none,
50 // because this is only an overview over all objects already defined in FAI.
51 var $objectclasses = array(); // ObjectClasses which the attributes are related to
52 var $dialog = array(); // This object contains every dialog we have currently opened
54 var $objects = array(); // This array contains all available objects shown in divlist
55 var $is_dialog = false;
57 var $dispNewBranch= false;
58 var $dispNewFreeze= false;
60 /* construction/reconstruction
61 * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last
62 * selected department and filter options
63 * If it is not defined already we create a new fresh faifilter.
64 */
65 function faiManagement ($config, $ui)
66 {
67 $this->ui = $ui;
69 /* Set current dn to "", */
70 $this->dn = "";
72 /* Assign config */
73 $this->config = $config;
75 /* Get global filter config */
76 if (!is_global("faifilter")){
77 $base = get_base_from_people($ui->dn);
78 $faifilter= array("base" => $base,
79 "regex" => "*","branch" => "main");
80 $faifilter['ShowProfiles'] = true;
81 $faifilter['ShowTemplates'] = true;
82 $faifilter['ShowScripts'] = true;
83 $faifilter['ShowHooks'] = true;
84 $faifilter['ShowVariables'] = true;
85 $faifilter['ShowPackages'] = true;
86 $faifilter['ShowPartitions']=true;
87 register_global("faifilter", $faifilter);
88 }
89 }
91 function execute()
92 {
94 /* Call parent execute */
95 plugin::execute();
97 $display = "";
98 $smarty = get_smarty();
99 $smarty->assign("BranchName","");
100 $s_action = "";
101 $s_entry = "";
102 /* filter management
103 * Filter will be changed if POST['regex'] or $_GET['search'] isset
104 * New Filter will be stored in session and is used to generate list contents
105 */
106 $faifilter = $_SESSION['faifilter'];
108 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
109 $faifilter['branch'] = $_POST['select_branch'];
110 }
112 /* Filter is posted by apply button
113 * Check every single chkbox
114 */
115 if(isset($_POST['regex'])){
116 $faifilter['regex'] = $_POST['regex']."*";
117 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
118 if(isset($_POST[$attrs])){
119 $faifilter[$attrs] = true;
120 }else{
121 $faifilter[$attrs] = false;
122 }
123 }
124 }
127 /* Check ImageButton posts
128 * Create new tab ich new_xx is posted
129 */
130 foreach($_POST as $key => $val){
131 if(preg_match("/remove_branch/",$key)){
132 $s_action = "remove_branch";
133 }elseif(preg_match("/branch_branch/",$key)){
134 $s_action = "branch_branch";
135 }elseif(preg_match("/freeze_branch/",$key)){
136 $s_action = "freeze_branch";
137 }elseif(preg_match("/create_partition/i",$key)){
138 $s_action = "new_partition";
139 }elseif(preg_match("/create_script/i",$key)){
140 $s_action = "new_script";
141 }elseif(preg_match("/create_hook/i",$key)){
142 $s_action = "new_hook";
143 }elseif(preg_match("/create_variable/i",$key)){
144 $s_action = "new_variable";
145 }elseif(preg_match("/create_template/i",$key)){
146 $s_action = "new_template";
147 }elseif(preg_match("/create_package/i",$key)){
148 $s_action = "new_package";
149 }elseif(preg_match("/create_profile/i",$key)){
150 $s_action = "new_profile";
151 }elseif(preg_match("/edit_continue/",$key)){
152 $s_action = "select_class_name_finished";
153 }elseif(preg_match("/^entry_edit_.*/",$key)){
154 $s_entry = preg_replace("/^entry_edit_/","",$key);
155 $s_entry = preg_replace("/_.*$/","",$s_entry);
156 $s_action = "edit";
157 }elseif(preg_match("/^entry_delete_.*/",$key)){
158 $s_entry = preg_replace("/^entry_delete_/","",$key);
159 $s_entry = preg_replace("/_.*$/","",$s_entry);
160 $s_action = "delete";
161 }elseif(preg_match("/dep_back.*/i",$key)){
162 $faifilter['branch'] = "main";
163 $s_action="back";
164 }elseif(preg_match("/dep_home.*/i",$key)){
165 $faifilter['branch'] = "main";
166 $s_action="home";
167 }elseif(preg_match("/dep_root.*/i",$key)){
168 $faifilter['branch'] = "main";
169 $s_action="root";
170 }
172 }
174 if($s_action=="root"){
175 $faifilter['base']=($this->config->current['BASE']);
176 }
178 if($s_action=="home"){
179 $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
180 $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
181 }
183 if($s_action=="back"){
184 $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']);
185 $base_back = convert_department_dn($base_back);
187 if(isset($this->config->departments[trim($base_back)])){
188 $faifilter['base']= $this->config->departments[trim($base_back)];
189 }else{
190 $faifilter['base']= $this->config->departments["/"];
191 }
192 }
194 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
195 $s_action="open";
196 $s_entry = base64_decode($_GET['dep_id']);
197 $faifilter['base']= $this->config->departments[trim($s_entry)];
198 }
200 if(isset($_GET['edit_entry'])){
201 $s_entry = $_GET['edit_entry'];
202 $s_action = "edit";
203 }
205 /* Confirm dialog
206 * Delte object
207 */
208 if ($s_action=="delete"){
210 /* Get 'dn' from posted termlinst */
211 $this->dn= $this->objects[$s_entry]['dn'];
213 /* Load permissions for selected 'dn' and check if
214 we're allowed to remove this 'dn' */
215 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
216 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
217 if (chkacl($this->acl, "delete") == ""){
219 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
220 if (($user= get_lock($this->dn)) != ""){
221 return(gen_locked_message ($user, $this->dn));
222 }
224 /* Lock the current entry, so nobody will edit it during deletion */
225 add_lock ($this->dn, $this->ui->dn);
226 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
227 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
228 } else {
230 /* Obviously the user isn't allowed to delete. Show message and
231 clean session. */
232 print_red (_("You are not allowed to delete this component!"));
233 }
234 }
236 /* Delete canceled? */
237 if (isset($_POST['delete_cancel'])){
238 del_lock ($this->dn);
239 }
242 /* Deltetion was confirmed, so delete this entry
243 */
244 if (isset($_POST['delete_terminal_confirm'])){
246 /* Some nice guy may send this as POST, so we've to check
247 for the permissions again. */
248 if (chkacl($this->acl, "delete") == ""){
250 /* Find out more about the object type */
251 $ldap = $this->config->get_ldap_link();
252 $ldap->cat($this->dn);
253 $attrs = $ldap->fetch();
255 $type = $this->get_type($attrs);
257 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
258 $this->dialog->set_acl(array($this->acl));
260 $this->dialog->by_object[$type[1]]->remove_from_parent ();
261 unset ($this->dialog);
262 gosa_log ("FAI class '".$this->dn."' has been removed");
263 $this->dialog= NULL;
265 /* Terminal list has changed, reload it. */
266 } else {
268 /* Normally this shouldn't be reached, send some extra
269 logs to notify the administrator */
270 print_red (_("You are not allowed to delete this component!"));
271 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
272 "deletion.");
273 }
275 /* Remove lock file after successfull deletion */
276 del_lock ($this->dn);
277 }
279 /* Edit Entry */
280 if($s_action == "edit"){
281 $entry = $this->objects[$s_entry];
283 $a_setup = ($this->get_type($entry));
285 $this->dn = $entry['dn'];
286 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
287 if (($user= get_lock($this->dn)) != ""){
288 return(gen_locked_message ($user, $this->dn));
289 }
290 add_lock ($this->dn, $this->ui->dn);
292 $this->dialog= new $a_setup[0]($this->config,
293 $this->config->data['TABS'][$a_setup[2]],$this->dn);
294 $this->is_dialog = true;
295 $_SESSION['objectinfo'] = $this->dn;
296 }
299 /* Branch handling
300 09.01.2006
301 */
303 /* Create new branch */
304 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
306 /* Check branch name */
307 $name = $_POST['BranchName'];
308 $is_ok = true;
310 $smarty->assign("BranchName",$name);
311 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
313 /* Check used characters */
314 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
315 print_red(_("Specified branch name is invalid."));
316 $is_ok = false;
317 }
319 /* Check if this name is already in use */
320 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
321 print_red(_("This name is already in use."));
322 $is_ok = false;
323 }
325 if($is_ok){
326 /* Create it know */
327 $ldap = $this->config->get_ldap_link();
329 $baseToUse = $base;
330 if($_SESSION['faifilter']['branch']!="main"){
331 $baseToUse = $_SESSION['faifilter']['branch'];
332 }
334 $ldap->cd($this->config->current['BASE']);
335 $ldap->create_missing_trees($baseToUse);
336 $ldap->cd ("ou=".$name.",".$baseToUse);
337 $ldap->recursive_remove();
339 $ldap->cd ($this->config->current['BASE']);
340 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
342 /* Postcreate */
344 /* Assign possible attributes */
345 $this->lock_type = "branch";
346 $this->lock_name = $name;
347 $this->lock_dn = $baseToUse;
348 $this->postcreate();
349 $this->dispNewBranch = false;
350 }
351 }
353 /* Abort creating new branch */
354 if(isset($_POST['CancelBranchName'])){
355 $this->dispNewBranch = false;
356 $this->dispNewFreeze = false;
357 }
359 /* Open dialog to insert new branch name */
360 if(($s_action == "branch_branch")||($this->dispNewBranch)){
361 $this->dispNewBranch=true;
362 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
363 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
364 return($display);
365 }
367 /* Remove branch */
368 if($s_action == "remove_branch"){
369 $base= $faifilter['branch'];
370 /* Load permissions for selected 'dn' and check if
371 we're allowed to remove this 'dn' */
372 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
373 $this->acl= get_module_permission($acl, "fai", $base);
374 if (chkacl($this->acl, "delete") == ""){
375 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
376 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
377 } else {
378 print_red (_("You are not allowed to delete this user!"));
379 }
380 }
382 /* Delete this entry */
383 if(isset($_POST['delete_branch_confirm'])){
384 $bb = $faifilter['branch'];
385 if(!isset($ldap)){
386 $ldap = $this->config->get_ldap_link();
387 }
389 $br = $this->getBranches();
391 if(isset($br[$bb])){
393 $name = $br[$bb];
395 $ldap->cd($bb);
396 $ldap->recursive_remove();
397 $faifilter['branch'] = "main";
399 /* Post remove */
401 // $this->lock_type is set from this->reload
402 $this->lock_name = $name;
403 $this->lock_dn = $bb;
405 $this->postremove();
406 }
407 }
410 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
411 /* Check branch name */
412 $name = $_POST['BranchName'];
413 $is_ok = true;
415 $smarty->assign("BranchName",$name);
417 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
419 /* Check used characters */
420 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
421 print_red(_("Specified branch name is invalid."));
422 $is_ok = false;
423 }
425 /* Check if this name is already in use */
426 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
427 print_red(_("This name is already in use."));
428 $is_ok = false;
429 }
431 if($is_ok){
432 /* Create it know */
433 $ldap = $this->config->get_ldap_link();
435 $baseToUse = $base;
436 if($_SESSION['faifilter']['branch']!="main"){
437 $baseToUse = $_SESSION['faifilter']['branch'];
438 }
440 $ldap->cd ("ou=".$name.",".$baseToUse);
441 $ldap->recursive_remove();
443 $ldap->cd ($this->config->current['BASE']);
444 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
446 $this->dispNewFreeze = false;
448 /* Postcreate */
450 /* Assign possible attributes */
451 $this->lock_type = "branch";
452 $this->lock_name = $name;
453 $this->lock_dn = "ou=".$name.",".$baseToUse;
454 $this->postcreate();
455 }
456 }
458 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
459 $this->dispNewFreeze = true;
460 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
461 return($display);
462 }
464 /* ENDE Branch handling
465 */
467 /* Dialog handling */
468 if($s_action == "new_partition"){
469 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
470 }
472 /* Dialog handling */
473 if($s_action == "new_script"){
474 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
475 }
477 /* Dialog handling */
478 if($s_action == "new_hook"){
479 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
480 }
482 /* Dialog handling */
483 if($s_action == "new_variable"){
484 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
485 }
487 /* Dialog handling */
488 if($s_action == "new_template"){
489 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
490 }
492 /* Dialog handling */
493 if($s_action == "new_package"){
494 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
495 }
497 /* New Profile */
498 if($s_action == "new_profile"){
499 $this->dn = "new" ;
500 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
502 $this->dialog = new $a_setup[0]($this->config,
503 $this->config->data['TABS'][$a_setup[2]],$this->dn);
504 $this->is_dialog = true;
506 }
508 if($s_action == "select_class_name_finished"){
509 $this->dialog->save_object();
510 if(count($this->dialog->check())!=0){
511 foreach($this->dialog->check() as $msg){
512 print_red($msg);
513 }
514 }else{
515 $this->dn = "new" ;
516 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
517 $name = $this->dialog->save();
519 $this->dialog = new $a_setup[0]($this->config,
520 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
521 $this->dialog->by_object[$a_setup[1]]->cn = $name;
522 $this->is_dialog = true;
523 }
524 }
526 /* Search is set */
527 if(isset($_GET['search'])){
528 $faifilter['regex']=$_GET['search']."*";
529 }
531 /* Department select */
532 if((isset($_POST['base']))&&($s_action=="")){
533 $faifilter['base']=$_POST['base'];
534 }
536 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
538 $br = $this->getBranches($base);
539 if(!isset($br[$faifilter['branch']])){
540 $faifilter['branch'] = "main";
541 }
543 $smarty->assign("select_branch",$faifilter['branch']);
545 /* remove double asterisks and save new filter */
546 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
547 $_SESSION['faifilter']= $faifilter;
549 /* Edit dialog was canceled
550 * Remove dialog an show management dialog
551 */
552 if(isset($_POST['edit_cancel'])){
553 unset($this->dialog);
554 $this->dialog=NULL;
555 $this->is_dialog = false;
556 unset($_SESSION['objectinfo']);
557 del_lock ($this->dn);
558 }
560 /* This check if the given tab could be saved
561 * If it was possible to save it, remove dialog object.
562 * If it wasn't possible, show errors and keep dialog.
563 */
564 if(isset($_POST['edit_finish'])){
565 $this->dialog->save_object();
566 if(count($this->dialog->check())!=0){
567 foreach($this->dialog->check() as $msg){
568 print_red($msg);
569 }
570 }else{
571 del_lock ($this->dn);
572 $this->dialog->save();
573 unset($this->dialog);
574 $this->dialog=NULL;
575 $this->is_dialog=false;
576 unset($_SESSION['objectinfo']);
577 }
578 }
580 /* If dialog is set, but $this->is_dialog==false, then
581 * only the "abort" button is shown, this are dialogs that must not be saved.
582 * If is_dialog == true, we are currently editing tab objects.
583 * Here we need both, save and cancel
584 */
586 if($this->dialog != NULL){
587 $display .= $this->dialog->execute();
588 /* Don't show buttons if tab dialog requests this */
589 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
591 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
592 $display.= "<p style=\"text-align:right\">\n";
593 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
594 $display.= " \n";
595 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
596 $display.= "</p>";
597 }elseif(!isset($this->dialog->current)){
598 $display.= "<p style=\"text-align:right\">\n";
599 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
600 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
601 $display.= "</p>";
602 }
603 return($display);
604 }
606 /* Show Management template
607 * The following code will only be reached if no dialog (tabs or dialogs)
608 * are currently opened.
609 * Assign all reguired vars to template engine
610 */
612 /* Prepare departments */
613 $options= "";
614 foreach ($this->config->idepartments as $key => $value){
615 if ($faifilter['base'] == $key){
616 $options.= "<option selected='selected' value='$key'>$value</option>";
617 } else {
618 $options.= "<option value='$key'>$value</option>";
619 }
620 }
622 /* Create listhead, it will be shown on top of the divlist.
623 * It provides general navigation and object creation
624 */
625 $faihead =
626 "<div style='background:#F0F0F9;padding:5px;'> ".
628 "<input class='center' type='image' src='images/list_up.png' align='middle'
629 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
631 "<input class='center' type='image' src='images/list_root.png' align='middle'
632 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
634 "<input class='center' type='image' src='images/list_home.png' align='middle'
635 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
637 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
639 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
640 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
642 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
644 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
645 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
647 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
648 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
650 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
651 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
653 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
654 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
656 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
657 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
659 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
660 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
662 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
664 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
665 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
667 "</div>";
669 $this->reload();
671 /* Create list with objects */
672 $divlist = new divlist("faiManagement");
673 $divlist->SetEntriesPerPage(0);
674 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
676 $divlist->SetHeader(array(
677 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
678 array("string" => _("Name of FAI class"), "attach" => "style=''"),
679 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
680 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
683 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
684 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
686 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
687 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
689 foreach($this->departments as $key => $val) {
690 if(!isset($this->config->departments[trim($key)])){
691 $this->config->departments[trim($key)]="";
692 }
694 $non_empty="";
695 $keys= str_replace("/","\/",$key);
696 foreach($this->config->departments as $keyd=>$vald ){
697 if(preg_match("/".$keys."\/.*/",$keyd)){
698 $non_empty="full";
699 }
700 }
703 $title = $this->config->departments[$key];
704 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
705 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
706 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
707 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
709 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
711 }
713 /* Attach objects */
714 foreach($this->objects as $key => $value){
715 $info= "";
716 $img = "";
717 $type = $value['type'];
718 $abort=false;
720 switch($type) {
721 case "FAIpartitionTable" :
722 if(!$faifilter['ShowPartitions']){
723 $abort = true;
724 }
725 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
726 $info = _("Partition table");
727 break;
728 case "FAIpackageList" :
729 if(!$faifilter['ShowPackages']){
730 $abort = true;
731 }
732 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
733 $info = _("Package list");
734 break;
735 case "FAIscript" :
736 if(!$faifilter['ShowScripts']){
737 $abort = true;
738 }
739 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
740 $info = _("Scripts");
741 break;
742 case "FAIvariable" :
743 if(!$faifilter['ShowVariables']){
744 $abort = true;
745 }
746 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
747 $info = _("Variables");
748 break;
749 case "FAIhook" :
750 if(!$faifilter['ShowHooks']){
751 $abort = true;
752 }
753 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
754 $info = _("Hooks");
755 break;
756 case "FAIprofile" :
757 if(!$faifilter['ShowProfiles']){
758 $abort = true;
759 }
760 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
761 $info = _("Profile");
762 break;
763 case "FAItemplate" :
764 if(!$faifilter['ShowTemplates']){
765 $abort = true;
766 }
767 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
768 $info = _("Templates");
769 break;
770 default :
771 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
773 }
775 if(!$abort) {
776 if((isset($value['description']))&&(!empty($value['description']))){
777 $desc= " [".$value['description']."]";
778 }else{
779 $desc= "";
780 }
782 if($value['FAIstate'] == "freeze"){
783 $acti = "";
784 $edi = "%NAME%";
785 }else{
786 $acti = $action;
787 $edi = $editlink;
788 }
790 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
791 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
792 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
793 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
794 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
796 }
797 }
799 foreach($faifilter as $attrs => $value){
800 if($value){
801 $smarty->assign($attrs."CHK", " checked ");
802 }else{
803 $smarty->assign($attrs."CHK", " ");
804 }
805 }
807 /* Assign all reguired vars to template engine */
809 $branches = $this->getBranches();
810 asort($branches);
811 $smarty->assign("branchKeys",array_flip($branches));
812 $smarty->assign("branches",$branches);
814 $smarty->assign("faihead" , $faihead);
815 $smarty->assign("failist" , $divlist->DrawList());
816 $smarty->assign("regex" , $faifilter['regex']);
817 $smarty->assign("infoimage" , get_template_path('images/info.png'));
818 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
819 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
820 $smarty->assign("alphabet" , generate_alphabet());
821 $smarty->assign("apply" , apply_filter());
822 $smarty->assign("search_image" , get_template_path('images/search.png'));
823 $smarty->assign("hint", print_sizelimit_warning());
825 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
826 return ($display);
827 }
829 function getBranches($base = false,$prefix = "")
830 {
831 $ret = array("main"=>"/");
832 $ldap = $this->config->get_ldap_link();
834 $ldap->cd($this->config->current['BASE']);
836 $faifilter = $_SESSION['faifilter'];
839 if(!$base){
840 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
841 }
842 $ldap->cd($base);
843 $ldap->ls("(objectClass=FAIbranch)",$base);
845 while($attrs = $ldap->fetch()){
847 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
848 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
849 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
850 }
851 }
852 return($ret);
853 }
855 function reload()
856 {
857 /* Create a new list of FAI object
858 * Object list depends on faifilter['regex']
859 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
860 */
861 $faifilter= get_global('faifilter');
862 // Added for dirlist function...
864 /* Set base for all searches */
865 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
867 if($faifilter['branch'] !="main"){
868 $base = $faifilter['branch'];
869 }
871 $regex = $faifilter['regex'];
873 /* Array to save objects */
874 $objects = array();
876 $this->objects=array();
878 /* NEW LIST MANAGMENT
879 * We also need to search for the departments
880 * So we are able to navigate like in konquerer
881 */
882 $base2 = $faifilter['base'];
884 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
885 TRUE, $base2, array("ou", "description"), TRUE);
887 $this->departments= array();
888 $tmp = array();
889 foreach ($res3 as $value){
890 $tmp[strtolower($value['dn']).$value['dn']]=$value;
891 }
892 ksort($tmp);
893 foreach($tmp as $value){
894 if(isset($value["description"][0])){
895 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
896 }else{
897 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
898 }
899 }
901 /* END NEW LIST MANAGMENT
902 */
905 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
906 FALSE, $base, array("cn","description","objectClass"),TRUE);
908 $str = "";
910 foreach($res as $objecttypes){
911 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
912 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
913 foreach($res2 as $object){
914 $type= "";
915 unset($object['objectClass']['count']);
916 if(!isset($object['description'][0])){
917 $object['description'][0]="";
918 }
920 /* Clean up object informations */
921 $obj['cn'] = $object['cn'][0];
922 $obj['dn'] = $object['dn'];
923 $obj['description'] = $object['description'][0];
924 $obj['objectClass'] = $object['objectClass'];
926 if(isset($object['FAIstate'])){
927 $obj['FAIstate'] = $object['FAIstate'][0];
929 /* Append type to this string, to be able to check if the selected
930 * entry is of type 'freeze' or 'branch'
931 */
932 $str.="|".$obj['FAIstate'];
933 }else{
934 $obj['FAIstate'] ="";
935 }
937 if(in_array("FAIpartitionTable",$obj['objectClass'])){
938 $type = "FAIpartitionTable";
939 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
940 $type = "FAIpackageList";
941 }elseif(in_array("FAIscript",$obj['objectClass'])){
942 $type = "FAIscript";
943 }elseif(in_array("FAIvariable",$obj['objectClass'])){
944 $type = "FAIvariable";
945 }elseif(in_array("FAIhook",$obj['objectClass'])){
946 $type = "FAIhook";
947 }elseif(in_array("FAIprofile",$obj['objectClass'])){
948 $obj['FAIclass'] = $object['FAIclass'][0];
949 $type = "FAIprofile";
950 }elseif(in_array("FAItemplate",$obj['objectClass'])){
951 $type = "FAItemplate";
952 }
953 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
954 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
956 }
957 }
959 /* Tell class what we have currently opened
960 'main' has type ''
961 */
962 if(preg_match("/freeze/",$str)){
963 $this->lock_type = "freeze";
964 }elseif(preg_match("/branch/",$str)){
965 $this->lock_type = "branch";
966 }else{
967 $this->lock_type = "";
968 }
970 ksort($this->objects);
971 reset ($this->objects);
973 /* use numeric index, thats a bit more secure */
974 $tmp0 = array();
975 foreach($this->objects as $obj){
976 $tmp0[]= $obj;
977 }
978 $this->objects = array();
979 $this->objects = $tmp0;
981 }
983 function remove_lock()
984 {
985 if (isset($this->dn)){
986 del_lock ($this->dn);
987 }
988 }
990 function get_type($array){
991 if(in_array("FAIpartitionTable",$array['objectClass'])){
992 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
993 }
994 if(in_array("FAIscript",$array['objectClass'])){
995 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
996 }
997 if(in_array("FAItemplate",$array['objectClass'])){
998 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
999 }
1000 if(in_array("FAIhook",$array['objectClass'])){
1001 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1002 }
1003 if(in_array("FAIvariable",$array['objectClass'])){
1004 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1005 }
1006 if(in_array("FAIprofile",$array['objectClass'])){
1007 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1008 }
1010 if(in_array("FAIpackageList",$array['objectClass'])){
1011 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1012 }
1013 }
1015 function CheckNewBranchName($name,$base){
1016 $f = $_SESSION['faifilter']['branch'];
1018 if($f == "main"){
1019 $f = $_SESSION['faifilter']['base'];
1020 }
1022 if(in_array($name,$this->getBranches($f))) {
1023 return(false);
1024 }
1026 if(empty($name)){
1027 return(false);
1028 }
1029 return(true);
1030 }
1032 }
1033 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1034 ?>