2014-01-16 08:47:25 +01:00
|
|
|
<?php
|
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
class SyncTool
|
|
|
|
{
|
|
|
|
// take a server as parameter and return a HttpSocket object using the ssl options defined in the server settings
|
|
|
|
public function setupHttpSocket($server = null)
|
|
|
|
{
|
|
|
|
$params = array();
|
|
|
|
if (!empty($server)) {
|
|
|
|
if ($server['Server']['cert_file']) {
|
|
|
|
$params['ssl_cafile'] = APP . "files" . DS . "certs" . DS . $server['Server']['id'] . '.pem';
|
|
|
|
}
|
|
|
|
if ($server['Server']['client_cert_file']) {
|
|
|
|
$params['ssl_local_cert'] = APP . "files" . DS . "certs" . DS . $server['Server']['id'] . '_client.pem';
|
|
|
|
}
|
|
|
|
if ($server['Server']['self_signed']) {
|
|
|
|
$params['ssl_allow_self_signed'] = true;
|
|
|
|
$params['ssl_verify_peer_name'] = false;
|
|
|
|
if (!isset($server['Server']['cert_file'])) {
|
|
|
|
$params['ssl_verify_peer'] = false;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 10:06:44 +01:00
|
|
|
if (!empty($server['Server']['skip_proxy'])) {
|
|
|
|
$params['skip_proxy'] = 1;
|
|
|
|
}
|
2018-07-19 11:48:22 +02:00
|
|
|
}
|
2019-09-26 14:26:58 +02:00
|
|
|
|
|
|
|
return $this->createHttpSocket($params);
|
2018-07-19 11:48:22 +02:00
|
|
|
}
|
2016-06-04 01:08:16 +02:00
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
public function setupHttpSocketFeed($feed = null)
|
|
|
|
{
|
2019-09-26 14:26:58 +02:00
|
|
|
return $this->setupHttpSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
* @return HttpSocket
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-11-06 21:20:04 +01:00
|
|
|
public function createHttpSocket($params = array())
|
2019-09-26 14:26:58 +02:00
|
|
|
{
|
|
|
|
// Use own CA PEM file
|
|
|
|
$caPath = Configure::read('MISP.ca_path');
|
|
|
|
if (!isset($params['ssl_cafile']) && $caPath) {
|
|
|
|
if (!file_exists($caPath)) {
|
|
|
|
throw new Exception("CA file '$caPath' doesn't exists.");
|
|
|
|
}
|
|
|
|
$params['ssl_cafile'] = $caPath;
|
|
|
|
}
|
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
App::uses('HttpSocket', 'Network/Http');
|
2019-09-26 14:26:58 +02:00
|
|
|
$HttpSocket = new HttpSocket($params);
|
2018-07-19 11:48:22 +02:00
|
|
|
$proxy = Configure::read('Proxy');
|
2019-11-08 10:06:44 +01:00
|
|
|
if (empty($params['skip_proxy']) && isset($proxy['host']) && !empty($proxy['host'])) {
|
2018-07-19 11:48:22 +02:00
|
|
|
$HttpSocket->configProxy($proxy['host'], $proxy['port'], $proxy['method'], $proxy['user'], $proxy['password']);
|
|
|
|
}
|
|
|
|
return $HttpSocket;
|
|
|
|
}
|
2014-01-16 08:47:25 +01:00
|
|
|
}
|