Code

Updates
[gosa.git] / gosa-plugins / systems / admin / systems / class_systemManagement.inc
index 75ac762c35d8375a477913f572e22f36c3aa4bcb..e5d66afcc17849ebad7e1ac8affb9f53a8291da9 100644 (file)
@@ -1,21 +1,23 @@
 <?php
 /*
-   This code is part of GOsa (https://gosa.gonicus.de)
-   Copyright (C) 2003  Cajus Pollmeier
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 class systems extends plugin
@@ -63,7 +65,7 @@ class systems extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/"));
+    session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
 
     /********************
       Check for functional posts, edit|delete|add|... system devices 
@@ -141,11 +143,27 @@ class systems extends plugin
       $s_action = "editPaste";
     }
 
+    /* Handle daemon events */
+    if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
+      $s_action = $_POST['menu_action'];
+    }
+    
+    /* Handle daemon events */
+    if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
+      $s_action = $_POST['menu_action'];
+    }
+
     /* handle remove from layers menu */
     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
       $s_action = "del_multiple";
     }
     
+    /* Handle instant actions from layers menu */
+    foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
+           if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
+             $s_action = "${act}_multiple";
+           }
+    }
 
     /* Check for exeeded sizelimit */
     if (($message= check_sizelimit()) != ""){
@@ -476,6 +494,69 @@ class systems extends plugin
     }
 
 
+    /********************
+      Action(s) for MULTIPLE
+     ********************/
+
+    /********************
+      SCHEDULE action in GOsa Daemon
+     ********************/
+
+    if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
+      $this->dns = array();
+      $ids = $this->list_get_selected_items();
+
+      if(count($ids)){
+        $mac= array();
+
+        $ldap = $this->config->get_ldap_link();
+        foreach($ids as $id){
+          $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
+          $attrs= $ldap->fetch();
+          if (isset($attrs['macAddress'][0])){
+            $mac[]= $attrs['macAddress'][0];
+          }
+        }
+        $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
+        $type = preg_replace("/^[a-z]*_event_/","",$s_action);
+
+        /* Prepare event to be added 
+         */
+        if(count($mac) && isset($events['BY_CLASS'][$type])){
+          $event = $events['BY_CLASS'][$type];
+          $this->systab = new $event['CLASS_NAME']($this->config);
+          $this->systab->add_targets($mac);
+          if(preg_match("/trigger_event/",$s_action)){
+            $this->systab->set_type(TRIGGERED_EVENT);
+          }else{
+            $this->systab->set_type(SCHEDULED_EVENT);
+          }
+        }
+      }
+    }
+
+    /* Insert scheduled events into queue */
+    if($this->systab instanceof DaemonEvent){
+      $this->systab->save_object();
+
+      /* Save event 
+       */
+      if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
+        $o_queue = new gosaSupportDaemon();
+        $o_queue->append($this->systab);
+        if($o_queue->is_error()){
+          msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
+                $o_queue->get_error()),ERROR_DIALOG);
+        }else{
+          $this->systab = FALSE;
+        }
+      }
+      if(isset($_POST['abort_event_dialog'])){
+        $this->systab = FALSE;
+      }
+    }
+
+
     /********************
       Delete MULTIPLE entries requested, display confirm dialog
      ********************/
@@ -488,11 +569,11 @@ class systems extends plugin
 
         foreach($ids as $id){
           $dn = $this->terminals[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
-          }
           $this->dns[$id] = $dn;
         }
