Code

Prepared headpage conformance
[gosa.git] / plugins / admin / fai / class_faiManagement.inc
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 management";
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));
218                 
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))){
335                                 
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.= "&nbsp;\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;'>&nbsp;".
362                         " <input type='image' src='images/fai_new_profile.png' align='middle' 
363                         title='"._("New profile bundle")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
364                         
365                         "<img src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
366                                 
367                         " <input type='image' src='images/fai_new_partitionTable.png' align='middle' 
368                         title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
370                         " <input type='image' src='images/fai_new_script.png' align='middle' 
371                         title='"._("New script bundle")."' name='Create_script' alt='"._("S")."'>&nbsp;".
373                         " <input type='image' src='images/fai_new_hook.png' align='middle' 
374                         title='"._("New hook bundle")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
376                         " <input type='image' src='images/fai_new_variable.png' align='middle' 
377                         title='"._("New variable bundle")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
378                         
379                         " <input type='image' src='images/fai_new_template.png' align='middle' 
380                         title='"._("New template bundle")."' name='Create_template' alt='"._("T")."'>&nbsp;".
382                         " <input type='image' src='images/fai_new_packages.png' align='middle' 
383                         title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
384                         
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" => "&nbsp;"),
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 object")."'>";
402                 $action .= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete object")."'>";
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='Set of 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='Variable set' 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")." (".$value['FAIclass']." )";
453                                         break;
454                                         case "FAItemplate"                      : 
455                                                 if(!$faifilter['ShowTemplates']){ 
456                                                         $abort = true;
457                                                 }
458                                         $img="<img src='images/fai_template.png' title='Template' alt='T'>";
459                                         $info = _("Templates");
460                                         break;
461                                         default                                         : 
462                                         $img="<img src='images/empty.png' >";$info = "";break;
464                                 }
465                                 if(!$abort)     {
466                                         if((isset($value['description']))&&(!empty($value['description']))){
467                                                 $desc= " [".$value['description']."]";
468                                         }else{
469                                                 $desc= "";
470                                         }
472                                         $field1 = array("string" => $img , "attach" => "style='height:26px;width=20px;'");
473                                         $field2 = array("string" => $value['cn'].$desc , "attach" => "");
474                                         $field3 = array("string" => $info, "attach" => "");
475                                         $field4 = array("string" => preg_replace("/%KEY%/",$key,$action) , "attach"=>"style='text-align:right;border:none'");
476                                         $divlist->AddEntry(array($field1,$field2,$field3,$field4));
478                         }
479                 }
481                 foreach($faifilter as $attrs => $value){
482                         if($value){
483                                 $smarty->assign($attrs."CHK", " checked ");
484                         }else{
485                                 $smarty->assign($attrs."CHK", " ");
486                         }
487                 }
489                 /* Assign all reguired vars to template engine */
490                 $smarty->assign("faihead"               , $faihead);    
491                 $smarty->assign("failist"               , $divlist->DrawList());
492                 $smarty->assign("regex"                 , $faifilter['regex']); 
493                 $smarty->assign("infoimage"             , get_template_path('images/info.png'));
494                 $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
495                 $smarty->assign("alphabet"              , generate_alphabet());
496                 $smarty->assign("apply"                 , apply_filter());
497                 $smarty->assign("search_image"  , get_template_path('images/search.png'));
499                 $display        = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
500                 return ($display);
501         }
504         function reload()
505         {
506                 /* Create a new list of FAI object 
507                  * Object list depends on faifilter['regex']
508                  * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
509                  */
510                 $faifilter= get_global('faifilter');
511                 // Added for dirlist function...
513                 /* Set base for all searches */
514                 $base= $faifilter['base'];
515                 $regex = $faifilter['regex'];   
517                 /* Array to save objects */
518                 $objects = array();
519         
520                 $this->objects=array();
522                 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", 
523                                 FALSE, $base, array("cn","description","objectClass"),TRUE);
525                 foreach($res as $objecttypes){
526                         $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
527                                         FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE);
528                         foreach($res2 as $object){
529                                 $type= "";      
530                                 unset($object['objectClass']['count']);
531                                 if(!isset($object['description'][0])){
532                                         $object['description'][0]="";
533                                 }
534                                 
535                                 /* Clean up object informations */
536                                 $obj['cn']                      = $object['cn'][0];
537                                 $obj['dn']                      = $object['dn'];
538                                 $obj['description'] = $object['description'][0];
539                                 $obj['objectClass'] = $object['objectClass'];
541                                 if(in_array("FAIpartitionTable",$obj['objectClass'])){
542                                         $type = "FAIpartitionTable";
543                                 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
544                                         $type = "FAIpackageList";
545                                 }elseif(in_array("FAIscript",$obj['objectClass'])){
546                                         $type = "FAIscript";
547                                 }elseif(in_array("FAIvariable",$obj['objectClass'])){
548                                         $type = "FAIvariable";
549                                 }elseif(in_array("FAIhook",$obj['objectClass'])){
550                                         $type = "FAIhook";
551                                 }elseif(in_array("FAIprofile",$obj['objectClass'])){
552                                         $obj['FAIclass']        = $object['FAIclass'][0];
553                                         $type = "FAIprofile";
554                                 }elseif(in_array("FAItemplate",$obj['objectClass'])){
555                                         $type = "FAItemplate";
556                                 }
557                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
558                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
559  
560                         }
561                 }
562                 ksort($this->objects);
563                 reset ($this->objects);
564         }
566         function remove_lock()
567         {
568                 if (isset($this->dn)){
569                         del_lock ($this->dn);
570                 }
571         }
573         function get_type($array){
574                 if(in_array("FAIpartitionTable",$array['objectClass'])){
575                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
576                 }
577                 if(in_array("FAIscript",$array['objectClass'])){
578                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
579                 }
580                 if(in_array("FAItemplate",$array['objectClass'])){
581                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
582                 }
583                 if(in_array("FAIhook",$array['objectClass'])){
584                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
585                 }
586                 if(in_array("FAIvariable",$array['objectClass'])){
587                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
588                 }
589                 if(in_array("FAIprofile",$array['objectClass'])){
590                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
591                 }
592                 
593                 if(in_array("FAIpackageList",$array['objectClass'])){
594                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
595                 }
596         }
600 ?>