getTransportMethod() public static method

Returns the "best" available transport method for {@link sendHttpRequest()} calls.
public static getTransportMethod ( ) : string | null
return string | null Either curl, fopen, socket or null if no method is supported.
 public function sendSMS($apiKey, $smsText, $phoneNumber, $from)
 {
     $account = explode(" ", $apiKey);
     $parameters = array('user' => $account[0], 'pass' => $account[1], 'msg' => $smsText);
     $url = self::API_URL . '?' . http_build_query($parameters, '', '&');
     $timeout = self::SOCKET_TIMEOUT;
     $result = Http::sendHttpRequestBy(Http::getTransportMethod(), $url, $timeout, $getExtendedInfo = true);
 }
 public function execute()
 {
     $label = $this->translator->translate('Installation_SystemCheckOpenURL');
     $httpMethod = Http::getTransportMethod();
     if ($httpMethod) {
         return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, $httpMethod));
     }
     $canAutoUpdate = Filechecks::canAutoUpdate();
     $comment = $this->translator->translate('Installation_SystemCheckOpenURLHelp');
     if (!$canAutoUpdate) {
         $comment .= '<br/>' . $this->translator->translate('Installation_SystemCheckAutoUpdateHelp');
     }
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
 }
Example #3
0
 /**
  * Downloads data from the given URL via a POST request. If a destination path is given, the downloaded data
  * will be stored in the given path and returned otherwise.
  *
  * Make sure to call {@link authenticate()} to download paid plugins.
  *
  * @param string $url An absolute URL to the marketplace including domain.
  * @param null|string $destinationPath
  * @param null|int $timeout  Defaults to 60 seconds see {@link self::HTTP_REQUEST_METHOD}
  * @return bool|string  Returns the downloaded data or true if a destination path was given.
  * @throws \Exception
  */
 public function download($url, $destinationPath = null, $timeout = null)
 {
     $method = Http::getTransportMethod();
     if (!isset($timeout)) {
         $timeout = static::HTTP_REQUEST_TIMEOUT;
     }
     $post = null;
     if ($this->accessToken) {
         $post = array('access_token' => $this->accessToken);
     }
     $file = Http::ensureDestinationDirectoryExists($destinationPath);
     $response = Http::sendHttpRequestBy($method, $url, $timeout, $userAgent = null, $destinationPath, $file, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'POST', $httpUsername = null, $httpPassword = null, $post);
     return $response;
 }
Example #4
0
 private function issueApiCall($apiKey, $resource, $additionalParameters = array())
 {
     $accountParameters = array('Key' => $apiKey);
     $parameters = array_merge($accountParameters, $additionalParameters);
     $url = self::BASE_API_URL . $resource . '?' . http_build_query($parameters, '', '&');
     $timeout = self::SOCKET_TIMEOUT;
     try {
         $result = Http::sendHttpRequestBy(Http::getTransportMethod(), $url, $timeout, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = true);
     } catch (Exception $e) {
         $result = self::ERROR_STRING . " " . $e->getMessage();
     }
     if (strpos($result, self::ERROR_STRING) !== false) {
         throw new APIException('Clockwork API returned the following error message : ' . $result);
     }
     return $result;
 }
Example #5
0
 public static function isUpdatingOverHttps()
 {
     $openSslEnabled = extension_loaded('openssl');
     $usingMethodSupportingHttps = Http::getTransportMethod() !== 'socket';
     return $openSslEnabled && $usingMethodSupportingHttps;
 }
