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 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
99 $display = "";
100 $smarty = get_smarty();
101 $smarty->assign("BranchName","");
102 $s_action = "";
103 $s_entry = "";
104 /* filter management
105 * Filter will be changed if POST['regex'] or $_GET['search'] isset
106 * New Filter will be stored in session and is used to generate list contents
107 */
108 $faifilter = $_SESSION['faifilter'];
110 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
111 $faifilter['branch'] = $_POST['select_branch'];
112 }
114 /* Filter is posted by apply button
115 * Check every single chkbox
116 */
117 if(isset($_POST['regex'])){
118 $faifilter['regex'] = $_POST['regex']."*";
119 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
120 if(isset($_POST[$attrs])){
121 $faifilter[$attrs] = true;
122 }else{
123 $faifilter[$attrs] = false;
124 }
125 }
126 }
129 /* Check ImageButton posts
130 * Create new tab ich new_xx is posted
131 */
132 foreach($_POST as $key => $val){
133 if(preg_match("/remove_branch/",$key)){
134 $s_action = "remove_branch";
135 }elseif(preg_match("/branch_branch/",$key)){
136 $s_action = "branch_branch";
137 }elseif(preg_match("/freeze_branch/",$key)){
138 $s_action = "freeze_branch";
139 }elseif(preg_match("/create_partition/i",$key)){
140 $s_action = "new_partition";
141 }elseif(preg_match("/create_script/i",$key)){
142 $s_action = "new_script";
143 }elseif(preg_match("/create_hook/i",$key)){
144 $s_action = "new_hook";
145 }elseif(preg_match("/create_variable/i",$key)){
146 $s_action = "new_variable";
147 }elseif(preg_match("/create_template/i",$key)){
148 $s_action = "new_template";
149 }elseif(preg_match("/create_package/i",$key)){
150 $s_action = "new_package";
151 }elseif(preg_match("/create_profile/i",$key)){
152 $s_action = "new_profile";
153 }elseif(preg_match("/edit_continue/",$key)){
154 $s_action = "select_class_name_finished";
155 }elseif(preg_match("/^entry_edit_.*/",$key)){
156 $s_entry = preg_replace("/^entry_edit_/","",$key);
157 $s_entry = preg_replace("/_.*$/","",$s_entry);
158 $s_action = "edit";
159 }elseif(preg_match("/^entry_delete_.*/",$key)){
160 $s_entry = preg_replace("/^entry_delete_/","",$key);
161 $s_entry = preg_replace("/_.*$/","",$s_entry);
162 $s_action = "delete";
163 }elseif(preg_match("/dep_back.*/i",$key)){
164 $faifilter['branch'] = "main";
165 $s_action="back";
166 }elseif(preg_match("/dep_home.*/i",$key)){
167 $faifilter['branch'] = "main";
168 $s_action="home";
169 }elseif(preg_match("/dep_root.*/i",$key)){
170 $faifilter['branch'] = "main";
171 $s_action="root";
172 }
174 }
176 if($s_action=="root"){
177 $faifilter['base']=($this->config->current['BASE']);
178 }
180 if($s_action=="home"){
181 $faifilter['base']= get_base_from_people($this->ui->dn);
182 //$faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
183 }
185 if($s_action=="back"){
186 $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']);
187 $base_back = convert_department_dn($base_back);
189 if(isset($this->config->departments[trim($base_back)])){
190 $faifilter['base']= $this->config->departments[trim($base_back)];
191 }else{
192 $faifilter['base']= $this->config->departments["/"];
193 }
194 }
196 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
197 $s_action="open";
198 $s_entry = base64_decode($_GET['dep_id']);
199 $faifilter['base']= $this->config->departments[trim($s_entry)];
200 }
202 if(isset($_GET['edit_entry'])){
203 $s_entry = $_GET['edit_entry'];
204 $s_action = "edit";
205 }
207 /* Confirm dialog
208 * Delte object
209 */
210 if ($s_action=="delete"){
212 /* Get 'dn' from posted termlinst */
213 $this->dn= $this->objects[$s_entry]['dn'];
215 /* Load permissions for selected 'dn' and check if
216 we're allowed to remove this 'dn' */
217 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
218 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
219 if (chkacl($this->acl, "delete") == ""){
221 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
222 if (($user= get_lock($this->dn)) != ""){
223 return(gen_locked_message ($user, $this->dn));
224 }
226 /* Lock the current entry, so nobody will edit it during deletion */
227 add_lock ($this->dn, $this->ui->dn);
228 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
229 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
230 } else {
232 /* Obviously the user isn't allowed to delete. Show message and
233 clean session. */
234 print_red (_("You are not allowed to delete this component!"));
235 }
236 }
238 /* Delete canceled? */
239 if (isset($_POST['delete_cancel'])){
240 del_lock ($this->dn);
241 }
244 /* Deltetion was confirmed, so delete this entry
245 */
246 if (isset($_POST['delete_terminal_confirm'])){
248 /* Some nice guy may send this as POST, so we've to check
249 for the permissions again. */
250 if (chkacl($this->acl, "delete") == ""){
252 /* Find out more about the object type */
253 $ldap = $this->config->get_ldap_link();
254 $ldap->cat($this->dn);
255 $attrs = $ldap->fetch();
257 $type = $this->get_type($attrs);
259 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
260 $this->dialog->set_acl(array($this->acl));
262 $this->dialog->by_object[$type[1]]->remove_from_parent ();
263 unset ($this->dialog);
264 gosa_log ("FAI class '".$this->dn."' has been removed");
265 $this->dialog= NULL;
267 /* Terminal list has changed, reload it. */
268 } else {
270 /* Normally this shouldn't be reached, send some extra
271 logs to notify the administrator */
272 print_red (_("You are not allowed to delete this component!"));
273 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
274 "deletion.");
275 }
277 /* Remove lock file after successfull deletion */
278 del_lock ($this->dn);
279 }
281 /* Edit Entry */
282 //if($s_action == "edit"){
283 if(($s_action == "edit") && (!isset($this->dialog->config))){
284 $entry = $this->objects[$s_entry];
286 $a_setup = ($this->get_type($entry));
288 $this->dn = $entry['dn'];
289 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
290 if (($user= get_lock($this->dn)) != ""){
291 return(gen_locked_message ($user, $this->dn));
292 }
293 add_lock ($this->dn, $this->ui->dn);
295 $this->dialog= new $a_setup[0]($this->config,
296 $this->config->data['TABS'][$a_setup[2]],$this->dn);
297 $this->is_dialog = true;
298 $_SESSION['objectinfo'] = $this->dn;
299 }
302 /* Branch handling
303 09.01.2006
304 */
306 /* Create new branch */
307 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
309 /* Check branch name */
310 $name = $_POST['BranchName'];
311 $is_ok = true;
313 $smarty->assign("BranchName",$name);
314 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
316 /* Check used characters */
317 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
318 print_red(_("Specified branch name is invalid."));
319 $is_ok = false;
320 }
322 /* Check if this name is already in use */
323 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
324 print_red(_("This name is already in use."));
325 $is_ok = false;
326 }
328 if($is_ok){
329 /* Create it know */
330 $ldap = $this->config->get_ldap_link();
332 $baseToUse = $base;
333 if($_SESSION['faifilter']['branch']!="main"){
334 $baseToUse = $_SESSION['faifilter']['branch'];
335 }
337 $ldap->cd($this->config->current['BASE']);
338 $ldap->create_missing_trees($baseToUse);
339 $ldap->cd ("ou=".$name.",".$baseToUse);
340 $ldap->recursive_remove();
342 $ldap->cd ($this->config->current['BASE']);
343 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
345 /* Postcreate */
347 /* Assign possible attributes */
348 $this->lock_type = "branch";
349 $this->lock_name = $name;
350 $this->lock_dn = $baseToUse;
351 $this->postcreate();
352 $this->dispNewBranch = false;
353 }
354 }
356 /* Abort creating new branch */
357 if(isset($_POST['CancelBranchName'])){
358 $this->dispNewBranch = false;
359 $this->dispNewFreeze = false;
360 }
362 /* Open dialog to insert new branch name */
363 if(($s_action == "branch_branch")||($this->dispNewBranch)){
364 $this->dispNewBranch=true;
365 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
366 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
367 return($display);
368 }
370 /* Remove branch */
371 if($s_action == "remove_branch"){
372 $base= $faifilter['branch'];
373 /* Load permissions for selected 'dn' and check if
374 we're allowed to remove this 'dn' */
375 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
376 $this->acl= get_module_permission($acl, "FAIclass", $base);
377 if (chkacl($this->acl, "delete") == ""){
378 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
379 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
380 } else {
381 print_red (_("You are not allowed to delete this release!"));
382 }
383 }
385 /* Delete this entry */
386 if(isset($_POST['delete_branch_confirm'])){
387 $bb = $faifilter['branch'];
388 if(!isset($ldap)){
389 $ldap = $this->config->get_ldap_link();
390 }
392 $br = $this->getBranches();
394 if(isset($br[$bb])){
396 $name = $br[$bb];
398 $ldap->cd($bb);
399 $ldap->recursive_remove();
400 $faifilter['branch'] = "main";
402 /* Post remove */
404 // $this->lock_type is set from this->reload
405 $this->lock_name = $name;
406 $this->lock_dn = $bb;
408 $this->postremove();
409 }
410 }
413 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
414 /* Check branch name */
415 $name = $_POST['BranchName'];
416 $is_ok = true;
418 $smarty->assign("BranchName",$name);
420 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
422 /* Check used characters */
423 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
424 print_red(_("Specified branch name is invalid."));
425 $is_ok = false;
426 }
428 /* Check if this name is already in use */
429 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
430 print_red(_("This name is already in use."));
431 $is_ok = false;
432 }
434 if($is_ok){
435 /* Create it know */
436 $ldap = $this->config->get_ldap_link();
438 $baseToUse = $base;
439 if($_SESSION['faifilter']['branch']!="main"){
440 $baseToUse = $_SESSION['faifilter']['branch'];
441 }
443 $ldap->cd ("ou=".$name.",".$baseToUse);
444 $ldap->recursive_remove();
446 $ldap->cd ($this->config->current['BASE']);
447 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
449 $this->dispNewFreeze = false;
451 /* Postcreate */
453 /* Assign possible attributes */
454 $this->lock_type = "branch";
455 $this->lock_name = $name;
456 $this->lock_dn = $baseToUse;
457 $this->postcreate();
458 }
459 }
461 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
462 $this->dispNewFreeze = true;
463 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
464 return($display);
465 }
467 /* ENDE Branch handling
468 */
470 /* Dialog handling */
471 if($s_action == "new_partition"){
472 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
473 }
475 /* Dialog handling */
476 if($s_action == "new_script"){
477 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
478 }
480 /* Dialog handling */
481 if($s_action == "new_hook"){
482 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
483 }
485 /* Dialog handling */
486 if($s_action == "new_variable"){
487 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
488 }
490 /* Dialog handling */
491 if($s_action == "new_template"){
492 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
493 }
495 /* Dialog handling */
496 if($s_action == "new_package"){
497 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
498 }
500 /* New Profile */
501 if($s_action == "new_profile"){
502 $this->dn = "new" ;
503 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
505 $this->dialog = new $a_setup[0]($this->config,
506 $this->config->data['TABS'][$a_setup[2]],$this->dn);
507 $this->is_dialog = true;
509 }
511 if($s_action == "select_class_name_finished"){
512 $this->dialog->save_object();
513 if(count($this->dialog->check())!=0){
514 foreach($this->dialog->check() as $msg){
515 print_red($msg);
516 }
517 }else{
518 $this->dn = "new" ;
519 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
520 $name = $this->dialog->save();
522 $this->dialog = new $a_setup[0]($this->config,
523 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
524 $this->dialog->by_object[$a_setup[1]]->cn = $name;
525 $this->is_dialog = true;
526 }
527 }
529 /* Search is set */
530 if(isset($_GET['search'])){
531 $faifilter['regex']=$_GET['search']."*";
532 }
534 /* Department select */
535 if((isset($_POST['base']))&&($s_action=="")){
536 $faifilter['base']=$_POST['base'];
537 }
539 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
541 $br = $this->getBranches($base);
542 if(!isset($br[$faifilter['branch']])){
543 $faifilter['branch'] = "main";
544 }
546 $smarty->assign("select_branch",$faifilter['branch']);
548 /* remove double asterisks and save new filter */
549 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
550 $_SESSION['faifilter']= $faifilter;
552 /* Edit dialog was canceled
553 * Remove dialog an show management dialog
554 */
555 if(isset($_POST['edit_cancel'])){
556 unset($this->dialog);
557 $this->dialog=NULL;
558 $this->is_dialog = false;
559 unset($_SESSION['objectinfo']);
560 del_lock ($this->dn);
561 }
563 /* This check if the given tab could be saved
564 * If it was possible to save it, remove dialog object.
565 * If it wasn't possible, show errors and keep dialog.
566 */
567 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
568 $this->dialog->save_object();
569 if(count($this->dialog->check())!=0){
570 foreach($this->dialog->check() as $msg){
571 print_red($msg);
572 }
573 }else{
574 del_lock ($this->dn);
575 $this->dialog->save();
576 unset($this->dialog);
577 $this->dialog=NULL;
578 $this->is_dialog=false;
579 unset($_SESSION['objectinfo']);
580 }
581 }
583 /* If dialog is set, but $this->is_dialog==false, then
584 * only the "abort" button is shown, this are dialogs that must not be saved.
585 * If is_dialog == true, we are currently editing tab objects.
586 * Here we need both, save and cancel
587 */
589 if(($this->dialog != NULL) && (isset($this->dialog->config))){
590 $display .= $this->dialog->execute();
591 /* Don't show buttons if tab dialog requests this */
592 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
594 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
595 $display.= "<p style=\"text-align:right\">\n";
596 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
597 $display.= " \n";
598 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
599 $display.= "</p>";
600 }elseif(!isset($this->dialog->current)){
601 $display.= "<p style=\"text-align:right\">\n";
602 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
603 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
604 $display.= "</p>";
605 }
606 return($display);
607 }
609 /* Show Management template
610 * The following code will only be reached if no dialog (tabs or dialogs)
611 * are currently opened.
612 * Assign all reguired vars to template engine
613 */
615 /* Prepare departments */
616 $options= "";
617 foreach ($this->config->idepartments as $key => $value){
618 if ($faifilter['base'] == $key){
619 $options.= "<option selected='selected' value='$key'>$value</option>";
620 } else {
621 $options.= "<option value='$key'>$value</option>";
622 }
623 }
625 /* Create listhead, it will be shown on top of the divlist.
626 * It provides general navigation and object creation
627 */
628 $faihead =
629 "<div style='background:#F0F0F9;padding:5px;'> ".
631 "<input class='center' type='image' src='images/list_up.png' align='middle'
632 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
634 "<input class='center' type='image' src='images/list_root.png' align='middle'
635 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
637 "<input class='center' type='image' src='images/list_home.png' align='middle'
638 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
640 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
642 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
643 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
645 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
647 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
648 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
650 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
651 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
653 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
654 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
656 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
657 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
659 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
660 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
662 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
663 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
665 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
667 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
668 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
670 "</div>";
672 $this->reload();
674 /* Create list with objects */
675 $divlist = new divlist("faiManagement");
676 $divlist->SetEntriesPerPage(0);
677 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
679 $divlist->SetHeader(array(
680 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
681 array("string" => _("Name of FAI class"), "attach" => "style=''"),
682 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
683 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
686 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
687 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
689 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
690 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
692 foreach($this->departments as $key => $val) {
693 if(!isset($this->config->departments[trim($key)])){
694 $this->config->departments[trim($key)]="";
695 }
697 $non_empty="";
698 $keys= str_replace("/","\/",$key);
699 foreach($this->config->departments as $keyd=>$vald ){
700 if(preg_match("/".$keys."\/.*/",$keyd)){
701 $non_empty="full";
702 }
703 }
706 $title = $this->config->departments[$key];
707 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
708 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
709 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
710 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
712 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
714 }
716 /* Attach objects */
717 foreach($this->objects as $key => $value){
718 $info= "";
719 $img = "";
720 $type = $value['type'];
721 $abort=false;
723 switch($type) {
724 case "FAIpartitionTable" :
725 if(!$faifilter['ShowPartitions']){
726 $abort = true;
727 }
728 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
729 $info = _("Partition table");
730 break;
731 case "FAIpackageList" :
732 if(!$faifilter['ShowPackages']){
733 $abort = true;
734 }
735 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
736 $info = _("Package list");
737 break;
738 case "FAIscript" :
739 if(!$faifilter['ShowScripts']){
740 $abort = true;
741 }
742 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
743 $info = _("Scripts");
744 break;
745 case "FAIvariable" :
746 if(!$faifilter['ShowVariables']){
747 $abort = true;
748 }
749 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
750 $info = _("Variables");
751 break;
752 case "FAIhook" :
753 if(!$faifilter['ShowHooks']){
754 $abort = true;
755 }
756 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
757 $info = _("Hooks");
758 break;
759 case "FAIprofile" :
760 if(!$faifilter['ShowProfiles']){
761 $abort = true;
762 }
763 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
764 $info = _("Profile");
765 break;
766 case "FAItemplate" :
767 if(!$faifilter['ShowTemplates']){
768 $abort = true;
769 }
770 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
771 $info = _("Templates");
772 break;
773 default :
774 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
776 }
778 if(!$abort) {
779 if((isset($value['description']))&&(!empty($value['description']))){
780 $desc= " [".$value['description']."]";
781 }else{
782 $desc= "";
783 }
785 if($value['FAIstate'] == "freeze"){
786 $acti = "";
787 $edi = "%NAME%";
788 }else{
789 $acti = $action;
790 $edi = $editlink;
791 }
793 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
794 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
795 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
796 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
797 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
799 }
800 }
802 foreach($faifilter as $attrs => $value){
803 if($value){
804 $smarty->assign($attrs."CHK", " checked ");
805 }else{
806 $smarty->assign($attrs."CHK", " ");
807 }
808 }
810 /* Assign all reguired vars to template engine */
812 $branches = $this->getBranches();
813 asort($branches);
814 $smarty->assign("branchKeys",array_flip($branches));
815 $smarty->assign("branches",$branches);
817 $smarty->assign("faihead" , $faihead);
818 $smarty->assign("failist" , $divlist->DrawList());
819 $smarty->assign("regex" , $faifilter['regex']);
820 $smarty->assign("infoimage" , get_template_path('images/info.png'));
821 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
822 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
823 $smarty->assign("alphabet" , generate_alphabet());
824 $smarty->assign("apply" , apply_filter());
825 $smarty->assign("search_image" , get_template_path('images/search.png'));
826 $smarty->assign("hint", print_sizelimit_warning());
828 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
829 return ($display);
830 }
832 function getBranches($base = false,$prefix = "")
833 {
834 $ret = array("main"=>"/");
835 $ldap = $this->config->get_ldap_link();
837 $ldap->cd($this->config->current['BASE']);
839 $faifilter = $_SESSION['faifilter'];
842 if(!$base){
843 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
844 }
845 $ldap->cd($base);
846 $ldap->ls("(objectClass=FAIbranch)",$base);
848 while($attrs = $ldap->fetch()){
850 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
851 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
852 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
853 }
854 }
855 return($ret);
856 }
858 function reload()
859 {
860 /* Create a new list of FAI object
861 * Object list depends on faifilter['regex']
862 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
863 */
864 $faifilter= get_global('faifilter');
865 // Added for dirlist function...
867 /* Set base for all searches */
868 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
870 if($faifilter['branch'] !="main"){
871 $base = $faifilter['branch'];
872 }
874 $regex = $faifilter['regex'];
876 /* Array to save objects */
877 $objects = array();
879 $this->objects=array();
881 /* NEW LIST MANAGMENT
882 * We also need to search for the departments
883 * So we are able to navigate like in konquerer
884 */
885 $base2 = $faifilter['base'];
887 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
888 TRUE, $base2, array("ou", "description"), TRUE);
890 $this->departments= array();
891 $tmp = array();
892 foreach ($res3 as $value){
893 $tmp[strtolower($value['dn']).$value['dn']]=$value;
894 }
895 ksort($tmp);
896 foreach($tmp as $value){
897 if(isset($value["description"][0])){
898 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
899 }else{
900 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
901 }
902 }
904 /* END NEW LIST MANAGMENT
905 */
908 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
909 FALSE, $base, array("cn","description","objectClass"),TRUE);
911 $str = "";
913 foreach($res as $objecttypes){
914 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
915 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
916 foreach($res2 as $object){
917 $type= "";
918 unset($object['objectClass']['count']);
919 if(!isset($object['description'][0])){
920 $object['description'][0]="";
921 }
923 /* Clean up object informations */
924 $obj['cn'] = $object['cn'][0];
925 $obj['dn'] = $object['dn'];
926 $obj['description'] = $object['description'][0];
927 $obj['objectClass'] = $object['objectClass'];
929 if(isset($object['FAIstate'])){
930 $obj['FAIstate'] = $object['FAIstate'][0];
932 /* Append type to this string, to be able to check if the selected
933 * entry is of type 'freeze' or 'branch'
934 */
935 $str.="|".$obj['FAIstate'];
936 }else{
937 $obj['FAIstate'] ="";
938 }
940 if(in_array("FAIpartitionTable",$obj['objectClass'])){
941 $type = "FAIpartitionTable";
942 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
943 $type = "FAIpackageList";
944 }elseif(in_array("FAIscript",$obj['objectClass'])){
945 $type = "FAIscript";
946 }elseif(in_array("FAIvariable",$obj['objectClass'])){
947 $type = "FAIvariable";
948 }elseif(in_array("FAIhook",$obj['objectClass'])){
949 $type = "FAIhook";
950 }elseif(in_array("FAIprofile",$obj['objectClass'])){
951 $obj['FAIclass'] = $object['FAIclass'][0];
952 $type = "FAIprofile";
953 }elseif(in_array("FAItemplate",$obj['objectClass'])){
954 $type = "FAItemplate";
955 }
956 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
957 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
959 }
960 }
962 /* Tell class what we have currently opened
963 'main' has type ''
964 */
965 if(preg_match("/freeze/",$str)){
966 $this->lock_type = "freeze";
967 }elseif(preg_match("/branch/",$str)){
968 $this->lock_type = "branch";
969 }else{
970 $this->lock_type = "";
971 }
973 ksort($this->objects);
974 reset ($this->objects);
976 /* use numeric index, thats a bit more secure */
977 $tmp0 = array();
978 foreach($this->objects as $obj){
979 $tmp0[]= $obj;
980 }
981 $this->objects = array();
982 $this->objects = $tmp0;
984 }
986 function remove_lock()
987 {
988 if (isset($this->dn)){
989 del_lock ($this->dn);
990 }
991 }
993 function get_type($array){
994 if(in_array("FAIpartitionTable",$array['objectClass'])){
995 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
996 }
997 if(in_array("FAIscript",$array['objectClass'])){
998 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
999 }
1000 if(in_array("FAItemplate",$array['objectClass'])){
1001 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1002 }
1003 if(in_array("FAIhook",$array['objectClass'])){
1004 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1005 }
1006 if(in_array("FAIvariable",$array['objectClass'])){
1007 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1008 }
1009 if(in_array("FAIprofile",$array['objectClass'])){
1010 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1011 }
1013 if(in_array("FAIpackageList",$array['objectClass'])){
1014 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1015 }
1016 }
1018 function CheckNewBranchName($name,$base){
1019 $f = $_SESSION['faifilter']['branch'];
1021 if($f == "main"){
1022 $f = $_SESSION['faifilter']['base'];
1023 }
1025 if(in_array($name,$this->getBranches($f))) {
1026 return(false);
1027 }
1029 if(empty($name)){
1030 return(false);
1031 }
1033 if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles"))){
1034 return(false);
1035 }
1037 return(true);
1038 }
1040 }
1041 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1042 ?>