public static function handleContext(array $context) { if (strlen($GLOBALS['cfg']['ProxyUrl']) > 0) { $context['http'] = array('proxy' => $GLOBALS['cfg']['ProxyUrl'], 'request_fulluri' => true); if (strlen($GLOBALS['cfg']['ProxyUser']) > 0) { $auth = base64_encode($GLOBALS['cfg']['ProxyUser'] . ':' . $GLOBALS['cfg']['ProxyPass']); $context['http']['header'] .= 'Proxy-Authorization: Basic ' . $auth . "\r\n"; } } return $context; }
/** * 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 = 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 = 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); } } } /* Parse response */ $data = json_decode($response); /* Basic sanity checking */ if (!is_object($data) || empty($data->version) || empty($data->releases) || empty($data->date)) { 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; }