Commit eb8f01cb authored by Sigrid Suski's avatar Sigrid Suski

(!) Updated User agent for Crawler to a newer version

    (!) CURL error message if Crawler does not work at all
   	(!) Includes Sobi Framework 1.0.12
parent 78159949
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* @created Thu, Dec 1, 2016 11:53:09 by Radek Suski
* @modified 30 April 2020 by Sigrid Suski
*/ */
namespace Sobi; namespace Sobi;
...@@ -22,9 +25,8 @@ namespace Sobi; ...@@ -22,9 +25,8 @@ namespace Sobi;
defined( 'SOBI' ) || exit( 'Restricted access' ); defined( 'SOBI' ) || exit( 'Restricted access' );
/** /**
* @author Radek Suski * Class C
* @created Thu, Dec 1, 2016 11:53:09 * @package Sobi
* @modified 21 January 2020 by Sigrid Suski
*/ */
abstract class C abstract class C
{ {
...@@ -42,5 +44,5 @@ abstract class C ...@@ -42,5 +44,5 @@ abstract class C
const NO = 0; const NO = 0;
const ROOT = JPATH_ROOT; const ROOT = JPATH_ROOT;
const DS = DIRECTORY_SEPARATOR; const DS = DIRECTORY_SEPARATOR;
const VERSION = '1.0.11'; const VERSION = '1.0.12';
} }
<?php <?php
/** /**
* @package: Sobi Framework * @package: Sobi Framework
*
* @author * @author
* Name: Sigrid Suski & Radek Suski, Sigsiu.NET GmbH * Name: Sigrid Suski & Radek Suski, Sigsiu.NET GmbH
* Email: sobi[at]sigsiu.net * Email: sobi[at]sigsiu.net
* Url: https://www.Sigsiu.NET * Url: https://www.Sigsiu.NET
* @copyright Copyright (C) 2006 - 2016 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved. *
* @copyright Copyright (C) 2006 - 2020 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @license GNU/LGPL Version 3 * @license GNU/LGPL Version 3
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3. * as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
* See http://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses. * See https://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* @created Sat, Dec 3, 2016 15:22:50 *
* @created Sat, Dec 3, 2016 15:22:50 by Radek Suski
* @modified 30 April 2020 by Sigrid Suski
*/ */
namespace Sobi\Communication; namespace Sobi\Communication;
...@@ -23,143 +27,160 @@ defined( 'SOBI' ) || exit( 'Restricted access' ); ...@@ -23,143 +27,160 @@ defined( 'SOBI' ) || exit( 'Restricted access' );
use Sobi\Error\Exception; use Sobi\Error\Exception;
use Sobi\Framework; use Sobi\Framework;
/**
* Class CURL
* @package Sobi\Communication
*/
class CURL class CURL
{ {
/**
* @var false|resource|null
*/
private $resource = null; private $resource = null;
/**
* @var array
*/
private $curlStatus = 0;
/**
* @var array
*/
static $infoCodes = [ static $infoCodes = [
'effective_url' => CURLINFO_EFFECTIVE_URL, 'effective_url' => CURLINFO_EFFECTIVE_URL,
'http_code' => CURLINFO_HTTP_CODE, 'http_code' => CURLINFO_HTTP_CODE,
'response_code' => CURLINFO_HTTP_CODE, 'response_code' => CURLINFO_HTTP_CODE,
'filetime' => CURLINFO_FILETIME, 'filetime' => CURLINFO_FILETIME,
'total_time' => CURLINFO_TOTAL_TIME, 'total_time' => CURLINFO_TOTAL_TIME,
'namelookup_time' => CURLINFO_NAMELOOKUP_TIME, 'namelookup_time' => CURLINFO_NAMELOOKUP_TIME,
'connect_time' => CURLINFO_CONNECT_TIME, 'connect_time' => CURLINFO_CONNECT_TIME,
'pretransfer_time' => CURLINFO_PRETRANSFER_TIME, 'pretransfer_time' => CURLINFO_PRETRANSFER_TIME,
'starttransfer_time' => CURLINFO_STARTTRANSFER_TIME, 'starttransfer_time' => CURLINFO_STARTTRANSFER_TIME,
'redirect_time' => CURLINFO_REDIRECT_TIME, 'redirect_time' => CURLINFO_REDIRECT_TIME,
'size_upload' => CURLINFO_SIZE_UPLOAD, 'size_upload' => CURLINFO_SIZE_UPLOAD,
'size_download' => CURLINFO_SIZE_DOWNLOAD, 'size_download' => CURLINFO_SIZE_DOWNLOAD,
'speed_download' => CURLINFO_SPEED_DOWNLOAD, 'speed_download' => CURLINFO_SPEED_DOWNLOAD,
'speed_upload' => CURLINFO_SPEED_UPLOAD, 'speed_upload' => CURLINFO_SPEED_UPLOAD,
'header_size' => CURLINFO_HEADER_SIZE, 'header_size' => CURLINFO_HEADER_SIZE,
'header_out' => CURLINFO_HEADER_OUT, 'header_out' => CURLINFO_HEADER_OUT,
'request_size' => CURLINFO_REQUEST_SIZE, 'request_size' => CURLINFO_REQUEST_SIZE,
'ssl_verifyresult' => CURLINFO_SSL_VERIFYRESULT, 'ssl_verifyresult' => CURLINFO_SSL_VERIFYRESULT,
'content_length_download' => CURLINFO_CONTENT_LENGTH_DOWNLOAD, 'content_length_download' => CURLINFO_CONTENT_LENGTH_DOWNLOAD,
'content_length_upload' => CURLINFO_CONTENT_LENGTH_UPLOAD, 'content_length_upload' => CURLINFO_CONTENT_LENGTH_UPLOAD,
'content_type' => CURLINFO_CONTENT_TYPE 'content_type' => CURLINFO_CONTENT_TYPE,
]; ];
/**
* @var array
*/
static $optionsCodes = [ static $optionsCodes = [
'autoreferer' => CURLOPT_AUTOREFERER, 'autoreferer' => CURLOPT_AUTOREFERER,
'binarytransfer' => CURLOPT_BINARYTRANSFER, 'binarytransfer' => CURLOPT_BINARYTRANSFER,
'cookiesession' => CURLOPT_COOKIESESSION, 'cookiesession' => CURLOPT_COOKIESESSION,
'crlf' => CURLOPT_CRLF, 'crlf' => CURLOPT_CRLF,
'dns_use_global_cache' => CURLOPT_DNS_USE_GLOBAL_CACHE, 'dns_use_global_cache' => CURLOPT_DNS_USE_GLOBAL_CACHE,
'failonerror' => CURLOPT_FAILONERROR, 'failonerror' => CURLOPT_FAILONERROR,
'filetime' => CURLOPT_FILETIME, 'filetime' => CURLOPT_FILETIME,
'followlocation' => CURLOPT_FOLLOWLOCATION, 'followlocation' => CURLOPT_FOLLOWLOCATION,
'forbid_reuse' => CURLOPT_FORBID_REUSE, 'forbid_reuse' => CURLOPT_FORBID_REUSE,
'fresh_connect' => CURLOPT_FRESH_CONNECT, 'fresh_connect' => CURLOPT_FRESH_CONNECT,
'ftp_use_eprt' => CURLOPT_FTP_USE_EPRT, 'ftp_use_eprt' => CURLOPT_FTP_USE_EPRT,
'ftp_use_epsv' => CURLOPT_FTP_USE_EPSV, 'ftp_use_epsv' => CURLOPT_FTP_USE_EPSV,
'ftpappend' => CURLOPT_FTPAPPEND, 'ftpappend' => CURLOPT_FTPAPPEND,
'ftpascii' => CURLOPT_TRANSFERTEXT, 'ftpascii' => CURLOPT_TRANSFERTEXT,
'ftplistonly' => CURLOPT_FTPLISTONLY, 'ftplistonly' => CURLOPT_FTPLISTONLY,
'header' => CURLOPT_HEADER, 'header' => CURLOPT_HEADER,
'httpget' => CURLOPT_HTTPGET, 'httpget' => CURLOPT_HTTPGET,
'httpproxytunnel' => CURLOPT_HTTPPROXYTUNNEL, 'httpproxytunnel' => CURLOPT_HTTPPROXYTUNNEL,
// 'mute' => CURLOPT_MUTE, // 'mute' => CURLOPT_MUTE,
'netrc' => CURLOPT_NETRC, 'netrc' => CURLOPT_NETRC,
'nobody' => CURLOPT_NOBODY, 'nobody' => CURLOPT_NOBODY,
'noprogress' => CURLOPT_NOPROGRESS, 'noprogress' => CURLOPT_NOPROGRESS,
'nosignal' => CURLOPT_NOSIGNAL, 'nosignal' => CURLOPT_NOSIGNAL,
'post' => CURLOPT_POST, 'post' => CURLOPT_POST,
'put' => CURLOPT_PUT, 'put' => CURLOPT_PUT,
'returntransfer' => CURLOPT_RETURNTRANSFER, 'returntransfer' => CURLOPT_RETURNTRANSFER,
'ssl_verifypeer' => CURLOPT_SSL_VERIFYPEER, 'ssl_verifypeer' => CURLOPT_SSL_VERIFYPEER,
'transfertext' => CURLOPT_TRANSFERTEXT, 'transfertext' => CURLOPT_TRANSFERTEXT,
'unrestricted_auth' => CURLOPT_UNRESTRICTED_AUTH, 'unrestricted_auth' => CURLOPT_UNRESTRICTED_AUTH,
'upload' => CURLOPT_UPLOAD, 'upload' => CURLOPT_UPLOAD,
'verbose' => CURLOPT_VERBOSE, 'verbose' => CURLOPT_VERBOSE,
'buffersize' => CURLOPT_BUFFERSIZE, 'buffersize' => CURLOPT_BUFFERSIZE,
// 'closepolicy' => CURLOPT_CLOSEPOLICY, // 'closepolicy' => CURLOPT_CLOSEPOLICY,
'connecttimeout' => CURLOPT_CONNECTTIMEOUT, 'connecttimeout' => CURLOPT_CONNECTTIMEOUT,
'dns_cache_timeout' => CURLOPT_DNS_CACHE_TIMEOUT, 'dns_cache_timeout' => CURLOPT_DNS_CACHE_TIMEOUT,
'ftpsslauth' => CURLOPT_FTPSSLAUTH, 'ftpsslauth' => CURLOPT_FTPSSLAUTH,
'http_version' => CURLOPT_HTTP_VERSION, 'http_version' => CURLOPT_HTTP_VERSION,
'httpauth' => CURLOPT_HTTPAUTH, 'httpauth' => CURLOPT_HTTPAUTH,
'curlauth_any' => CURLAUTH_ANY, 'curlauth_any' => CURLAUTH_ANY,
'curlauth_anysafe' => CURLAUTH_ANYSAFE, 'curlauth_anysafe' => CURLAUTH_ANYSAFE,
'infilesize' => CURLOPT_INFILESIZE, 'infilesize' => CURLOPT_INFILESIZE,
'low_speed_limit' => CURLOPT_LOW_SPEED_LIMIT, 'low_speed_limit' => CURLOPT_LOW_SPEED_LIMIT,
'low_speed_time' => CURLOPT_LOW_SPEED_TIME, 'low_speed_time' => CURLOPT_LOW_SPEED_TIME,
'maxconnects' => CURLOPT_MAXCONNECTS, 'maxconnects' => CURLOPT_MAXCONNECTS,
'maxredirs' => CURLOPT_MAXREDIRS, 'maxredirs' => CURLOPT_MAXREDIRS,
'port' => CURLOPT_PORT, 'port' => CURLOPT_PORT,
'proxyauth' => CURLOPT_PROXYAUTH, 'proxyauth' => CURLOPT_PROXYAUTH,
'proxyport' => CURLOPT_PROXYPORT, 'proxyport' => CURLOPT_PROXYPORT,
'proxytype' => CURLOPT_PROXYTYPE, 'proxytype' => CURLOPT_PROXYTYPE,
'resume_from' => CURLOPT_RESUME_FROM, 'resume_from' => CURLOPT_RESUME_FROM,
'ssl_verifyhost' => CURLOPT_SSL_VERIFYHOST, 'ssl_verifyhost' => CURLOPT_SSL_VERIFYHOST,
'sslversion' => CURLOPT_SSLVERSION, 'sslversion' => CURLOPT_SSLVERSION,
'timecondition' => CURLOPT_TIMECONDITION, 'timecondition' => CURLOPT_TIMECONDITION,
'timeout' => CURLOPT_TIMEOUT, 'timeout' => CURLOPT_TIMEOUT,
'timevalue' => CURLOPT_TIMEVALUE, 'timevalue' => CURLOPT_TIMEVALUE,
'cainfo' => CURLOPT_CAINFO, 'cainfo' => CURLOPT_CAINFO,
'capath' => CURLOPT_CAPATH, 'capath' => CURLOPT_CAPATH,
'cookie' => CURLOPT_COOKIE, 'cookie' => CURLOPT_COOKIE,
'cookiefile' => CURLOPT_COOKIEFILE, 'cookiefile' => CURLOPT_COOKIEFILE,
'cookiejar' => CURLOPT_COOKIEJAR, 'cookiejar' => CURLOPT_COOKIEJAR,
'customrequest' => CURLOPT_CUSTOMREQUEST, 'customrequest' => CURLOPT_CUSTOMREQUEST,
'egdsocket' => CURLOPT_EGDSOCKET, 'egdsocket' => CURLOPT_EGDSOCKET,
'encoding' => CURLOPT_ENCODING, 'encoding' => CURLOPT_ENCODING,
'ftpport' => CURLOPT_FTPPORT, 'ftpport' => CURLOPT_FTPPORT,
'interface' => CURLOPT_INTERFACE, 'interface' => CURLOPT_INTERFACE,
'krb4level' => CURLOPT_KRB4LEVEL, 'krb4level' => CURLOPT_KRB4LEVEL,
'postfields' => CURLOPT_POSTFIELDS, 'postfields' => CURLOPT_POSTFIELDS,
'proxy' => CURLOPT_PROXY, 'proxy' => CURLOPT_PROXY,
'proxyuserpwd' => CURLOPT_PROXYUSERPWD, 'proxyuserpwd' => CURLOPT_PROXYUSERPWD,
'random_file' => CURLOPT_RANDOM_FILE, 'random_file' => CURLOPT_RANDOM_FILE,
'range' => CURLOPT_RANGE, 'range' => CURLOPT_RANGE,
'referer' => CURLOPT_REFERER, 'referer' => CURLOPT_REFERER,
'ssl_cipher_list' => CURLOPT_SSL_CIPHER_LIST, 'ssl_cipher_list' => CURLOPT_SSL_CIPHER_LIST,
'sslcert' => CURLOPT_SSLCERT, 'sslcert' => CURLOPT_SSLCERT,
'sslcertpasswd' => CURLOPT_SSLCERTPASSWD, 'sslcertpasswd' => CURLOPT_SSLCERTPASSWD,
'sslcerttype' => CURLOPT_SSLCERTTYPE, 'sslcerttype' => CURLOPT_SSLCERTTYPE,
'sslengine' => CURLOPT_SSLENGINE, 'sslengine' => CURLOPT_SSLENGINE,
'sslengine_default' => CURLOPT_SSLENGINE_DEFAULT, 'sslengine_default' => CURLOPT_SSLENGINE_DEFAULT,
'sslkey' => CURLOPT_SSLKEY, 'sslkey' => CURLOPT_SSLKEY,
'sslkeypasswd' => CURLOPT_SSLKEYPASSWD, 'sslkeypasswd' => CURLOPT_SSLKEYPASSWD,
'sslkeytype' => CURLOPT_SSLKEYTYPE, 'sslkeytype' => CURLOPT_SSLKEYTYPE,
'url' => CURLOPT_URL, 'url' => CURLOPT_URL,
'useragent' => CURLOPT_USERAGENT, 'useragent' => CURLOPT_USERAGENT,
'userpwd' => CURLOPT_USERPWD, 'userpwd' => CURLOPT_USERPWD,
'http200aliases' => CURLOPT_HTTP200ALIASES, 'http200aliases' => CURLOPT_HTTP200ALIASES,
'httpheader' => CURLOPT_HTTPHEADER, 'httpheader' => CURLOPT_HTTPHEADER,
'postquote' => CURLOPT_POSTQUOTE, 'postquote' => CURLOPT_POSTQUOTE,
'quote' => CURLOPT_QUOTE, 'quote' => CURLOPT_QUOTE,
'file' => CURLOPT_FILE, 'file' => CURLOPT_FILE,
'infile' => CURLOPT_INFILE, 'infile' => CURLOPT_INFILE,
'stderr' => CURLOPT_STDERR, 'stderr' => CURLOPT_STDERR,
'writeheader' => CURLOPT_WRITEHEADER, 'writeheader' => CURLOPT_WRITEHEADER,
'headerfunction' => CURLOPT_HEADERFUNCTION, 'headerfunction' => CURLOPT_HEADERFUNCTION,
'readfunction' => CURLOPT_READFUNCTION, 'readfunction' => CURLOPT_READFUNCTION,
'writefunction' => CURLOPT_WRITEFUNCTION, 'writefunction' => CURLOPT_WRITEFUNCTION,
]; ];
/** @noinspection PhpInconsistentReturnPointsInspection */ /** @noinspection PhpInconsistentReturnPointsInspection */
/** /**
* Initialize a cURL session * Initialize a cURL session
*
* @param null $url * @param null $url
* @throws Exception *
* @return CURL * @return CURL
* @throws Exception
*/ */
public function __construct( $url = null ) public function __construct( $url = null )
{ {
if ( function_exists( 'curl_init' ) ) { if ( function_exists( 'curl_init' ) ) {
/* /* For some reason on certain PHP/CURL version it causes error if the $url is null */
* For some reason on certain PHP/CURL version it causes error if the $url is null
*/
if ( $url ) { if ( $url ) {
$this->resource = curl_init( $url ); $this->resource = curl_init( $url );
} }
...@@ -168,14 +189,16 @@ class CURL ...@@ -168,14 +189,16 @@ class CURL
} }
} }
else { else {
throw new Exception( Framework::Txt( 'CURL_NOT_INSTALLED' ) ); $this->curlStatus = 999;
} }
} }
/** /**
* Sets an option on the given cURL session handle. * Sets an option on the given cURL session handle.
*
* @param string $option - The CURLOPT_XXX option to set. * @param string $option - The CURLOPT_XXX option to set.
* @param mixed $value - The value to be set on option * @param mixed $value - The value to be set on option
*
* @return bool * @return bool
*/ */
public function setOption( $option, $value ) public function setOption( $option, $value )
...@@ -183,12 +206,15 @@ class CURL ...@@ -183,12 +206,15 @@ class CURL
if ( is_string( $option ) && isset( self::$optionsCodes[ $option ] ) ) { if ( is_string( $option ) && isset( self::$optionsCodes[ $option ] ) ) {
$option = self::$optionsCodes[ $option ]; $option = self::$optionsCodes[ $option ];
} }
return curl_setopt( $this->resource, $option, $value ); return curl_setopt( $this->resource, $option, $value );
} }
/** /**
* Sets multiple options for a cURL session * Sets multiple options for a cURL session
*
* @param array $options - An array specifying which options to set and their values. The keys should be valid curl_setopt() constants or their integer equivalents. * @param array $options - An array specifying which options to set and their values. The keys should be valid curl_setopt() constants or their integer equivalents.
*
* @return bool * @return bool
*/ */
public function setOptions( $options ) public function setOptions( $options )
...@@ -201,12 +227,23 @@ class CURL ...@@ -201,12 +227,23 @@ class CURL
} }
} }
} }
return curl_setopt_array( $this->resource, $options ); return curl_setopt_array( $this->resource, $options );
} }
/** /**
* set an URL * @return array
*/
public function status()
{
return $this->curlStatus;
}
/**
* Sets an URL.
*
* @param string $url * @param string $url
*
* @return bool * @return bool
*/ */
public function setUrl( $url ) public function setUrl( $url )
...@@ -216,9 +253,11 @@ class CURL ...@@ -216,9 +253,11 @@ class CURL
/** /**
* TRUE to include the header in the output. * TRUE to include the header in the output.
*
* @param $timeOut * @param $timeOut
* @internal param bool $header *
* @return bool * @return bool
* @internal param bool $header
*/ */
public function setTimeOut( $timeOut ) public function setTimeOut( $timeOut )
{ {
...@@ -227,7 +266,9 @@ class CURL ...@@ -227,7 +266,9 @@ class CURL
/** /**
* TRUE to include the header in the output. * TRUE to include the header in the output.
*
* @param bool $header * @param bool $header
*
* @return bool * @return bool
*/ */
public function setHeader( $header ) public function setHeader( $header )
...@@ -244,7 +285,8 @@ class CURL ...@@ -244,7 +285,8 @@ class CURL
} }
/** /**
* Closes a cURL session and frees all resources * Closes a cURL session and frees all resources.
*
* @return mixed * @return mixed
*/ */
public function close() public function close()
...@@ -265,6 +307,7 @@ class CURL ...@@ -265,6 +307,7 @@ class CURL
*/ */
public function exec() public function exec()
{ {
$this->error[ 'active' ] = false;
$r = curl_exec( $this->resource ); $r = curl_exec( $this->resource );
$inf = $this->info(); $inf = $this->info();
if ( $inf[ 'http_code' ] == 301 || $inf[ 'http_code' ] == 302 ) { if ( $inf[ 'http_code' ] == 301 || $inf[ 'http_code' ] == 302 ) {
...@@ -273,20 +316,25 @@ class CURL ...@@ -273,20 +316,25 @@ class CURL
preg_match( '/Location: (http.*)/', $r, $newUrl ); preg_match( '/Location: (http.*)/', $r, $newUrl );
$this->setOption( 'header', false ); $this->setOption( 'header', false );
$this->setOption( 'url', $newUrl[ 1 ] ); $this->setOption( 'url', $newUrl[ 1 ] );
return $this->exec(); return $this->exec();
} }
return $r; return $r;
} }
/** /**
* Gets information about the last transfer * Gets information about the last transfer.
*
* @param string $opt - correspond option * @param string $opt - correspond option
*
* @return bool * @return bool
*/ */
public function info( $opt = null ) public function info( $opt = null )
{ {
if ( $opt && is_string( $opt ) && isset( self::$infoCodes[ $opt ] ) ) { if ( $opt && is_string( $opt ) && isset( self::$infoCodes[ $opt ] ) ) {
$opt = self::$infoCodes[ $opt ]; $opt = self::$infoCodes[ $opt ];
return curl_getinfo( $this->resource, $opt ); return curl_getinfo( $this->resource, $opt );
} }
else { else {
...@@ -294,6 +342,12 @@ class CURL ...@@ -294,6 +342,12 @@ class CURL
} }
} }
/**
* @param $url
*
* @return array|false
* @throws Exception
*/
public function certificate( $url ) public function certificate( $url )
{ {
$errno = null; $errno = null;
...@@ -309,18 +363,19 @@ class CURL ...@@ -309,18 +363,19 @@ class CURL
return [ 'err' => 500, 'msg' => Framework::Txt( 'INVALID_URL', 'https://' . $url ) ]; return [ 'err' => 500, 'msg' => Framework::Txt( 'INVALID_URL', 'https://' . $url ) ];
} }
$this->setOptions( $this->setOptions(
[ [
'url' => 'https://' . $url, 'url' => 'https://' . $url,
'connecttimeout' => 10, 'connecttimeout' => 10,
'header' => true, 'header' => true,
'returntransfer' => true, 'returntransfer' => true,
'ssl_verifypeer' => false, 'ssl_verifypeer' => false,
'ssl_verifyhost' => 2, 'ssl_verifyhost' => 2,
'nobody' => true, 'nobody' => true,
] ]
); );
if ( !( $this->validCode( $this->exec() ) ) ) { if ( !( $this->validCode( $this->exec() ) ) ) {
$err = $this->info(); $err = $this->info();
return [ 'err' => $err[ 'http_code' ], 'msg' => Framework::Txt( 'NO_CONNECT', 'https://' . $url ) ]; return [ 'err' => $err[ 'http_code' ], 'msg' => Framework::Txt( 'NO_CONNECT', 'https://' . $url ) ];
} }
$res = stream_context_create( [ 'ssl' => [ 'capture_peer_cert' => true ] ] ); $res = stream_context_create( [ 'ssl' => [ 'capture_peer_cert' => true ] ] );
...@@ -334,42 +389,65 @@ class CURL ...@@ -334,42 +389,65 @@ class CURL
} }
} }
/**
* @param $url
*
* @return false|int
*/
private function validateHttp( $url ) private function validateHttp( $url )
{ {
return preg_match( '|http[s]?:\/\/[a-z0-9\.\-\_]{3,}\.[a-z]{2,5}.*|i', $url ); return preg_match( '|http[s]?:\/\/[a-z0-9\.\-\_]{3,}\.[a-z]{2,5}.*|i', $url );
} }
/**
* @param $response
*
* @return bool|int
*/
public function getCode( $response ) public function getCode( $response )
{ {
$matches = []; $matches = [];
if ( preg_match( '/HTTP\/1\.\d+\s+(\d+)/', $response, $matches ) ) { if ( preg_match( '/HTTP\/1\.\d+\s+(\d+)/', $response, $matches ) ) {
return ( int )$matches[ 1 ]; return ( int ) $matches[ 1 ];
} }
else { else {
return false; return false;
} }
} }
/**
* @param $response
*
* @return bool
*/
public function validCode( $response ) public function validCode( $response )
{ {