Пример #1
0
 public static function setup($client_id, $client_secret, $options = array('session_manager' => null, 'curl_options' => array()))
 {
     // Setup client info
     self::$client_id = $client_id;
     self::$client_secret = $client_secret;
     // Setup curl
     self::$url = empty($options['api_url']) ? 'https://api.podio.com:443' : $options['api_url'];
     self::$debug = self::$debug ? self::$debug : false;
     self::$ch = curl_init();
     self::$headers = array('Accept' => 'application/json');
     curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt(self::$ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt(self::$ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt(self::$ch, CURLOPT_USERAGENT, 'Podio PHP Client/' . self::VERSION);
     curl_setopt(self::$ch, CURLOPT_HEADER, true);
     curl_setopt(self::$ch, CURLINFO_HEADER_OUT, true);
     //Update CA root certificates - require: https://github.com/Kdyby/CurlCaBundle
     if (class_exists('\\Kdyby\\CurlCaBundle\\CertificateHelper')) {
         \Kdyby\CurlCaBundle\CertificateHelper::setCurlCaInfo(self::$ch);
     }
     if ($options && !empty($options['curl_options'])) {
         curl_setopt_array(self::$ch, $options['curl_options']);
     }
     self::$session_manager = null;
     if ($options && !empty($options['session_manager']) && class_exists($options['session_manager'])) {
         self::$session_manager = new $options['session_manager']();
         self::$oauth = self::$session_manager->get();
     }
     // Register shutdown function for debugging and session management
     register_shutdown_function('Podio::shutdown');
 }
Пример #2
0
 /**
  * Constructs the cURL object wrapper
  * @throws \Communique\CommuniqueRESTConnectionException
  */
 public function __construct()
 {
     if (!extension_loaded('curl')) {
         throw new \Communique\CommuniqueRESTConnectionException('cURL Error: ' . $this->error() . ' cURL Error Code: ' . $this->errno());
     } else {
         $this->_ch = curl_init();
         $this->setopt(CURLOPT_CAINFO, \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile());
     }
 }
Пример #3
0
 /**
  * Get certificate path.
  *
  * @return string
  */
 public function getCertificatePath()
 {
     if ($this->certificatePath) {
         return $this->certificatePath;
     }
     if (class_exists('\\Kdyby\\CurlCaBundle\\CertificateHelper')) {
         return \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile();
     }
     // Key downloaded from https://www.geotrust.com/resources/root-certificates/
     return __DIR__ . '/keys/Geotrust_PCA_G3_Root.pem';
 }
Пример #4
0
 /** @inheritdoc */
 public function request(IRequest $request)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->getUrl($request));
     curl_setopt($ch, CURLOPT_CAINFO, CertificateHelper::getCaInfoFile());
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getConnectionParameters($this->config));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     curl_close($ch);
     return $response;
 }
Пример #5
0
 /**
  * Makes an HTTP request. This method can be overridden by subclasses if
  * developers want to do fancier things or use something other than curl to
  * make the request.
  *
  * @param Request $request
  * @throws Github\ApiException
  * @return Response
  */
 public function makeRequest(Request $request)
 {
     if (isset($this->memoryCache[$cacheKey = md5(serialize($request))])) {
         return $this->memoryCache[$cacheKey];
     }
     $ch = $this->buildCurlResource($request);
     $result = curl_exec($ch);
     // provide certificate if needed
     if (curl_errno($ch) == CURLE_SSL_CACERT || curl_errno($ch) === CURLE_SSL_CACERT_BADFILE) {
         Debugger::log('Invalid or no certificate authority found, using bundled information', 'github');
         $this->curlOptions[CURLOPT_CAINFO] = CertificateHelper::getCaInfoFile();
         curl_setopt($ch, CURLOPT_CAINFO, CertificateHelper::getCaInfoFile());
         $result = curl_exec($ch);
     }
     // With dual stacked DNS responses, it's possible for a server to
     // have IPv6 enabled but not have IPv6 connectivity.  If this is
     // the case, curl will try IPv4 first and if that fails, then it will
     // fall back to IPv6 and the error EHOSTUNREACH is returned by the operating system.
     if ($result === FALSE && empty($opts[CURLOPT_IPRESOLVE])) {
         $matches = array();
         if (preg_match('/Failed to connect to ([^:].*): Network is unreachable/', curl_error($ch), $matches)) {
             if (strlen(@inet_pton($matches[1])) === 16) {
                 Debugger::log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.', 'github');
                 $this->curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
                 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
                 $result = curl_exec($ch);
             }
         }
     }
     $info = curl_getinfo($ch);
     $info['http_code'] = (int) $info['http_code'];
     if (isset($info['request_header'])) {
         list($info['request_header']) = self::parseHeaders($info['request_header']);
     }
     $info['method'] = isset($post['method']) ? $post['method'] : 'GET';
     $info['headers'] = self::parseHeaders(substr($result, 0, $info['header_size']));
     $info['error'] = $result === FALSE ? array('message' => curl_error($ch), 'code' => curl_errno($ch)) : array();
     $request->setHeaders($info['request_header']);
     $response = new Response($request, substr($result, $info['header_size']), $info['http_code'], end($info['headers']), $info);
     if (!$response->isOk()) {
         $e = $response->toException();
         curl_close($ch);
         $this->onError($e, $response);
         throw $e;
     }
     $this->onSuccess($response);
     curl_close($ch);
     return $this->memoryCache[$cacheKey] = $response;
 }
