From 437527d4fb93f9c3e04aa03f9370b4ae01fb8724 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 25 Aug 2008 13:59:45 +0000 Subject: [PATCH] Opsi updates -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 | 159 +++++++++--------- .../opsi/admin/opsi/class_opsigeneric.inc | 2 +- .../opsi/admin/opsi/class_opsiware.inc | 41 ++++- 3 files changed, 123 insertions(+), 79 deletions(-) diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi.inc b/gosa-plugins/opsi/admin/opsi/class_opsi.inc index f878fcbaa..b0f6bbb12 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsi.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsi.inc @@ -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) { - /* -
gosa_opsi_get_client_software
- GOSA - GOSA - limux-cl-2.intranet.gonicus.de -
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 */ } - - - /*! \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: ?> diff --git a/gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc b/gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc index ea511b15a..3b8a11656 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc @@ -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; } } diff --git a/gosa-plugins/opsi/admin/opsi/class_opsiware.inc b/gosa-plugins/opsi/admin/opsi/class_opsiware.inc index 6612ae46a..d192ea63f 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsiware.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsiware.inc @@ -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: ?> -- 2.30.2