Example #6
0
 /**
  * Get system information
  */
 public static function getSystemInformation()
 {
     global $piwik_minimumPHPVersion;
     $minimumMemoryLimit = Config::getInstance()->General['minimum_memory_limit'];
     $infos = array();
     $directoriesToCheck = array('/tmp/', '/tmp/assets/', '/tmp/cache/', '/tmp/climulti/', '/tmp/latest/', '/tmp/logs/', '/tmp/sessions/', '/tmp/tcpdf/', '/tmp/templates_c/');
     if (!DbHelper::isInstalled()) {
         // at install, need /config to be writable (so we can create config.ini.php)
         $directoriesToCheck[] = '/config/';
     }
     $infos['directories'] = Filechecks::checkDirectoriesWritable($directoriesToCheck);
     $infos['can_auto_update'] = Filechecks::canAutoUpdate();
     self::initServerFilesForSecurity();
     $infos['phpVersion_minimum'] = $piwik_minimumPHPVersion;
     $infos['phpVersion'] = PHP_VERSION;
     $infos['phpVersion_ok'] = self::isPhpVersionValid($infos['phpVersion']);
     // critical errors
     $extensions = @get_loaded_extensions();
     $needed_extensions = array('zlib', 'SPL', 'iconv', 'json', 'mbstring');
     // HHVM provides the required subset of Reflection but lists Reflections as missing
     if (!defined('HHVM_VERSION')) {
         $needed_extensions[] = 'Reflection';
     }
     $infos['needed_extensions'] = $needed_extensions;
     $infos['missing_extensions'] = array();
     foreach ($needed_extensions as $needed_extension) {
         if (!in_array($needed_extension, $extensions)) {
             $infos['missing_extensions'][] = $needed_extension;
         }
     }
     // Special case for mbstring
     if (!function_exists('mb_get_info') || (int) ini_get('mbstring.func_overload') != 0) {
         $infos['missing_extensions'][] = 'mbstring';
     }
     $infos['pdo_ok'] = false;
     if (in_array('PDO', $extensions)) {
         $infos['pdo_ok'] = true;
     }
     $infos['adapters'] = Adapter::getAdapters();
     $needed_functions = array('debug_backtrace', 'create_function', 'eval', 'gzcompress', 'gzuncompress', 'pack');
     $infos['needed_functions'] = $needed_functions;
     $infos['missing_functions'] = array();
     foreach ($needed_functions as $needed_function) {
         if (!self::functionExists($needed_function)) {
             $infos['missing_functions'][] = $needed_function;
         }
     }
     // warnings
     $desired_extensions = array('json', 'libxml', 'dom', 'SimpleXML');
     $infos['desired_extensions'] = $desired_extensions;
     $infos['missing_desired_extensions'] = array();
     foreach ($desired_extensions as $desired_extension) {
         if (!in_array($desired_extension, $extensions)) {
             $infos['missing_desired_extensions'][] = $desired_extension;
         }
     }
     $desired_functions = array('set_time_limit', 'mail', 'parse_ini_file', 'glob', 'gzopen');
     $infos['missing_desired_functions'] = array();
     foreach ($desired_functions as $desired_function) {
         if (!self::functionExists($desired_function)) {
             $infos['missing_desired_functions'][] = $desired_function;
         }
     }
     $sessionAutoStarted = (int) ini_get('session.auto_start');
     if ($sessionAutoStarted) {
         $infos['missing_desired_functions'][] = 'session.auto_start';
     }
     $desired_settings = array('session.auto_start');
     $infos['desired_functions'] = array_merge($desired_functions, $desired_settings);
     $infos['openurl'] = Http::getTransportMethod();
     $infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
     $serverSoftware = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
     $infos['serverVersion'] = addslashes($serverSoftware);
     $infos['serverOs'] = @php_uname();
     $infos['serverTime'] = date('H:i:s');
     $infos['memoryMinimum'] = $minimumMemoryLimit;
     $infos['memory_ok'] = true;
     $infos['memoryCurrent'] = '';
     $raised = SettingsServer::raiseMemoryLimitIfNecessary();
     if (($memoryValue = SettingsServer::getMemoryLimitValue()) > 0) {
         $infos['memoryCurrent'] = $memoryValue . 'M';
         $infos['memory_ok'] = $memoryValue >= $minimumMemoryLimit;
     }
     $infos['isWindows'] = SettingsServer::isWindows();
     $integrityInfo = Filechecks::getFileIntegrityInformation();
     $infos['integrity'] = $integrityInfo[0];
     $infos['integrityErrorMessages'] = array();
     if (isset($integrityInfo[1])) {
         if ($infos['integrity'] == false) {
             $infos['integrityErrorMessages'][] = Piwik::translate('General_FileIntegrityWarningExplanation');
         }
         $infos['integrityErrorMessages'] = array_merge($infos['integrityErrorMessages'], array_slice($integrityInfo, 1));
     }
     $infos['timezone'] = SettingsServer::isTimezoneSupportEnabled();
     $process = new CliMulti();
     $infos['cli_process_ok'] = $process->supportsAsync();
     $infos['tracker_status'] = Common::getRequestVar('trackerStatus', 0, 'int');
     // check if filesystem is NFS, if it is file based sessions won't work properly
     $infos['is_nfs'] = Filesystem::checkIfFileSystemIsNFS();
     $infos = self::enrichSystemChecks($infos);
     return $infos;
 }
Example #7
0
 /**
  * @group Core
  * 
  * @dataProvider getMethodsToTest
  */
 public function testFetchRemoteFile($method)
 {
     $this->assertNotNull(Http::getTransportMethod());
     $version = Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 30);
     $this->assertTrue((bool) preg_match('/^([0-9.]+)$/', $version));
 }