Пример #6
0
 /**
  * Class constructor.
  *
  * @param array $options Options provided to the SimpleCAS protocol object.
  * @param boolean $gateway If SSO is in gateway mode.
  */
 public function __construct($options = array(), $gateway = false)
 {
     // Store gateway mode.
     $this->_gateway = $gateway;
     // Create a new SimpleCAS protocol object with specified options.
     $this->_protocol = new SimpleCAS_Protocol_Version2($options);
     // User's should be redirected back to Omeka after logout.
     $this->_protocol->setLogoutServiceRedirect(true);
     // Specify a certificate authority file so that SSL is validated.
     $this->_protocol->getRequest()->setConfig('ssl_cafile', \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile());
     // Create a new SimpleCAS client object with the protocol.
     $this->_client = SimpleCAS::client($this->_protocol);
     // Handle Single Log Out (SLO).
     $this->_client->handleSingleLogOut();
 }
Пример #7
0
 /**
  * Makes an HTTP request. This method can be overridden by subclasses if
  * developers want to do fancier things or use something other than curl to
  * make the request.
  *
  * @param Request $request
  * @param string $signatureMethodName
  *
  * @return Response
  *
  * @throws Exceptions\ApiException
  * @throws Exceptions\InvalidArgumentException
  */
 public function makeRequest(Request $request, $signatureMethodName = 'PLAINTEXT')
 {
     if (!($signatureMethod = $this->getSignatureMethod($signatureMethodName))) {
         throw new Exceptions\InvalidArgumentException("Signature method '{$signatureMethodName}' was not found. Please provide valid signature method name");
     }
     if (isset($this->memoryCache[$cacheKey = md5(serialize($request))])) {
         return $this->memoryCache[$cacheKey];
     }
     // Sign request with selected method
     $request->signRequest($signatureMethod);
     $ch = $this->buildCurlResource($request);
     $result = curl_exec($ch);
     // provide certificate if needed
     if (curl_errno($ch) == CURLE_SSL_CACERT || curl_errno($ch) === CURLE_SSL_CACERT_BADFILE) {
         Debugger::log('Invalid or no certificate authority found, using bundled information', 'oauth');
         $this->curlOptions[CURLOPT_CAINFO] = CurlCaBundle\CertificateHelper::getCaInfoFile();
         curl_setopt($ch, CURLOPT_CAINFO, CurlCaBundle\CertificateHelper::getCaInfoFile());
         $result = curl_exec($ch);
     }
     // With dual stacked DNS responses, it's possible for a server to
     // have IPv6 enabled but not have IPv6 connectivity.  If this is
     // the case, curl will try IPv4 first and if that fails, then it will
     // fall back to IPv6 and the error EHOSTUNREACH is returned by the operating system.
     if ($result === FALSE && (!isset($this->curlOptions[CURLOPT_IPRESOLVE]) || empty($this->curlOptions[CURLOPT_IPRESOLVE]))) {
         $matches = [];
         if (preg_match('/Failed to connect to ([^:].*): Network is unreachable/', curl_error($ch), $matches)) {
             if (strlen(@inet_pton($matches[1])) === 16) {
                 Debugger::log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.', 'oauth');
                 $this->curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
                 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
                 $result = curl_exec($ch);
             }
         }
     }
     $info = $this->getRequestInfo($ch, $request, $result);
     if (isset($info['request_header'])) {
         $request->setHeaders($info['request_header']);
     }
     $response = new Response($request, substr($result, $info['header_size']), $info['http_code'], end($info['headers']), $info);
     if (!$response->isOk()) {
         $e = $response->toException();
         curl_close($ch);
         $this->onError($e, $response);
         throw $e;
     }
     $this->onSuccess($response);
     curl_close($ch);
     return $this->memoryCache[$cacheKey] = $response;
 }
Пример #8
0
 public function sendOrder(Order $order)
 {
     $request = $this->createRequest($order);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->getUrl());
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     $headers = [];
     foreach ($request->getHeaders() as $name => $lines) {
         $headers[$name] = $request->getHeaderLine($name);
     }
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, (string) $request->getBody());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if (class_exists('Kdyby\\CurlCaBundle\\CertificateHelper')) {
         curl_setopt($ch, CURLOPT_CAINFO, \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile());
     }
     $result = curl_exec($ch);
     if ($result === false) {
         throw new IOException('Unable to establish connection to ZboziKonverze service: curl error (' . curl_errno($ch) . ') - ' . curl_error($ch));
     }
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     if ($httpCode !== 200) {
         $data = json_decode($result, true);
         if ($data && !empty($data['statusMessage'])) {
             throw new IOException('Request was not accepted HTTP ' . $httpCode . ': ' . $data['statusMessage']);
         }
         throw new IOException('Request was not accepted (HTTP ' . $httpCode . ')');
     }
 }
