Code

Added multiple remove to group list
[gosa.git] / plugins / admin / systems / class_systemManagement.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 "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31   /* Definitions */
32   var $plHeadline     = "Systems";
33   var $plDescription  = "This does something";
34   var $departments    = array();
36   /* Dialog attributes */
37   var $systab   = NULL;
38   var $terminals= array();
39   var $ui       = NULL;
40   var $DivListSystem;
42   function systems ($config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= $config;
46     $this->ui= $ui;
48     /* Creat dialog object */
49     $this->DivListSystem = new divListSystem($this->config,$this);
50   }
52   function execute()
53   {
54     /* Call parent execute */
55     plugin::execute();
57     $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/");
59     /********************
60       Check for functional posts, edit|delete|add|... system devices 
61      ********************/
62     $s_action     = "";                       // Contains the action to proceed
63     $s_entry      = "";                       // The value for s_action
64     $base_back    = "";                       // The Link for Backbutton
65     $smarty       = get_smarty();
67     /* Test Posts */
68     foreach($_POST as $key => $val){
69       // Post for delete
70       if(preg_match("/system_del.*/",$key)){
71         $s_action = "del";
72         $s_entry  = preg_replace("/system_del_/i","",$key);
73         // Post for edit
74       }elseif(preg_match("/system_edit_.*/",$key)){
75         $s_action="edit";
76         $s_entry  = preg_replace("/system_edit_/i","",$key);
77         // Post for new
78       }elseif(preg_match("/system_new.*/",$key)){
79         $s_action="new";
80       }elseif(preg_match("/system_tplnew.*/i",$key)){
81         $s_action="new_tpl";
82       }elseif(preg_match("/system_setpwd_.*/i",$key)){
83         $s_action="change_pw";
84         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
85       }elseif(preg_match("/gen_cd_.*/i",$key)){
86         $s_action="gen_cd";
87         $s_entry  = preg_replace("/gen_cd_/i","",$key);
88       }elseif(preg_match("/newsystem_.*/i",$key)){
89         $s_action="newsystem";
90         $s_entry  = preg_replace("/newsystem_/i","",$key);
91       }
92     }
94     /* Incoming handling  
95      * If someone made a systemtype and ogroup selection 
96      * Display the new requested entry type ... servtab  in case of server and so on.
97      */
98     if(isset($_POST['SystemTypeChoosen'])){
99       $s_action = "SelectedSystemType";
100       $s_entry  = $_POST['SystemType'];
101       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
102       $this->systab = NULL;
103     }
105     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
106     $s_entry  = preg_replace("/_.$/","",$s_entry);
108     /* Edit was requested by pressing the name(link) of an item */
109     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
110       $s_action ="edit";
111       $s_entry  = $_GET['id'];
112     }
114     /* Check for exeeded sizelimit */
115     if (($message= check_sizelimit()) != ""){
116       return($message);
117     }
119     /* Try to get informations about what kind of system to create */
120     if ($s_action=="new") {
121       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
122     }
125     /********************
126       Create FAI CD ...   
127      ********************/
128     if ($s_action=="gen_cd"){
129       $this->dn= $this->terminals[$s_entry]['dn'];
130       $_SESSION['objectinfo']= $this->dn;
131       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
132     }
135     /* Start CD-Creation */
136     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
137       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
138       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
139     }
142     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
144       $return_button   = "<form method='get' action='main.php' target='_parent'>
145         <input type='submit' value='"._("Back")."'>
146         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
147         </form>";
149       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
151       /* Get and check command */
152       $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
153       if (check_command($command)){
154         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
156         /* Print out html introduction */
157         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
158           <html>
159           <head>
160           <title></title>
161           <style type="text/css">@import url("themes/default/style.css");</style>
162           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
163           </head>
164           <body style="background: none; margin:4px;" id="body" >
165           <pre>';
167         /* Open process handle and check if it is a valid process */
168         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
169         if (is_resource($process)) {
170           fclose($pipes[0]);
172           /* Print out returned lines && write JS to scroll down each line */
173           while (!feof($pipes[1])){
174             $cur_dat = fgets($pipes[1], 1024);
175             echo $cur_dat;
176             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
177             flush();
178           }
179         }
181         /* Get error string && close streams */
182         $buffer= stream_get_contents($pipes[2]);
184         fclose($pipes[1]);
185         fclose($pipes[2]);
186         echo "</pre>";
188         /* Check return code */
189         $ret= proc_close($process);
190         if ($ret != 0){
191           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
192           echo "<pre style='color:red'>$buffer</pre>";
193         }
197         echo $return_button."<br>";
199       } else {
200         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
201         echo $tmp;
202       }
204       /* Scroll down completly */
205       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
206       echo '</body></html>';
207       flush();
208       exit;
209     }
212     /********************
213       Create new system ...   
214      ********************/
215     /* Create new default terminal 
216      * Or create specified object of selected system type, from given incoming object  
217      */
219     $save_object_directly = false;
220     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
221       $save_object_directly = true;
222     }
224     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
226       /* If the current entry is an incoming object 
227        * $sw = System type as posted in new incoming handling dialog 
228        */ 
229       if($s_action == "SelectedSystemType") {
230         $sw         = $s_entry;
231       }else{
232         if(isset($_POST['system'])){
233           $sw = $_POST['system'];
234         }else{
235           $sw = $s_entry;
236         }
237         $this->dn= "new";
238       }
239       $tabs = array(
240           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
241           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
242           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
243           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
244           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
245           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
247       if(isset($tabs[$sw])){
248         $class    = $tabs[$sw]["CLASS"];
249         $tabname  = $tabs[$sw]["TABNAME"];
250         $tabclass = $tabs[$sw]["TABCLASS"];
251         $acl_cat  = $tabs[$sw]["ACL"];
253         /* Load permissions for selected 'dn' and check if
254            we're allowed to remove this 'dn' */
255         $ui       = get_userinfo();
256         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
257         if(preg_match("/c/",$tabacl)){
258           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
259           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
260           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
261           $this->systab->base = $this->DivListSystem->selectedBase;
262         }else{
263           print_red(_("You are not allowed to create a new object of this type."));
264         }
265       }
266     }
268     /********************
269       Edit system ...   
270      ********************/
272     /* User wants to edit data? */
273     if (($s_action == "edit") && (!isset($this->systab->config))){
275       $this->dn= $this->terminals[$s_entry]['dn'];
277       /* Check locking, save current plugin in 'back_plugin', so
278          the dialog knows where to return. */
279       if (($user= get_lock($this->dn)) != ""){
280         return(gen_locked_message ($user, $this->dn));
281       }
283       /* Find out more about the object type */
284       $ldap= $this->config->get_ldap_link();
285       $ldap->cat($this->dn, array('objectClass'));
286       $attrs= $ldap->fetch();
287       $type= $this->get_system_type($attrs['objectClass']);
289       /* Lock the current entry, so everyone will get the
290          above dialog */
291       $tabs = array(
292           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
293           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
294           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
295           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
296           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
297           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
298           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
301       if($type == "NewDevice"){
302         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
303       }elseif(isset($tabs[$type])){
305         $class    = $tabs[$type]["CLASS"];
306         $acl_cat  = $tabs[$type]["ACL"];
307         $tabclass = $tabs[$type]["TABCLASS"];
309         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
310         $this->systab->set_acl_base($this->dn);
311         $_SESSION['objectinfo']= $this->dn;
312         add_lock ($this->dn, $this->ui->dn);
313       }else{ 
314         print_red (_("You can't edit this object type yet!"));
315         del_lock($this->dn);
316       }
317     }
320     /********************
321       Change password ...   
322      ********************/
324     /* Set terminals root password */
325     if ($s_action=="change_pw"){
326       $tabs = array(
327           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
328           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
330       $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
331       $class    = $tabs[$type]["CLASS"];
332       $tabname  = $tabs[$type]["TABNAME"];
333       $acl_cat  = $tabs[$type]["ACL"];
334       $tabclass = $tabs[$type]["TABCLASS"];
335       $ui       = get_userinfo();
336       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
337       if(preg_match("/w/",$tabacl)){
338         $this->dn= $this->terminals[$s_entry]['dn'];
339         $_SESSION['objectinfo']= $this->dn;
340         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
341       }else{
342         print_red(_("You are not allowed to change the password for this object."));
343       }
344     }
347     /********************
348       Password change finish, but check if entered data is ok 
349      ********************/
351     /* Correctly specified? */
352     if (isset($_POST['password_finish'])){
353       if ($_POST['new_password'] != $_POST['repeated_password']){
354         print_red (_("Passwords entered as new and repeated do not match!"));
355         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
356       }
357     }
359     /********************
360       Password change finish
361      ********************/
363     /* Change terminal password */
364     if (isset($_POST['password_finish']) && 
365         $_POST['new_password'] == $_POST['repeated_password']){
367       /* Check if user is allowed to set password */
368       $tabs = array(
369           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
370           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
372       /* Detect object type */
373       $type = "";
374       foreach($this->terminals as $terminal){
375         if($terminal['dn'] == $this->dn){
376           $type = $this->get_system_type($terminal['objectClass']);
377           break;
378         } 
379       }
381       /* Type detected */
382       if(!empty($type)){
384         /* Get infos */
385         $class    = $tabs[$type]["CLASS"];
386         $tabname  = $tabs[$type]["TABNAME"];
387         $acl_cat  = $tabs[$type]["ACL"];
388         $tabclass = $tabs[$type]["TABCLASS"];
389     
390         /* Get acls */
391         $ui       = get_userinfo();
392         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
394         /* Check acls */
395         if(preg_match("/w/",$tabacl)){
396           $ldap = $this->config->get_ldap_link();
397           $ldap->cd($this->dn);
399           $attrs= array();
400           if ($_POST['new_password'] == ""){
401             $attrs['gotoRootPasswd']= array();
402           } else {
403             $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
404           }
405           $ldap->modify($attrs);
406           gosa_log ("Password for '".$this->dn."' has been changed");
407         }else{
408           print_red(_("You are not allowed to change the password for this object."));
409         }
410       }else{
411         print_red(_("Can't detect object to change password."));
412       }
413       unset($_SESSION['objectinfo']);
414     }
417     /********************
418       Delete system cancel
419      ********************/
421     /* Delete terminal canceled? */
422     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
423       del_lock ($this->dn);
424       unset($_SESSION['objectinfo']);
425     }
428     /********************
429       Delete system, confirm dialog
430      ********************/
432     /* Remove terminal was requested */
433     if ($s_action=="del"){
435       /* Get 'dn' from posted termlinst */
436       $this->dn = $this->terminals[$s_entry]['dn'];
437       $attrs    = $this->terminals[$s_entry];
439       $type= $this->get_system_type($attrs['objectClass']);
440       $ui = get_userinfo();
441       $tabs = array(
442           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
443           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
444           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
445           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
446           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
447           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
448           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
451       /* get object type */
452       $tabtype  = "termtabs";
453       $tabobj   = "TERMTABS";
454       $tabacl   = "";
455       if(isset($tabs[$type])){
456         $tabtype = $tabs[$type]['TABCLASS'];
457         $tabobj  = $tabs[$type]['CLASS'];
458         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
459       }
461       /* Load permissions for selected 'dn' and check if
462          we're allowed to remove this 'dn' */
463       if(preg_match("/d/",$tabacl)){ 
465         /* Check locking, save current plugin in 'back_plugin', so
466            the dialog knows where to return. */
467         if (($user= get_lock($this->dn)) != ""){
468           return(gen_locked_message ($user, $this->dn));
469         }
471         /* Lock the current entry, so nobody will edit it during deletion */
472         add_lock ($this->dn, $this->ui->dn);
473         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
474         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
475       } else {
477         /* Obviously the user isn't allowed to delete. Show message and
478            clean session. */
479         print_red (_("You are not allowed to delete this component!"));
480       }
481     }
484     /********************
485       Delete system, confirmed
486      ********************/
487     /* Confirmation for deletion has been passed. Terminal should be deleted. */
488     if (isset($_POST['delete_terminal_confirm'])){
490       /* Find out more about the object type */
491       $ldap= $this->config->get_ldap_link();
492       $ldap->cat($this->dn, array('objectClass'));
493       $attrs= $ldap->fetch();
494       $type= $this->get_system_type($attrs['objectClass']);
496       $ui = get_userinfo();
498       $tabs = array(
499           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
500           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
501           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
502           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
503           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
504           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
505           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
507       /* get object type */
508       $tabtype  = "termtabs";
509       $tabobj   = "TERMTABS";
510       $tabacl   = "";
511       if(isset($tabs[$type])){
512         $tabtype = $tabs[$type]['TABCLASS'];
513         $tabobj  = $tabs[$type]['CLASS'];
514         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
515       }
517       /* Check if we are allowed to remove this object */
518       if(preg_match("/d/",$tabacl)){
520         /* Delete request is permitted, perform LDAP action */
521         if($tabtype=="phonetabs"){
522           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
523           $this->systab->set_acl_base($this->dn);
524           $this->systab->by_object['phonegeneric']->remove_from_parent ();
525         }else{  
526           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
527           $this->systab->set_acl_base($this->dn);
528           $this->systab->delete();
529         }
530         unset ($this->systab);
531         gosa_log ("System object'".$this->dn."' has been removed");
532         $this->systab= NULL;
534         /* Terminal list has changed, reload it. */
535       } else {
537         /* Normally this shouldn't be reached, send some extra
538            logs to notify the administrator */
539         print_red (_("You are not allowed to delete this component!"));
540         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
541             "deletion.");
542       }
544       /* Remove lock file after successfull deletion */
545       del_lock ($this->dn);
546     }
556    /********************
557       Edit system type finished, check if everything went ok
558      ********************/
559     /* Finish user edit is triggered by the tabulator dialog, so
560        the user wants to save edited data. Check and save at this
561        point. */
562     if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
564       /* Check tabs, will feed message array */
565       $message = array();
566       if(!$save_object_directly){
567         $message = $this->systab->check();
568       }else{
569         $found = false;
571         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
572         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
573           if(isset($this->systab->by_object[$tab]->gotoMode)) {
574             $found = true;
575             $this->systab->by_object[$tab]->gotoMode = $value;
576           }
577         }
578         if(!$found){
579           print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
580         }
582       }
583       /* Save, or display error message? */
584       if (count($message) == 0){
586         /* Save terminal data to ldap */
587         if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
588           foreach (array("workservice", "termservice") as $cls){
589             if (isset($this->systab->by_object[$cls])){
590               $this->systab->by_object[$cls]->gotoXMouseport= "";
591               $this->systab->by_object[$cls]->gotoXMouseType= "";
592               $this->systab->by_object[$cls]->gotoXResolution= "";
593               $this->systab->by_object[$cls]->gotoXColordepth= "";
594             }
595           }
596         }
598         $this->systab->save();
599         gosa_log ("System object'".$this->dn."' has been saved");
601         /* Incoming behavior; you can select a system type and an ogroup membership.
602          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
603          * Check if we must add the new object to an object group.
604          *
605          * If this is done, delete the old incoming entry... it is still there, because this is a new
606          * entry and not an edited one, so we will delete it.
607          *
608          */
610         if(isset($_SESSION['SelectedSystemType'])){
611           $SelectedSystemType= $_SESSION['SelectedSystemType'];
612           unset($_SESSION['SelectedSystemType']);
613           if($SelectedSystemType['ogroup'] != "none"){
614             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
615             if($og){
616               $og->AddDelMembership($this->systab->dn);
617               $og->save();
618             }
619           }
620           if(!isset($ldap)){
621             $ldap = $this->config->get_ldap_link();
622           }
623           $ldap->cd ($this->dn);
624           $ldap->cat($this->dn, array('dn'));
625           if(count($ldap->fetch())){
626             $ldap->cd($this->dn);
627             $ldap->rmDir($this->dn);
628           }
629           $ldap->cd($this->config->current['BASE']);
630         }
632         /* Terminal has been saved successfully, remove lock from
633            LDAP. */
634         if ($this->dn != "new"){
635           del_lock ($this->dn);
636         }
638         unset ($this->systab);
639         $this->systab= NULL;
640         unset($_SESSION['objectinfo']);
641       } else {
642         /* Ok. There seem to be errors regarding to the tab data,
643            show message and continue as usual. */
644         show_errors($message);
645       }
646     }
649     /********************
650       Edit system was canceled 
651      ********************/
652     /* Cancel dialogs */
653     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
654       if (isset($this->systab)){
655         del_lock ($this->systab->dn);
656         unset ($this->systab);
657       }
658       $this->systab= NULL;
659       unset($_SESSION['objectinfo']);
661       /* Remove ogroup selection, which was set while editing a new incoming entry */
662       if(isset($_SESSION['SelectedSystemType'])){
663         unset($_SESSION['SelectedSystemType']);
664       }
665     }
667     /********************
668       Display edit dialog, or some other
669      ********************/
671     /* Show tab dialog if object is present */
672     if (isset($this->systab->config)){
673       $display= $this->systab->execute();
675       /* Don't show buttons if tab dialog requests this */
676       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
677         $display.= "<p style=\"text-align:right\">\n";
678         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
679         $display.= "&nbsp;\n";
680         if ($this->dn != "new"){
681           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
682           $display.= "&nbsp;\n";
683         }
684         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
685         $display.= "</p>";
686       }
687       return ($display);
688     }
690     /* Check if there is a snapshot dialog open */
691     $base = $this->DivListSystem->selectedBase;
692     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
693       return($str);
694     }
696     /* Display dialog with system list */
697     $this->DivListSystem->parent = $this;
698     $this->DivListSystem->execute();
700     /* Add departments if subsearch is disabled */
701     if(!$this->DivListSystem->SubSearch){
702       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
703     }
704     $this->reload();
705     $this->DivListSystem->setEntries($this->terminals);
706     return($this->DivListSystem->Draw());
707   }
710   /* Return departments, that will be included within snapshot detection */
711   function get_used_snapshot_bases()
712   {
713     $tmp = array();
715     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
717     $tabs = array(
718         "terminal"        => "ou=terminals,ou=systems,",
719         "workstation"     => "ou=workstations,ou=systems,",
720         "incoming"        => "ou=incoming,",
721         "server"          => "ou=servers,ou=systems,",
722         "printer"         => "ou=printers,ou=systems,",
723         "phone"           => "ou=phones,ou=systems,",
724         "winworkstation"  => get_winstations_ou(),
725         "component"       => "ou=netdevices,ou=systems,"
726         ); 
728     foreach($tabs as $acl_cat => $dn){
730       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
731       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
732         $tmp[] = $dn.$this->DivListSystem->selectedBase;
733       }
734     }
735     return($tmp); 
736   }
739   function remove_from_parent()
740   {
741     /* Optionally execute a command after we're done */
742     $this->postremove();
743   }
746   /* Save data to object */
747   function save_object()
748   {
749     $this->DivListSystem->save_object();
750   }
753   /* Check values */
754   function check()
755   {
756   }
759   /* Save to LDAP */
760   function save()
761   {
762   }
764   function adapt_from_template($dn)
765   {
766   }
768   function password_change_needed()
769   {
770   }
772   function reload()
773   {
774     /* some var init */
775     $ui = get_userinfo();
776     $res              = array();
777     $this->terminals  = array();
778     $userregex        = "";
780     /* Set base for all searches */
781     $base=  $this->DivListSystem->selectedBase;
783     /* Prepare samba class name */
784     $samba  ="";
785     if ($this->DivListSystem->ShowWinWorkstations){
786       if ($this->config->current['SAMBAVERSION'] == "3"){
787         $samba= "sambaSamAccount";
788       } else {
789         $samba= "sambaAccount";
790       }
791     }
793     /* This array represents the combination between checkboxes and search filters */
794     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
795         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
796         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
797         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
798         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
799         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
800         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
802     /* Include the 'Display Systems of user' attribute */ 
803     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
804       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
805     }
807     /* Attributes to fetch */
808     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName");
809     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer");
811     /* Add FAIstate to attributes if FAI is activated */
812     $tmp = search_config($this->config->data,"faiManagement","CLASS");
813     if(!empty($tmp)){
814       $sys_attrs[] = "FAIstate";
815     }    
817     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
818     foreach($objs as $checkBox => $oc){
819       if($this->DivListSystem->$checkBox){
820         if($this->DivListSystem->SubSearch){
821           if($oc['CLASS'] != ""){
822             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
823             $new_res = get_list($filter, $sys_categories , $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
824       
825             /* Remove all objects that are not in the expected sub department */
826             foreach($new_res as $key => $obj){
827               if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
828                 $res[$obj['dn']] = $obj;
829               }
830             }
831           }
832         }else{
833           /* User filter? */
834           if($oc['CLASS'] != ""){
835             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
836             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
837           }
838         }
839       } 
840     }
842     /* Search for incoming objects */ 
843     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
844     $res = array_merge($res,get_list($filter,$sys_categories,"ou=incoming,".$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
846     /* Get all gotoTerminal's */
847     foreach ($res as $value){
849       $tmp= $value['dn'];
850       $add= "";
852       /* Extract base */
853       foreach($objs as $obj){
854         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
855           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
856         }
857       }
859       /* Create a string containing the last part of the department. */
860       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
861       if(empty($dn_name)){
862         $dn_name = "/";
863       }
865       /* check if current object is a new one */
866       if (preg_match ("/,ou=incoming,/i", $tmp)){
867         if (in_array_ics('gotoTerminal', $value['objectClass'])){
868           $add= "- "._("New terminal");
869         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
870           $add= "- "._("New workstation");
871         }elseif (in_array_ics('GOhard', $value['objectClass'])){
872           $add= "- "._("New Device");
873         }
874       } 
876       /* Detect type of object and create an entry for $this->terminals */
877       $terminal = array();
879       if (in_array_ics('gotoTerminal', $value["objectClass"])){
881         /* check acl */
882         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
883         if($add != "" || preg_match("/r/",$acl)) {
884           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
885             $terminal             = $value;
886             $terminal['type']     = "T";
887             $terminal['is_new']   = $add;
888           } else {
889             $terminal             = $value;
890             $terminal['type']     = "D";
891             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
892             $terminal['location'] = array_search($tmp, $this->config->departments); 
893           }
894         }
895       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
897         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
898         if($add != "" || preg_match("/r/",$acl)) {
899           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
900             $terminal             = $value;
901             $terminal['type']     = "L";
902             $terminal['is_new']   = $add;
903           } else {
904             $terminal             = $value;
905             $terminal['type']     = "D";
906             $terminal['location'] = array_search($tmp, $this->config->departments);
907             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
908           }
909           if (isset($value["FAIstate"][0])){
910             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
911           }
912         }
913       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
914        
915    
916         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
917         if($add != "" || preg_match("/r/",$acl)) {
919           $terminal             = $value;
920           $terminal['type']     = "P";
921         }
922       } elseif (in_array_ics('goServer', $value["objectClass"])){
924         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
925         if($add != "" || preg_match("/r/",$acl)) {
927           $terminal             = $value;
928           $terminal['type']     = "S";
929           if (isset($value["FAIstate"][0])){
930             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
931           }
932         }
933       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
935         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
936         if($add != "" || preg_match("/r/",$acl)) {
938           $terminal             = $value;
939           $terminal['type']     = "F";
940         }
941       }elseif (in_array_ics("GOhard",$value['objectClass'])){
943         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
944                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
945                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
946         if($add != "" || preg_match("/r/",$acl)) {
948           $terminal = $value;
949           $terminal['type']   = "Q";
950           $terminal['is_new'] = $add;
951         }
952       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
954         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
955         if($add != "" || preg_match("/r/",$acl)) {
957           $terminal             = $value;
958           $terminal['type']     = "C";
959         }
960       } else{
962         $name= preg_replace('/\$$/', '', $value['cn'][0]);
963         if (isset($value['sambaDomainName'])){
964           $domain= " [".$value['sambaDomainName'][0]."]";
965         } else {
966           $domain= "";
967         }
968         $terminal=$value;
969         $terminal['type']     ="W";
970         $terminal['domain']   = $name.$domain;
971       }
973       if(count($terminal)){
974         $this->terminals[]=$terminal;
975       }
976     }
978     $tmp=array();
979     foreach($this->terminals as $tkey => $val ){
980       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
981     }
982     ksort($tmp);
983     $this->terminals=array();
984     foreach($tmp as $val){
985       $this->terminals[]=$val;
986     }
987     reset ($this->terminals);
988   }
990   function remove_lock()
991   {
992     if (isset($this->systab->dn)){
993       del_lock ($this->systab->dn);
994     }
995   }
998   function get_system_type($classes)
999   {
1000     $type= "";
1001     if (in_array_ics('ieee802Device', $classes)){
1002       $type= "component";
1003     }elseif (in_array_ics('gotoTerminal', $classes)){
1004       $type= "terminal";
1005     }elseif (in_array_ics('gotoWorkstation', $classes)){
1006       $type= "workstation";
1007     }elseif (in_array_ics('gotoPrinter', $classes)){
1008       $type= "printer";
1009     }elseif (in_array_ics('goFonHardware', $classes)){
1010       $type= "phone";
1011     }elseif (in_array_ics('goServer', $classes)){
1012       $type= "server";
1013     }elseif (in_array_ics('GOhard', $classes)){
1014       $type= "NewDevice";
1015     }elseif (in_array_ics('sambaAccount', $classes) ||
1016         in_array_ics('sambaSamAccount', $classes)){
1017       $type= "winstation";
1018     }
1019     return ($type);
1020   }
1023   function convert_list($input)
1024   {
1025     $temp= "";
1026     $conv= array(       
1027         "NQ" => array("select_newsystem.png",_("New System from incoming")),
1028         "D" => array("select_default.png",_("Template")),
1029         "T" => array("select_terminal.png",_("Terminal")),
1030         "L" => array("select_workstation.png",_("Workstation")),
1031         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1032         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1033         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1034         "F" => array("select_phone.png",_("Phone")),
1035         "S" => array("select_server.png",_("Server")),
1036         "GS" => array("select_server_green.png",_("Server is installing")),
1037         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1038         "RS" => array("select_server_red.png",_("Server installation failed")),
1039         "W" => array("select_winstation.png",_("Winstation")),
1040         "C" => array("select_component.png",_("Network Device")),
1041         "NT"=> array("select_new_terminal.png",_("New Terminal")),
1042         "NL"=> array("select_new_workstation.png",_("New Workstation")),
1043         "P" => array("select_printer.png",_("Printer")));
1045     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1046       $input['type']="N".$input['type'];
1047     }
1048     foreach ($conv  as $key => $value){
1049       if($input['type']==$key){
1050         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1051         $tmp['class']=$key;
1052         return $tmp;
1053       }
1054     }
1055   }
1057   
1058   function getState($type, $state)
1059   {
1060     switch (preg_replace('/:.*$/', '', $state)) {
1061       case 'installing':
1062                 $type= 'G'.$type;
1063                 break;
1064       case 'error':
1065                 $type= 'R'.$type;
1066                 break;
1067       case 'install':
1068                 $type= 'Y'.$type;
1069                 break;
1070       case 'sysinfo':
1071                 $type= 'Y'.$type;
1072                 break;
1073       case 'softupdate':
1074                 $type= 'Y'.$type;
1075                 break;
1076     }
1079     return ($type);
1080   }
1083   /* !! Incoming dummy acls, required to defined acls for incoming objects
1084    */
1085   function plInfo()
1086   {
1087     return (array(
1088           "plShortName"   => _("Incoming objects"),
1089           "plDescription" => _("Incoming objects"),
1090           "plSelfModify"  => FALSE,
1091           "plDepends"     => array(),
1092           "plPriority"    => 99,
1093           "plSection"     => array("administration"),
1094           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1095                                                           "objectClass"  => "")),
1096           "plProvidedAcls"=> array()
1097             
1098           ));
1099   }
1102   
1106 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1107 ?>