Code

Updated setup to use xmlentities
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index dcfe2dd44b55492d17da0b2b8179178e4c6caa11..b6eff67e502b5a1766dfa5d08a4a963bbf652796 100644 (file)
@@ -68,14 +68,18 @@ class gosaSupportDaemon
    */
   public function connect()
   {
-    $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout);
-    if($this->o_sock->connected()){ 
-      $this->o_sock->setEncryptionKey($this->s_encryption_key); 
-      $this->is_connected = TRUE;
+    if(!empty($this->s_host) && !empty($this->i_port)){
+      $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout);
+      if($this->o_sock->connected()){ 
+        $this->o_sock->setEncryptionKey($this->s_encryption_key); 
+        $this->is_connected = TRUE;
+      }else{
+        $this->set_error($this->o_sock->get_error());
+        $this->disconnect();
+        new log("debug","gosaSupportDaemon::connect()", "Cannot connect to si-server", array(),$this->get_error());
+      }
     }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());
+      $this->set_error(msgPool::cmdnotfound("GOSA_SI",_("GOsa support daemon")));
     }
     return($this->is_connected);
   }
@@ -130,6 +134,79 @@ class gosaSupportDaemon
   }
 
 
+  public function FAI_get_packages($release,$attrs, $package="")
+  {
+    $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);
+    }
+
+    /* Create list of attributes to fetch */
+    $attr = ""; 
+    foreach($attrs as $at){
+      $attr.= $at.", ";
+    }
+
+    /* Create Daemon query */
+    if(empty($package)){
+      $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+        "<select> ".trim($attr,", ")." </select>".
+        "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where>
+        </xml>";
+    }else{
+         $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+        "<select> ".trim($attr,", ")." </select>".
+        "<where><clause>
+            <connector>AND</connector>
+            <phrase><distribution>".$release."</distribution></phrase>
+            <phrase><package>".$package."</package></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_server($name = "")
   {
     $this->reset_error();
@@ -139,6 +216,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'])){
 
@@ -169,11 +253,19 @@ class gosaSupportDaemon
   public function FAI_get_classes($name)
   {
     $this->reset_error();
-    $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source><where><release>".$name."</release></where></xml>";;
+    $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source>".
+                  "<where><clause><phrase><release>".$name."</release></phrase></clause></where></xml>";;
     $ret = array();
     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'])){
 
@@ -241,6 +333,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'])){
 
@@ -297,6 +396,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){
@@ -344,6 +450,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){
@@ -391,6 +504,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){
@@ -434,6 +554,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" && 
@@ -474,6 +601,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" &&
@@ -520,6 +654,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");
@@ -645,6 +786,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'])) {
@@ -670,6 +818,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']);
@@ -776,6 +931,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;