/** * Fetches update information from the server using cURL * @return string The raw server data */ private function fetchCURL() { $config = LiveUpdateConfig::getInstance(); $extInfo = $config->getExtensionInformation(); $url = $extInfo['updateurl']; $process = curl_init($url); $config = new LiveUpdateConfig(); $config->applyCACert($process); curl_setopt($process, CURLOPT_HEADER, 0); // Pretend we are Firefox, so that webservers play nice with us curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110105 Firefox/3.6.14'); curl_setopt($process, CURLOPT_ENCODING, 'gzip'); curl_setopt($process, CURLOPT_TIMEOUT, 10); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false); // The @ sign allows the next line to fail if open_basedir is set or if safe mode is enabled @curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); @curl_setopt($process, CURLOPT_MAXREDIRS, 20); $inidata = curl_exec($process); curl_close($process); return $inidata; }
/** * Downloads the contents of a URL and writes them to disk (if $fp is not null) * or returns them as a string (if $fp is null) * @param string $url The URL to download from * @param resource $fp The file pointer to download to. Omit to return the contents. * @return bool|string False on failure, true on success ($fp not null) or the URL contents (if $fp is null) */ private static function &getCURL($url, $fp = null, $nofollow = false) { $result = false; $ch = curl_init($url); $config = new LiveUpdateConfig(); $config->applyCACert($ch); if (!@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1) && !$nofollow) { // Safe Mode is enabled. We have to fetch the headers and // parse any redirections present in there. curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Get the headers $data = curl_exec($ch); curl_close($ch); // Init $newURL = $url; // Parse the headers $lines = explode("\n", $data); foreach ($lines as $line) { if (substr($line, 0, 9) == "Location:") { $newURL = trim(substr($line, 9)); } } // Download from the new URL if ($url != $newURL) { return self::getCURL($newURL, $fp); } else { return self::getCURL($newURL, $fp, true); } } else { @curl_setopt($ch, CURLOPT_MAXREDIRS, 20); } curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Pretend we are IE7, so that webservers play nice with us curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)'); if (is_resource($fp)) { curl_setopt($ch, CURLOPT_FILE, $fp); } $result = curl_exec($ch); curl_close($ch); return $result; }