Code

Opsi updates
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 13:59:45 +0000 (13:59 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 13:59:45 +0000 (13:59 +0000)
-Updated error handling
-Fixed Hard and Software gathering

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

gosa-plugins/opsi/admin/opsi/class_opsi.inc
gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc
gosa-plugins/opsi/admin/opsi/class_opsiware.inc

index f878fcbaae741b0d62361524d96eae75b4e44644..b0f6bbb1251d1523fbbfd7e2329c74da6e5b9ca2 100644 (file)
@@ -96,6 +96,74 @@ class opsi extends gosaSupportDaemon
    ******************/
 
 
+
+  /*! \brief           Returns a list of all opsi clients.
+    @param
+    @return            
+   */
+  public function list_clients( $hostId = "")
+  {
+    $data   = array();
+    $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
+    $items  = array();
+    if(isset($res['XML'][0]['ITEM'])){
+      $items = $res['XML'][0]['ITEM'];
+    }
+    return($items);
+  }
+
+
+  /*! \brief           Adds a new opsi client.
+    @param
+    @return            
+   */
+  public function add_client($hostId,$macaddress,$notes,$description)
+  {
+    $data = array("hostId" => $hostId,"macaddress" => $macaddress);
+
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
+  
+    /* Add optional attributes */ 
+    foreach(array("notes","description") as $attr) {
+      if(!empty($$attr)){
+        $data[$attr] = $$attr;
+      }
+    }
+
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
+  }
+
+
+  /*! \brief           Modify an opsi client.
+    @param
+    @return            
+   */
+  public function modify_client($hostId,$mac,$notes,$description)
+  {
+    $data = array("hostId" => $hostId,"mac" => $mac);
+
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
+  
+    /* Add optional attributes */ 
+    foreach(array("notes","description") as $attr) {
+      if(!empty($$attr)){
+        $data[$attr] = $$attr;
+      }
+    }
+
+    /* Query SI server */
+    $res = $this->send_data("gosa_opsi_modify_client",$this->target,$data,TRUE);
+  }
+
+
+
   /*! \brief           Returns a list of netboot products.
     @param
     @return            
@@ -279,7 +347,10 @@ class opsi extends gosaSupportDaemon
 
     /* Query SI server */
     $res    = $this->send_data("gosa_opsi_get_client_hardware",$this->target,$data,TRUE);
-    print_a($res);
+    if(isset($res['XML'][0]['ITEM'])){
+      return($res['XML'][0]['ITEM']);
+    }
+    return(array());
   }
 
 
@@ -287,36 +358,26 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function get_client_software()
+  public function get_client_software($hostId)
   {
-    /*  <xml> 
-        <header>gosa_opsi_get_client_software</header> 
-        <source>GOSA</source> 
-        <target>GOSA</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        </xml> i
-     */
-  }
-
-
+    $data = array("hostId" => $hostId);
 
+    /* Check parameter */ 
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
 
-  /*! \brief           Returns a list of all opsi clients.
-    @param
-    @return            
-   */
-  public function list_clients( $hostId = "")
-  {
-    $data   = array();
-    $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
-    $items  = array();
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_get_client_software",$this->target,$data,TRUE);
     if(isset($res['XML'][0]['ITEM'])){
-      $items = $res['XML'][0]['ITEM'];
+      return($res['XML'][0]['ITEM']);
     }
-    return($items);
+    return(array());
   }
 
 
+
   /*! \brief           Deletes the given opsi client.
     @param
     @return            
@@ -348,58 +409,6 @@ class opsi extends gosaSupportDaemon
         </xml>
      */
   }
-
-
-  /*! \brief           Adds a new opsi client.
-    @param
-    @return            
-   */
-  public function add_client($hostId,$macaddress,$notes,$description)
-  {
-    $data = array("hostId" => $hostId,"macaddress" => $macaddress);
-
-    if(empty($hostId)){
-      trigger_error("No valid host id given, check parameter 1.");
-      return;
-    }
-  
-    /* Add optional attributes */ 
-    foreach(array("notes","description") as $attr) {
-      if(!empty($$attr)){
-        $data[$attr] = $$attr;
-      }
-    }
-
-    /* Query SI server */
-    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
-  }
-
-
-  /*! \brief           Modify an opsi client.
-    @param
-    @return            
-   */
-  public function modify_client($hostId,$mac,$notes,$description)
-  {
-    $data = array("hostId" => $hostId,"mac" => $mac);
-
-    if(empty($hostId)){
-      trigger_error("No valid host id given, check parameter 1.");
-      return;
-    }
-  
-    /* Add optional attributes */ 
-    foreach(array("notes","description") as $attr) {
-      if(!empty($$attr)){
-        $data[$attr] = $$attr;
-      }
-    }
-
-    /* Query SI server */
-    $res    = $this->send_data("gosa_opsi_modify_client",$this->target,$data,TRUE);
-  }
-
-
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index ea511b15a7a3514a16901ca191b609f2c97bf098..3b8a1165654360e5a897d963cec4c70c6bdf3bd1 100644 (file)
@@ -49,12 +49,12 @@ class opsigeneric extends plugin
 
     if($this->hostId != "new"){
       $list = $this->opsi->list_clients($this->hostId);
+      $err |= $this->opsi->is_error();
       foreach($list as $entry){
         if($entry['NAME'][0]['VALUE'] == $this->hostId){  
           foreach(array("description" => "DESCRIPTION","mac" => "MAC", "note" => "NOTES") as $des => $src){
             $this->$des = $entry[$src][0]['VALUE'];
           } 
-
           break;
         }
       }
index 6612ae46a075c88b17dcf182adf70be7232443cc..d192ea63f050c6876d1e46a30ebd0711084acf97 100644 (file)
@@ -6,20 +6,55 @@ class opsiware extends plugin
   private $SW_info;
   private $HW_info;
   private $hostId;
+  private $type = 0;
+  private $init_failed = FALSE;
 
   public function __construct($config,$hostId)
   {
     $this->config = $config;
     $this->opsi   = new opsi($config);
     $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId);
+    $this->init();
   }
 
-  public function execute()
+  private function init()
   {
-    print_a($this->opsi->get_client_hardware($this->hostId));
-      
+    $err = FALSE;
+    if(!$err){
+      $this->HW_info = $this->opsi->get_client_hardware($this->hostId);
+      $err |= $this->opsi->is_error(); 
+    }
+    if(!$err){
+      $this->SW_info = $this->opsi->get_client_software($this->hostId);
+      $err |= $this->opsi->is_error(); 
+    }
+    $this->init_failed = $err;
   }
 
+  public function execute()
+  {
+    if(isset($_POST['reinit']) && $this->init_failed){
+      $this->init();
+    }
+    if(isset($_GET['type'])) $this->type = $_GET['type'];
+
+    $smarty = get_smarty();
+    $smarty->assign("init_failed",$this->init_failed);
+    if($this->init_failed){
+      $smarty->assign("type", $this->type);
+      $smarty->assign("message",$this->opsi->get_error());
+      return($smarty->fetch(get_template_path("opsiware.tpl",TRUE,dirname(__FILE__))));
+    }  
+
+    $smarty->assign("type", $this->type);
+
+    if($this->type == 1){
+      $smarty->assign("info", $this->HW_info);
+    }else{
+      $smarty->assign("info", $this->SW_info);
+    }
+    return($smarty->fetch(get_template_path("opsiware.tpl",TRUE,dirname(__FILE__))));
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>