Skip to content

Commit

Permalink
bugfix for issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
domibarton committed Oct 2, 2015
1 parent d993c90 commit 00ab1e9
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions build/ZabbixApiAbstract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public function __construct($apiUrl='', $user='', $password='', $httpUser='', $h
if($apiUrl)
$this->setApiUrl($apiUrl);

if ($httpUser && $httpPassword)
$this->setBasicAuthorization($httpUser, $httpPassword);

if($user && $password)
$this->userLogin(array('user' => $user, 'password' => $password));

if ($httpUser && $httpPassword)
$this->extraHeaders = 'Authorization: Basic ' . base64_encode($httpUser.':'.$httpPassword);
}

/**
Expand All @@ -160,7 +160,6 @@ public function getApiUrl()
return $this->apiUrl;
}


/**
* @brief Sets the API url for all requests.
*
Expand All @@ -175,6 +174,25 @@ public function setApiUrl($apiUrl)
return $this;
}

/**
* @brief Sets the username and password for the HTTP basic authorization.
*
* @param $user HTTP basic authorization username
* @param $password HTTP basic authorization password
*
* @retval ZabbixApiAbstract
*/

public function setBasicAuthorization($user, $password)
{
if($user && $password)
$this->extraHeaders = 'Authorization: Basic ' . base64_encode($user.':'.$password);
else
$this->extraHeaders = '';

return $this;
}

/**
* @brief Returns the default params.
*
Expand Down Expand Up @@ -277,7 +295,7 @@ public function request($method, $params=NULL, $resultArrayKey='', $auth=TRUE)
)));

// get file handler
$fileHandler = fopen($this->getApiUrl(), 'rb', false, $streamContext);
$fileHandler = @fopen($this->getApiUrl(), 'rb', false, $streamContext);
if(!$fileHandler)
throw new Exception('Could not connect to "'.$this->getApiUrl().'"');

Expand Down

0 comments on commit 00ab1e9

Please sign in to comment.