7d0c56636fcf7ac7f38790348704b10af0bcbd14
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 */
20 require "tabsPartition.inc";
21 require "tabsVariable.inc";
22 require "tabsHook.inc";
23 require "tabsTemplate.inc";
24 require "tabsScript.inc";
25 require "tabsProfile.inc";
26 require "tabsPackage.inc";
28 class faiManagement extends plugin
29 {
30 /* Definitions */
31 var $plHeadline = "FAI";
32 var $plDescription = "Fully Automatic Installation - management";
34 /* CLI vars */
35 var $cli_summary = "Handling of FAI entries";
36 var $cli_description = "This plugin represents a management tool\n
37 which allows us to manage all needed attributes for fully automatic installations (FAI)";
38 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
40 /* Headpage attributes */
41 var $departments= array();
42 var $deptabs= NULL;
44 /* attribute list for save action */
45 var $attributes = array(); // Attributes Managed by this plugin, none,
46 // because this is only an overview over all objects already defined in FAI.
47 var $objectclasses = array(); // ObjectClasses which the attributes are related to
48 var $dialog = array(); // This object contains every dialog we have currently opened
50 var $objects = array(); // This array contains all available objects shown in divlist
51 var $is_dialog = false;
53 /* construction/reconstruction
54 * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last
55 * selected department and filter options
56 * If it is not defined already we create a new fresh faifilter.
57 */
58 function faiManagement ($config, $ui)
59 {
60 $this->ui = $ui;
62 /* Set current dn to "", */
63 $this->dn = "";
65 /* Assign config */
66 $this->config = $config;
68 /* Get global filter config */
69 if (!is_global("faifilter")){
70 $base = get_base_from_people($ui->dn);
71 $faifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base,
72 "regex" => "*");
73 $faifilter['ShowProfiles'] = true;
74 $faifilter['ShowTemplates'] = true;
75 $faifilter['ShowScripts'] = true;
76 $faifilter['ShowHooks'] = true;
77 $faifilter['ShowVariables'] = true;
78 $faifilter['ShowPackages'] = true;
79 $faifilter['ShowPartitions']=true;
80 register_global("faifilter", $faifilter);
81 }
82 }
84 function execute()
85 {
86 $display = "";
87 $smarty = get_smarty();
88 $s_action = "";
89 $s_entry = "";
90 /* filter management
91 * Filter will be changed if POST['regex'] or $_GET['search'] isset
92 * New Filter will be stored in session and is used to generate list contents
93 */
94 $faifilter = $_SESSION['faifilter'];
96 /* Filter is posted by apply button
97 * Check every single chkbox
98 */
99 if(isset($_POST['regex'])){
100 $faifilter['regex'] = $_POST['regex']."*";
101 foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
102 if(isset($_POST[$attrs])){
103 $faifilter[$attrs] = true;
104 }else{
105 $faifilter[$attrs] = false;
106 }
107 }
108 }
110 /* Check ImageButton posts
111 * Create new tab ich new_xx is posted
112 */
113 foreach($_POST as $key => $val){
114 if(preg_match("/create_partition/i",$key)){
115 $s_action = "new_partition";
116 }elseif(preg_match("/create_script/i",$key)){
117 $s_action = "new_script";
118 }elseif(preg_match("/create_hook/i",$key)){
119 $s_action = "new_hook";
120 }elseif(preg_match("/create_variable/i",$key)){
121 $s_action = "new_variable";
122 }elseif(preg_match("/create_template/i",$key)){
123 $s_action = "new_template";
124 }elseif(preg_match("/create_package/i",$key)){
125 $s_action = "new_package";
126 }elseif(preg_match("/create_profile/i",$key)){
127 $s_action = "new_profile";
128 }elseif(preg_match("/UseNewClass/",$key)){
129 $s_action = "select_class_name_finished";
130 }elseif(preg_match("/UseSelectedClass/",$key)){
131 $s_action = "select_class_name_finished";
132 }elseif(preg_match("/^entry_edit_.*/",$key)){
133 $s_entry = preg_replace("/^entry_edit_/","",$key);
134 $s_entry = preg_replace("/_.*$/","",$s_entry);
135 $s_action = "edit";
136 }elseif(preg_match("/^entry_delete_.*/",$key)){
137 $s_entry = preg_replace("/^entry_delete_/","",$key);
138 $s_entry = preg_replace("/_.*$/","",$s_entry);
139 $s_action = "delete";
140 }
142 }
144 /* Confirm dialog
145 * Delte object
146 */
147 if ($s_action=="delete"){
149 /* Get 'dn' from posted termlinst */
150 $this->dn= $this->objects[$s_entry]['dn'];
152 /* Load permissions for selected 'dn' and check if
153 we're allowed to remove this 'dn' */
154 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
155 $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
156 if (chkacl($this->acl, "delete") == ""){
158 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
159 if (($user= get_lock($this->dn)) != ""){
160 return(gen_locked_message ($user, $this->dn));
161 }
163 /* Lock the current entry, so nobody will edit it during deletion */
164 add_lock ($this->dn, $this->ui->dn);
165 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
166 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
167 } else {
169 /* Obviously the user isn't allowed to delete. Show message and
170 clean session. */
171 print_red (_("You are not allowed to delete this component!"));
172 }
173 }
175 /* Deltetion was confirmed, so delete this entry
176 */
177 if (isset($_POST['delete_terminal_confirm'])){
179 /* Some nice guy may send this as POST, so we've to check
180 for the permissions again. */
181 if (chkacl($this->acl, "delete") == ""){
183 /* Find out more about the object type */
184 $ldap = $this->config->get_ldap_link();
185 $ldap->cat($this->dn);
186 $attrs = $ldap->fetch();
188 $type = $this->get_type($attrs);
190 $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn);
191 $this->dialog->set_acl(array($this->acl));
193 $this->dialog->by_object[$type[1]]->remove_from_parent ();
194 unset ($this->dialog);
195 gosa_log ("FAI class '".$this->dn."' has been removed");
196 $this->dialog= NULL;
198 /* Terminal list has changed, reload it. */
199 $this->reload ();
200 } else {
202 /* Normally this shouldn't be reached, send some extra
203 logs to notify the administrator */
204 print_red (_("You are not allowed to delete this component!"));
205 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
206 "deletion.");
207 }
209 /* Remove lock file after successfull deletion */
210 del_lock ($this->dn);
211 }
213 /* Edit Entry */
214 if($s_action == "edit"){
215 $entry = $this->objects[$s_entry];
217 $a_setup = ($this->get_type($entry));
219 $this->dn = $entry['dn'];
221 $this->dialog= new $a_setup[0]($this->config,
222 $this->config->data['TABS'][$a_setup[2]],$this->dn);
223 $this->is_dialog = true;
224 }
227 /* Dialog handling */
228 if($s_action == "new_partition"){
229 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
230 }
232 /* Dialog handling */
233 if($s_action == "new_script"){
234 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
235 }
237 /* Dialog handling */
238 if($s_action == "new_hook"){
239 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
240 }
242 /* Dialog handling */
243 if($s_action == "new_variable"){
244 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
245 }
247 /* Dialog handling */
248 if($s_action == "new_template"){
249 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
250 }
252 /* Dialog handling */
253 if($s_action == "new_package"){
254 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
255 }
257 /* New Profile */
258 if($s_action == "new_profile"){
259 $this->dn = "new" ;
260 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
262 $this->dialog = new $a_setup[0]($this->config,
263 $this->config->data['TABS'][$a_setup[2]],$this->dn);
264 $this->is_dialog = true;
266 }
268 if($s_action == "select_class_name_finished"){
269 $this->dialog->save_object();
270 if(count($this->dialog->check())!=0){
271 foreach($this->dialog->check() as $msg){
272 print_red($msg);
273 }
274 }else{
275 $this->dn = "new" ;
276 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
277 $name = $this->dialog->save();
279 $this->dialog = new $a_setup[0]($this->config,
280 $this->config->data['TABS'][$a_setup[2]],$this->dn);
281 $this->dialog->by_object[$a_setup[1]]->cn = $name;
282 $this->is_dialog = true;
283 }
284 }
287 /* Search is set */
288 if(isset($_GET['search'])){
289 $faifilter['regex']=$_GET['search']."*";
290 }
292 /* remove double asterisks and save new filter */
293 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
294 $_SESSION['faifilter']= $faifilter;
296 /* Edit dialog was canceled
297 * Remove dialog an show management dialog
298 */
299 if(isset($_POST['edit_cancel'])){
300 unset($this->dialog);
301 $this->dialog=NULL;
302 $this->is_dialog = false;
303 }
306 /* This check if the given tab could be saved
307 * If it was possible to save it, remove dialog object.
308 * If it wasn't possible, show errors and keep dialog.
309 */
310 if(isset($_POST['edit_finish'])){
311 $this->dialog->save_object();
312 if(count($this->dialog->check())!=0){
313 foreach($this->dialog->check() as $msg){
314 print_red($msg);
315 }
316 }else{
317 $this->dialog->save();
318 unset($this->dialog);
319 $this->dialog=NULL;
320 $this->is_dialog=false;
321 }
322 }
325 /* If dialog is set, but $this->is_dialog==false, then
326 * only the "abort" button is shown, this are dialogs that must not be saved.
327 * If is_dialog == true, we are currently editing tab objects.
328 * Here we need both, save and cancel
329 */
331 if($this->dialog != NULL){
332 $display .= $this->dialog->execute();
333 /* Don't show buttons if tab dialog requests this */
334 if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
336 }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
337 $display.= "<p style=\"text-align:right\">\n";
338 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
339 $display.= " \n";
340 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
341 $display.= "</p>";
342 }elseif(!isset($this->dialog->current)){
343 $display.= "<p style=\"text-align:right\">\n";
344 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
345 $display.= "</p>";
346 }
347 return($display);
348 }
350 /* Show Management template
351 * The following code will only be reached if no dialog (tabs or dialogs)
352 * are currently opened.
353 * Assign all reguired vars to template engine
354 */
356 /* Create listhead, it will be shown on top of the divlist.
357 * It provides general navigation and object creation
358 */
359 $faihead =
360 "<div style='background:#F0F0F9;padding:5px;'> ".
362 " <input type='image' src='images/fai_new_profile.png' align='middle'
363 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ".
365 "<img src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ".
367 " <input type='image' src='images/fai_new_partitionTable.png' align='middle'
368 title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'> ".
370 " <input type='image' src='images/fai_new_script.png' align='middle'
371 title='"._("New scripts")."' name='Create_script' alt='"._("S")."'> ".
373 " <input type='image' src='images/fai_new_hook.png' align='middle'
374 title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'> ".
376 " <input type='image' src='images/fai_new_variable.png' align='middle'
377 title='"._("New variables")."' name='Create_variable' alt='"._("V")."'> ".
379 " <input type='image' src='images/fai_new_template.png' align='middle'
380 title='"._("New templates")."' name='Create_template' alt='"._("T")."'> ".
382 " <input type='image' src='images/fai_new_packages.png' align='middle'
383 title='"._("New package list")."' name='Create_package' alt='"._("PK")."'> ".
385 "</div>";
387 $this->reload();
389 /* Create list with objects */
390 $divlist = new divlist("faiManagement");
391 $divlist->SetEntriesPerPage(20);
392 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
394 $divlist->SetHeader(array(
395 array("string" => " "),
396 array("string" => _("Name of FAI class")),
397 array("string" => _("Class type")),
398 array("string" => _("Actions"), "attach"=>"style='border:none;width:40px;'")));
401 $action = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='entry_edit_%KEY%' title='"._("Edit class")."'>";
402 $action .= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
404 /* Attach objects */
405 foreach($this->objects as $key => $value){
406 $info= "";
407 $img = "";
408 $type = $value['type'];
409 $abort=false;
411 switch($type) {
412 case "FAIpartitionTable" :
413 if(!$faifilter['ShowPartitions']){
414 $abort = true;
415 }
416 $img="<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
417 $info = _("Partition table");
418 break;
419 case "FAIpackageList" :
420 if(!$faifilter['ShowPackages']){
421 $abort = true;
422 }
423 $img="<img src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
424 $info = _("Package list");
425 break;
426 case "FAIscript" :
427 if(!$faifilter['ShowScripts']){
428 $abort = true;
429 }
430 $img="<img src='images/fai_script' title='"._("Scripts")."' alt='S'>";
431 $info = _("Scripts");
432 break;
433 case "FAIvariable" :
434 if(!$faifilter['ShowVariables']){
435 $abort = true;
436 }
437 $img="<img src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
438 $info = _("Variables");
439 break;
440 case "FAIhook" :
441 if(!$faifilter['ShowHooks']){
442 $abort = true;
443 }
444 $img="<img src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
445 $info = _("Hooks");
446 break;
447 case "FAIprofile" :
448 if(!$faifilter['ShowProfiles']){
449 $abort = true;
450 }
451 $img="<img src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
452 $info = _("Profile");
453 break;
454 case "FAItemplate" :
455 if(!$faifilter['ShowTemplates']){
456 $abort = true;
457 }
458 $img="<img src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
459 $info = _("Templates");
460 break;
461 default :
462 $img="<img src='images/empty.png' >";$info = "";break;
464 }
466 if(!$abort) {
467 if((isset($value['description']))&&(!empty($value['description']))){
468 $desc= " [".$value['description']."]";
469 }else{
470 $desc= "";
471 }
473 $field1 = array("string" => $img , "attach" => "style='height:26px;width=20px;'");
474 $field2 = array("string" => $value['cn'].$desc , "attach" => "");
475 $field3 = array("string" => $info, "attach" => "");
476 $field4 = array("string" => preg_replace("/%KEY%/",$key,$action) , "attach"=>"style='text-align:right;border:none'");
477 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
479 }
480 }
482 foreach($faifilter as $attrs => $value){
483 if($value){
484 $smarty->assign($attrs."CHK", " checked ");
485 }else{
486 $smarty->assign($attrs."CHK", " ");
487 }
488 }
490 /* Assign all reguired vars to template engine */
491 $smarty->assign("faihead" , $faihead);
492 $smarty->assign("failist" , $divlist->DrawList());
493 $smarty->assign("regex" , $faifilter['regex']);
494 $smarty->assign("infoimage" , get_template_path('images/info.png'));
495 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
496 $smarty->assign("alphabet" , generate_alphabet());
497 $smarty->assign("apply" , apply_filter());
498 $smarty->assign("search_image" , get_template_path('images/search.png'));
500 $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
501 return ($display);
502 }
505 function reload()
506 {
507 /* Create a new list of FAI object
508 * Object list depends on faifilter['regex']
509 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
510 */
511 $faifilter= get_global('faifilter');
512 // Added for dirlist function...
514 /* Set base for all searches */
515 $base= $faifilter['base'];
516 $regex = $faifilter['regex'];
518 /* Array to save objects */
519 $objects = array();
521 $this->objects=array();
523 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",
524 FALSE, $base, array("cn","description","objectClass"),TRUE);
526 foreach($res as $objecttypes){
527 $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
528 FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE);
529 foreach($res2 as $object){
530 $type= "";
531 unset($object['objectClass']['count']);
532 if(!isset($object['description'][0])){
533 $object['description'][0]="";
534 }
536 /* Clean up object informations */
537 $obj['cn'] = $object['cn'][0];
538 $obj['dn'] = $object['dn'];
539 $obj['description'] = $object['description'][0];
540 $obj['objectClass'] = $object['objectClass'];
542 if(in_array("FAIpartitionTable",$obj['objectClass'])){
543 $type = "FAIpartitionTable";
544 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
545 $type = "FAIpackageList";
546 }elseif(in_array("FAIscript",$obj['objectClass'])){
547 $type = "FAIscript";
548 }elseif(in_array("FAIvariable",$obj['objectClass'])){
549 $type = "FAIvariable";
550 }elseif(in_array("FAIhook",$obj['objectClass'])){
551 $type = "FAIhook";
552 }elseif(in_array("FAIprofile",$obj['objectClass'])){
553 $obj['FAIclass'] = $object['FAIclass'][0];
554 $type = "FAIprofile";
555 }elseif(in_array("FAItemplate",$obj['objectClass'])){
556 $type = "FAItemplate";
557 }
558 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
559 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
561 }
562 }
563 ksort($this->objects);
564 reset ($this->objects);
565 }
567 function remove_lock()
568 {
569 if (isset($this->dn)){
570 del_lock ($this->dn);
571 }
572 }
574 function get_type($array){
575 if(in_array("FAIpartitionTable",$array['objectClass'])){
576 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
577 }
578 if(in_array("FAIscript",$array['objectClass'])){
579 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
580 }
581 if(in_array("FAItemplate",$array['objectClass'])){
582 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
583 }
584 if(in_array("FAIhook",$array['objectClass'])){
585 return(array("tabsHook","faiHook","FAIHOOKTABS"));
586 }
587 if(in_array("FAIvariable",$array['objectClass'])){
588 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
589 }
590 if(in_array("FAIprofile",$array['objectClass'])){
591 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
592 }
594 if(in_array("FAIpackageList",$array['objectClass'])){
595 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
596 }
597 }
599 }
601 ?>