From 3d686b161014864273e26e17da03fc3f14d5035d Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 3 Aug 2010 09:22:14 +0000 Subject: [PATCH] Updated curl handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19351 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_config.inc | 6 +- gosa-core/include/class_jsonRPC.inc | 55 ++++++++++++------- .../dbChannelStatus/class_dbChannelStatus.inc | 10 ++-- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gosa-core/include/class_config.inc b/gosa-core/include/class_config.inc index 4480396be..8c49425ea 100644 --- a/gosa-core/include/class_config.inc +++ b/gosa-core/include/class_config.inc @@ -314,11 +314,11 @@ class config { } - function getRpcHandle() + function getRpcHandle($url="", $user="", $pwd="", $digest = FALSE ) { // Create jsonRPC handle on demand. - if(!$this->jsonRPChandle){ - $this->jsonRPChandle = new jsonRPC($this); + if(!$this->jsonRPChandle || TRUE){ + $this->jsonRPChandle = new jsonRPC($this, $url, $user, $pwd, $digest); } return($this->jsonRPChandle); } diff --git a/gosa-core/include/class_jsonRPC.inc b/gosa-core/include/class_jsonRPC.inc index d9084f61c..041babce5 100644 --- a/gosa-core/include/class_jsonRPC.inc +++ b/gosa-core/include/class_jsonRPC.inc @@ -7,39 +7,54 @@ class jsonRPC { private $lastStats = array(); private $lastAction = "none"; - public function __construct($config) + + private $url = ""; + private $user = ""; + private $password = ""; + + private $authModeDigest = FALSE; + + public function __construct($config, $url = "", $user = "", $password = "", $digest = FALSE) { $this->config = $config; $this->id = 0; + + // Get connection data + $this->url = (!empty($url)) ? $url : $this->config->get_cfg_value('core','gosaRpcServer'); + $this->user = (!empty($user)) ? $user : $this->config->get_cfg_value('core','gosaRpcUser'); + $this->passwd = (!empty($password)) ? $password : $this->config->get_cfg_value('core','gosaRpcPassword'); + $this->authModeDigest = $digest; + + // Put some usefull info in the logs + DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($this->url), "Initiated RPC "); + DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($this->user), "RPC user: "); + DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($this->passwd),"RPC password: "); + DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($this->authModeDigest),"Digest Auth (0: No, 1: Yes): "); + $this->__login(); } private function __login() { - // Get connection data - $url = $this->config->get_cfg_value('core','gosaRpcServer'); - $user = $this->config->get_cfg_value('core','gosaRpcUser'); - $passwd = $this->config->get_cfg_value('core','gosaRpcPassword'); - - DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($url), "Initiated RPC "); - DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($user), "RPC user: "); - DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($passwd),"RPC password: "); - // Init Curl handler - $this->curlHandler = curl_init($url); + $this->curlHandler = curl_init($this->url); // Set curl options - curl_setopt($this->curlHandler, CURLOPT_URL , $url); - curl_setopt($this->curlHandler, CURLOPT_COOKIESESSION , TRUE); - curl_setopt($this->curlHandler, CURLOPT_COOKIEFILE, 'cookiefile.txt'); - curl_setopt($this->curlHandler, CURLOPT_POST , TRUE); - curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER , TRUE); - curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYPEER, TRUE); - curl_setopt($this->curlHandler, CURLOPT_HTTPHEADER , array('Content-Type: application/json')); + curl_setopt($this->curlHandler, CURLOPT_URL , $this->url); + curl_setopt($this->curlHandler, CURLOPT_POST , TRUE); + curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER ,TRUE); + curl_setopt($this->curlHandler, CURLOPT_HTTPHEADER , array('Content-Type: application/json')); + curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYPEER, FALSE); // Try to login - $this->login($user, $passwd); - + if($this->authModeDigest){ + curl_setopt($this->curlHandler, CURLOPT_USERPWD , "{$this->user}:{$this->passwd}"); + curl_setopt($this->curlHandler, CURLOPT_HTTPAUTH , CURLAUTH_ANYSAFE); + }else{ + curl_setopt($this->curlHandler, CURLOPT_COOKIESESSION , TRUE); + curl_setopt($this->curlHandler, CURLOPT_COOKIEFILE, 'cookiefile.txt'); + $this->login($this->user, $this->passwd); + } } diff --git a/gosa-core/plugins/generic/dashBoard/dbChannelStatus/class_dbChannelStatus.inc b/gosa-core/plugins/generic/dashBoard/dbChannelStatus/class_dbChannelStatus.inc index 86664bbb7..d3a5d5cbe 100644 --- a/gosa-core/plugins/generic/dashBoard/dbChannelStatus/class_dbChannelStatus.inc +++ b/gosa-core/plugins/generic/dashBoard/dbChannelStatus/class_dbChannelStatus.inc @@ -25,13 +25,15 @@ class dbChannelStatus extends plugin // First try to retrieve values via RPC if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $dump = stats::dumpTables(); - $rpc = $this->config->getRpcHandle(); - $hash = $rpc->updateInstanceStatus($dump); + $rpc = $this->config->getRpcHandle( + "http://10.3.64.59:4000", + "65717fe6-9e3e-11df-b010-5452005f1250", + "WyukwauWoid2", + TRUE); + $rpc->updateInstanceStatus($dump); if(!$rpc->success()){ msg_dialog::display(_("Error"),msgPool::rpcError($rpc->get_error()),ERROR_DIALOG); - return(""); } } } -- 2.30.2