2017-06-28 00:31:40 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class TCP {
|
|
|
|
|
2017-10-25 19:50:57 +02:00
|
|
|
public static function http($url, $method='GET', $verifySSL=true, $timeOut=10, $followRedirections=true, $binary=true, $headers=false)
|
2017-06-28 00:31:40 +02:00
|
|
|
{
|
2018-09-18 19:46:10 +02:00
|
|
|
if (function_exists('curl_version')) {
|
2017-06-28 00:31:40 +02:00
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
2017-07-02 18:55:27 +02:00
|
|
|
curl_setopt($ch, CURLOPT_HEADER, $headers);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $followRedirections);
|
|
|
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, $binary);
|
2017-06-28 00:31:40 +02:00
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
2017-06-29 22:13:25 +02:00
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
2018-09-18 19:46:10 +02:00
|
|
|
if ($method=='POST') {
|
2017-06-28 00:31:40 +02:00
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
}
|
|
|
|
$output = curl_exec($ch);
|
2018-09-18 19:46:10 +02:00
|
|
|
if ($output===false) {
|
2017-06-28 00:31:40 +02:00
|
|
|
Log::set('Curl error: '.curl_error($ch));
|
|
|
|
}
|
|
|
|
curl_close($ch);
|
2018-09-18 19:46:10 +02:00
|
|
|
} else {
|
2017-06-28 00:31:40 +02:00
|
|
|
$options = array(
|
|
|
|
'http'=>array(
|
2017-06-29 22:13:25 +02:00
|
|
|
'method'=>$method,
|
2017-07-02 18:55:27 +02:00
|
|
|
'timeout'=>$timeOut,
|
|
|
|
'follow_location'=>$followRedirections
|
2017-06-28 00:31:40 +02:00
|
|
|
),
|
|
|
|
"ssl"=>array(
|
2017-07-02 18:55:27 +02:00
|
|
|
"verify_peer"=>false,
|
|
|
|
"verify_peer_name"=>false
|
2017-06-28 00:31:40 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$stream = stream_context_create($options);
|
|
|
|
$output = file_get_contents($url, false, $stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2017-07-02 18:55:27 +02:00
|
|
|
public static function download($url, $destination)
|
|
|
|
{
|
2017-10-13 00:15:13 +02:00
|
|
|
$data = self::http($url, $method='GET', $verifySSL=true, $timeOut=30, $followRedirections=true, $binary=true, $headers=false);
|
2017-07-02 18:55:27 +02:00
|
|
|
return file_put_contents($destination, $data);
|
|
|
|
}
|
2017-06-28 00:31:40 +02:00
|
|
|
|
2018-06-03 21:51:47 +02:00
|
|
|
public static function getIP()
|
|
|
|
{
|
|
|
|
if (getenv('HTTP_CLIENT_IP'))
|
|
|
|
$ip = getenv('HTTP_CLIENT_IP');
|
|
|
|
else if(getenv('HTTP_X_FORWARDED_FOR'))
|
|
|
|
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
else if(getenv('HTTP_X_FORWARDED'))
|
|
|
|
$ip = getenv('HTTP_X_FORWARDED');
|
|
|
|
else if(getenv('HTTP_FORWARDED_FOR'))
|
|
|
|
$ip = getenv('HTTP_FORWARDED_FOR');
|
|
|
|
else if(getenv('HTTP_FORWARDED'))
|
|
|
|
$ip = getenv('HTTP_FORWARDED');
|
|
|
|
else if(getenv('REMOTE_ADDR'))
|
|
|
|
$ip = getenv('REMOTE_ADDR');
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $ip;
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
}
|