+        if ($user= get_multiple_locks($this->dns)){
+          return(gen_locked_message($user,$this->dns));
+        }
 
         $dns_names = "<br><pre>";
         foreach($this->dns as $dn){
@@ -522,6 +603,8 @@ class systems extends plugin
 
       $ui = get_userinfo();
       $tabs = array(
+          "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
+          "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
@@ -552,7 +635,11 @@ class systems extends plugin
           if(preg_match("/d/",$tabacl)){ 
 
             /* Delete request is permitted, perform LDAP action */
-            if($tabtype=="phonetabs"){
+            if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
+              $this->systab= new termgeneric($this->config, $dn);
+              $this->systab->set_acl_base($dn);
+              $this->systab->remove_from_parent();
+            }elseif($tabtype=="phonetabs"){
               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
               $this->systab->set_acl_base($dn);
               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
@@ -601,9 +688,13 @@ class systems extends plugin
       $this->dn = $this->terminals[$s_entry]['dn'];
       $attrs    = $this->terminals[$s_entry];
 
+  
+
       $type= $this->get_system_type($attrs);
       $ui = get_userinfo();
       $tabs = array(
+          "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
+          "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
@@ -612,7 +703,6 @@ class systems extends plugin
           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
 
-
       /* get object type */
       $tabtype  = "termtabs";
       $tabobj   = "TERMTABS";
@@ -662,6 +752,8 @@ class systems extends plugin
       $ui = get_userinfo();
 
       $tabs = array(
+          "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
+          "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
@@ -684,7 +776,11 @@ class systems extends plugin
       if(preg_match("/d/",$tabacl)){
 
         /* Delete request is permitted, perform LDAP action */
-        if($tabtype=="phonetabs"){
+        if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
+          $this->systab= new termgeneric($this->config, $this->dn);
+          $this->systab->set_acl_base($this->dn);
+          $this->systab->remove_from_parent();
+        }elseif($tabtype=="phonetabs"){
           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
           $this->systab->set_acl_base($this->dn);
           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
@@ -781,6 +877,40 @@ class systems extends plugin
         }
 
         $this->systab->save();
+        /* Get macAddress to be able to an installation event 
+         */ 
+        if($this->systab instanceof ArpNewDeviceTabs || session::is_set('SelectedSystemType')){
+          $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
+         
+          /* Get mac of currently edited entry */ 
+          $mac = "";
+          if($this->systab instanceof ArpNewDeviceTabs){
+            $mac = $this->systab->by_object['ArpNewDevice']->netConfigDNS->macAddress;
+          }else{
+            foreach(array("workgeneric","termgeneric","servgeneric") as $type){
+              if(isset($this->systab->by_object[$type]->netConfigDNS->macAddress)){
+                $mac = $this->systab->by_object[$type]->netConfigDNS->macAddress;
+                break;
+              }
+            } 
+          }
+
+          /* Add installation event
+           */
+          if(!empty($mac) && isset($events['BY_CLASS']['DaemonEvent_install'])){
+            $evt = $events['BY_CLASS']['DaemonEvent_install'];
+            $tmp = new $evt['CLASS_NAME']($this->config);
+            $tmp->add_targets(array($mac));
+            $tmp->set_type(TRIGGERED_EVENT);
+            $o_queue = new gosaSupportDaemon();
+            $o_queue->append($tmp);
+            if($o_queue->is_error()){
+              msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
+                    $o_queue->get_error()),ERROR_DIALOG);
+            }
+          }
+        }
 
         if(session::is_set('SelectedSystemType')){
           session::un_set('SelectedSystemType');
@@ -853,7 +983,7 @@ class systems extends plugin
           $dialog = TRUE;
         }  
       }
-      if(isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
+      if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
         $dialog = TRUE;
       }
@@ -992,7 +1122,7 @@ class systems extends plugin
 
     /* Attributes to fetch */
     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
-    $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer");
+    $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
 
     /* Add FAIstate to attributes if FAI is activated */
     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
@@ -1001,33 +1131,25 @@ class systems extends plugin
     }    
 
     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
+    $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
     foreach($objs as $checkBox => $oc){
       if($this->DivListSystem->$checkBox){
         if($this->DivListSystem->SubSearch){
           if($oc['CLASS'] != ""){
-            $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
-            $new_res = get_sub_list($filter, $sys_categories ,preg_replace("/,.*$/","",$base), $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
-      
-            /* Remove all objects that are not in the expected sub department */
-            foreach($new_res as $key => $obj){
-              if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
-                $res[$obj['dn']] = $obj;
-              }
-            }
+            $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
+            $res = array_merge($res,$new_res);
           }
         }else{
           /* User filter? */
           if($oc['CLASS'] != ""){
-            $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
-            $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
+            $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
           }
         }
       } 
     }
 
     /* Search for incoming objects */ 
-    $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
-    $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou'),get_ou('incomingou').$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
+    $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
 
     /* Get all gotoTerminal's */
     foreach ($res as $value){
@@ -1063,7 +1185,6 @@ class systems extends plugin
 
       /* Detect type of object and create an entry for $this->terminals */
       $terminal = array();
-
       if (in_array_ics('gotoTerminal', $value["objectClass"])){
 
         /* check acl */
@@ -1257,13 +1378,10 @@ class systems extends plugin
   
     /* Return C&P dialog */
     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
-    
-      /* Load entry from queue and set base */
-      $this->CopyPasteHandler->load_entry_from_queue();
-      $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
 
       /* Get dialog */
       $data = $this->CopyPasteHandler->execute();
+      $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
 
       /* Return dialog data */
       if(!empty($data)){