MISP/app/Lib/Tools/SyncTool.php

64 lines
2.2 KiB
PHP
Raw Normal View History

<?php
class SyncTool
{
// take a server as parameter and return a HttpSocket object using the ssl options defined in the server settings
2020-03-02 23:09:47 +01:00
public function setupHttpSocket($server = null, $timeout = false)
{
$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;
}
}
if (!empty($server['Server']['skip_proxy'])) {
$params['skip_proxy'] = 1;
}
2020-03-02 23:09:47 +01:00
if (!empty($timeout)) {
$params['timeout'] = $timeout;
}
}
2019-09-26 14:26:58 +02:00
return $this->createHttpSocket($params);
}
public function setupHttpSocketFeed($feed = null)
{
2019-09-26 14:26:58 +02:00
return $this->setupHttpSocket();
}
/**
* @param array $params
* @return HttpSocket
* @throws Exception
*/
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;
}
App::uses('HttpSocket', 'Network/Http');
2019-09-26 14:26:58 +02:00
$HttpSocket = new HttpSocket($params);
$proxy = Configure::read('Proxy');
if (empty($params['skip_proxy']) && isset($proxy['host']) && !empty($proxy['host'])) {
$HttpSocket->configProxy($proxy['host'], $proxy['port'], $proxy['method'], $proxy['user'], $proxy['password']);
}
return $HttpSocket;
}
}