Пример #9
0
 /**
  * Makes an HTTP request. This method can be overridden by subclasses if
  * developers want to do fancier things or use something other than curl to
  * make the request.
  *
  * @param string $url The URL to make the request to
  * @param array $params The parameters to use for the POST body
  * @param resource $ch Initialized curl handle
  *
  * @throws Facebook\FacebookApiException
  * @return string The response text
  */
 protected function makeRequest($url, array $params, $ch = NULL)
 {
     if (isset($this->cache[$cacheKey = md5(serialize(array($url, $params)))])) {
         return $this->cache[$cacheKey];
     }
     $url = new UrlScript($url);
     $method = strtoupper(isset($params['method']) ? $params['method'] : 'GET');
     $this->onRequest((string) $url, $params);
     $ch = $ch ?: curl_init();
     $opts = $this->curlOptions;
     if ($this->fb->config->graphVersion !== '' && $this->fb->config->graphVersion !== 'v1.0') {
         // v2.0 or later
         unset($params['method']);
         if ($method === 'GET') {
             $url->appendQuery($params);
             $params = array();
         }
         if ($method === 'DELETE' || $method === 'PUT') {
             $opts[CURLOPT_CUSTOMREQUEST] = $method;
         }
         if ($method !== 'GET') {
             $opts[CURLOPT_POSTFIELDS] = $params;
         }
         $opts[CURLOPT_HTTPHEADER][] = 'Accept-Encoding: *';
     } else {
         // BC
         $opts[CURLOPT_POSTFIELDS] = $this->fb->config->fileUploadSupport ? $params : http_build_query($params, NULL, '&');
         // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
         // for 2 seconds if the server does not support this header.
         $opts[CURLOPT_HTTPHEADER][] = 'Expect:';
     }
     $opts[CURLOPT_URL] = (string) $url;
     // execute request
     curl_setopt_array($ch, $opts);
     $result = curl_exec($ch);
     // provide certificate if needed
     if (curl_errno($ch) == CURLE_SSL_CACERT || curl_errno($ch) === CURLE_SSL_CACERT_BADFILE) {
         Debugger::log('Invalid or no certificate authority found, using bundled information', 'facebook');
         $this->curlOptions[CURLOPT_CAINFO] = CertificateHelper::getCaInfoFile();
         curl_setopt($ch, CURLOPT_CAINFO, CertificateHelper::getCaInfoFile());
         $result = curl_exec($ch);
     }
     // With dual stacked DNS responses, it's possible for a server to
     // have IPv6 enabled but not have IPv6 connectivity.  If this is
     // the case, curl will try IPv4 first and if that fails, then it will
     // fall back to IPv6 and the error EHOSTUNREACH is returned by the
     // operating system.
     if ($result === FALSE && empty($opts[CURLOPT_IPRESOLVE])) {
         $matches = array();
         if (preg_match('/Failed to connect to ([^:].*): Network is unreachable/', curl_error($ch), $matches)) {
             if (strlen(@inet_pton($matches[1])) === 16) {
                 Debugger::log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.', 'facebook');
                 $this->curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
                 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
                 $result = curl_exec($ch);
             }
         }
     }
     $info = curl_getinfo($ch);
     if (isset($info['request_header'])) {
         list($info['request_header']) = self::parseHeaders($info['request_header']);
     }
     $info['method'] = $method;
     if ($result === FALSE) {
         $e = new Facebook\FacebookApiException(array('error_code' => curl_errno($ch), 'error' => array('message' => curl_error($ch), 'type' => 'CurlException')));
         curl_close($ch);
         $this->onError($e, $info);
         throw $e;
     }
     if (!$result && isset($info['redirect_url'])) {
         $result = Json::encode(array('url' => $info['redirect_url']));
     }
     $info['headers'] = self::parseHeaders(substr($result, 0, $info['header_size']));
     $result = trim(substr($result, $info['header_size']));
     $this->onSuccess($result, $info);
     curl_close($ch);
     return $this->cache[$cacheKey] = $result;
 }
Пример #10
0
 /**
  * Set curl certificate
  *
  * @param $curl
  * @return bool
  */
 protected function setCertificate($curl)
 {
     if (!class_exists('\\Kdyby\\CurlCaBundle\\CertificateHelper')) {
         return false;
     }
     \Kdyby\CurlCaBundle\CertificateHelper::setCurlCaInfo($curl);
     return true;
 }
Пример #11
0
 /**
  * Withdraws btc.
  *
  * @param string $btcAmount
  * @param string $address
  * @return array Withdrawal info
  */
 public function withdrawBtc($btcAmount, $address)
 {
     $nonce = $this->getNonce();
     $params = array('key' => $this->apiKey, 'nonce' => $nonce, 'signature' => $this->getSignature($nonce), 'amount' => $btcAmount, 'address' => $address);
     $request = new Request(static::BTC_WITHDRAWAL_URL);
     $request->setTrustedCertificate(CertificateHelper::getCaInfoFile());
     $response = $request->post($params);
     return json_decode($response->getResponse(), TRUE);
 }