/**
  * Returns information with latest version from phpmyadmin.net
  *
  * @return object JSON decoded object with the data
  */
 public function getLatestVersion()
 {
     if (!$GLOBALS['cfg']['VersionCheck']) {
         return null;
     }
     // wait 3s at most for server response, it's enough to get information
     // from a working server
     $connection_timeout = 3;
     $response = '{}';
     // Get response text from phpmyadmin.net or from the session
     // Update cache every 6 hours
     if (isset($_SESSION['cache']['version_check']) && time() < $_SESSION['cache']['version_check']['timestamp'] + 3600 * 6) {
         $save = false;
         $response = $_SESSION['cache']['version_check']['response'];
     } else {
         $save = true;
         $file = 'https://www.phpmyadmin.net/home_page/version.json';
         if (ini_get('allow_url_fopen')) {
             $context = array('http' => array('request_fulluri' => true, 'timeout' => $connection_timeout));
             $context = PMA_Util::handleContext($context);
             if (!defined('TESTSUITE')) {
                 session_write_close();
             }
             $response = file_get_contents($file, false, stream_context_create($context));
         } else {
             if (function_exists('curl_init')) {
                 $curl_handle = curl_init($file);
                 if ($curl_handle === false) {
                     return null;
                 }
                 $curl_handle = PMA_Util::configureCurl($curl_handle);
                 curl_setopt($curl_handle, CURLOPT_HEADER, false);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($curl_handle, CURLOPT_TIMEOUT, $connection_timeout);
                 if (!defined('TESTSUITE')) {
                     session_write_close();
                 }
                 $response = curl_exec($curl_handle);
             }
         }
     }
     $data = json_decode($response);
     if (!is_object($data) || empty($data->version) || empty($data->date) || empty($data->releases)) {
         return null;
     }
     if ($save) {
         if (!isset($_SESSION) && !defined('TESTSUITE')) {
             ini_set('session.use_only_cookies', 'false');
             ini_set('session.use_cookies', 'false');
             ini_set('session.use_trans_sid', 'false');
             ini_set('session.cache_limiter', 'nocache');
             session_start();
         }
         $_SESSION['cache']['version_check'] = array('response' => $response, 'timestamp' => time());
     }
     return $data;
 }
Ejemplo n.º 2
0
/**
 * Sends report data to the error reporting server
 *
 * @param Array $report the report info to be sent
 *
 * @return String the reply of the server
 */
function PMA_sendErrorReport($report)
{
    $data_string = json_encode($report);
    if (ini_get('allow_url_fopen')) {
        $context = array("http" => array('method' => 'POST', 'content' => $data_string, 'header' => "Content-Type: multipart/form-data\r\n"));
        $context = PMA_Util::handleContext($context);
        $response = file_get_contents(SUBMISSION_URL, false, stream_context_create($context));
        return $response;
    }
    if (!function_exists('curl_init')) {
        return null;
    }
    $curl_handle = curl_init(SUBMISSION_URL);
    $curl_handle = PMA_Util::configureCurl($curl_handle);
    curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($curl_handle);
    curl_close($curl_handle);
    return $response;
}
Ejemplo n.º 3
0
 /**
  * Checks if given URL is 200 or 404, optionally returns data
  *
  * @param string  $link     the URL to check
  * @param boolean $get_body whether to retrieve body of document
  *
  * @return string|boolean test result or data
  */
 public function checkHTTP($link, $get_body = false)
 {
     if (!function_exists('curl_init')) {
         return null;
     }
     $handle = curl_init($link);
     if ($handle === false) {
         return null;
     }
     PMA_Util::configureCurl($handle);
     curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 0);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
     curl_setopt($handle, CURLOPT_TIMEOUT, 5);
     if (!defined('TESTSUITE')) {
         session_write_close();
     }
     $data = @curl_exec($handle);
     if (!defined('TESTSUITE')) {
         ini_set('session.use_only_cookies', '0');
         ini_set('session.use_cookies', '0');
         ini_set('session.use_trans_sid', '0');
         ini_set('session.cache_limiter', 'nocache');
         session_start();
     }
     if ($data === false) {
         return null;
     }
     $http_status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
     if ($http_status == 200) {
         return $get_body ? $data : true;
     }
     if ($http_status == 404) {
         return false;
     }
     return null;
 }
 /**
  * Checks if given URL is 200 or 404, optionally returns data
  *
  * @param string  $link     the URL to check
  * @param boolean $get_body whether to retrieve body of document
  *
  * @return string|boolean test result or data
  */
 function checkHTTP($link, $get_body = false)
 {
     if (!function_exists('curl_init')) {
         return null;
     }
     $ch = curl_init($link);
     PMA_Util::configureCurl($ch);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
     curl_setopt($ch, CURLOPT_TIMEOUT, 5);
     if (!defined('TESTSUITE')) {
         session_write_close();
     }
     $data = @curl_exec($ch);
     if (!defined('TESTSUITE')) {
         ini_set('session.use_only_cookies', '0');
         ini_set('session.use_cookies', '0');
         ini_set('session.use_trans_sid', '0');
         ini_set('session.cache_limiter', 'nocache');
         session_start();
     }
     if ($data === false) {
         return null;
     }
     $httpOk = 'HTTP/1.1 200 OK';
     $httpNotFound = 'HTTP/1.1 404 Not Found';
     if (substr($data, 0, strlen($httpOk)) === $httpOk) {
         return $get_body ? mb_substr($data, mb_strpos($data, "\r\n\r\n") + 4) : true;
     }
     $httpNOK = substr($data, 0, strlen($httpNotFound));
     if ($httpNOK === $httpNotFound) {
         return false;
     }
     return null;
 }