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 if(!isset($_SESSION['CurrentMainBase'])){
89 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
90 }
91 }
93 function execute()
94 {
95 /* Call parent execute */
96 plugin::execute();
98 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
100 $display = "";
101 $smarty = get_smarty();
102 $smarty->assign("BranchName","");
103 $s_action = "";
104 $s_entry = "";
105 /* filter management
106 * Filter will be changed if POST['regex'] or $_GET['search'] isset
107 * New Filter will be stored in session and is used to generate list contents
108 */
109 $faifilter = $_SESSION['faifilter'];
111 if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
112 $faifilter['branch'] = $_POST['select_branch'];
113 }
115 /* Filter is posted by apply button
116 * Check every single chkbox
117 */
118 if(isset($_POST['regex'])){
119 $faifilter['regex'] = $_POST['regex']."*";
120 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
121 if(isset($_POST[$attrs])){
122 $faifilter[$attrs] = true;
123 }else{
124 $faifilter[$attrs] = false;
125 }
126 }
127 }
130 /* Check ImageButton posts
131 * Create new tab ich new_xx is posted
132 */
133 foreach($_POST as $key => $val){
134 if(preg_match("/remove_branch/",$key)){
135 $s_action = "remove_branch";
136 }elseif(preg_match("/branch_branch/",$key)){
137 $s_action = "branch_branch";
138 }elseif(preg_match("/freeze_branch/",$key)){
139 $s_action = "freeze_branch";
140 }elseif(preg_match("/create_partition/i",$key)){
141 $s_action = "new_partition";
142 }elseif(preg_match("/create_script/i",$key)){
143 $s_action = "new_script";
144 }elseif(preg_match("/create_hook/i",$key)){
145 $s_action = "new_hook";
146 }elseif(preg_match("/create_variable/i",$key)){
147 $s_action = "new_variable";
148 }elseif(preg_match("/create_template/i",$key)){
149 $s_action = "new_template";
150 }elseif(preg_match("/create_package/i",$key)){
151 $s_action = "new_package";
152 }elseif(preg_match("/create_profile/i",$key)){
153 $s_action = "new_profile";
154 }elseif(preg_match("/edit_continue/",$key)){
155 $s_action = "select_class_name_finished";
156 }elseif(preg_match("/^entry_edit_.*/",$key)){
157 $s_entry = preg_replace("/^entry_edit_/","",$key);
158 $s_entry = preg_replace("/_.*$/","",$s_entry);
159 $s_action = "edit";
160 }elseif(preg_match("/^entry_delete_.*/",$key)){
161 $s_entry = preg_replace("/^entry_delete_/","",$key);
162 $s_entry = preg_replace("/_.*$/","",$s_entry);
163 $s_action = "delete";
164 }elseif(preg_match("/dep_back.*/i",$key)){
165 $faifilter['branch'] = "main";
166 $s_action="back";
167 }elseif(preg_match("/dep_home.*/i",$key)){
168 $faifilter['branch'] = "main";
169 $s_action="home";
170 }elseif(preg_match("/dep_root.*/i",$key)){
171 $faifilter['branch'] = "main";
172 $s_action="root";
173 }
175 }
177 if($s_action=="root"){
178 $_SESSION['CurrentMainBase']=($this->config->current['BASE']);
179 }
181 if($s_action=="home"){
182 $_SESSION['CurrentMainBase']= get_base_from_people($this->ui->dn);
183 }
185 if($s_action=="back"){
186 $base_back = preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
187 $base_back = convert_department_dn($base_back);
189 if(isset($this->config->departments[trim($base_back)])){
190 $_SESSION['CurrentMainBase']= $this->config->departments[trim($base_back)];
191 }else{
192 $_SESSION['CurrentMainBase']= $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 $_SESSION['CurrentMainBase']= $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 if($entry['FAIstate'] == "freeze"){
299 $this->dialog->set_acl(array("*none*")) ;
300 }
301 $_SESSION['objectinfo'] = $this->dn;
302 }
304 /* Branch handling
305 09.01.2006
306 */
308 /* Abort creating new branch
309 */
310 if(isset($_POST['CancelBranchName'])){
311 $this->dispNewBranch = false;
312 $this->dispNewFreeze = false;
313 }
315 /* Remove branch
316 */
317 if($s_action == "remove_branch"){
318 $base= $faifilter['branch'];
319 /* Load permissions for selected 'dn' and check if
320 we're allowed to remove this 'dn' */
321 $acl= get_permissions ($_SESSION['CurrentMainBase'], $this->ui->subtreeACL);
322 $this->acl= get_module_permission($acl, "FAIclass", $base);
323 if (chkacl($this->acl, "delete") == ""){
324 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch']));
325 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
326 } else {
327 print_red (_("You are not allowed to delete this release!"));
328 }
329 }
331 /* Delete this entry
332 */
333 if(isset($_POST['delete_branch_confirm'])){
334 $bb = $faifilter['branch'];
335 if(!isset($ldap)){
336 $ldap = $this->config->get_ldap_link();
337 }
339 $br = $this->getBranches();
341 if(isset($br[$bb])){
343 $name = $br[$bb];
345 $ldap->cd($bb);
346 $ldap->recursive_remove();
347 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
348 $ldap->recursive_remove();
349 $faifilter['branch'] = "main";
351 /* Post remove */
352 // $this->lock_type is set from this->reload
353 $this->lock_name = $name;
354 $this->lock_dn = $bb;
356 $this->postremove();
357 }
358 }
360 /* Open dialog to insert new branch name
361 */
363 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
364 $_SESSION['LASTPOST'] = $_POST;
366 if($this->dispNewBranch){
367 $type = "branch";
368 }else{
369 $type = "freeze";
370 }
372 /* Check branch name */
373 $name = $_POST['BranchName'];
374 $is_ok = true;
376 $smarty->assign("BranchName",$name);
378 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
380 /* Check used characters */
381 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
382 if($type == "branch"){
383 print_red(_("Specified branch name is invalid."));
384 }else{
385 print_red(_("Specified freeze name is invalid."));
386 }
387 $is_ok = false;
388 }
390 /* Check if this name is already in use */
391 if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
392 print_red(_("This name is already in use."));
393 $is_ok = false;
394 }
396 if($is_ok){
397 $_SESSION['LASTPOST']['base'] = $base;
398 $_SESSION['LASTPOST']['type'] = $type;
399 $smarty->assign("iframe", true);
400 $smarty->assign("plugID", $_GET['plug']);
401 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
402 return($display);
403 }
404 }
406 if(isset($_GET['PerformBranch'])){
407 /* Create it know */
408 $this->dispNewBranch = false;
409 $this->dispNewFreeze = false;
410 $base = $_SESSION['LASTPOST']['base'];
411 $_POST = $_SESSION['LASTPOST'];
412 $name = $_POST['BranchName'];
414 $type = $_SESSION['LASTPOST']['type'];
416 $ldap = $this->config->get_ldap_link();
418 $baseToUse = $base;
419 if($_SESSION['faifilter']['branch']!="main"){
420 $baseToUse = $_SESSION['faifilter']['branch'];
421 }
423 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
424 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
426 /* Print header to have styles included */
427 echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
428 echo "<body style='background-image:none;margin:3px;color:black'>";
430 /* Duplicate applications
431 */
432 $ldap->cd ($appdst);
433 $ldap->recursive_remove();
434 $ldap->cd ($this->config->current['BASE']);
435 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$type,true);
437 /* Duplicate fai objects
438 */
439 $ldap->cd ("ou=".$name.",".$baseToUse);
440 $ldap->recursive_remove();
441 $ldap->cd ($this->config->current['BASE']);
442 $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true);
444 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
445 <br><input type='submit' name='back' value='"._("Continue")."'>
446 </form></div>";
448 /* Print footer to have valid html */
449 echo "</body></html>";
451 $this->dispNewFreeze = false;
453 /* Postcreate */
455 /* Assign possible attributes */
456 $this->lock_type = $type;
457 $this->lock_name = $name;
458 $this->lock_dn = $baseToUse;
459 $this->postcreate();
460 exit();
461 }
463 if(($s_action == "branch_branch")||($this->dispNewBranch)){
464 $this->dispNewBranch=true;
465 $smarty->assign("iframe",false);
466 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
467 return($display);
468 }
470 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
471 $this->dispNewFreeze = true;
472 $smarty->assign("iframe",false);
473 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
474 return($display);
475 }
477 /* ENDE Branch handling
478 */
480 /* Dialog handling */
481 if($s_action == "new_partition"){
482 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
483 }
485 /* Dialog handling */
486 if($s_action == "new_script"){
487 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
488 }
490 /* Dialog handling */
491 if($s_action == "new_hook"){
492 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
493 }
495 /* Dialog handling */
496 if($s_action == "new_variable"){
497 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
498 }
500 /* Dialog handling */
501 if($s_action == "new_template"){
502 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
503 }
505 /* Dialog handling */
506 if($s_action == "new_package"){
507 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
508 }
510 /* New Profile */
511 if($s_action == "new_profile"){
512 $this->dn = "new" ;
513 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
515 $this->dialog = new $a_setup[0]($this->config,
516 $this->config->data['TABS'][$a_setup[2]],$this->dn);
517 $this->is_dialog = true;
519 }
521 if($s_action == "select_class_name_finished"){
522 $this->dialog->save_object();
523 if(count($this->dialog->check())!=0){
524 foreach($this->dialog->check() as $msg){
525 print_red($msg);
526 }
527 }else{
528 $this->dn = "new" ;
529 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
530 $name = $this->dialog->save();
532 $this->dialog = new $a_setup[0]($this->config,
533 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
534 $this->dialog->by_object[$a_setup[1]]->cn = $name;
535 $this->is_dialog = true;
536 }
537 }
539 /* Search is set */
540 if(isset($_GET['search'])){
541 $faifilter['regex']=$_GET['search']."*";
542 }
544 /* Department select */
545 if((isset($_POST['base']))&&($s_action=="")){
546 $_SESSION['CurrentMainBase']=$_POST['base'];
547 }
549 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
551 $br = $this->getBranches($base);
552 if(!isset($br[$faifilter['branch']])){
553 $faifilter['branch'] = "main";
554 }
556 $smarty->assign("select_branch",$faifilter['branch']);
558 /* remove double asterisks and save new filter */
559 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
560 $_SESSION['faifilter']= $faifilter;
562 /* Edit dialog was canceled
563 * Remove dialog an show management dialog
564 */
565 if(isset($_POST['edit_cancel'])){
566 unset($this->dialog);
567 $this->dialog=NULL;
568 $this->is_dialog = false;
569 unset($_SESSION['objectinfo']);
570 del_lock ($this->dn);
571 }
573 /* This check if the given tab could be saved
574 * If it was possible to save it, remove dialog object.
575 * If it wasn't possible, show errors and keep dialog.
576 */
577 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
578 $this->dialog->save_object();
579 if(count($this->dialog->check())!=0){
580 foreach($this->dialog->check() as $msg){
581 print_red($msg);
582 }
583 }else{
584 del_lock ($this->dn);
585 $this->dialog->save();
586 unset($this->dialog);
587 $this->dialog=NULL;
588 $this->is_dialog=false;
589 unset($_SESSION['objectinfo']);
590 }
591 }
593 /* If dialog is set, but $this->is_dialog==false, then
594 * only the "abort" button is shown, this are dialogs that must not be saved.
595 * If is_dialog == true, we are currently editing tab objects.
596 * Here we need both, save and cancel
597 */
599 if(($this->dialog != NULL) && (isset($this->dialog->config))){
600 $display .= $this->dialog->execute();
601 /* Don't show buttons if tab dialog requests this */
602 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
604 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
605 $display.= "<p style=\"text-align:right\">\n";
606 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
607 $display.= " \n";
608 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
609 $display.= "</p>";
610 }elseif(!isset($this->dialog->current)){
611 $display.= "<p style=\"text-align:right\">\n";
612 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
613 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
614 $display.= "</p>";
615 }
616 return($display);
617 }
619 /* Show Management template
620 * The following code will only be reached if no dialog (tabs or dialogs)
621 * are currently opened.
622 * Assign all reguired vars to template engine
623 */
625 /* Prepare departments */
626 $options= "";
627 foreach ($this->config->idepartments as $key => $value){
628 if ($_SESSION['CurrentMainBase'] == $key){
629 $options.= "<option selected='selected' value='$key'>$value</option>";
630 } else {
631 $options.= "<option value='$key'>$value</option>";
632 }
633 }
635 /* Create listhead, it will be shown on top of the divlist.
636 * It provides general navigation and object creation
637 */
638 $faihead =
639 "<div style='background:#F0F0F9;padding:5px;'> ".
641 "<input class='center' type='image' src='images/list_root.png' align='middle'
642 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
644 "<input class='center' type='image' src='images/list_up.png' align='middle'
645 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
647 "<input class='center' type='image' src='images/list_home.png' align='middle'
648 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
650 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
652 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
654 " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
655 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
657 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
659 " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
660 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
662 " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
663 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
665 " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
666 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
668 " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
669 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
671 " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
672 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
674 " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
675 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
677 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
679 _("Base")." <select name='base' onChange='mainform.submit()' class='center'>$options</select>".
680 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
682 "</div>";
684 $this->reload();
686 /* Create list with objects */
687 $divlist = new divlist("faiManagement");
688 $divlist->SetEntriesPerPage(0);
689 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
691 $divlist->SetHeader(array(
692 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
693 array("string" => _("Name of FAI class"), "attach" => "style=''"),
694 array("string" => _("Class type"), "attach" => "style='width:200px;'"),
695 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
698 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
699 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
701 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%'>%NAME%</a>";
702 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
704 foreach($this->departments as $key => $val) {
705 if(!isset($this->config->departments[trim($key)])){
706 $this->config->departments[trim($key)]="";
707 }
709 $non_empty="";
710 $keys= str_replace("/","\/",$key);
711 foreach($this->config->departments as $keyd=>$vald ){
712 if(preg_match("/".$keys."\/.*/",$keyd)){
713 $non_empty="full";
714 }
715 }
718 $title = $this->config->departments[$key];
719 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
720 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
721 $field2 = array("string" => " ", "attach" => "style='width:200px;'");
722 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
724 $divlist->AddEntry( array($field0,$field1,$field2,$field3));
726 }
728 /* Attach objects */
729 foreach($this->objects as $key => $value){
730 $info= "";
731 $img = "";
732 $type = $value['type'];
733 $abort=false;
735 switch($type) {
736 case "FAIpartitionTable" :
737 if(!$faifilter['ShowPartitions']){
738 $abort = true;
739 }
740 $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
741 $info = _("Partition table");
742 break;
743 case "FAIpackageList" :
744 if(!$faifilter['ShowPackages']){
745 $abort = true;
746 }
747 $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
748 $info = _("Package list");
749 break;
750 case "FAIscript" :
751 if(!$faifilter['ShowScripts']){
752 $abort = true;
753 }
754 $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
755 $info = _("Scripts");
756 break;
757 case "FAIvariable" :
758 if(!$faifilter['ShowVariables']){
759 $abort = true;
760 }
761 $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
762 $info = _("Variables");
763 break;
764 case "FAIhook" :
765 if(!$faifilter['ShowHooks']){
766 $abort = true;
767 }
768 $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
769 $info = _("Hooks");
770 break;
771 case "FAIprofile" :
772 if(!$faifilter['ShowProfiles']){
773 $abort = true;
774 }
775 $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
776 $info = _("Profile");
777 break;
778 case "FAItemplate" :
779 if(!$faifilter['ShowTemplates']){
780 $abort = true;
781 }
782 $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
783 $info = _("Templates");
784 break;
785 default :
786 $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
788 }
790 if(!$abort) {
791 if((isset($value['description']))&&(!empty($value['description']))){
792 $desc= " [".$value['description']."]";
793 }else{
794 $desc= "";
795 }
797 if($value['FAIstate'] == "freeze"){
798 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
799 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
800 $edi = $editlink;
801 $acti = $action;
802 }else{
803 $action = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
804 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
805 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
806 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
807 $acti = $action;
808 $edi = $editlink;
809 }
811 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
812 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
813 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
814 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
815 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
817 }
818 }
820 foreach($faifilter as $attrs => $value){
821 if($value){
822 $smarty->assign($attrs."CHK", " checked ");
823 }else{
824 $smarty->assign($attrs."CHK", " ");
825 }
826 }
828 /* Assign all reguired vars to template engine */
830 $branches = $this->getBranches();
831 asort($branches);
832 $smarty->assign("branches",$branches);
834 $smarty->assign("faihead" , $faihead);
835 $smarty->assign("failist" , $divlist->DrawList());
836 $smarty->assign("regex" , $faifilter['regex']);
837 $smarty->assign("infoimage" , get_template_path('images/info.png'));
838 $smarty->assign("branchimage" , get_template_path('images/branch.png'));
839 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
840 $smarty->assign("alphabet" , generate_alphabet());
841 $smarty->assign("apply" , apply_filter());
842 $smarty->assign("search_image" , get_template_path('images/search.png'));
843 $smarty->assign("hint", print_sizelimit_warning());
845 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
846 return ($display);
847 }
849 function getBranches($base = false,$prefix = "")
850 {
851 $ret = array("main"=>"/");
852 $ldap = $this->config->get_ldap_link();
854 $ldap->cd($this->config->current['BASE']);
856 $faifilter = $_SESSION['faifilter'];
859 if(!$base){
860 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
861 }
862 $ldap->cd($base);
863 $ldap->ls("(objectClass=FAIbranch)",$base);
865 while($attrs = $ldap->fetch()){
867 if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
868 $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
869 $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
870 }
871 }
872 return($ret);
873 }
875 function reload()
876 {
877 /* Create a new list of FAI object
878 * Object list depends on faifilter['regex']
879 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
880 */
881 $faifilter= get_global('faifilter');
882 // Added for dirlist function...
884 /* Set base for all searches */
885 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
887 if($faifilter['branch'] !="main"){
888 $base = $faifilter['branch'];
889 }
891 $regex = $faifilter['regex'];
893 /* Array to save objects */
894 $objects = array();
896 $this->objects=array();
898 /* NEW LIST MANAGMENT
899 * We also need to search for the departments
900 * So we are able to navigate like in konquerer
901 */
902 $base2 = $_SESSION['CurrentMainBase'];
904 /* Get all departments within this subtree */
905 $deps= get_list("(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
906 $base2, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
908 $this->departments = array();
909 foreach($deps as $value){
910 if(isset($value['description'][0])){
911 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
912 }else{
913 $this->departments[$value['dn']]= get_sub_department($value['dn']);
914 }
915 }
916 natcasesort($this->departments);
918 /* END NEW LIST MANAGMENT
919 */
920 $res= get_list("(objectClass=organizationalUnit)", $this->ui->subtreeACL, $base,
921 array("cn","description","objectClass"), GL_SIZELIMIT);
923 $str = "";
925 foreach($res as $objecttypes){
926 $res2= get_list("(&(objectClass=*)(cn=$regex))", $this->ui->subtreeACL, $objecttypes['dn'],
927 array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT);
928 foreach($res2 as $object){
929 $type= "";
930 unset($object['objectClass']['count']);
931 if(!isset($object['description'][0])){
932 $object['description'][0]="";
933 }
935 /* Clean up object informations */
936 $obj['cn'] = $object['cn'][0];
937 $obj['dn'] = $object['dn'];
938 $obj['description'] = $object['description'][0];
939 $obj['objectClass'] = $object['objectClass'];
941 if(isset($object['FAIstate'])){
942 $obj['FAIstate'] = $object['FAIstate'][0];
944 /* Append type to this string, to be able to check if the selected
945 * entry is of type 'freeze' or 'branch'
946 */
947 $str.="|".$obj['FAIstate'];
948 }else{
949 $obj['FAIstate'] ="";
950 }
952 if(in_array("FAIpartitionTable",$obj['objectClass'])){
953 $type = "FAIpartitionTable";
954 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
955 $type = "FAIpackageList";
956 }elseif(in_array("FAIscript",$obj['objectClass'])){
957 $type = "FAIscript";
958 }elseif(in_array("FAIvariable",$obj['objectClass'])){
959 $type = "FAIvariable";
960 }elseif(in_array("FAIhook",$obj['objectClass'])){
961 $type = "FAIhook";
962 }elseif(in_array("FAIprofile",$obj['objectClass'])){
963 $obj['FAIclass'] = $object['FAIclass'][0];
964 $type = "FAIprofile";
965 }elseif(in_array("FAItemplate",$obj['objectClass'])){
966 $type = "FAItemplate";
967 }
968 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
969 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
971 }
972 }
974 /* Tell class what we have currently opened
975 'main' has type ''
976 */
977 if(preg_match("/freeze/",$str)){
978 $this->lock_type = "freeze";
979 }elseif(preg_match("/branch/",$str)){
980 $this->lock_type = "branch";
981 }else{
982 $this->lock_type = "";
983 }
985 ksort($this->objects);
986 reset ($this->objects);
988 /* use numeric index, thats a bit more secure */
989 $tmp0 = array();
990 foreach($this->objects as $obj){
991 $tmp0[]= $obj;
992 }
993 $this->objects = array();
994 $this->objects = $tmp0;
996 }
998 function remove_lock()
999 {
1000 if (isset($this->dn)){
1001 del_lock ($this->dn);
1002 }
1003 }
1005 function get_type($array){
1006 if(in_array("FAIpartitionTable",$array['objectClass'])){
1007 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1008 }
1009 if(in_array("FAIscript",$array['objectClass'])){
1010 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1011 }
1012 if(in_array("FAItemplate",$array['objectClass'])){
1013 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1014 }
1015 if(in_array("FAIhook",$array['objectClass'])){
1016 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1017 }
1018 if(in_array("FAIvariable",$array['objectClass'])){
1019 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1020 }
1021 if(in_array("FAIprofile",$array['objectClass'])){
1022 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1023 }
1025 if(in_array("FAIpackageList",$array['objectClass'])){
1026 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1027 }
1028 }
1030 function CheckNewBranchName($name,$base){
1031 $f = $_SESSION['faifilter']['branch'];
1033 if(empty($name)){
1034 return(false);
1035 }
1037 if($f == "main"){
1038 $f = $_SESSION['CurrentMainBase'];
1039 }
1041 if(in_array($name,$this->getBranches($f))) {
1042 return(false);
1043 }
1045 if(empty($name)){
1046 return(false);
1047 }
1049 if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles","apps"))){
1050 return(false);
1051 }
1053 return(true);
1054 }
1056 }
1057 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1058 ?>