Code

Fixed Problem with saving new ACL for a tagged department.
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index 219fdbb36ca2ed0d03dcce6ff3d5524e5527e3c8..0d86efe43e9a3160f782c166089f5fc541571281 100644 (file)
@@ -76,7 +76,7 @@ class gosaSupportDaemon
       }else{
         $this->set_error($this->o_sock->get_error());
         $this->disconnect();
-        new log("debug","gosaSupportDaemon::connect()", "Could not connect to server.", array(),$this->get_error());
+        new log("debug","gosaSupportDaemon::connect()", "Cannot connect to si-server", array(),$this->get_error());
       }
     }else{
       $this->set_error(msgPool::cmdnotfound("GOSA_SI",_("GOsa support daemon")));
@@ -134,28 +134,150 @@ class gosaSupportDaemon
   }
 
 
-  public function FAI_get_packages($release,$package = "")
+  public function FAI_get_kernels($release)
+  {
+    $xml_msg = "<xml><header>gosa_get_available_kernel</header><source>GOSA</source><target>GOSA</target><release>halut</release></xml>";
+
+    if($this->connect()){
+      $this->o_sock->write($xml_msg);
+      $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
+      $entries = $this->xml_to_array($str);
+      if(isset($entries['XML']) && is_array($entries['XML'])){
+
+        /* Check if returned values represent a valid answer */
+        if(isset($entries['XML'])){
+          if(isset($entries['XML']['ERROR_STRING'])) {
+            $this->set_error($entries['XML']['ERROR_STRING']);
+            new log("debug","GOsa-si",
+                get_class($this)."::".__FUNCTION__, array(),
+                "FAILED error was ".$this->get_error());
+            return($ret);
+          }
+
+          /* Unset header tags */
+          $ret = $entries['XML'];
+          foreach($ret as $key => $entry){
+            if(!preg_match("/^answer/i",$key)){
+              unset($ret[$key]);
+            }
+          }
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+  public function FAI_get_package_sections($release)
+  {
+    $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+      "<select>distinct section</select>".
+      "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where></xml>";
+
+    if($this->connect()){
+      $this->o_sock->write($xml_msg);
+      $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
+      $entries = $this->xml_to_array($str);
+      if(isset($entries['XML']) && is_array($entries['XML'])){
+
+        /* Check if returned values represent a valid answer */
+        if(isset($entries['XML'])){
+          if(isset($entries['XML']['ERROR_STRING'])) {
+            $this->set_error($entries['XML']['ERROR_STRING']);
+            new log("debug","GOsa-si",
+                get_class($this)."::".__FUNCTION__, array(),
+                "FAILED error was ".$this->get_error());
+            return($ret);
+          }
+
+          /* Unset header tags */
+          foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
+            if(isset($entries['XML'][$type])){
+              unset($entries['XML'][$type]);
+            }
+          }
+          $ret = $entries['XML'];
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+  public function FAI_get_packages($release,$attrs,$package,$from=-1,$to=-1)
   {
     $this->reset_error();
+    $ret = array();
+
+    /* Check Parameter */
+    if(!is_array($attrs) || !count($attrs)){
+      trigger_error("Second parameter must be an array. With at least one attribute name.");
+      return($ret);
+    }
+
+    /* Check Parameter */
+    if(!is_array($package)){
+      trigger_error("Third parameter must be an array. With at least one attribute name.");
+      return($ret);
+    }
+
+    /* Create list of attributes to fetch */
+    $attr = ""; 
+    foreach($attrs as $at){
+      $attr.= "<select>".$at."</select>";
+    }
+
+    /* If no package is given, search for all */
+    if(!count($package)) $package = array("%");
 
-    if(empty($package)){
-      $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
-        "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where></xml>";
+    /* Create limit tag */
+    if($from == -1){
+      $limit =""; 
     }else{
-      $xml_msg = 
-        "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
-          "<where><clause>".
-            "<connector>AND</connector>".
-            "<phrase><distribution>".$release."</distribution></phrase>".
-            "<phrase><package>".$package."</package></phrase>".
-          "</clause></where>".
-        "</xml>";
+      $limit = "<limit><from>".$from."</from><to>".$to."</to></limit>";
     }
 
-    $ret = array();
+    /* Create list of attributes to fetch */
+    $pkgs = ""; 
+    foreach($package as $pkg){
+      $pkgs .="<phrase><operator>like</operator><package>".$pkg."</package></phrase>";
+    }
+
+    $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+      $attr.
+      "<where>
+      <clause><phrase><distribution>".$release."</distribution></phrase></clause>
+      <clause><connector>OR</connector>
+      ".$pkgs."
+      </clause>
+      </where>".
+      $limit.
+      "</xml>";
+
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
 
@@ -194,6 +316,13 @@ class gosaSupportDaemon
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
 
@@ -230,6 +359,13 @@ class gosaSupportDaemon
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
 
@@ -297,6 +433,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
 
@@ -353,6 +496,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
         foreach($entries['XML'] as $entry){
@@ -400,6 +550,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str); 
       if(isset($entries['XML'])){
         foreach($entries['XML'] as $name => $entry){
@@ -447,6 +604,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str); 
       if(isset($entries['XML'])){
         foreach($entries['XML'] as $name => $entry){
@@ -490,6 +654,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return(FALSE);
+      }
+
       $entries = $this->xml_to_array($str); 
       if( isset($entries['XML']['HEADER']) && 
           $entries['XML']['HEADER']=="answer" && 
@@ -530,6 +701,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str); 
       if( isset($entries['XML']['HEADER']) &&
           $entries['XML']['HEADER']=="answer" &&
@@ -576,6 +754,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = $this->o_sock->read();
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) || isset($entries['COUNT'])){
         new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"SUCCESS");
@@ -701,6 +886,13 @@ $xml_msg.= "
 
       $this->o_sock->write($xml_msg);
       $str      = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return(FALSE);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML'])){
         if(isset($entries['XML']['ERROR_STRING'])) {
@@ -726,6 +918,13 @@ $xml_msg.= "
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str     = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return(0);
+      }
+
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML'])){
         return($entries['XML']['COUNT']);
@@ -832,6 +1031,13 @@ $xml_msg.= "
       $this->o_sock->write($data);
       if ($answer_expected){
         $str = trim($this->o_sock->read());
+
+        /* Check if something went wrong while reading */
+        if($this->o_sock->is_error()){
+          $this->set_error($this->o_sock->get_error());
+          return($ret);
+        }
+
         $entries = $this->xml_to_array($str);
         if(isset($entries['XML']) && is_array($entries['XML'])){
           $ret = $entries;