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 /* Abort creating new branch
307 */
308 if(isset($_POST['CancelBranchName'])){
309 $this->dispNewBranch = false;
310 $this->dispNewFreeze = false;
311 }
313 /* Remove branch
314 */
315 if($s_action == "remove_branch"){
316 $base= $faifilter['branch'];
317 /* Load permissions for selected 'dn' and check if
318 we're allowed to remove this 'dn' */
319 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
320 $this->acl= get_module_permission($acl, "FAIclass", $base);
321 if (chkacl($this->acl, "delete") == ""){
322 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
323 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
324 } else {
325 print_red (_("You are not allowed to delete this release!"));
326 }
327 }
329 /* Delete this entry
330 */
331 if(isset($_POST['delete_branch_confirm'])){
332 $bb = $faifilter['branch'];
333 if(!isset($ldap)){
334 $ldap = $this->config->get_ldap_link();
335 }
337 $br = $this->getBranches();
339 if(isset($br[$bb])){
341 $name = $br[$bb];
343 $ldap->cd($bb);
344 $ldap->recursive_remove();
345 $faifilter['branch'] = "main";
347 /* Post remove */
349 // $this->lock_type is set from this->reload
350 $this->lock_name = $name;
351 $this->lock_dn = $bb;
353 $this->postremove();
354 }
355 }
357 /* Open dialog to insert new branch name
358 */
360 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
361 $_SESSION['LASTPOST'] = $_POST;
363 if($this->dispNewBranch){
364 $type = "branch";
365 }else{
366 $type = "freeze";
367 }
369 /* Check branch name */
370 $name = $_POST['BranchName'];
371 $is_ok = true;
373 $smarty->assign("BranchName",$name);
375 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
377 /* Check used characters */
378 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
379 if($type == "branch"){
380 print_red(_("Specified branch name is invalid."));
381 }else{
382 print_red(_("Specified freeze name is invalid."));
383 }
384 $is_ok = false;
385 }
387 /* Check if this name is already in use */
388 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
389 print_red(_("This name is already in use."));
390 $is_ok = false;
391 }
393 if($is_ok){
394 $_SESSION['LASTPOST']['base'] = $base;
395 $_SESSION['LASTPOST']['type'] = $type;
396 $smarty->assign("iframe", true);
397 $smarty->assign("plugID", $_GET['plug']);
398 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
399 return($display);
400 }
401 }
403 if(isset($_GET['PerformBranch'])){
404 /* Create it know */
405 $this->dispNewBranch = false;
406 $this->dispNewFreeze = false;
407 $base = $_SESSION['LASTPOST']['base'];
408 $_POST = $_SESSION['LASTPOST'];
409 $name = $_POST['BranchName'];
411 $type = $_SESSION['LASTPOST']['type'];
413 $ldap = $this->config->get_ldap_link();
415 $baseToUse = $base;
416 if($_SESSION['faifilter']['branch']!="main"){
417 $baseToUse = $_SESSION['faifilter']['branch'];
418 }
420 $ldap->cd ("ou=".$name.",".$baseToUse);
421 $ldap->recursive_remove();
423 $ldap->cd ($this->config->current['BASE']);
424 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true);
426 $this->dispNewFreeze = false;
428 /* Postcreate */
430 /* Assign possible attributes */
431 $this->lock_type = $type;
432 $this->lock_name = $name;
433 $this->lock_dn = $baseToUse;
434 $this->postcreate();
435 exit();
436 }
438 if(($s_action == "branch_branch")||($this->dispNewBranch)){
439 $this->dispNewBranch=true;
440 $smarty->assign("iframe",false);
441 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
442 return($display);
443 }
445 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
446 $this->dispNewFreeze = true;
447 $smarty->assign("iframe",false);
448 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
449 return($display);
450 }
452 /* ENDE Branch handling
453 */
455 /* Dialog handling */
456 if($s_action == "new_partition"){
457 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
458 }
460 /* Dialog handling */
461 if($s_action == "new_script"){
462 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
463 }
465 /* Dialog handling */
466 if($s_action == "new_hook"){
467 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
468 }
470 /* Dialog handling */
471 if($s_action == "new_variable"){
472 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
473 }
475 /* Dialog handling */
476 if($s_action == "new_template"){
477 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
478 }
480 /* Dialog handling */
481 if($s_action == "new_package"){
482 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
483 }
485 /* New Profile */
486 if($s_action == "new_profile"){
487 $this->dn = "new" ;
488 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
490 $this->dialog = new $a_setup[0]($this->config,
491 $this->config->data['TABS'][$a_setup[2]],$this->dn);
492 $this->is_dialog = true;
494 }
496 if($s_action == "select_class_name_finished"){
497 $this->dialog->save_object();
498 if(count($this->dialog->check())!=0){
499 foreach($this->dialog->check() as $msg){
500 print_red($msg);
501 }
502 }else{
503 $this->dn = "new" ;
504 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
505 $name = $this->dialog->save();
507 $this->dialog = new $a_setup[0]($this->config,
508 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
509 $this->dialog->by_object[$a_setup[1]]->cn = $name;
510 $this->is_dialog = true;
511 }
512 }
514 /* Search is set */
515 if(isset($_GET['search'])){
516 $faifilter['regex']=$_GET['search']."*";
517 }
519 /* Department select */
520 if((isset($_POST['base']))&&($s_action=="")){
521 $faifilter['base']=$_POST['base'];
522 }
524 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
526 $br = $this->getBranches($base);
527 if(!isset($br[$faifilter['branch']])){
528 $faifilter['branch'] = "main";
529 }
531 $smarty->assign("select_branch",$faifilter['branch']);
533 /* remove double asterisks and save new filter */
534 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
535 $_SESSION['faifilter']= $faifilter;
537 /* Edit dialog was canceled
538 * Remove dialog an show management dialog
539 */
540 if(isset($_POST['edit_cancel'])){
541 unset($this->dialog);
542 $this->dialog=NULL;
543 $this->is_dialog = false;
544 unset($_SESSION['objectinfo']);
545 del_lock ($this->dn);
546 }
548 /* This check if the given tab could be saved
549 * If it was possible to save it, remove dialog object.
550 * If it wasn't possible, show errors and keep dialog.
551 */
552 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
553 $this->dialog->save_object();
554 if(count($this->dialog->check())!=0){
555 foreach($this->dialog->check() as $msg){
556 print_red($msg);
557 }
558 }else{
559 del_lock ($this->dn);
560 $this->dialog->save();
561 unset($this->dialog);
562 $this->dialog=NULL;
563 $this->is_dialog=false;
564 unset($_SESSION['objectinfo']);
565 }
566 }
568 /* If dialog is set, but $this->is_dialog==false, then
569 * only the "abort" button is shown, this are dialogs that must not be saved.
570 * If is_dialog == true, we are currently editing tab objects.
571 * Here we need both, save and cancel
572 */
574 if(($this->dialog != NULL) && (isset($this->dialog->config))){
575 $display .= $this->dialog->execute();
576 /* Don't show buttons if tab dialog requests this */
577 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
579 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
580 $display.= "<p style=\"text-align:right\">\n";
581 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
582 $display.= " \n";
583 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
584 $display.= "</p>";
585 }elseif(!isset($this->dialog->current)){
586 $display.= "<p style=\"text-align:right\">\n";
587 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
588 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
589 $display.= "</p>";
590 }
591 return($display);
592 }
594 /* Show Management template
595 * The following code will only be reached if no dialog (tabs or dialogs)
596 * are currently opened.
597 * Assign all reguired vars to template engine
598 */
600 /* Prepare departments */
601 $options= "";
602 foreach ($this->config->idepartments as $key => $value){
603 if ($faifilter['base'] == $key){
604 $options.= "<option selected='selected' value='$key'>$value</option>";
605 } else {
606 $options.= "<option value='$key'>$value</option>";
607 }
608 }
610 /* Create listhead, it will be shown on top of the divlist.
611 * It provides general navigation and object creation
612 */
613 $faihead =
614 "<div style='background:#F0F0F9;padding:5px;'> ".
616 "<input class='center' type='image' src='images/list_up.png' align='middle'
617 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
619 "<input class='center' type='image' src='images/list_root.png' align='middle'
620 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
622 "<input class='center' type='image' src='images/list_home.png' align='middle'
623 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
625 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
627 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
628 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
630 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
632 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
633 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
635 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
636 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
638 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
639 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
641 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
642 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
644 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
645 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
647 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
648 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
650 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
652 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
653 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
655 "</div>";
657 $this->reload();
659 /* Create list with objects */
660 $divlist = new divlist("faiManagement");
661 $divlist->SetEntriesPerPage(0);
662 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
664 $divlist->SetHeader(array(
665 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
666 array("string" => _("Name of FAI class"), "attach" => "style=''"),
667 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
668 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
671 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
672 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
674 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
675 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
677 foreach($this->departments as $key => $val) {
678 if(!isset($this->config->departments[trim($key)])){
679 $this->config->departments[trim($key)]="";
680 }
682 $non_empty="";
683 $keys= str_replace("/","\/",$key);
684 foreach($this->config->departments as $keyd=>$vald ){
685 if(preg_match("/".$keys."\/.*/",$keyd)){
686 $non_empty="full";
687 }
688 }
691 $title = $this->config->departments[$key];
692 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
693 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
694 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
695 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
697 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
699 }
701 /* Attach objects */
702 foreach($this->objects as $key => $value){
703 $info= "";
704 $img = "";
705 $type = $value['type'];
706 $abort=false;
708 switch($type) {
709 case "FAIpartitionTable" :
710 if(!$faifilter['ShowPartitions']){
711 $abort = true;
712 }
713 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
714 $info = _("Partition table");
715 break;
716 case "FAIpackageList" :
717 if(!$faifilter['ShowPackages']){
718 $abort = true;
719 }
720 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
721 $info = _("Package list");
722 break;
723 case "FAIscript" :
724 if(!$faifilter['ShowScripts']){
725 $abort = true;
726 }
727 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
728 $info = _("Scripts");
729 break;
730 case "FAIvariable" :
731 if(!$faifilter['ShowVariables']){
732 $abort = true;
733 }
734 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
735 $info = _("Variables");
736 break;
737 case "FAIhook" :
738 if(!$faifilter['ShowHooks']){
739 $abort = true;
740 }
741 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
742 $info = _("Hooks");
743 break;
744 case "FAIprofile" :
745 if(!$faifilter['ShowProfiles']){
746 $abort = true;
747 }
748 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
749 $info = _("Profile");
750 break;
751 case "FAItemplate" :
752 if(!$faifilter['ShowTemplates']){
753 $abort = true;
754 }
755 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
756 $info = _("Templates");
757 break;
758 default :
759 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
761 }
763 if(!$abort) {
764 if((isset($value['description']))&&(!empty($value['description']))){
765 $desc= " [".$value['description']."]";
766 }else{
767 $desc= "";
768 }
770 if($value['FAIstate'] == "freeze"){
771 $acti = "";
772 $edi = "%NAME%";
773 }else{
774 $acti = $action;
775 $edi = $editlink;
776 }
778 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
779 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
780 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
781 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
782 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
784 }
785 }
787 foreach($faifilter as $attrs => $value){
788 if($value){
789 $smarty->assign($attrs."CHK", " checked ");
790 }else{
791 $smarty->assign($attrs."CHK", " ");
792 }
793 }
795 /* Assign all reguired vars to template engine */
797 $branches = $this->getBranches();
798 asort($branches);
799 $smarty->assign("branchKeys",array_flip($branches));
800 $smarty->assign("branches",$branches);
802 $smarty->assign("faihead" , $faihead);
803 $smarty->assign("failist" , $divlist->DrawList());
804 $smarty->assign("regex" , $faifilter['regex']);
805 $smarty->assign("infoimage" , get_template_path('images/info.png'));
806 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
807 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
808 $smarty->assign("alphabet" , generate_alphabet());
809 $smarty->assign("apply" , apply_filter());
810 $smarty->assign("search_image" , get_template_path('images/search.png'));
811 $smarty->assign("hint", print_sizelimit_warning());
813 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
814 return ($display);
815 }
817 function getBranches($base = false,$prefix = "")
818 {
819 $ret = array("main"=>"/");
820 $ldap = $this->config->get_ldap_link();
822 $ldap->cd($this->config->current['BASE']);
824 $faifilter = $_SESSION['faifilter'];
827 if(!$base){
828 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
829 }
830 $ldap->cd($base);
831 $ldap->ls("(objectClass=FAIbranch)",$base);
833 while($attrs = $ldap->fetch()){
835 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
836 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
837 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
838 }
839 }
840 return($ret);
841 }
843 function reload()
844 {
845 /* Create a new list of FAI object
846 * Object list depends on faifilter['regex']
847 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
848 */
849 $faifilter= get_global('faifilter');
850 // Added for dirlist function...
852 /* Set base for all searches */
853 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
855 if($faifilter['branch'] !="main"){
856 $base = $faifilter['branch'];
857 }
859 $regex = $faifilter['regex'];
861 /* Array to save objects */
862 $objects = array();
864 $this->objects=array();
866 /* NEW LIST MANAGMENT
867 * We also need to search for the departments
868 * So we are able to navigate like in konquerer
869 */
870 $base2 = $faifilter['base'];
872 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
873 TRUE, $base2, array("ou", "description"), TRUE);
875 $this->departments= array();
876 $tmp = array();
877 foreach ($res3 as $value){
878 $tmp[strtolower($value['dn']).$value['dn']]=$value;
879 }
880 ksort($tmp);
881 foreach($tmp as $value){
882 if(isset($value["description"][0])){
883 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
884 }else{
885 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
886 }
887 }
889 /* END NEW LIST MANAGMENT
890 */
893 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
894 FALSE, $base, array("cn","description","objectClass"),TRUE);
896 $str = "";
898 foreach($res as $objecttypes){
899 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
900 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
901 foreach($res2 as $object){
902 $type= "";
903 unset($object['objectClass']['count']);
904 if(!isset($object['description'][0])){
905 $object['description'][0]="";
906 }
908 /* Clean up object informations */
909 $obj['cn'] = $object['cn'][0];
910 $obj['dn'] = $object['dn'];
911 $obj['description'] = $object['description'][0];
912 $obj['objectClass'] = $object['objectClass'];
914 if(isset($object['FAIstate'])){
915 $obj['FAIstate'] = $object['FAIstate'][0];
917 /* Append type to this string, to be able to check if the selected
918 * entry is of type 'freeze' or 'branch'
919 */
920 $str.="|".$obj['FAIstate'];
921 }else{
922 $obj['FAIstate'] ="";
923 }
925 if(in_array("FAIpartitionTable",$obj['objectClass'])){
926 $type = "FAIpartitionTable";
927 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
928 $type = "FAIpackageList";
929 }elseif(in_array("FAIscript",$obj['objectClass'])){
930 $type = "FAIscript";
931 }elseif(in_array("FAIvariable",$obj['objectClass'])){
932 $type = "FAIvariable";
933 }elseif(in_array("FAIhook",$obj['objectClass'])){
934 $type = "FAIhook";
935 }elseif(in_array("FAIprofile",$obj['objectClass'])){
936 $obj['FAIclass'] = $object['FAIclass'][0];
937 $type = "FAIprofile";
938 }elseif(in_array("FAItemplate",$obj['objectClass'])){
939 $type = "FAItemplate";
940 }
941 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
942 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
944 }
945 }
947 /* Tell class what we have currently opened
948 'main' has type ''
949 */
950 if(preg_match("/freeze/",$str)){
951 $this->lock_type = "freeze";
952 }elseif(preg_match("/branch/",$str)){
953 $this->lock_type = "branch";
954 }else{
955 $this->lock_type = "";
956 }
958 ksort($this->objects);
959 reset ($this->objects);
961 /* use numeric index, thats a bit more secure */
962 $tmp0 = array();
963 foreach($this->objects as $obj){
964 $tmp0[]= $obj;
965 }
966 $this->objects = array();
967 $this->objects = $tmp0;
969 }
971 function remove_lock()
972 {
973 if (isset($this->dn)){
974 del_lock ($this->dn);
975 }
976 }
978 function get_type($array){
979 if(in_array("FAIpartitionTable",$array['objectClass'])){
980 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
981 }
982 if(in_array("FAIscript",$array['objectClass'])){
983 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
984 }
985 if(in_array("FAItemplate",$array['objectClass'])){
986 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
987 }
988 if(in_array("FAIhook",$array['objectClass'])){
989 return(array("tabsHook","faiHook","FAIHOOKTABS"));
990 }
991 if(in_array("FAIvariable",$array['objectClass'])){
992 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
993 }
994 if(in_array("FAIprofile",$array['objectClass'])){
995 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
996 }
998 if(in_array("FAIpackageList",$array['objectClass'])){
999 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1000 }
1001 }
1003 function CheckNewBranchName($name,$base){
1004 $f = $_SESSION['faifilter']['branch'];
1006 if(empty($name)){
1007 return(false);
1008 }
1010 if($f == "main"){
1011 $f = $_SESSION['faifilter']['base'];
1012 }
1014 if(in_array($name,$this->getBranches($f))) {
1015 return(false);
1016 }
1018 if(empty($name)){
1019 return(false);
1020 }
1022 if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles"))){
1023 return(false);
1024 }
1026 return(true);
1027 }
1029 }
1030 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1031 ?>