Validates PHP/cURL extension for use with SSL/TLS.

@param  array $curlinfo array of cURL information as returned by curl_version()
@param  int   $zts 0 or 1 as defined by PHP_ZTS
@return bool
767888
public static function validate_php_curl_tls(array $curlinfo, $zts) {
        if (empty($curlinfo['ssl_version'])) {
            return false;
        }

        $flavour = explode('/', $curlinfo['ssl_version'])[0];
        // In threadsafe mode the only valid choices are OpenSSL and GnuTLS.
        if ($zts === 1 && $flavour != 'OpenSSL' && $flavour !== 'GnuTLS') {
            return false;
        }

        return true;
    }
150224
public function setSSLCert($certPath, $passPhrase = null)
    {
        $this->curlOptions[CURLOPT_SSLCERT] = realpath($certPath);
        if (isset($passPhrase) && trim($passPhrase) != "") {
            $this->curlOptions[CURLOPT_SSLCERTPASSWD] = $passPhrase;
        }
    }
177649
function curlPostWithCert($url, $vars, $certPemPath, $keyPemPath, $second=50,$aHeader=array())
    {
        $ch = curl_init();
        //超时时间
        curl_setopt($ch,CURLOPT_TIMEOUT,$second);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
        curl_setopt($ch,CURLOPT_SSLCERT, $certPemPath);  //__DIR__ . '/cert/apiclient_cert.pem'
        curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
        curl_setopt($ch,CURLOPT_SSLKEY, $keyPemPath); //__DIR__ . '/cert/apiclient_key.pem'

        if( count($aHeader) >= 1 ){
            curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
        }

        curl_setopt($ch,CURLOPT_POST, 1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
        $result = curl_exec($ch);
        if($result === false){
            $error = curl_error($ch);
            echo "curl错误信息:$error\n";
        }

        curl_close($ch);
        return $result;
    }
960983
public function get_curl_object() {
        if (!is_null($this->curl)) {
            return $this->curl;
        }

        // Connection to Solr is allowed to use 'localhost' and other potentially blocked hosts/ports.
        $this->curl = new \curl(['ignoresecurity' => true]);

        $options = array();
        // Build the SSL options. Based on pecl-solr and general testing.
        if (!empty($this->config->secure)) {
            if (!empty($this->config->ssl_cert)) {
                $options['CURLOPT_SSLCERT'] = $this->config->ssl_cert;
                $options['CURLOPT_SSLCERTTYPE'] = 'PEM';
            }

            if (!empty($this->config->ssl_key)) {
                $options['CURLOPT_SSLKEY'] = $this->config->ssl_key;
                $options['CURLOPT_SSLKEYTYPE'] = 'PEM';
            }

            if (!empty($this->config->ssl_keypassword)) {
                $options['CURLOPT_KEYPASSWD'] = $this->config->ssl_keypassword;
            }

            if (!empty($this->config->ssl_cainfo)) {
                $options['CURLOPT_CAINFO'] = $this->config->ssl_cainfo;
            }

            if (!empty($this->config->ssl_capath)) {
                $options['CURLOPT_CAPATH'] = $this->config->ssl_capath;
            }
        }

        // Set timeout as for Solr client.
        $options['CURLOPT_TIMEOUT'] = !empty($this->config->server_timeout) ? $this->config->server_timeout : '30';

        $this->curl->setopt($options);

        if (!empty($this->config->server_username) && !empty($this->config->server_password)) {
            $authorization = $this->config->server_username . ':' . $this->config->server_password;
            $this->curl->setHeader('Authorization: Basic ' . base64_encode($authorization));
        }

        return $this->curl;
    }
623959
public function validateLinks($urlLinks = []){
        if(!is_array($urlLinks))
            return false;
        foreach($urlLinks as $keyLink=>$Link){
            if(\SapiStudio\Http\Html::isValidURL($Link)){
                $promises[$keyLink] = $this->headAsync($Link,self::$clientConfig['testConfig']);
            }
        }
        $results = Promise\settle($promises)->wait();
        if($results){
            foreach($results as $promiseIndex=>$promiseResponse){
                $response = $promiseResponse['value'];
                $linkHash = md5($urlLinks[$promiseIndex]);
                $this->validatedLinks[$linkHash]['isAlive']     = ($response) ? true : false;
                $this->validatedLinks[$linkHash]['url']         = $urlLinks[$promiseIndex];
                $this->validatedLinks[$linkHash]['isImage']     = ($response) ? \SapiStudio\Http\Html::urlIsImage($response->getHeaderLine('content-type')) : false;
                $this->validatedLinks[$linkHash]['contentType'] = ($response) ? $response->getHeaderLine('content-type') : false;
            }
        }
        return $this->validatedLinks;
    }
146499
static function CurlRequest($method, $url, $data, $verify_cert = false, $timeout = 30)
	{
		// if the data provided is in array format, convert it to a querystring
		$qs = HttpRequest::ArrayToQueryString($data);

		$agent = "verysimple::HttpRequest";

		// $header[] = "Accept: text/vnd.wap.wml,*.*";

		$fp = null;

		if ($method == "POST")
		{
			$ch = curl_init($url);
			curl_setopt($ch,		CURLOPT_POST, 1);
			curl_setopt($ch,		CURLOPT_POSTFIELDS, $qs);
		}
		elseif ($method == 'PUT')
		{
			$ch = curl_init($url);
			curl_setopt($ch, CURLOPT_PUT, true);

			if ($data)
			{
				// with a PUT request the body must be written to a file stream
				$fp = fopen('php://temp/maxmemory:256000', 'w');
				if (!$fp) {
					throw new Exception('Unable to write to php://temp for PUT request');
				}
				fwrite($fp, $data);
				fseek($fp, 0);

				// if the PUT request contains JSON data then add the content type header
				if (json_encode($data)) curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json") );

				curl_setopt($ch, CURLOPT_INFILE, $fp);
				curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
				curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
			}

		}
		else
		{
			$full_url = $url . ($qs ? "?" . $qs : "");
			$ch = curl_init($full_url);
		}

		curl_setopt($ch,		CURLOPT_HTTPHEADER, array("Expect:  ") );  //Fixes the HTTP/1.1 417 Expectation Failed Bug
		
		curl_setopt($ch,		CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch,		CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch,		CURLOPT_VERBOSE, 0); ########### debug
		curl_setopt($ch,	    CURLOPT_USERAGENT, $agent);
		curl_setopt($ch,		CURLOPT_SSL_VERIFYPEER, $verify_cert);
		curl_setopt($ch,		CURLOPT_NOPROGRESS, 1);
		// curl_setopt($ch,	    CURLOPT_HTTPHEADER, $header);
		// curl_setopt($ch,		CURLOPT_COOKIEJAR, "curl_cookie");
		// curl_setopt($ch,		CURLOPT_COOKIEFILE, "curl_cookie");
		curl_setopt($ch,		CURLOPT_TIMEOUT,$timeout);

		$tmp = curl_exec ($ch);
		$error = curl_error($ch);

		if ($fp) @fclose($fp); // if a PUT request had body data, close the file stream

		if ($error != "") {$tmp .= $error;}
		curl_close ($ch);

		return $tmp;
	}
260675
public function curl($url)
    {
        $ip = '127.0.0.1';
        $port = '9051';
        $auth = 'PASSWORD';
        $command = 'signal NEWNYM';

        $fp = fsockopen($ip, $port, $error_number, $err_string, 2);
        if (!$fp) {
            echo "ERROR: $error_number : $err_string";

            return false;
        } else {
            fwrite($fp, "AUTHENTICATE \"".$auth."\"\n");
            fread($fp, 512);
            fwrite($fp, $command."\n");
            fread($fp, 512);
        }

        fclose($fp);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050');
        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());  // $this->getUserAgent(true) for random);
        curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
        $response = curl_exec($ch);

        return [$response, $ch];
    }
