diff --git a/main/admin/index.php b/main/admin/index.php index 24a96be364..d926100f87 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -358,8 +358,9 @@ function version_check() { $return .= ''; $return .= ''; + check_system_version(); } else { - //$return = 'site registered. '; + // site not registered. Call anyway $return .= check_system_version(); } return $return; @@ -392,6 +393,7 @@ function register_site() { * The code is borrowed from phpBB and slighlty modified * @author The phpBB Group (the code) * @author Patrick Cool , Ghent University (the modifications) + * @author Yannick Warnier for the move to HTTP request * @copyright (C) 2001 The phpBB Group * @return language string with some layout (color) */ @@ -406,10 +408,23 @@ function check_system_version() { // The number of users $number_of_users = statistics::count_users(); - $version_url = 'http://version.chamilo.org/version.php?url='.urlencode(api_get_path(WEB_PATH)).'&campus='.urlencode(api_get_setting('siteName')).'&contact='.urlencode(api_get_setting('emailAdministrator')).'&version='.urlencode($system_version).'&numberofcourses='.urlencode($number_of_courses).'&numberofusers='.urlencode($number_of_users).'&donotlistcampus='.api_get_setting('donotlistcampus').'&organisation='.urlencode(api_get_setting('Institution')).'&language='.api_get_setting('platformLanguage').'&adminname='.urlencode(api_get_setting('administratorName').' '.api_get_setting('administratorSurname')); - $handle = @fopen($version_url, 'r'); - if ($handle !== false) { - $version_info = trim(@fread($handle, 1024)); + $data = array( + 'url' => api_get_path(WEB_PATH), + 'campus' => api_get_setting('siteName'), + 'contact' => api_get_setting('emailAdministrator'), + 'version' => $system_version, + 'numberofcourses' => $number_of_courses, + 'numberofusers' => $number_of_users, + 'donotlistcampus' => api_get_setting('donotlistcampus'), + 'organisation' => api_get_setting('Institution'), + 'language' => api_get_setting('platformLanguage'), + 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), + ); + + $res = http_request('version.chamilo.org', 80, '/version.php', $data); + + if ($res !== false) { + $version_info = $res; if ($system_version != $version_info) { $output = '
' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' Chamilo '.$version_info.'. '.get_lang('YourVersionIs').' Chamilo '.$system_version. '. '.str_replace('http://www.chamilo.org', 'http://www.chamilo.org', get_lang('PleaseVisitOurWebsite')).''; @@ -424,3 +439,52 @@ function check_system_version() { } return $output; } + +/** + * Function to make an HTTP request through fsockopen (specialised for GET) + * Derived from Jeremy Saintot: http://www.php.net/manual/en/function.fsockopen.php#101872 + * @param string IP or hostname + * @param int Target port + * @param string URI (defaults to '/') + * @param array GET data + * @param float Timeout + * @param bool Include HTTP Request headers? + * @param bool Include HTTP Response headers? + */ +function http_request($ip, $port = 80, $uri = '/', $getdata = array(), $timeout = 1, $req_hdr = false, $res_hdr = false) { + $verb = 'GET'; + $ret = ''; + $getdata_str = count($getdata) ? '?' : ''; + + foreach ($getdata as $k => $v) { + $getdata_str .= urlencode($k) .'='. urlencode($v) . '&'; + } + + $crlf = "\r\n"; + $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; + $req .= 'Host: '. $ip . $crlf; + $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf; + $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; + $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; + $req .= 'Accept-Encoding: deflate' . $crlf; + $req .= 'Accept-Charset: utf-8;q=0.7,*;q=0.7' . $crlf; + + $req .= $crlf; + + if ($req_hdr) { $ret .= $req; } + if (($fp = @fsockopen($ip, $port, $errno, $errstr, $timeout)) == false) { + return "Error $errno: $errstr\n"; + } + + stream_set_timeout($fp, $timeout); + $r = @fwrite($fp, $req); + $line = @fread($fp,512); + $ret .= $line; + fclose($fp); + + if (!$res_hdr) { + $ret = substr($ret, strpos($ret, "\r\n\r\n") + 4); + } + + return trim($ret); +}