Code

Added ability to change FAIstate via ogroup
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Sep 2006 10:14:20 +0000 (10:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Sep 2006 10:14:20 +0000 (10:14 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@4638 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/ogroups/class_termgroup.inc

index e0bde96a50e47d40f33079dbdee60ff6e8873641..967ebc6f836f65699aff134e0394f1c74ecb3bd9 100644 (file)
@@ -19,6 +19,14 @@ class termgroup extends plugin
   var $orig_dn               = "";
   var $didAction                 = FALSE;
 
+  var $mapActions   = array("reboot"          => "localboot",
+                            "instant_update"  => "softupdate",
+                            "update"          => "sceduledupdate",
+                            "reinstall"       => "install",
+                            "rescan"          => "",
+                            "memcheck"        => "memcheck",
+                            "sysinfo"         => "sysinfo");
+
 
   function termgroup ($config, $dn= NULL)
   {
@@ -129,6 +137,52 @@ class termgroup extends plugin
     $this->handle_post_events("remove");
   }
 
+
+  function update_term_member_FAIstate($act)
+  {
+    /* Get required informations */
+    $og     = $this->parent->by_object['ogroup'];
+    $allobs = $og->allobjects;
+    $mem    = $og->member;
+
+    /* Get correct value for FAIstate */
+    $action = $this->mapActions[$act];
+
+    /* Get ldap connection */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd ($this->config->current['BASE']);
+
+    /* Foreach member of mthis ogroup  ... */
+    foreach($mem  as $key ){
+  
+      /* check objectClasses and create attributes array */
+      $attrs = array("FAIstate"=>$action);  
+      for($i = 0; $i < $allobs[$key]['objectClass']['count'] ; $i ++){
+        $attrs['objectClass'][] = $allobs[$key]['objectClass'][$i];
+      }
+      if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
+        $attrs['objectClass'][] = "FAIobject";
+      }
+      if($attrs['FAIstate'] == ""){
+        $attrs['FAIstate'] = array();
+      }
+
+      /* If this objects is workstation,terminal or server upodate FAIstate */ 
+      if(preg_match("/(w|t|s)/i",$allobs[$key]['type'])){
+        $ldap->cd ($key);
+        $ldap->modify($attrs);
+        show_ldap_error($ldap->get_error(),sprintf(_("Setting action state (FAIstate) failed for object '%s', value was '%s'."),$key,$action));
+        
+        if(!preg_match("/success/i",$ldap->get_error())) {
+          gosa_log("FAILED !! Updating FAIstate to '".$action."' : ".$key);
+        }else{
+          gosa_log("OK.  Updating FAIstate to '".$action."' : ".$key);
+        }
+      }
+    }
+  }
+
+
   function execute()
   {
     /* Call parent execute */
@@ -149,6 +203,10 @@ class termgroup extends plugin
       }
 
       if (isset($_POST['action'])){
+
+        /* Update members fai state */
+        $this->update_term_member_FAIstate(trim($_POST['saction']));
+
         $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
         if ($cmd == ""){
           print_red(_("No ACTIONCMD definition found in your gosa.conf"));