875482
public static function isBehindSsl() : bool
  {
      // Check for proxy first
      if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
          return self::protocolWithActiveSsl($_SERVER['HTTP_X_FORWARDED_PROTO']);
      }

      if (isset($_SERVER['HTTPS'])) {
          return self::protocolWithActiveSsl($_SERVER['HTTPS']);
      }

      return $_SERVER['SERVER_PORT'] == 443;
  }
890238
public static function isSSL() : bool {
		if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
			return true;
		} else if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
			return true;
		} else {
			return false;
		}
	}
1334327
private function setSSL()
    {
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); 
    }
924382
private function executeCurl()
    {
        if ($this->initCurl()){
            $this->configureCurl();
            $this->CurlResponse = curl_exec($this->CurlRequest);
            $this->checkForError();
            return TRUE;
        }
        return FALSE;
    }
1128202
public function check()
    {
        $extensionName = 'curl';
        $result = extension_loaded($extensionName);

        if ($result === true) {
            $curlVersion = curl_version();
            $this->extensionVersion = $curlVersion['version'];
        }

        return $result;
    }
1245987
public static function _isSSL() {
        // Check if SSL is enabled
        if (isset($_SERVER) && (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on") || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") ) {
            return TRUE;
        }
        return FALSE;
    }
1222433
protected function _validateOldDebitInfo($debitInfo)
    {
        $stringHelper = getStr();
        $debitInfo = $this->_fixAccountNumber($debitInfo);

        $validationResult = true;

        if (!$stringHelper->preg_match("/^\d{5,8}$/", $debitInfo['lsblz'])) {
            // Bank code is invalid
            $validationResult = self::INVALID_BANK_CODE;
        }

        if (true === $validationResult && !$stringHelper->preg_match("/^\d{10,12}$/", $debitInfo['lsktonr'])) {
            // Account number is invalid
            $validationResult = self::INVALID_ACCOUNT_NUMBER;
        }


        return $validationResult;
    }
804927
public function isValidPHPExtensions()
    {
        $extensions = array('xml', 'soap', 'curl');
        foreach ($extensions as $extension) {
            if (!extension_loaded($extension)) {
                return Splash::log()->err(
                    'PHP :'.$extension.' PHP Extension is required to use Splash PHP Module.'
                );
            }
        }

        return Splash::log()->msg(
            'PHP : Required PHP Extension are installed ('.implode(', ', $extensions).')'
        );
    }
752889
public function isValidRequest(): bool
    {
        // If we're running from CLI, requests are always valid, unless we're running the tests.
        if ((!self::inTest() && 'cli' === PHP_SAPI) || false === $this->params->getBotParam('validate_request')) {
            return true;
        }

        $ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
        foreach (['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'] as $key) {
            if (filter_var($_SERVER[$key] ?? null, FILTER_VALIDATE_IP)) {
                $ip = $_SERVER[$key];
                break;
            }
        }

        return Ip::match($ip, array_merge(
            [self::TELEGRAM_IP_RANGE],
            (array) $this->params->getBotParam('valid_ips', [])
        ));
    }
312739
protected function curl()
    {
        $curl    = curl_init();
        curl_setopt_array($curl, [
            CURLOPT_URL            => $this->url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
        ]);
        $result = curl_exec($curl);
        curl_close($curl);

        return $result;
    }