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']=(preg_replace("/^[^,]+,/","",$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 $entry = $this->objects[$s_entry];
285 $a_setup = ($this->get_type($entry));
287 $this->dn = $entry['dn'];
288 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
289 if (($user= get_lock($this->dn)) != ""){
290 return(gen_locked_message ($user, $this->dn));
291 }
292 add_lock ($this->dn, $this->ui->dn);
294 $this->dialog= new $a_setup[0]($this->config,
295 $this->config->data['TABS'][$a_setup[2]],$this->dn);
296 $this->is_dialog = true;
297 $_SESSION['objectinfo'] = $this->dn;
298 }
301 /* Branch handling
302 09.01.2006
303 */
305 /* Create new branch */
306 if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
308 /* Check branch name */
309 $name = $_POST['BranchName'];
310 $is_ok = true;
312 $smarty->assign("BranchName",$name);
313 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
315 /* Check used characters */
316 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
317 print_red(_("Specified branch name is invalid."));
318 $is_ok = false;
319 }
321 /* Check if this name is already in use */
322 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
323 print_red(_("This name is already in use."));
324 $is_ok = false;
325 }
327 if($is_ok){
328 /* Create it know */
329 $ldap = $this->config->get_ldap_link();
331 $baseToUse = $base;
332 if($_SESSION['faifilter']['branch']!="main"){
333 $baseToUse = $_SESSION['faifilter']['branch'];
334 }
336 $ldap->cd($this->config->current['BASE']);
337 $ldap->create_missing_trees($baseToUse);
338 $ldap->cd ("ou=".$name.",".$baseToUse);
339 $ldap->recursive_remove();
341 $ldap->cd ($this->config->current['BASE']);
342 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
344 /* Postcreate */
346 /* Assign possible attributes */
347 $this->lock_type = "branch";
348 $this->lock_name = $name;
349 $this->lock_dn = $baseToUse;
350 $this->postcreate();
351 $this->dispNewBranch = false;
352 }
353 }
355 /* Abort creating new branch */
356 if(isset($_POST['CancelBranchName'])){
357 $this->dispNewBranch = false;
358 $this->dispNewFreeze = false;
359 }
361 /* Open dialog to insert new branch name */
362 if(($s_action == "branch_branch")||($this->dispNewBranch)){
363 $this->dispNewBranch=true;
364 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
365 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
366 return($display);
367 }
369 /* Remove branch */
370 if($s_action == "remove_branch"){
371 $base= $faifilter['branch'];
372 /* Load permissions for selected 'dn' and check if
373 we're allowed to remove this 'dn' */
374 $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
375 $this->acl= get_module_permission($acl, "FAIclass", $base);
376 if (chkacl($this->acl, "delete") == ""){
377 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
378 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
379 } else {
380 print_red (_("You are not allowed to delete this release!"));
381 }
382 }
384 /* Delete this entry */
385 if(isset($_POST['delete_branch_confirm'])){
386 $bb = $faifilter['branch'];
387 if(!isset($ldap)){
388 $ldap = $this->config->get_ldap_link();
389 }
391 $br = $this->getBranches();
393 if(isset($br[$bb])){
395 $name = $br[$bb];
397 $ldap->cd($bb);
398 $ldap->recursive_remove();
399 $faifilter['branch'] = "main";
401 /* Post remove */
403 // $this->lock_type is set from this->reload
404 $this->lock_name = $name;
405 $this->lock_dn = $bb;
407 $this->postremove();
408 }
409 }
412 if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
413 /* Check branch name */
414 $name = $_POST['BranchName'];
415 $is_ok = true;
417 $smarty->assign("BranchName",$name);
419 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
421 /* Check used characters */
422 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
423 print_red(_("Specified branch name is invalid."));
424 $is_ok = false;
425 }
427 /* Check if this name is already in use */
428 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
429 print_red(_("This name is already in use."));
430 $is_ok = false;
431 }
433 if($is_ok){
434 /* Create it know */
435 $ldap = $this->config->get_ldap_link();
437 $baseToUse = $base;
438 if($_SESSION['faifilter']['branch']!="main"){
439 $baseToUse = $_SESSION['faifilter']['branch'];
440 }
442 $ldap->cd ("ou=".$name.",".$baseToUse);
443 $ldap->recursive_remove();
445 $ldap->cd ($this->config->current['BASE']);
446 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
448 $this->dispNewFreeze = false;
450 /* Postcreate */
452 /* Assign possible attributes */
453 $this->lock_type = "branch";
454 $this->lock_name = $name;
455 $this->lock_dn = $baseToUse;
456 $this->postcreate();
457 }
458 }
460 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
461 $this->dispNewFreeze = true;
462 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
463 return($display);
464 }
466 /* ENDE Branch handling
467 */
469 /* Dialog handling */
470 if($s_action == "new_partition"){
471 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
472 }
474 /* Dialog handling */
475 if($s_action == "new_script"){
476 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
477 }
479 /* Dialog handling */
480 if($s_action == "new_hook"){
481 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
482 }
484 /* Dialog handling */
485 if($s_action == "new_variable"){
486 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
487 }
489 /* Dialog handling */
490 if($s_action == "new_template"){
491 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
492 }
494 /* Dialog handling */
495 if($s_action == "new_package"){
496 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
497 }
499 /* New Profile */
500 if($s_action == "new_profile"){
501 $this->dn = "new" ;
502 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
504 $this->dialog = new $a_setup[0]($this->config,
505 $this->config->data['TABS'][$a_setup[2]],$this->dn);
506 $this->is_dialog = true;
508 }
510 if($s_action == "select_class_name_finished"){
511 $this->dialog->save_object();
512 if(count($this->dialog->check())!=0){
513 foreach($this->dialog->check() as $msg){
514 print_red($msg);
515 }
516 }else{
517 $this->dn = "new" ;
518 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
519 $name = $this->dialog->save();
521 $this->dialog = new $a_setup[0]($this->config,
522 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
523 $this->dialog->by_object[$a_setup[1]]->cn = $name;
524 $this->is_dialog = true;
525 }
526 }
528 /* Search is set */
529 if(isset($_GET['search'])){
530 $faifilter['regex']=$_GET['search']."*";
531 }
533 /* Department select */
534 if((isset($_POST['base']))&&($s_action=="")){
535 $faifilter['base']=$_POST['base'];
536 }
538 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
540 $br = $this->getBranches($base);
541 if(!isset($br[$faifilter['branch']])){
542 $faifilter['branch'] = "main";
543 }
545 $smarty->assign("select_branch",$faifilter['branch']);
547 /* remove double asterisks and save new filter */
548 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
549 $_SESSION['faifilter']= $faifilter;
551 /* Edit dialog was canceled
552 * Remove dialog an show management dialog
553 */
554 if(isset($_POST['edit_cancel'])){
555 unset($this->dialog);
556 $this->dialog=NULL;
557 $this->is_dialog = false;
558 unset($_SESSION['objectinfo']);
559 del_lock ($this->dn);
560 }
562 /* This check if the given tab could be saved
563 * If it was possible to save it, remove dialog object.
564 * If it wasn't possible, show errors and keep dialog.
565 */
566 if(isset($_POST['edit_finish'])){
567 $this->dialog->save_object();
568 if(count($this->dialog->check())!=0){
569 foreach($this->dialog->check() as $msg){
570 print_red($msg);
571 }
572 }else{
573 del_lock ($this->dn);
574 $this->dialog->save();
575 unset($this->dialog);
576 $this->dialog=NULL;
577 $this->is_dialog=false;
578 unset($_SESSION['objectinfo']);
579 }
580 }
582 /* If dialog is set, but $this->is_dialog==false, then
583 * only the "abort" button is shown, this are dialogs that must not be saved.
584 * If is_dialog == true, we are currently editing tab objects.
585 * Here we need both, save and cancel
586 */
588 if($this->dialog != NULL){
589 $display .= $this->dialog->execute();
590 /* Don't show buttons if tab dialog requests this */
591 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
593 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
594 $display.= "<p style=\"text-align:right\">\n";
595 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
596 $display.= " \n";
597 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
598 $display.= "</p>";
599 }elseif(!isset($this->dialog->current)){
600 $display.= "<p style=\"text-align:right\">\n";
601 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
602 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
603 $display.= "</p>";
604 }
605 return($display);
606 }
608 /* Show Management template
609 * The following code will only be reached if no dialog (tabs or dialogs)
610 * are currently opened.
611 * Assign all reguired vars to template engine
612 */
614 /* Prepare departments */
615 $options= "";
616 foreach ($this->config->idepartments as $key => $value){
617 if ($faifilter['base'] == $key){
618 $options.= "<option selected='selected' value='$key'>$value</option>";
619 } else {
620 $options.= "<option value='$key'>$value</option>";
621 }
622 }
624 /* Create listhead, it will be shown on top of the divlist.
625 * It provides general navigation and object creation
626 */
627 $faihead =
628 "<div style='background:#F0F0F9;padding:5px;'> ".
630 "<input class='center' type='image' src='images/list_up.png' align='middle'
631 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
633 "<input class='center' type='image' src='images/list_root.png' align='middle'
634 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
636 "<input class='center' type='image' src='images/list_home.png' align='middle'
637 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
639 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
641 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
642 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
644 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
646 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
647 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
649 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
650 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
652 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
653 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
655 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
656 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
658 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
659 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
661 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
662 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
664 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
666 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
667 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
669 "</div>";
671 $this->reload();
673 /* Create list with objects */
674 $divlist = new divlist("faiManagement");
675 $divlist->SetEntriesPerPage(0);
676 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
678 $divlist->SetHeader(array(
679 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
680 array("string" => _("Name of FAI class"), "attach" => "style=''"),
681 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
682 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
685 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
686 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
688 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
689 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
691 foreach($this->departments as $key => $val) {
692 if(!isset($this->config->departments[trim($key)])){
693 $this->config->departments[trim($key)]="";
694 }
696 $non_empty="";
697 $keys= str_replace("/","\/",$key);
698 foreach($this->config->departments as $keyd=>$vald ){
699 if(preg_match("/".$keys."\/.*/",$keyd)){
700 $non_empty="full";
701 }
702 }
705 $title = $this->config->departments[$key];
706 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
707 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
708 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
709 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
711 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
713 }
715 /* Attach objects */
716 foreach($this->objects as $key => $value){
717 $info= "";
718 $img = "";
719 $type = $value['type'];
720 $abort=false;
722 switch($type) {
723 case "FAIpartitionTable" :
724 if(!$faifilter['ShowPartitions']){
725 $abort = true;
726 }
727 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
728 $info = _("Partition table");
729 break;
730 case "FAIpackageList" :
731 if(!$faifilter['ShowPackages']){
732 $abort = true;
733 }
734 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
735 $info = _("Package list");
736 break;
737 case "FAIscript" :
738 if(!$faifilter['ShowScripts']){
739 $abort = true;
740 }
741 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
742 $info = _("Scripts");
743 break;
744 case "FAIvariable" :
745 if(!$faifilter['ShowVariables']){
746 $abort = true;
747 }
748 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
749 $info = _("Variables");
750 break;
751 case "FAIhook" :
752 if(!$faifilter['ShowHooks']){
753 $abort = true;
754 }
755 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
756 $info = _("Hooks");
757 break;
758 case "FAIprofile" :
759 if(!$faifilter['ShowProfiles']){
760 $abort = true;
761 }
762 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
763 $info = _("Profile");
764 break;
765 case "FAItemplate" :
766 if(!$faifilter['ShowTemplates']){
767 $abort = true;
768 }
769 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
770 $info = _("Templates");
771 break;
772 default :
773 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
775 }
777 if(!$abort) {
778 if((isset($value['description']))&&(!empty($value['description']))){
779 $desc= " [".$value['description']."]";
780 }else{
781 $desc= "";
782 }
784 if($value['FAIstate'] == "freeze"){
785 $acti = "";
786 $edi = "%NAME%";
787 }else{
788 $acti = $action;
789 $edi = $editlink;
790 }
792 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
793 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
794 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
795 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
796 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
798 }
799 }
801 foreach($faifilter as $attrs => $value){
802 if($value){
803 $smarty->assign($attrs."CHK", " checked ");
804 }else{
805 $smarty->assign($attrs."CHK", " ");
806 }
807 }
809 /* Assign all reguired vars to template engine */
811 $branches = $this->getBranches();
812 asort($branches);
813 $smarty->assign("branchKeys",array_flip($branches));
814 $smarty->assign("branches",$branches);
816 $smarty->assign("faihead" , $faihead);
817 $smarty->assign("failist" , $divlist->DrawList());
818 $smarty->assign("regex" , $faifilter['regex']);
819 $smarty->assign("infoimage" , get_template_path('images/info.png'));
820 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
821 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
822 $smarty->assign("alphabet" , generate_alphabet());
823 $smarty->assign("apply" , apply_filter());
824 $smarty->assign("search_image" , get_template_path('images/search.png'));
825 $smarty->assign("hint", print_sizelimit_warning());
827 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
828 return ($display);
829 }
831 function getBranches($base = false,$prefix = "")
832 {
833 $ret = array("main"=>"/");
834 $ldap = $this->config->get_ldap_link();
836 $ldap->cd($this->config->current['BASE']);
838 $faifilter = $_SESSION['faifilter'];
841 if(!$base){
842 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
843 }
844 $ldap->cd($base);
845 $ldap->ls("(objectClass=FAIbranch)",$base);
847 while($attrs = $ldap->fetch()){
849 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
850 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
851 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
852 }
853 }
854 return($ret);
855 }
857 function reload()
858 {
859 /* Create a new list of FAI object
860 * Object list depends on faifilter['regex']
861 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
862 */
863 $faifilter= get_global('faifilter');
864 // Added for dirlist function...
866 /* Set base for all searches */
867 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
869 if($faifilter['branch'] !="main"){
870 $base = $faifilter['branch'];
871 }
873 $regex = $faifilter['regex'];
875 /* Array to save objects */
876 $objects = array();
878 $this->objects=array();
880 /* NEW LIST MANAGMENT
881 * We also need to search for the departments
882 * So we are able to navigate like in konquerer
883 */
884 $base2 = $faifilter['base'];
886 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
887 TRUE, $base2, array("ou", "description"), TRUE);
889 $this->departments= array();
890 $tmp = array();
891 foreach ($res3 as $value){
892 $tmp[strtolower($value['dn']).$value['dn']]=$value;
893 }
894 ksort($tmp);
895 foreach($tmp as $value){
896 if(isset($value["description"][0])){
897 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
898 }else{
899 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
900 }
901 }
903 /* END NEW LIST MANAGMENT
904 */
907 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
908 FALSE, $base, array("cn","description","objectClass"),TRUE);
910 $str = "";
912 foreach($res as $objecttypes){
913 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
914 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
915 foreach($res2 as $object){
916 $type= "";
917 unset($object['objectClass']['count']);
918 if(!isset($object['description'][0])){
919 $object['description'][0]="";
920 }
922 /* Clean up object informations */
923 $obj['cn'] = $object['cn'][0];
924 $obj['dn'] = $object['dn'];
925 $obj['description'] = $object['description'][0];
926 $obj['objectClass'] = $object['objectClass'];
928 if(isset($object['FAIstate'])){
929 $obj['FAIstate'] = $object['FAIstate'][0];
931 /* Append type to this string, to be able to check if the selected
932 * entry is of type 'freeze' or 'branch'
933 */
934 $str.="|".$obj['FAIstate'];
935 }else{
936 $obj['FAIstate'] ="";
937 }
939 if(in_array("FAIpartitionTable",$obj['objectClass'])){
940 $type = "FAIpartitionTable";
941 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
942 $type = "FAIpackageList";
943 }elseif(in_array("FAIscript",$obj['objectClass'])){
944 $type = "FAIscript";
945 }elseif(in_array("FAIvariable",$obj['objectClass'])){
946 $type = "FAIvariable";
947 }elseif(in_array("FAIhook",$obj['objectClass'])){
948 $type = "FAIhook";
949 }elseif(in_array("FAIprofile",$obj['objectClass'])){
950 $obj['FAIclass'] = $object['FAIclass'][0];
951 $type = "FAIprofile";
952 }elseif(in_array("FAItemplate",$obj['objectClass'])){
953 $type = "FAItemplate";
954 }
955 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
956 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
958 }
959 }
961 /* Tell class what we have currently opened
962 'main' has type ''
963 */
964 if(preg_match("/freeze/",$str)){
965 $this->lock_type = "freeze";
966 }elseif(preg_match("/branch/",$str)){
967 $this->lock_type = "branch";
968 }else{
969 $this->lock_type = "";
970 }
972 ksort($this->objects);
973 reset ($this->objects);
975 /* use numeric index, thats a bit more secure */
976 $tmp0 = array();
977 foreach($this->objects as $obj){
978 $tmp0[]= $obj;
979 }
980 $this->objects = array();
981 $this->objects = $tmp0;
983 }
985 function remove_lock()
986 {
987 if (isset($this->dn)){
988 del_lock ($this->dn);
989 }
990 }
992 function get_type($array){
993 if(in_array("FAIpartitionTable",$array['objectClass'])){
994 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
995 }
996 if(in_array("FAIscript",$array['objectClass'])){
997 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
998 }
999 if(in_array("FAItemplate",$array['objectClass'])){
1000 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1001 }
1002 if(in_array("FAIhook",$array['objectClass'])){
1003 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1004 }
1005 if(in_array("FAIvariable",$array['objectClass'])){
1006 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1007 }
1008 if(in_array("FAIprofile",$array['objectClass'])){
1009 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1010 }
1012 if(in_array("FAIpackageList",$array['objectClass'])){
1013 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1014 }
1015 }
1017 function CheckNewBranchName($name,$base){
1018 $f = $_SESSION['faifilter']['branch'];
1020 if($f == "main"){
1021 $f = $_SESSION['faifilter']['base'];
1022 }
1024 if(in_array($name,$this->getBranches($f))) {
1025 return(false);
1026 }
1028 if(empty($name)){
1029 return(false);
1030 }
1032 if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles"))){
1033 return(false);
1034 }
1036 return(true);
1037 }
1039 }
1040 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1041 ?>