Example #8
0
 /**
  * @dataProvider getMethodsToTest
  */
 public function testFetchRemoteFile($method)
 {
     $this->assertNotNull(Http::getTransportMethod());
     $result = Http::sendHttpRequestBy($method, Fixture::getRootUrl() . 'piwik.js', 30);
     $this->assertTrue(strpos($result, 'Piwik') !== false);
 }
 /**
  * Get system information
  */
 public static function getSystemInformation()
 {
     global $piwik_minimumPHPVersion;
     $minimumMemoryLimit = Config::getInstance()->General['minimum_memory_limit'];
     $infos = array();
     $infos['general_infos'] = array();
     $directoriesToCheck = array();
     if (!DbHelper::isInstalled()) {
         // at install, need /config to be writable (so we can create config.ini.php)
         $directoriesToCheck[] = '/config/';
     }
     $directoriesToCheck = array_merge($directoriesToCheck, array('/tmp/', '/tmp/assets/', '/tmp/cache/', '/tmp/latest/', '/tmp/logs/', '/tmp/sessions/', '/tmp/tcpdf/', '/tmp/templates_c/'));
     $infos['directories'] = Filechecks::checkDirectoriesWritable($directoriesToCheck);
     $infos['can_auto_update'] = Filechecks::canAutoUpdate();
     self::initServerFilesForSecurity();
     $infos['phpVersion_minimum'] = $piwik_minimumPHPVersion;
     $infos['phpVersion'] = PHP_VERSION;
     $infos['phpVersion_ok'] = version_compare($piwik_minimumPHPVersion, $infos['phpVersion']) === -1;
     // critical errors
     $extensions = @get_loaded_extensions();
     $needed_extensions = array('zlib', 'SPL', 'iconv', 'Reflection');
     $infos['needed_extensions'] = $needed_extensions;
     $infos['missing_extensions'] = array();
     foreach ($needed_extensions as $needed_extension) {
         if (!in_array($needed_extension, $extensions)) {
             $infos['missing_extensions'][] = $needed_extension;
         }
     }
     $infos['pdo_ok'] = false;
     if (in_array('PDO', $extensions)) {
         $infos['pdo_ok'] = true;
     }
     $infos['adapters'] = Adapter::getAdapters();
     $needed_functions = array('debug_backtrace', 'create_function', 'eval', 'gzcompress', 'gzuncompress', 'pack');
     $infos['needed_functions'] = $needed_functions;
     $infos['missing_functions'] = array();
     foreach ($needed_functions as $needed_function) {
         if (!self::functionExists($needed_function)) {
             $infos['missing_functions'][] = $needed_function;
         }
     }
     // warnings
     $desired_extensions = array('json', 'libxml', 'dom', 'SimpleXML');
     $infos['desired_extensions'] = $desired_extensions;
     $infos['missing_desired_extensions'] = array();
     foreach ($desired_extensions as $desired_extension) {
         if (!in_array($desired_extension, $extensions)) {
             $infos['missing_desired_extensions'][] = $desired_extension;
         }
     }
     $desired_functions = array('set_time_limit', 'mail', 'parse_ini_file', 'glob');
     $infos['desired_functions'] = $desired_functions;
     $infos['missing_desired_functions'] = array();
     foreach ($desired_functions as $desired_function) {
         if (!self::functionExists($desired_function)) {
             $infos['missing_desired_functions'][] = $desired_function;
         }
     }
     $infos['openurl'] = Http::getTransportMethod();
     $infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
     $infos['hasMbstring'] = false;
     $infos['multibyte_ok'] = true;
     if (function_exists('mb_internal_encoding')) {
         $infos['hasMbstring'] = true;
         if ((int) ini_get('mbstring.func_overload') != 0) {
             $infos['multibyte_ok'] = false;
         }
     }
     $serverSoftware = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
     $infos['serverVersion'] = addslashes($serverSoftware);
     $infos['serverOs'] = @php_uname();
     $infos['serverTime'] = date('H:i:s');
     $infos['registerGlobals_ok'] = ini_get('register_globals') == 0;
     $infos['memoryMinimum'] = $minimumMemoryLimit;
     $infos['memory_ok'] = true;
     $infos['memoryCurrent'] = '';
     $raised = SettingsServer::raiseMemoryLimitIfNecessary();
     if (($memoryValue = SettingsServer::getMemoryLimitValue()) > 0) {
         $infos['memoryCurrent'] = $memoryValue . 'M';
         $infos['memory_ok'] = $memoryValue >= $minimumMemoryLimit;
     }
     $infos['isWindows'] = SettingsServer::isWindows();
     $integrityInfo = Filechecks::getFileIntegrityInformation();
     $infos['integrity'] = $integrityInfo[0];
     $infos['integrityErrorMessages'] = array();
     if (isset($integrityInfo[1])) {
         if ($infos['integrity'] == false) {
             $infos['integrityErrorMessages'][] = Piwik::translate('General_FileIntegrityWarningExplanation');
         }
         $infos['integrityErrorMessages'] = array_merge($infos['integrityErrorMessages'], array_slice($integrityInfo, 1));
     }
     $infos['timezone'] = SettingsServer::isTimezoneSupportEnabled();
     $infos['tracker_status'] = Common::getRequestVar('trackerStatus', 0, 'int');
     $infos['protocol'] = ProxyHeaders::getProtocolInformation();
     if (!\Piwik\ProxyHttp::isHttps() && $infos['protocol'] !== null) {
         $infos['general_infos']['assume_secure_protocol'] = '1';
     }
     if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
         $infos['general_infos']['proxy_client_headers'] = $headers;
     }
     if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
         $infos['general_infos']['proxy_host_headers'] = $headers;
     }
     // check if filesystem is NFS, if it is file based sessions won't work properly
     $infos['is_nfs'] = Filesystem::checkIfFileSystemIsNFS();
     $infos = self::enrichSystemChecks($infos);
     return $infos;
 }