Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+136 -73
View File
@@ -2,9 +2,9 @@
/**
* @brief cURL REST Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 18 Mar 2013
* @version SVN_VERSION_NUMBER
*/
@@ -128,7 +128,7 @@ class _Curl
}
$httpVersion = ( $httpVersion == '1.1' ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0 );
/* Set our basic settings */
curl_setopt_array( $this->curl, array(
CURLOPT_HEADER => TRUE, // Specifies that we want the headers
@@ -215,62 +215,7 @@ class _Curl
return $this;
}
/**
* HTTP GET
*
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
public function get()
{
/* Specify that this is a GET request */
curl_setopt( $this->curl, CURLOPT_HTTPGET, TRUE );
$this->dataForLog = NULL;
/* Execute */
$response = $this->_execute();
/* Either return it or follow it */
if ( $this->followRedirects and ( $response->httpResponseCode == 302 OR $response->httpResponseCode == 301 ) )
{
$newRequest = \IPS\Http\Url::external( $response->httpHeaders['Location'] )->request( $this->timeout, $this->httpVersion, is_int( $this->followRedirects ) ? ( $this->followRedirects - 1 ) : $this->followRedirects );
return $newRequest->get();
}
return $response;
}
/**
* HTTP POST
*
* @param mixed $data Data to post (can be array or string)
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
public function post( $data=NULL )
{
/* Specify that this is a POST request */
curl_setopt( $this->curl, CURLOPT_POST, TRUE );
/* Set the data */
$this->dataForLog = $data;
if ( !$this->modifiedContentType and is_array( $data ) )
{
$data = http_build_query( $data, '', '&' );
}
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $data );
/* Execute */
$response = $this->_execute();
/* Either return it or follow it */
if ( $this->followRedirects and ( $response->httpResponseCode == 302 OR $response->httpResponseCode == 301 ) )
{
$newRequest = \IPS\Http\Url::external( $response->httpHeaders['Location'] )->request( $this->timeout, $this->httpVersion, is_int( $this->followRedirects ) ? ( $this->followRedirects - 1 ) : $this->followRedirects );
return call_user_func_array( array( $newRequest, 'post' ), $data );
}
return $response;
}
/**
* Toggle SSL checks
@@ -288,6 +233,89 @@ class _Curl
return $this;
}
/**
* Force TLS
*
* @return \IPS\Http\Request\Socket
*/
public function forceTls()
{
$curlVersionData = curl_version();
if ( preg_match( '/^OpenSSL\/(\d+\.\d+\.\d+)/', $curlVersionData['ssl_version'], $openSSLVersionData ) )
{
if ( version_compare( $openSSLVersionData[1], '1.0.1', '>=' ) )
{
if ( !defined('CURL_SSLVERSION_TLSv1_2') ) // constant not defined in PHP < 5.5
{
define( 'CURL_SSLVERSION_TLSv1_2', 6 );
}
curl_setopt( $this->curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2 );
}
else
{
if ( !defined('CURL_SSLVERSION_TLSv1') ) // constant not defined in PHP < 5.5
{
define( 'CURL_SSLVERSION_TLSv1', 1 );
}
curl_setopt( $this->curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1 );
}
}
return $this;
}
/**
* HTTP GET
*
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
public function get()
{
/* Specify that this is a GET request */
curl_setopt( $this->curl, CURLOPT_HTTPGET, TRUE );
$this->dataForLog = NULL;
return $this->_executeAndFollowRedirects( 'GET', NULL );
}
/**
* HTTP POST
*
* @param mixed $data Data to post (can be array or string)
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
public function post( $data=NULL )
{
/* Specify that this is a POST request */
curl_setopt( $this->curl, CURLOPT_POST, TRUE );
/* Set the data */
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->_dataToSend( $data ) );
/* Execute */
return $this->_executeAndFollowRedirects( 'POST', $data );
}
/**
* HTTP HEAD
*
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
public function head()
{
/* Specify the request method */
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD' );
/* For HEAD requests, do not try to fetch the body or curl times out */
curl_setopt( $this->curl, CURLOPT_NOBODY, true );
/* Execute */
return $this->_executeAndFollowRedirects( 'HEAD', NULL );
}
/**
* Magic Method: __call
* Used for other HTTP methods (like PUT and DELETE)
@@ -301,25 +329,31 @@ class _Curl
{
/* Specify the request method */
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, mb_strtoupper( $method ) );
/* If we have any data to send, set it */
if ( isset( $params[0] ) )
{
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $params[0] );
$this->dataForLog = $params[0];
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->_dataToSend( $params[0] ) );
}
/* Execute */
$response = $this->_execute();
/* Either return it or follow it */
if ( $this->followRedirects and ( $response->httpResponseCode == 302 OR $response->httpResponseCode == 301 ) )
return $this->_executeAndFollowRedirects( mb_strtoupper( $method ), $params );
}
/**
* Data to send
*
* @param mixed $data Data to post (can be array or string)
* @return mixed
*/
protected function _dataToSend( $data=NULL )
{
$this->dataForLog = $data;
if ( !$this->modifiedContentType and is_array( $data ) )
{
$newRequest = \IPS\Http\Url::external( $response->httpHeaders['Location'] )->request( $this->timeout, $this->httpVersion, is_int( $this->followRedirects ) ? ( $this->followRedirects - 1 ) : $this->followRedirects );
return call_user_func_array( array( $newRequest, $method ), $params );
$data = http_build_query( $data, '', '&' );
}
return $response;
return $data;
}
/**
@@ -333,12 +367,11 @@ class _Curl
/* Execute */
$output = curl_exec( $this->curl );
/* Log */
try
/* Log - but because the output can be large, only do this if we explicitly have debug logging enabled */
if ( defined('\IPS\DEBUG_LOG') and \IPS\DEBUG_LOG )
{
\IPS\Log::i( LOG_DEBUG )->write( "\n\n------------------------------------\ncURL REQUEST: {$this->url}\n------------------------------------\n\n" . var_export( $this->dataForLog, TRUE ) . "\n\n------------------------------------\nRESPONSE\n------------------------------------\n\n" . $output, 'request' );
\IPS\Log::debug( "\n\n------------------------------------\ncURL REQUEST: {$this->url}\n------------------------------------\n\n" . var_export( $this->dataForLog, TRUE ) . "\n\n------------------------------------\nRESPONSE\n------------------------------------\n\n" . $output, 'request' );
}
catch( \Exception $e ){}
/* Errors? */
if ( $output === FALSE )
@@ -355,6 +388,36 @@ class _Curl
/* Return it */
return new \IPS\Http\Response( $output );
}
/**
* Execute the request and follow redirects id necessary
*
* @param string $method Request method to use
* @param NULL|array $params Parameters to send with request
* @return \IPS\Http\Response
* @throws \IPS\Http\Request\CurlException
*/
protected function _executeAndFollowRedirects( $method, $params=NULL )
{
/* Execute */
$response = $this->_execute();
/* Either return it or follow it */
if ( $this->followRedirects and in_array( $response->httpResponseCode, array( 301, 302, 303, 307, 308 ) ) )
{
/* Fix missing hostname in location */
$location = $response->httpHeaders['Location'];
if( parse_url( $location, PHP_URL_HOST ) === NULL )
{
$location = $this->url->data['scheme'] . '://' . $this->url->data['host'] . $location;
}
$newRequest = \IPS\Http\Url::external( $location )->request( $this->timeout, $this->httpVersion, is_int( $this->followRedirects ) ? ( $this->followRedirects - 1 ) : $this->followRedirects );
return call_user_func_array( array( $newRequest, $method ), $params );
}
return $response;
}
}
/**