Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -269,11 +269,16 @@ class _Curl
|
||||
* @return \IPS\Http\Response
|
||||
* @throws \IPS\Http\Request\CurlException
|
||||
*/
|
||||
public function get()
|
||||
public function get( $data=NULL )
|
||||
{
|
||||
/* Specify that this is a GET request */
|
||||
curl_setopt( $this->curl, CURLOPT_HTTPGET, TRUE );
|
||||
$this->dataForLog = NULL;
|
||||
|
||||
if ( $data )
|
||||
{
|
||||
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $data );
|
||||
}
|
||||
|
||||
return $this->_executeAndFollowRedirects( 'GET', NULL );
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class _Sockets
|
||||
$this->httpVersion = $httpVersion ?: '1.1';
|
||||
$this->timeout = $timeout;
|
||||
$this->followRedirects = $followRedirects;
|
||||
|
||||
|
||||
/* Set our basic settings */
|
||||
stream_context_set_option( $this->context, array(
|
||||
'http' => array(
|
||||
@@ -79,6 +79,7 @@ class _Sockets
|
||||
),
|
||||
'ssl' => array(
|
||||
'verify_peer' => FALSE,
|
||||
'crypto_method' => STREAM_CRYPTO_METHOD_ANY_CLIENT
|
||||
)
|
||||
) );
|
||||
}
|
||||
@@ -180,7 +181,7 @@ class _Sockets
|
||||
/* Set the method and the Content-Length header if this is a POST, PUT or PATCH request */
|
||||
stream_context_set_option( $this->context, 'http', 'method', $method );
|
||||
|
||||
if( in_array( $method, array( 'POST', 'PUT', 'PATCH' ) ) )
|
||||
if( $data )
|
||||
{
|
||||
$this->setHeaders( array( 'Content-Length' => \strlen( $data ) ) );
|
||||
}
|
||||
@@ -192,7 +193,7 @@ class _Sockets
|
||||
}
|
||||
|
||||
$hostname = sprintf( '%s%s:%d',
|
||||
( $this->url->data['scheme'] === 'https' ) ? 'tls://' : '',
|
||||
( $this->url->data['scheme'] === 'https' ) ? 'ssl://' : '',
|
||||
$this->url->data['host'],
|
||||
isset( $this->url->data['port'] )
|
||||
? $this->url->data['port']
|
||||
@@ -217,7 +218,7 @@ class _Sockets
|
||||
|
||||
/* Get the location */
|
||||
$location = $this->url->data['path'] ? \IPS\Http\Url::encodeComponent( \IPS\Http\Url::COMPONENT_PATH, $this->url->data['path'] ) : '';
|
||||
$location .= $this->url->data['query'] ? '?' . \IPS\Http\Url::encodeComponent( \IPS\Http\Url::COMPONENT_QUERY, $this->url->data['query'] ) : '';
|
||||
$location .= ( count( $this->url->queryString ) ) ? '?' . \IPS\Http\Url::convertQueryAsArrayToString( $this->url->queryString, true ) : '';
|
||||
$location .= $this->url->data['fragment'] ? '#' . \IPS\Http\Url::encodeComponent( \IPS\Http\Url::COMPONENT_FRAGMENT, $this->url->data['fragment'] ) : '';
|
||||
|
||||
/* Send request */
|
||||
|
||||
+36
-7
@@ -104,7 +104,7 @@ class _Url
|
||||
{
|
||||
return \IPS\Http\Url\Internal::createInternalFromComponents(
|
||||
'admin',
|
||||
\IPS\Settings::i()->logins_over_https ? static::PROTOCOL_HTTPS : $protocol,
|
||||
$protocol,
|
||||
\IPS\CP_DIRECTORY . '/'
|
||||
);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class _Url
|
||||
{
|
||||
return \IPS\Http\Url\Internal::createInternalFromComponents(
|
||||
'admin',
|
||||
\IPS\Settings::i()->logins_over_https ? static::PROTOCOL_HTTPS : $protocol,
|
||||
$protocol,
|
||||
\IPS\CP_DIRECTORY . '/',
|
||||
array( 'adsess' => session_id() ) + static::convertQueryAsStringToArray( $queryString )
|
||||
);
|
||||
@@ -209,6 +209,7 @@ class _Url
|
||||
|
||||
/* Is it internal? */
|
||||
$baseUrlComponents = static::componentsFromUrlString( static::baseUrl() );
|
||||
|
||||
if ( $components[ static::COMPONENT_HOST ] === $baseUrlComponents[ static::COMPONENT_HOST ] and
|
||||
$components[ static::COMPONENT_USERNAME ] === $baseUrlComponents[ static::COMPONENT_USERNAME ] and
|
||||
$components[ static::COMPONENT_PASSWORD ] === $baseUrlComponents[ static::COMPONENT_PASSWORD ] and
|
||||
@@ -528,7 +529,24 @@ class _Url
|
||||
*/
|
||||
public function isLocalhost()
|
||||
{
|
||||
return ( isset( $this->data['host'] ) and ( in_array( $this->data['host'], array( 'localhost', static::internal('')->data['host'] ) ) or ( filter_var( $this->data['host'], FILTER_VALIDATE_IP ) and filter_var( $this->data['host'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === FALSE ) ) );
|
||||
$baseUrlHostname = static::internal('')->data['host'];
|
||||
|
||||
return (
|
||||
isset( $this->data['host'] )
|
||||
and
|
||||
(
|
||||
(
|
||||
$this->data['host'] == 'localhost' or
|
||||
preg_match( "#\." . preg_quote( $baseUrlHostname ) . "$#", '.' . $this->data['host'] ) or
|
||||
preg_match( "#\." . preg_quote( $this->data['host'] ) . "$#", '.' . $baseUrlHostname )
|
||||
)
|
||||
or
|
||||
(
|
||||
filter_var( $this->data['host'], FILTER_VALIDATE_IP ) and
|
||||
filter_var( $this->data['host'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === FALSE
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -595,7 +613,7 @@ class _Url
|
||||
throw new \RuntimeException( "COULD_NOT_IMPORT" );
|
||||
}
|
||||
|
||||
return \IPS\File::create( $storageExtension, basename( $this->data[ static::COMPONENT_PATH ] ), $response );
|
||||
return \IPS\File::create( $storageExtension, basename( $this->data[ static::COMPONENT_PATH ] ), (string) $response );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1047,7 +1065,7 @@ class _Url
|
||||
* @param bool $encode If true, will encode for output
|
||||
* @return string
|
||||
*/
|
||||
protected static function convertQueryAsArrayToString( $query, $encode = FALSE )
|
||||
public static function convertQueryAsArrayToString( $query, $encode = FALSE )
|
||||
{
|
||||
$return = array();
|
||||
foreach ( $query as $k => $v )
|
||||
@@ -1082,19 +1100,30 @@ class _Url
|
||||
*
|
||||
* @param string $key The key for this query string parameter
|
||||
* @param array $value The query as an array (e.g. [ 'foo'=>'bar', 'moo'=>'baz' ])
|
||||
* @param bool $encode If true, will encode for output
|
||||
* @return string
|
||||
*/
|
||||
protected static function squashQueryStringArray( $key, $value )
|
||||
protected static function squashQueryStringArray( $key, $value, $encode = FALSE )
|
||||
{
|
||||
$return = array();
|
||||
foreach ( $value as $k => $v )
|
||||
{
|
||||
if ( $encode )
|
||||
{
|
||||
$k = static::encodeComponent( static::COMPONENT_QUERY_KEY, $k );
|
||||
}
|
||||
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
$return[] = static::squashQueryStringArray( "{$key}[{$k}]", $v );
|
||||
$return[] = static::squashQueryStringArray( "{$key}[{$k}]", $v, $encode );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $encode )
|
||||
{
|
||||
$v = static::encodeComponent( static::COMPONENT_QUERY_VALUE, $v );
|
||||
}
|
||||
|
||||
$return[] = "{$key}[{$k}]={$v}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ class _Useragent
|
||||
*/
|
||||
public $useragent = NULL;
|
||||
|
||||
/**
|
||||
* @brief Store parsed agents
|
||||
*/
|
||||
protected static $parsedAgents = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -72,11 +77,16 @@ class _Useragent
|
||||
public static function parse( $userAgent=NULL )
|
||||
{
|
||||
$userAgent = $userAgent ?: ( ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '' );
|
||||
|
||||
if ( ! isset( static::$parsedAgents[ $userAgent ] ) )
|
||||
{
|
||||
$obj = new static( $userAgent );
|
||||
$obj->parseUserAgent();
|
||||
|
||||
$obj = new static( $userAgent );
|
||||
$obj->parseUserAgent();
|
||||
|
||||
return $obj;
|
||||
static::$parsedAgents[ $userAgent ] = $obj;
|
||||
}
|
||||
|
||||
return static::$parsedAgents[ $userAgent ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user