Private GIT

Skip to content
Snippets Groups Projects
Commit 0419bcba authored by Loic Laurent's avatar Loic Laurent
Browse files

#4779 add proxy in http options

parent c2da0d19
No related branches found
No related tags found
No related merge requests found
......@@ -15,9 +15,12 @@
* limitations under the License.
*/
require_once realpath(dirname(__FILE__) . "/../../config/centreon.config.php");
require_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php";
require_once _CENTREON_PATH_ . '/www/api/exceptions.php';
require_once _CENTREON_PATH_ . "/www/class/centreonLog.class.php";
/**
* Utils class for call HTTP JSON REST
*
......@@ -32,6 +35,11 @@ class CentreonRestHttp
*/
private $contentType = 'application/json';
/**
* @var using a proxy
*/
private $proxy = null;
/**
* @var logFileThe The log file for call errors
*/
......@@ -44,6 +52,7 @@ class CentreonRestHttp
*/
public function __construct($contentType = 'application/json', $logFile = null)
{
$this->getProxy();
$this->contentType = $contentType;
if (!is_null($logFile)) {
$this->logObj = new CentreonLog(array(4 => $logFile));
......@@ -76,14 +85,17 @@ class CentreonRestHttp
$headers[] = 'Content-type: ' . $this->contentType;
$headers[] = 'Connection: close';
/* Create stream context */
$httpOpts = array(
'http' => array(
'proxy' => $this->proxy,
'ignore_errors' => true,
'protocol_version' => '1.1',
'method' => $method,
'header' => join("\r\n", $headers)
)
);
/* Add body json data */
if (false === is_null($data)) {
$httpOpts['http']['content'] = json_encode($data);
......@@ -180,4 +192,32 @@ class CentreonRestHttp
return $headers;
}
/**
* get proxy data
*
*/
private function getProxy()
{
$db = new CentreonDB();
$query = "SELECT `key`, `value` FROM `options`
WHERE (`key` = 'proxy_protocol'
OR `key` = 'proxy_url'
OR `key` = 'proxy_port')";
$res = $db->query($query);
while ($row = $res->fetchRow()) {
$dataProxy[$row['key']] = $row['value'];
}
if (isset($dataProxy['proxy_url']) && $dataProxy['proxy_url'] != '') {
if ($dataProxy['proxy_protocol']) {
$this->proxy .= $dataProxy['proxy_protocol'] . '://';
}
$this->proxy .= $dataProxy['proxy_url'];
if ($dataProxy['proxy_port']) {
$this->proxy .= ':' . $dataProxy['proxy_port'];
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment