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 $faifilter= array(
78 "regex" => "*","branch" => "main");
79 $faifilter['ShowProfiles'] = true;
80 $faifilter['ShowTemplates'] = true;
81 $faifilter['ShowScripts'] = true;
82 $faifilter['ShowHooks'] = true;
83 $faifilter['ShowVariables'] = true;
84 $faifilter['ShowPackages'] = true;
85 $faifilter['ShowPartitions']=true;
86 register_global("faifilter", $faifilter);
87 }
88 }
90 function execute()
91 {
92 /* Call parent execute */
93 plugin::execute();
95 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
97 $display = "";
98 $smarty = get_smarty();
99 $smarty->assign("BranchName","");
100 $s_action = "";
101 $s_entry = "";
102 /* filter management
103 * Filter will be changed if POST['regex'] or $_GET['search'] isset
104 * New Filter will be stored in session and is used to generate list contents
105 */
106 $faifilter = $_SESSION['faifilter'];
108 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
109 $faifilter['branch'] = $_POST['select_branch'];
110 }
112 /* Filter is posted by apply button
113 * Check every single chkbox
114 */
115 if(isset($_POST['regex'])){
116 $faifilter['regex'] = $_POST['regex']."*";
117 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
118 if(isset($_POST[$attrs])){
119 $faifilter[$attrs] = true;
120 }else{
121 $faifilter[$attrs] = false;
122 }
123 }
124 }
127 /* Check ImageButton posts
128 * Create new tab ich new_xx is posted
129 */
130 foreach($_POST as $key => $val){
131 if(preg_match("/remove_branch/",$key)){
132 $s_action = "remove_branch";
133 }elseif(preg_match("/branch_branch/",$key)){
134 $s_action = "branch_branch";
135 }elseif(preg_match("/freeze_branch/",$key)){
136 $s_action = "freeze_branch";
137 }elseif(preg_match("/create_partition/i",$key)){
138 $s_action = "new_partition";
139 }elseif(preg_match("/create_script/i",$key)){
140 $s_action = "new_script";
141 }elseif(preg_match("/create_hook/i",$key)){
142 $s_action = "new_hook";
143 }elseif(preg_match("/create_variable/i",$key)){
144 $s_action = "new_variable";
145 }elseif(preg_match("/create_template/i",$key)){
146 $s_action = "new_template";
147 }elseif(preg_match("/create_package/i",$key)){
148 $s_action = "new_package";
149 }elseif(preg_match("/create_profile/i",$key)){
150 $s_action = "new_profile";
151 }elseif(preg_match("/edit_continue/",$key)){
152 $s_action = "select_class_name_finished";
153 }elseif(preg_match("/^entry_edit_.*/",$key)){
154 $s_entry = preg_replace("/^entry_edit_/","",$key);
155 $s_entry = preg_replace("/_.*$/","",$s_entry);
156 $s_action = "edit";
157 }elseif(preg_match("/^entry_delete_.*/",$key)){
158 $s_entry = preg_replace("/^entry_delete_/","",$key);
159 $s_entry = preg_replace("/_.*$/","",$s_entry);
160 $s_action = "delete";
161 }elseif(preg_match("/dep_back.*/i",$key)){
162 $faifilter['branch'] = "main";
163 $s_action="back";
164 }elseif(preg_match("/dep_home.*/i",$key)){
165 $faifilter['branch'] = "main";
166 $s_action="home";
167 }elseif(preg_match("/dep_root.*/i",$key)){
168 $faifilter['branch'] = "main";
169 $s_action="root";
170 }
172 }
174 if($s_action=="root"){
175 $_SESSION['CurrentMainBase']=($this->config->current['BASE']);
176 }
178 if($s_action=="home"){
179 $_SESSION['CurrentMainBase']= get_base_from_people($this->ui->dn);
180 }
182 if($s_action=="back"){
183 $base_back = preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
184 $base_back = convert_department_dn($base_back);
186 if(isset($this->config->departments[trim($base_back)])){
187 $_SESSION['CurrentMainBase']= $this->config->departments[trim($base_back)];
188 }else{
189 $_SESSION['CurrentMainBase']= $this->config->departments["/"];
190 }
191 }
193 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
194 $s_action="open";
195 $s_entry = base64_decode($_GET['dep_id']);
196 $_SESSION['CurrentMainBase']= $this->config->departments[trim($s_entry)];
197 }
199 if(isset($_GET['edit_entry'])){
200 $s_entry = $_GET['edit_entry'];
201 $s_action = "edit";
202 }
204 /* Confirm dialog
205 * Delte object
206 */
207 if ($s_action=="delete"){
209 /* Get 'dn' from posted termlinst */
210 $this->dn= $this->objects[$s_entry]['dn'];
212 /* Load permissions for selected 'dn' and check if
213 we're allowed to remove this 'dn' */
214 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
215 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
216 if (chkacl($this->acl, "delete") == ""){
218 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
219 if (($user= get_lock($this->dn)) != ""){
220 return(gen_locked_message ($user, $this->dn));
221 }
223 /* Lock the current entry, so nobody will edit it during deletion */
224 add_lock ($this->dn, $this->ui->dn);
225 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
226 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
227 } else {
229 /* Obviously the user isn't allowed to delete. Show message and
230 clean session. */
231 print_red (_("You are not allowed to delete this component!"));
232 }
233 }
235 /* Delete canceled? */
236 if (isset($_POST['delete_cancel'])){
237 del_lock ($this->dn);
238 }
241 /* Deltetion was confirmed, so delete this entry
242 */
243 if (isset($_POST['delete_terminal_confirm'])){
245 /* Some nice guy may send this as POST, so we've to check
246 for the permissions again. */
247 if (chkacl($this->acl, "delete") == ""){
249 /* Find out more about the object type */
250 $ldap = $this->config->get_ldap_link();
251 $ldap->cat($this->dn);
252 $attrs = $ldap->fetch();
254 $type = $this->get_type($attrs);
256 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
257 $this->dialog->set_acl(array($this->acl));
259 $this->dialog->by_object[$type[1]]->remove_from_parent ();
260 unset ($this->dialog);
261 gosa_log ("FAI class '".$this->dn."' has been removed");
262 $this->dialog= NULL;
264 /* Terminal list has changed, reload it. */
265 } else {
267 /* Normally this shouldn't be reached, send some extra
268 logs to notify the administrator */
269 print_red (_("You are not allowed to delete this component!"));
270 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
271 "deletion.");
272 }
274 /* Remove lock file after successfull deletion */
275 del_lock ($this->dn);
276 }
278 /* Edit Entry */
279 //if($s_action == "edit"){
280 if(($s_action == "edit") && (!isset($this->dialog->config))){
281 $entry = $this->objects[$s_entry];
283 $a_setup = ($this->get_type($entry));
285 $this->dn = $entry['dn'];
286 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
287 if (($user= get_lock($this->dn)) != ""){
288 return(gen_locked_message ($user, $this->dn));
289 }
290 add_lock ($this->dn, $this->ui->dn);
292 $this->dialog= new $a_setup[0]($this->config,
293 $this->config->data['TABS'][$a_setup[2]],$this->dn);
294 $this->is_dialog = true;
295 if($entry['FAIstate'] == "freeze"){
296 $this->dialog->set_acl(array("*none*")) ;
297 }
298 $_SESSION['objectinfo'] = $this->dn;
299 }
301 /* Branch handling
302 09.01.2006
303 */
305 /* Abort creating new branch
306 */
307 if(isset($_POST['CancelBranchName'])){
308 $this->dispNewBranch = false;
309 $this->dispNewFreeze = false;
310 }
312 /* Remove branch
313 */
314 if($s_action == "remove_branch"){
315 $base= $faifilter['branch'];
316 /* Load permissions for selected 'dn' and check if
317 we're allowed to remove this 'dn' */
318 $acl= get_permissions ($_SESSION['CurrentMainBase'], $this->ui->subtreeACL);
319 $this->acl= get_module_permission($acl, "FAIclass", $base);
320 if (chkacl($this->acl, "delete") == ""){
321 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
322 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
323 } else {
324 print_red (_("You are not allowed to delete this release!"));
325 }
326 }
328 /* Delete this entry
329 */
330 if(isset($_POST['delete_branch_confirm'])){
331 $bb = $faifilter['branch'];
332 if(!isset($ldap)){
333 $ldap = $this->config->get_ldap_link();
334 }
336 $br = $this->getBranches();
338 if(isset($br[$bb])){
340 $name = $br[$bb];
342 $ldap->cd($bb);
343 $ldap->recursive_remove();
344 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
345 $ldap->recursive_remove();
346 $faifilter['branch'] = "main";
348 /* 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,".$_SESSION['CurrentMainBase'];
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 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
421 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
423 /* Print header to have styles included */
424 echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
425 echo "<body style='background-image:none;margin:3px;color:black'>";
427 /* Duplicate applications
428 */
429 $ldap->cd ($appdst);
430 $ldap->recursive_remove();
431 $ldap->cd ($this->config->current['BASE']);
432 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$type,true);
434 /* Duplicate fai objects
435 */
436 $ldap->cd ("ou=".$name.",".$baseToUse);
437 $ldap->recursive_remove();
438 $ldap->cd ($this->config->current['BASE']);
439 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true);
441 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
442 <br><input type='submit' name='back' value='"._("Continue")."'>
443 </form></div>";
445 /* Print footer to have valid html */
446 echo "</body></html>";
448 $this->dispNewFreeze = false;
450 /* Postcreate */
452 /* Assign possible attributes */
453 $this->lock_type = $type;
454 $this->lock_name = $name;
455 $this->lock_dn = $baseToUse;
456 $this->postcreate();
457 exit();
458 }
460 if(($s_action == "branch_branch")||($this->dispNewBranch)){
461 $this->dispNewBranch=true;
462 $smarty->assign("iframe",false);
463 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
464 return($display);
465 }
467 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
468 $this->dispNewFreeze = true;
469 $smarty->assign("iframe",false);
470 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
471 return($display);
472 }
474 /* ENDE Branch handling
475 */
477 /* Dialog handling */
478 if($s_action == "new_partition"){
479 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
480 }
482 /* Dialog handling */
483 if($s_action == "new_script"){
484 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
485 }
487 /* Dialog handling */
488 if($s_action == "new_hook"){
489 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
490 }
492 /* Dialog handling */
493 if($s_action == "new_variable"){
494 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
495 }
497 /* Dialog handling */
498 if($s_action == "new_template"){
499 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
500 }
502 /* Dialog handling */
503 if($s_action == "new_package"){
504 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
505 }
507 /* New Profile */
508 if($s_action == "new_profile"){
509 $this->dn = "new" ;
510 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
512 $this->dialog = new $a_setup[0]($this->config,
513 $this->config->data['TABS'][$a_setup[2]],$this->dn);
514 $this->is_dialog = true;
516 }
518 if($s_action == "select_class_name_finished"){
519 $this->dialog->save_object();
520 if(count($this->dialog->check())!=0){
521 foreach($this->dialog->check() as $msg){
522 print_red($msg);
523 }
524 }else{
525 $this->dn = "new" ;
526 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
527 $name = $this->dialog->save();
529 $this->dialog = new $a_setup[0]($this->config,
530 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
531 $this->dialog->by_object[$a_setup[1]]->cn = $name;
532 $this->is_dialog = true;
533 }
534 }
536 /* Search is set */
537 if(isset($_GET['search'])){
538 $faifilter['regex']=$_GET['search']."*";
539 }
541 /* Department select */
542 if((isset($_POST['base']))&&($s_action=="")){
543 $_SESSION['CurrentMainBase']=$_POST['base'];
544 }
546 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
548 $br = $this->getBranches($base);
549 if(!isset($br[$faifilter['branch']])){
550 $faifilter['branch'] = "main";
551 }
553 $smarty->assign("select_branch",$faifilter['branch']);
555 /* remove double asterisks and save new filter */
556 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
557 $_SESSION['faifilter']= $faifilter;
559 /* Edit dialog was canceled
560 * Remove dialog an show management dialog
561 */
562 if(isset($_POST['edit_cancel'])){
563 unset($this->dialog);
564 $this->dialog=NULL;
565 $this->is_dialog = false;
566 unset($_SESSION['objectinfo']);
567 del_lock ($this->dn);
568 }
570 /* This check if the given tab could be saved
571 * If it was possible to save it, remove dialog object.
572 * If it wasn't possible, show errors and keep dialog.
573 */
574 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
575 $this->dialog->save_object();
576 if(count($this->dialog->check())!=0){
577 foreach($this->dialog->check() as $msg){
578 print_red($msg);
579 }
580 }else{
581 del_lock ($this->dn);
582 $this->dialog->save();
583 unset($this->dialog);
584 $this->dialog=NULL;
585 $this->is_dialog=false;
586 unset($_SESSION['objectinfo']);
587 }
588 }
590 /* If dialog is set, but $this->is_dialog==false, then
591 * only the "abort" button is shown, this are dialogs that must not be saved.
592 * If is_dialog == true, we are currently editing tab objects.
593 * Here we need both, save and cancel
594 */
596 if(($this->dialog != NULL) && (isset($this->dialog->config))){
597 $display .= $this->dialog->execute();
598 /* Don't show buttons if tab dialog requests this */
599 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
601 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
602 $display.= "<p style=\"text-align:right\">\n";
603 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
604 $display.= " \n";
605 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
606 $display.= "</p>";
607 }elseif(!isset($this->dialog->current)){
608 $display.= "<p style=\"text-align:right\">\n";
609 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
610 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
611 $display.= "</p>";
612 }
613 return($display);
614 }
616 /* Show Management template
617 * The following code will only be reached if no dialog (tabs or dialogs)
618 * are currently opened.
619 * Assign all reguired vars to template engine
620 */
622 /* Prepare departments */
623 $options= "";
624 foreach ($this->config->idepartments as $key => $value){
625 if ($_SESSION['CurrentMainBase'] == $key){
626 $options.= "<option selected='selected' value='$key'>$value</option>";
627 } else {
628 $options.= "<option value='$key'>$value</option>";
629 }
630 }
632 /* Create listhead, it will be shown on top of the divlist.
633 * It provides general navigation and object creation
634 */
635 $faihead =
636 "<div style='background:#F0F0F9;padding:5px;'> ".
638 "<input class='center' type='image' src='images/list_root.png' align='middle'
639 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
641 "<input class='center' type='image' src='images/list_up.png' align='middle'
642 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
644 "<input class='center' type='image' src='images/list_home.png' align='middle'
645 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
647 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
649 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
651 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
652 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
654 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
656 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
657 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
659 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
660 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
662 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
663 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
665 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
666 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
668 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
669 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
671 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
672 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
674 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
676 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
677 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
679 "</div>";
681 $this->reload();
683 /* Create list with objects */
684 $divlist = new divlist("faiManagement");
685 $divlist->SetEntriesPerPage(0);
686 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
688 $divlist->SetHeader(array(
689 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
690 array("string" => _("Name of FAI class"), "attach" => "style=''"),
691 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
692 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
695 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
696 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
698 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
699 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
701 foreach($this->departments as $key => $val) {
702 if(!isset($this->config->departments[trim($key)])){
703 $this->config->departments[trim($key)]="";
704 }
706 $non_empty="";
707 $keys= str_replace("/","\/",$key);
708 foreach($this->config->departments as $keyd=>$vald ){
709 if(preg_match("/".$keys."\/.*/",$keyd)){
710 $non_empty="full";
711 }
712 }
715 $title = $this->config->departments[$key];
716 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
717 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
718 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
719 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
721 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
723 }
725 /* Attach objects */
726 foreach($this->objects as $key => $value){
727 $info= "";
728 $img = "";
729 $type = $value['type'];
730 $abort=false;
732 switch($type) {
733 case "FAIpartitionTable" :
734 if(!$faifilter['ShowPartitions']){
735 $abort = true;
736 }
737 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
738 $info = _("Partition table");
739 break;
740 case "FAIpackageList" :
741 if(!$faifilter['ShowPackages']){
742 $abort = true;
743 }
744 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
745 $info = _("Package list");
746 break;
747 case "FAIscript" :
748 if(!$faifilter['ShowScripts']){
749 $abort = true;
750 }
751 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
752 $info = _("Scripts");
753 break;
754 case "FAIvariable" :
755 if(!$faifilter['ShowVariables']){
756 $abort = true;
757 }
758 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
759 $info = _("Variables");
760 break;
761 case "FAIhook" :
762 if(!$faifilter['ShowHooks']){
763 $abort = true;
764 }
765 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
766 $info = _("Hooks");
767 break;
768 case "FAIprofile" :
769 if(!$faifilter['ShowProfiles']){
770 $abort = true;
771 }
772 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
773 $info = _("Profile");
774 break;
775 case "FAItemplate" :
776 if(!$faifilter['ShowTemplates']){
777 $abort = true;
778 }
779 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
780 $info = _("Templates");
781 break;
782 default :
783 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
785 }
787 if(!$abort) {
788 if((isset($value['description']))&&(!empty($value['description']))){
789 $desc= " [".$value['description']."]";
790 }else{
791 $desc= "";
792 }
794 if($value['FAIstate'] == "freeze"){
795 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
796 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
797 $edi = $editlink;
798 $acti = $action;
799 }else{
800 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
801 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
802 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
803 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
804 $acti = $action;
805 $edi = $editlink;
806 }
808 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
809 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
810 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
811 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
812 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
814 }
815 }
817 foreach($faifilter as $attrs => $value){
818 if($value){
819 $smarty->assign($attrs."CHK", " checked ");
820 }else{
821 $smarty->assign($attrs."CHK", " ");
822 }
823 }
825 /* Assign all reguired vars to template engine */
827 $branches = $this->getBranches();
828 asort($branches);
829 $smarty->assign("branchKeys",array_flip($branches));
830 $smarty->assign("branches",$branches);
832 $smarty->assign("faihead" , $faihead);
833 $smarty->assign("failist" , $divlist->DrawList());
834 $smarty->assign("regex" , $faifilter['regex']);
835 $smarty->assign("infoimage" , get_template_path('images/info.png'));
836 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
837 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
838 $smarty->assign("alphabet" , generate_alphabet());
839 $smarty->assign("apply" , apply_filter());
840 $smarty->assign("search_image" , get_template_path('images/search.png'));
841 $smarty->assign("hint", print_sizelimit_warning());
843 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
844 return ($display);
845 }
847 function getBranches($base = false,$prefix = "")
848 {
849 $ret = array("main"=>"/");
850 $ldap = $this->config->get_ldap_link();
852 $ldap->cd($this->config->current['BASE']);
854 $faifilter = $_SESSION['faifilter'];
857 if(!$base){
858 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
859 }
860 $ldap->cd($base);
861 $ldap->ls("(objectClass=FAIbranch)",$base);
863 while($attrs = $ldap->fetch()){
865 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
866 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
867 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
868 }
869 }
870 return($ret);
871 }
873 function reload()
874 {
875 /* Create a new list of FAI object
876 * Object list depends on faifilter['regex']
877 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
878 */
879 $faifilter= get_global('faifilter');
880 // Added for dirlist function...
882 /* Set base for all searches */
883 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
885 if($faifilter['branch'] !="main"){
886 $base = $faifilter['branch'];
887 }
889 $regex = $faifilter['regex'];
891 /* Array to save objects */
892 $objects = array();
894 $this->objects=array();
896 /* NEW LIST MANAGMENT
897 * We also need to search for the departments
898 * So we are able to navigate like in konquerer
899 */
900 $base2 = $_SESSION['CurrentMainBase'];
902 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
903 TRUE, $base2, array("ou", "description"), TRUE);
905 $this->departments= array();
906 $tmp = array();
907 foreach ($res3 as $value){
908 $tmp[strtolower($value['dn']).$value['dn']]=$value;
909 }
910 ksort($tmp);
911 foreach($tmp as $value){
912 if(isset($value["description"][0])){
913 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
914 }else{
915 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
916 }
917 }
919 /* END NEW LIST MANAGMENT
920 */
923 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
924 FALSE, $base, array("cn","description","objectClass"),TRUE);
926 $str = "";
928 foreach($res as $objecttypes){
929 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
930 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
931 foreach($res2 as $object){
932 $type= "";
933 unset($object['objectClass']['count']);
934 if(!isset($object['description'][0])){
935 $object['description'][0]="";
936 }
938 /* Clean up object informations */
939 $obj['cn'] = $object['cn'][0];
940 $obj['dn'] = $object['dn'];
941 $obj['description'] = $object['description'][0];
942 $obj['objectClass'] = $object['objectClass'];
944 if(isset($object['FAIstate'])){
945 $obj['FAIstate'] = $object['FAIstate'][0];
947 /* Append type to this string, to be able to check if the selected
948 * entry is of type 'freeze' or 'branch'
949 */
950 $str.="|".$obj['FAIstate'];
951 }else{
952 $obj['FAIstate'] ="";
953 }
955 if(in_array("FAIpartitionTable",$obj['objectClass'])){
956 $type = "FAIpartitionTable";
957 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
958 $type = "FAIpackageList";
959 }elseif(in_array("FAIscript",$obj['objectClass'])){
960 $type = "FAIscript";
961 }elseif(in_array("FAIvariable",$obj['objectClass'])){
962 $type = "FAIvariable";
963 }elseif(in_array("FAIhook",$obj['objectClass'])){
964 $type = "FAIhook";
965 }elseif(in_array("FAIprofile",$obj['objectClass'])){
966 $obj['FAIclass'] = $object['FAIclass'][0];
967 $type = "FAIprofile";
968 }elseif(in_array("FAItemplate",$obj['objectClass'])){
969 $type = "FAItemplate";
970 }
971 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
972 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
974 }
975 }
977 /* Tell class what we have currently opened
978 'main' has type ''
979 */
980 if(preg_match("/freeze/",$str)){
981 $this->lock_type = "freeze";
982 }elseif(preg_match("/branch/",$str)){
983 $this->lock_type = "branch";
984 }else{
985 $this->lock_type = "";
986 }
988 ksort($this->objects);
989 reset ($this->objects);
991 /* use numeric index, thats a bit more secure */
992 $tmp0 = array();
993 foreach($this->objects as $obj){
994 $tmp0[]= $obj;
995 }
996 $this->objects = array();
997 $this->objects = $tmp0;
999 }
1001 function remove_lock()
1002 {
1003 if (isset($this->dn)){
1004 del_lock ($this->dn);
1005 }
1006 }
1008 function get_type($array){
1009 if(in_array("FAIpartitionTable",$array['objectClass'])){
1010 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1011 }
1012 if(in_array("FAIscript",$array['objectClass'])){
1013 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1014 }
1015 if(in_array("FAItemplate",$array['objectClass'])){
1016 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1017 }
1018 if(in_array("FAIhook",$array['objectClass'])){
1019 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1020 }
1021 if(in_array("FAIvariable",$array['objectClass'])){
1022 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1023 }
1024 if(in_array("FAIprofile",$array['objectClass'])){
1025 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1026 }
1028 if(in_array("FAIpackageList",$array['objectClass'])){
1029 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1030 }
1031 }
1033 function CheckNewBranchName($name,$base){
1034 $f = $_SESSION['faifilter']['branch'];
1036 if(empty($name)){
1037 return(false);
1038 }
1040 if($f == "main"){
1041 $f = $_SESSION['CurrentMainBase'];
1042 }
1044 if(in_array($name,$this->getBranches($f))) {
1045 return(false);
1046 }
1048 if(empty($name)){
1049 return(false);
1050 }
1052 if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles","apps"))){
1053 return(false);
1054 }
1056 return(true);
1057 }
1059 }
1060 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1061 ?>