Code

Updated system management.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 27 Feb 2008 07:24:36 +0000 (07:24 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 27 Feb 2008 07:24:36 +0000 (07:24 +0000)
-Trigger actions from menu updated. (Only Schedule works right now.)

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9139 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/systems/admin/systems/class_divListSystem.inc
gosa-plugins/systems/admin/systems/class_systemManagement.inc

index dc5467a9872b452b2b153d9a45a77d0cfd7e9eb5..909cc65d8f2333494601224311a6b15ec904b811 100644 (file)
@@ -199,21 +199,18 @@ class divListSystem extends MultiSelectWindow
         "&nbsp;"._("Component")."|"."newsystem_component|\n";
     }
 
-    # Actions
+    $events  = DaemonEvent::get_event_types();
     $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
       "&nbsp;"._("Trigger action")."|\n";
-    $s.= "...|"."&nbsp;"._("Halt")."|"."halt_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Reboot")."|"."reboot_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Re-install")."|"."reinstall_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Softupdate")."|"."update_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Wake up")."|"."wake_multiple|\n";
+    foreach($events['BY_CLASS'] as $name =>  $event){
+      $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|trigger_event_".$name."\n";
+    }
+
     $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
       "&nbsp;"._("Schedule action")."|\n";
-    $s.= "...|"."&nbsp;"._("Halt")."|"."schedule_halt_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Reboot")."|"."schedule_reboot_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Re-install")."|"."schedule_reinstall_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Softupdate")."|"."schedule_update_multiple|\n";
-    $s.= "...|"."&nbsp;"._("Wake up")."|"."schedule_wake_multiple|\n";
+    foreach($events['BY_CLASS'] as $name =>  $event){
+      $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|schedule_event_".$name."\n";
+    }
 
     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
index e626517c405bcdc5b76e4e8bcfefcabf5e5644da..d2f695baab99468eeb2794c0c7b6db979392ca27 100644 (file)
@@ -141,6 +141,16 @@ 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";
@@ -483,28 +493,57 @@ class systems extends plugin
 
 
     /********************
-      Action for MULTIPLE entries requested
+      Action(s) for MULTIPLE
      ********************/
-    if (preg_match("/(halt|reboot|reinstall|update|wake|)_multiple/", $s_action)){
+
+    /********************
+      SCHEDULE action in GOsa Daemon
+     ********************/
+    if(preg_match("/^schedule_event_/",$s_action)){
       $this->dns = array();
       $ids = $this->list_get_selected_items();
 
       if(count($ids)){
-       $mac= array();
-        $ldap = $this->config->get_ldap_link();
+        $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];
-         }
+          $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();
+        $type = preg_replace("/^schedule_event_/","",$s_action);
+        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);
+        }
+      }
+    }
 
-       /* Action.... */
-       $action= preg_replace('/_multiple.*$/', '', $s_action);
-       gosaSupportDaemon::send("gosa_trigger_action_".$action, $mac, array("macAddress" => $mac));
-
+    /* Insert scheduled events into queue */
+    if($this->systab instanceof DaemonEvent){
+      $this->systab->save_object();
+      if(isset($_POST['save_event_dialog'])){
+        $header     = $this->systab->get_header_tag();
+        $targets    = $this->systab->get_targets();
+        $data       = $this->systab->save();
+        $data['timestamp'] = $this->systab->get_timestamp();
+        $o_queue = new gosaSupportDaemon();
+        foreach($targets as $target){
+          $data['mac'] =  $target;
+          if(!$o_queue->send($header,$target,$data,TRUE)){
+            msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
+                  $o_queue->get_error()),ERROR_DIALOG);
+          }
+        }
+        $this->systab = FALSE;
+      }
+      if(isset($_POST['abort_event_dialog'])){
+        $this->systab = FALSE;
       }
     }