| <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include("_projectCommon.php"); # All on the same line to unclutter the user's desktop' |
| /******************************************************************************* |
| * Copyright (c) 2006-2010 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Denis Roy (Eclipse Foundation) - initial API and implementation |
| *******************************************************************************/ |
| |
| |
| #***************************************************************************** |
| # |
| # download.php |
| # |
| # Author: Denis Roy |
| # Date: 2004-11-23 |
| # |
| # Description: Logic for finding mirror sites that have a specific file |
| # |
| # HISTORY: 2005-03-19: moved to new infra |
| # HISTORY: 2005-04-07: stopped probing external sites |
| # HISTORY: 2005-08-13: rewrote selects to use UNIONs instead of temp tables |
| # HISTORY: 2005-08-23: added format=plain functionality |
| # HISTORY: 2006-01-16: added countryCode functionality |
| # HISTORY: 2006-01-25: added GeoIP functionality |
| # HISTORY: 2006-01-25: added file_id functionality (1.13) |
| # HISTORY: 2006-03-17: added no_mirror and $exclude_string functionality to match RSYNC stanza (1.21) |
| # HISTORY: 2006-10-03: added functionality for looking at archive.eclipse.org |
| # HISTORY: 2006-12-19: removed file index lookups on slave, as slave lags are bad |
| # HISTORY: 2007-02-12: added code to self-clean the download logs |
| # HISTORY: 2007-02-12: added holding tables for download logs |
| # HISTORY: 2008-03-25: added functionality to return a 404 |
| # HISTORY: 2009-04-25: added bittorrent functionality |
| # HISTORY: 2009-05-26: better sorting of mirrors after my country, my continent |
| # HISTORY: 2010-01-13: implement last_known_sync/ztime (bug 291039) |
| # HISTORY: 2010-01-13: implement caching of file timestamps (bug 299504) |
| # HISTORY: 2010-06-14: Checksums (316820) |
| # HISTORY: 2010-09-10: No mirrors for local subnets (324983) |
| # HISTORY: 2012-04-05: Throttle IP addresses which frequently abuse site (no referer + multiple accesses per minute = cooldown) |
| # HISTORY: 2012-04-17: Provide privileged download access for comitters with their username and password (376732) |
| # |
| #***************************************************************************** |
| |
| |
| |
| # |
| # Begin: page-specific settings. Change these. |
| $pageTitle = "Eclipse downloads - mirror selection"; |
| $pageKeywords = ""; |
| $pageAuthor = "Denis Roy"; |
| header("Cache-control: no-cache"); |
| |
| |
| # End: page-specific settings |
| # |
| |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php"; |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection.class.php"; |
| require_once("classes/mirror.class.php"); |
| |
| # Initiate session |
| $Session = $App->useSession("optional"); |
| $Friend = $Session->getFriend(); |
| |
| $archiveBasePath = "/home/data2/httpd/archive.eclipse.org"; |
| $archiveBaseURL = "http://archive.eclipse.org"; |
| |
| $_format = $App->getHTTPParameter("format"); |
| $_debug = $App->getHTTPParameter("debug"); |
| $_protocol = $App->getHTTPParameter("protocol"); |
| $_file = $App->getHTTPParameter("file"); |
| $_file_id = $App->getHTTPParameter("file_id"); # Committers-only fast download |
| |
| # don't display mirrors, just redirect |
| $_redirect = $App->getHTTPParameter("r"); |
| |
| # if the file is invalid, return a 404 instead of a lovely page |
| $_send_404 = $App->getHTTPParameter("nf"); |
| |
| # Identify that the file cannot (or must not) use mirrors. |
| # This is for files that are in the exclude list |
| $no_mirror = false; |
| |
| # to downloads |
| $_mirror_id = $App->getHTTPParameter("mirror_id"); |
| if($_mirror_id != "" && !preg_match('/^[0-9]+/', $_mirror_id)) { |
| $_mirror_id = 1; |
| $no_mirror = true; |
| } |
| $_url = ""; |
| |
| if($_debug == 1) { |
| echo "Mirror id: " . $_mirror_id . "<br />"; |
| } |
| |
| |
| # extended functionality |
| $_country_code = $App->getHTTPParameter("countryCode"); |
| $_time_zone = $App->getHTTPParameter("timeZone"); |
| |
| # set country_code to bogus if none specified |
| if ($_country_code == "") { |
| $_country_code = "xx"; |
| } |
| |
| $Mirror = new Mirror(); |
| $ip_ccode = $Mirror->selectCountryCodeByIP($_SERVER['REMOTE_ADDR']); |
| if($_debug == 1) { |
| echo "Country given: " . $_country_code . " IP Geolocation: " . $ip_ccode . "<br />"; |
| } |
| |
| if($ip_ccode != "") { |
| # We got a country code from the IP. Use it instead. |
| $_country_code = $ip_ccode; |
| } |
| $_country_code = substr($_country_code, 0, 2); |
| |
| # project and file index information for logging and statistics |
| $file_id = 0; |
| $project_id = ""; |
| $torrentname= ""; |
| |
| |
| # Throttle the percentage of downloads we accept for update manager redirects |
| $our_download_percentage = 5; |
| |
| define('MAX_DOWNLOADS_PER_MINUTE', 5); |
| |
| # delay between a mirror's timestamp and the actual file |
| # h * m * s |
| # $mirror_delay = 6 * 60 * 60; |
| |
| # space-separated list of files for which we bypass looking up mirrors altogether. |
| # This should match the exclude = parameter in the rsyncd.conf file and the Apache download.conf |
| $exclude_string = "*.nfs* apitools/ apidocs/ archive/ archives/ /athena builds/N* */doc/* */documentation/* drops*/I* drops*/N* drops/M* *.jpg *.gif callisto/* compilelogs/ eclipse.org-common/ eclipse/testUpdates* eclipse/updates/3.2milestones /eclipse/updates/3.6-I-builds/ dev/TPTP* /tools/cdt/builds modeling/gmf/downloads/drops/B* *drops*/*/N* *drops*/*/I* *javadoc/ *javadocs/ linuxtools/N* *nightly* *Nightly* *staging* /webtools/downloads/drops/*/M* performance/ /releases/maintenance /releases/staging /releases/europa testresults/ /rt/eclipselink/nightly* /technology/cosmos /technology/ohf /technology/tigerstripe testcompilelogs/ testResults/ /tools/downloads /tools/orbit/committers */N201* */I201* */I.I201* */I-* */N-* *integration*/ xref/ */M20* /rt/eclipselink/maven.repo* */scripts* */logs*"; |
| //$exclude_string = str_replace("*", "", $exclude_string); |
| $exclude_array = explode(" ", $exclude_string); |
| |
| # Log download stats, and to which table. log_download_table will be suffixed with a number later |
| $log_download = !$App->getDBReadOnly(); |
| $log_download_table = "downloads"; |
| |
| # Clean up download records older than this number of days |
| $download_log_max_age = 365; |
| |
| # Do a reverse lookup on the client IP - for internal mirror matching and logging |
| $client_hostname = @gethostbyaddr($_SERVER['REMOTE_ADDR']) ; |
| |
| # Get preferred mirror (if any) |
| $MIR_PREF = ""; # $_COOKIE['MIR_PREF']; |
| |
| $error = ""; |
| $mtime = 0; |
| |
| # make sure some incoming params are sane |
| if($_format != "html" && $_format != "xml" && $_format != "plain") { |
| $_format = "html"; |
| } |
| if($_protocol != "http" && $_protocol != "ftp" && $_protocol != "rsync" && $_protocol != "bittorrent") { |
| $_protocol = ""; |
| } |
| # strip potentially bad characters from file |
| $_file = str_replace("\%", "", $_file); |
| $_file = str_replace("../", "", $_file); |
| $_file = str_replace("'", "", $_file); |
| |
| |
| # Bypass the entire SQL statement if the file is in the excluded list |
| for($i = 0; $i < count($exclude_array); $i++) { |
| # replace leading and ending * |
| $exclude_array[$i] = preg_replace('(^\*|\*$)', "", $exclude_array[$i]); |
| $exclude_array[$i] = str_replace("*", ".*", $exclude_array[$i]); |
| if($_debug == 1) { |
| echo "Checking $_file for " . $exclude_array[$i] . "<br />"; |
| } |
| //if(strpos($_file, $exclude_array[$i]) > 0) { |
| if(preg_match("#" . $exclude_array[$i] . "#", $_file)) { |
| # File is in the exclude list. Can't use mirrors, so why not redirect to the actual file? |
| # 2008-09-25: What about Friends? |
| $no_mirror = true; |
| # $_redirect = 1; |
| break; |
| } |
| } |
| |
| # Don't send a mirror list if the request comes from within our network |
| if(substr($_SERVER['REMOTE_ADDR'], 0, 11) == "206.191.52." |
| || substr($_SERVER['REMOTE_ADDR'], 0, 11) == "209.217.126." |
| || !$Mirror->isValidPublicIP($_SERVER['REMOTE_ADDR'])) { |
| $no_mirror = true; |
| if($_debug == 1) { |
| echo "Coming from " . $_SERVER['REMOTE_ADDR'] . "; client should use home site.<br />"; |
| } |
| } |
| |
| # Connect to databases |
| # dbc is a read-only database (good for slave servers) |
| $dbc = new DBConnection(); |
| $dbh = $dbc->connect(); |
| |
| # this is for logging the request |
| $dbc_RW = new DBConnectionRW(); |
| $dbh_RW = $dbc_RW->connect(); |
| |
| $app = new App(); |
| |
| # Process an incoming request for a committers-only download |
| if(isset($_file_id)) { |
| if($_file_id > 0) { |
| if($Friend->getIsCommitter()) { |
| $sql = "SELECT file_name FROM download_file_index WHERE file_id = " . $app->sqlSanitize($_file_id); |
| $rs = mysql_query($sql, $dbh); |
| if($myrow = mysql_fetch_assoc($rs)) { |
| $file_name = $app->getDownloadBasePath() . $myrow['file_name']; |
| |
| if(file_exists($file_name)) { |
| logDownload($_file_id, 4); |
| header('Content-Description: File Transfer'); |
| header('Content-Type: application/octet-stream'); |
| header('Content-Disposition: attachment; filename=' . basename($file_name)); |
| header('Content-Transfer-Encoding: binary'); |
| header('Expires: 0'); |
| header('Cache-Control: must-revalidate'); |
| header('Pragma: public'); |
| header('Content-Length: ' . filesize($file_name)); |
| ob_clean(); |
| flush(); |
| readfile($file_name); |
| exit; |
| } |
| } |
| } |
| else { |
| header("HTTP/1.0 403 Forbidden"); |
| echo "<html><head><title>403 Forbidden</title></head><body><h1>403 Forbidden</h1><p>Sorry, this type of request is for Eclipse committers only. Please <a href='" . $Session->getLoginPageURL() . "'>log in</a> if you are a committer and wish to download this file.</p></body></html>"; |
| exit; |
| } |
| } |
| } |
| |
| # find lowest drop location for this file |
| # file could be in Release, which is in Full, which is in EclipseFull, |
| # so we want to find all the possible mirrors |
| $filetime = 0; |
| $filetime_update = false; |
| $filename_fileonly = ""; # filename portion only |
| if($_file != "") { |
| # locate file on download.eclipse.org to ensure it's valid |
| |
| $filename = $app->getDownloadBasePath() . $_file; |
| $filename_fileonly = substr($_file, strrpos($_file, "/") + 1); # filename portion only |
| |
| |
| # find lowest drop and get basic project/file info |
| # I originally tried to lump the GeoIP ccode lookup here to save a connection, |
| # but the query ended up taking 11 seconds |
| |
| # 2008-07-31: broke down the SQL in two different queries |
| # using left joins for the download_file_index took .55 sec, two queries uses < .15 sec |
| |
| # q1: get file info from slave |
| $sql = "SELECT IDX.file_id, IDX.timestamp_disk, IF(IDX.md5sum = '0', '', IDX.md5sum) AS md5sum, IF(IDX.sha1sum = '0', '', IDX.sha1sum) AS sha1sum FROM download_file_index AS IDX WHERE IDX.file_name = '$_file'"; |
| if($_debug == 1) { |
| echo $sql . "<br />"; |
| } |
| # Get the file_id from the slave, but if the file_id is 0, then re-check the master just in case |
| $rs = mysql_query($sql, $dbh); |
| |
| if($myrow = mysql_fetch_assoc($rs)) { |
| $file_id = $myrow['file_id']; |
| $filetime = $myrow['timestamp_disk']; |
| $md5sum = $myrow['md5sum']; |
| $sha1sum = $myrow['sha1sum']; |
| } |
| # If this is a new file, check the master DB in case the slave is simply lagged |
| if($file_id == 0 || $file_id == "") { |
| if($_debug == 1) { |
| echo "This is a new file. Checking the Master DB.<br />"; |
| } |
| $rs = mysql_query($sql, $dbh_RW); |
| if($myrow = mysql_fetch_assoc($rs)) { |
| $file_id = $myrow['file_id']; |
| $filetime = $myrow['timestamp_disk']; |
| $md5sum = $myrow['md5sum']; |
| $sha1sum = $myrow['sha1sum']; |
| } |
| |
| # Still no file_id? Then this is the first time this file is seen (bug 379376) |
| if($file_id == 0 || $file_id == "") { |
| $file_id = &addFileToIndex($_file); |
| } |
| } |
| # No file time in the index. Check the filesystem |
| if($filetime == 0) { |
| if($_debug == 1) { |
| echo "Checking filesystem for $filename time.<br />"; |
| } |
| if(@fopen($filename, "r")) { |
| $filetime = @filemtime($filename); |
| } |
| |
| if(!$filetime || $filetime == 0) { |
| # unable to open file |
| $dbc_RW->disconnect(); |
| |
| # check on archive.eclipse.org |
| $filename = $archiveBasePath . $_file; |
| if(@fopen($filename, "r")) { |
| $filetime = @filemtime($filename); |
| } |
| |
| if(!$filetime || $filetime == 0) { |
| # File isn't on download nor on archive. |
| $error = 1; |
| if($_format == "xml") { |
| $app->sendXMLHeader(); |
| include("content/en_mir_list_xml.php"); |
| } |
| else { |
| if($_send_404) { |
| header("HTTP/1.0 404 Not Found"); |
| echo "<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1></body></html>"; |
| } |
| else { |
| include("content/en_mir_download_invalid_file.php"); |
| } |
| } |
| return false; |
| } |
| else { |
| if($Friend->getIsCommitter() || $Friend->getIsBenefit()) { |
| $file_name = preg_replace("/download\.eclipse\.org/", "archive.eclipse.org", $app->getDownloadBasePath() . $_file); |
| if(file_exists($file_name)) { |
| logDownload($file_id, 4); |
| header('Content-Description: File Transfer'); |
| header('Content-Type: application/octet-stream'); |
| header('Content-Disposition: attachment; filename=' . basename($file_name)); |
| header('Content-Transfer-Encoding: binary'); |
| header('Expires: 0'); |
| header('Cache-Control: must-revalidate'); |
| header('Pragma: public'); |
| header('Content-Length: ' . filesize($file_name)); |
| ob_clean(); |
| flush(); |
| readfile($file_name); |
| exit; |
| } |
| exit; |
| } |
| else { |
| header("Location: " . $archiveBaseURL . $_file); |
| exit; |
| } |
| } |
| } |
| else { |
| $filetime_update = true; |
| } |
| } |
| |
| # q2: get drop info |
| $sql = "SELECT DRP.drop_id, VAR.key_value, TOR.torrentname |
| FROM drops AS DRP |
| LEFT JOIN SYS_variables AS VAR ON VAR.key_name = 'download_table' |
| LEFT JOIN torrents_index AS TOR ON (TOR.torrentname LIKE '%${filename_fileonly}.torrent') |
| WHERE LEFT('$_file', LENGTH(DRP.our_path)) = DRP.our_path |
| AND LOCATE(DRP.file_pattern, '$_file') > 0 |
| ORDER BY LENGTH(DRP.our_path) DESC LIMIT 1"; |
| # Get the file_id from the slave, but if the file_id is 0, then re-check the master just in case |
| $rs = mysql_query($sql, $dbh); |
| |
| if($myrow = mysql_fetch_assoc($rs)) { |
| $_drop_id = $myrow['drop_id']; |
| $key_value = $myrow['key_value']; |
| $torrentname= $myrow['torrentname']; |
| } |
| if($_debug == 1) { |
| echo "Project SQL: ". $sql . "<br /><br />"; |
| } |
| $log_download_table .= $key_value; |
| |
| } |
| if($_debug == 1) { |
| echo "File ID: " . $file_id . "<br />"; |
| echo "Log download table: " . $log_download_table . "<br />"; |
| } |
| |
| # Build where string |
| if($_drop_id == "") { |
| $_drop_id = "EclipseFull"; |
| } |
| |
| $fullDropSQL = ""; |
| $eclipseFullDropSQL = ""; |
| |
| # First select: get mirrors at the lowest drop |
| $where = " MRD.drop_id = '$_drop_id'"; |
| $having = "((MIR.is_internal <> 1 AND last_known_sync > " . $filetime . ") |
| OR LOCATE(MIR.internal_host_pattern, '" . $client_hostname . "') > 1)"; |
| |
| |
| if($_protocol != "") { |
| $where .= " AND MRP.protocol = '$_protocol'"; |
| } |
| if($_mirror_id > 0) { |
| $where .= " AND MIR.mirror_id = '$_mirror_id'"; |
| } |
| $lowestDropSQL = "SELECT |
| IF(LOCATE(MIR.internal_host_pattern, '" . $client_hostname . "') > 1, 1, 0) AS SuggestInternal, |
| IF(MRP.protocol = 'http' AND COU.ccode = '$_country_code', RAND() + 1, IF(COU.ccode = '$_country_code', RAND(), 0)) AS SameCountry, |
| IF(MRP.protocol = 'http' AND COU.continent_code = MYCOU.continent_code, RAND() + 1, IF(COU.continent_code = MYCOU.continent_code, RAND(), 0)) AS SameContinent, |
| MIR.mirror_id, |
| MIR.organization, |
| MIR.ccode, |
| MIR.is_internal, |
| MIR.internal_host_pattern, |
| MRD.drop_id, |
| DRP.our_path, |
| DRP.file_pattern, |
| MRP.protocol, |
| MRP.base_path, |
| MRD.rel_path_override, |
| MRD.timestamp, |
| IF(MRD.timestamp > MRD.timestamp_end, IF(MRD.timestamp_last_complete > 0, MRD.timestamp_last_complete, IF(MRD.timestamp_end > 0, MRD.timestamp_end, 0)), MRD.timestamp) AS last_known_sync, |
| DRW.our_path AS our_path2, |
| COU.en_description AS country_desc, |
| CON.en_description AS continent_desc, |
| CON.sort_order |
| FROM mirrors AS MIR |
| INNER JOIN mirror_protocols AS MRP on MRP.mirror_id = MIR.mirror_id |
| INNER JOIN mirror_drops AS MRD ON MRD.mirror_id = MIR.mirror_id |
| AND MRD.protocol = MRP.protocol |
| INNER JOIN drops as DRP ON DRP.drop_id = '$_drop_id' |
| INNER JOIN drops as DRW ON DRW.drop_id = '$_drop_id' |
| INNER JOIN SYS_countries AS COU ON COU.ccode = MIR.ccode |
| INNER JOIN SYS_continents AS CON ON CON.continent_code = COU.continent_code |
| LEFT JOIN SYS_countries AS MYCOU ON MYCOU.ccode = '$_country_code' |
| WHERE |
| MIR.is_advertise = 1 |
| AND MIR.create_status = 'active' |
| AND $where |
| HAVING " . $having; |
| |
| |
| |
| # Second select: get mirrors in Full if ... |
| if($_drop_id == "Update" || $_drop_id == "Stable" || $_drop_id == "Release") { |
| $where = " MRD.drop_id = 'Full'"; |
| if($_protocol != "") { |
| $where .= " AND MRP.protocol = '$_protocol'"; |
| } |
| if($_mirror_id > 0) { |
| $where .= " AND MIR.mirror_id = '$_mirror_id'"; |
| } |
| $fullDropSQL = " |
| SELECT |
| IF(LOCATE(MIR.internal_host_pattern, '" . $client_hostname . "') > 1, 1, 0) AS SuggestInternal, |
| IF(MRP.protocol = 'http' AND COU.ccode = '$_country_code', RAND() + 1, IF(COU.ccode = '$_country_code', RAND(), 0)) AS SameCountry, |
| IF(MRP.protocol = 'http' AND COU.continent_code = MYCOU.continent_code, RAND() + 1, IF(COU.continent_code = MYCOU.continent_code, RAND(), 0)) AS SameContinent, |
| MIR.mirror_id, |
| MIR.organization, |
| MIR.ccode, |
| MIR.is_internal, |
| MIR.internal_host_pattern, |
| MRD.drop_id, |
| DRP.our_path, |
| DRP.file_pattern, |
| MRP.protocol, |
| MRP.base_path, |
| MRD.rel_path_override, |
| MRD.timestamp, |
| IF(MRD.timestamp > MRD.timestamp_end, IF(MRD.timestamp_last_complete > 0, MRD.timestamp_last_complete, IF(MRD.timestamp_end > 0, MRD.timestamp_end, 0)), MRD.timestamp) AS last_known_sync, |
| DRW.our_path AS our_path2, |
| COU.en_description AS country_desc, |
| CON.en_description AS continent_desc, |
| CON.sort_order |
| FROM mirrors AS MIR |
| INNER JOIN mirror_protocols AS MRP on MRP.mirror_id = MIR.mirror_id |
| INNER JOIN mirror_drops AS MRD ON MRD.mirror_id = MIR.mirror_id |
| AND MRD.protocol = MRP.protocol |
| INNER JOIN drops as DRP ON DRP.drop_id = 'Full' |
| INNER JOIN drops as DRW ON DRW.drop_id = '$_drop_id' |
| INNER JOIN SYS_countries AS COU ON COU.ccode = MIR.ccode |
| INNER JOIN SYS_continents AS CON ON CON.continent_code = COU.continent_code |
| LEFT JOIN SYS_countries AS MYCOU ON MYCOU.ccode = '$_country_code' |
| WHERE |
| MIR.is_advertise = 1 |
| AND MIR.create_status = 'active' |
| AND $where |
| HAVING " . $having; |
| } |
| |
| |
| # Add EclipseFull |
| if($_drop_id != "EclipseFull") { |
| $where = " MRD.drop_id = 'EclipseFull'"; |
| if($_protocol != "") { |
| $where .= " AND MRP.protocol = '$_protocol'"; |
| } |
| if($_mirror_id > 0) { |
| $where .= " AND MIR.mirror_id = '$_mirror_id'"; |
| } |
| $eclipseFullDropSQL = " |
| SELECT |
| IF(LOCATE(MIR.internal_host_pattern, '" . $client_hostname . "') > 1, 1, 0) AS SuggestInternal, |
| IF(MRP.protocol = 'http' AND COU.ccode = '$_country_code', RAND() + 1, IF(COU.ccode = '$_country_code', RAND(), 0)) AS SameCountry, |
| IF(MRP.protocol = 'http' AND COU.continent_code = MYCOU.continent_code, RAND() + 1, IF(COU.continent_code = MYCOU.continent_code, RAND(), 0)) AS SameContinent, |
| MIR.mirror_id, |
| MIR.organization, |
| MIR.ccode, |
| MIR.is_internal, |
| MIR.internal_host_pattern, |
| MRD.drop_id, |
| DRP.our_path, |
| DRP.file_pattern, |
| MRP.protocol, |
| MRP.base_path, |
| MRD.rel_path_override, |
| MRD.timestamp, |
| IF(MRD.timestamp > MRD.timestamp_end, IF(MRD.timestamp_last_complete > 0, MRD.timestamp_last_complete, IF(MRD.timestamp_end > 0, MRD.timestamp_end, 0)), MRD.timestamp) AS last_known_sync, |
| DRW.our_path AS our_path2, |
| COU.en_description AS country_desc, |
| CON.en_description AS continent_desc, |
| CON.sort_order |
| FROM mirrors AS MIR |
| INNER JOIN mirror_protocols AS MRP on MRP.mirror_id = MIR.mirror_id |
| INNER JOIN mirror_drops AS MRD ON MRD.mirror_id = MIR.mirror_id |
| AND MRD.protocol = MRP.protocol |
| INNER JOIN drops as DRP ON DRP.drop_id = 'EclipseFull' |
| INNER JOIN drops as DRW ON DRW.drop_id = '$_drop_id' |
| INNER JOIN SYS_countries AS COU ON COU.ccode = MIR.ccode |
| INNER JOIN SYS_continents AS CON ON CON.continent_code = COU.continent_code |
| LEFT JOIN SYS_countries AS MYCOU ON MYCOU.ccode = '$_country_code' |
| WHERE |
| MIR.is_advertise = 1 |
| AND MIR.create_status = 'active' |
| AND $where |
| HAVING " . $having; |
| } |
| |
| |
| $orderby = "is_internal DESC, |
| SuggestInternal DESC, |
| SameCountry DESC, |
| SameContinent DESC, |
| sort_order DESC, |
| continent_desc ASC, |
| RAND()"; |
| |
| if($_redirect == 1) { |
| $orderby .= " LIMIT 1"; |
| } |
| |
| $mirrorListSQL = $lowestDropSQL; |
| |
| if(strlen($fullDropSQL) > 0) { |
| $mirrorListSQL .= " UNION " . $fullDropSQL; |
| } |
| if(strlen($eclipseFullDropSQL) > 0) { |
| $mirrorListSQL .= " UNION " . $eclipseFullDropSQL; |
| } |
| |
| $mirrorListSQL .= " ORDER BY " . $orderby; |
| |
| # Bypass the whole mirror SQL if we can't pick a mirror for this file |
| $rs; |
| if(!$no_mirror && $_mirror_id != 1) { |
| $rs = mysql_query($mirrorListSQL, $dbh); |
| $myrow = mysql_fetch_assoc($rs); |
| $_url = $myrow['base_path']. getPath($myrow['drop_id'], $_drop_id, $myrow['rel_path_override'], $myrow['our_path'], $myrow['our_path2']); |
| if($_redirect == 1) { |
| $_mirror_id = $myrow['mirror_id']; |
| } |
| } |
| else { |
| $_url = $app->getPubDownloadServerUrl() . $_file; |
| } |
| |
| if($_debug == 1) { |
| echo $mirrorListSQL . "<br /><br />"; |
| } |
| |
| |
| if($_redirect == 1) { |
| # fetch row & build URL |
| # Higher weight = more to our server. Set weight above ($our_download_percentage) |
| $random = rand(1, 100); |
| |
| # download from eclipse.org |
| if($random <= $our_download_percentage || $no_mirror || mysql_num_rows($rs) == 0) { |
| $_mirror_id = 1; |
| $_url = $app->getPubDownloadServerUrl() . $_file; |
| } |
| |
| if($_debug == 1) { |
| echo "Redirect: $_url <br /><br />"; |
| } |
| |
| } |
| if($_debug == 1) { |
| echo "Pre phase-II<br /> URL: $_url <br />File: $_file:<br />Mirror: $_mirror"; |
| } |
| |
| |
| # Phase 2 - a user picked a mirror for his file (or redirect) |
| if($_file != "" && $_mirror_id > 0 && $_url != "") { |
| |
| $ip = $_SERVER["REMOTE_ADDR"]; |
| $cnt = 0; # recent downloads |
| |
| # Throttle the amount of downloads we count (and redirect to) to prevent ballot stuffers |
| $sql = "SELECT file_id, COUNT(1) AS cnt FROM $log_download_table WHERE remote_addr = '$ip' AND download_date > DATE_SUB(NOW(), INTERVAL 1 MINUTE) GROUP BY file_id, remote_addr HAVING cnt > " . MAX_DOWNLOADS_PER_MINUTE; |
| $rs = mysql_query($sql, $dbh); |
| if($myrow = mysql_fetch_assoc($rs)) { |
| include("content/en_too_many_downloads.php"); |
| } |
| else { |
| if($_redirect == 1) { |
| # Blindly send user off to a mirror site |
| header("Location: " . $_url); |
| $is_success = 2; |
| } |
| else { |
| $is_success = 2; |
| |
| # Redirect user to the file instead of an HTML/meta redirect |
| # Bug 134634 |
| # include("content/en_mir_download_success.php"); |
| if(!isset($_COOKIE['thankyou_page']['donation']) || !isset($_COOKIE['thankyou_page']['newsletter'])){ |
| //if((rand(1,100) <= 50) && (!isset($_COOKIE['thankyou_page']['donation']))){ |
| include("content/en_mir_download_success.php"); |
| }else{ |
| header("Location: " . $_url); |
| } |
| } |
| |
| |
| if ($log_download) { |
| # We couldn't find a file_id up there, so insert the actual file here |
| if($file_id == "") { |
| $file_id = &addFileToIndex($_file); |
| } |
| |
| $sql = "INSERT DELAYED INTO $log_download_table (file_id, download_date, remote_host, remote_addr, mirror_id, ccode) |
| VALUES ( $file_id, NOW(), '$client_hostname', '$ip', $_mirror_id, '$_country_code') "; |
| mysql_query($sql, $dbh_RW); |
| |
| $string = ""; |
| if($filetime_update) { |
| $string = ", timestamp_disk = $filetime"; |
| } |
| $sql = "UPDATE LOW_PRIORITY download_file_index SET download_count = download_count + 1 " . $string . " WHERE file_id = " . $file_id; |
| mysql_query($sql, $dbh_RW); |
| |
| # do some cleanup |
| # This was moved to a nightly job since the holding table has been in place |
| |
| /* it only takes a fraction of a second to delete old rows very, very often |
| * it takes many seconds to delete many rows less often |
| * so running a nightly cleanup takes minutes (locking tables) whereas this, |
| * although seemingly inefficient, takes no time at all |
| * |
| * we do run a rand() so that we don't necessarily clean up on every hit |
| * |
| */ |
| |
| #if(rand(0, 100) < 1) { |
| # # 1 of every 100 hits (1%) will clean up |
| # $sql = "DELETE FROM downloads WHERE download_date < DATE_SUB(NOW(), INTERVAL $download_log_max_age DAY)"; |
| # mysql_query($sql, $dbh_RW); |
| #} |
| } |
| } |
| |
| if($_debug == 1) { |
| echo $sql . mysql_error() . "<br />"; |
| } |
| |
| } |
| else { |
| if($_file != "") { |
| if($_format == "html") { |
| include("content/en_" . $App->getScriptName()); |
| # AMD promo for ESE |
| #if(substr($_SERVER['REMOTE_ADDR'],0,3) == "79.") { |
| # include("content/en_download-dev.php"); |
| #} |
| #else { |
| # include("content/en_" . $App->getScriptName()); |
| #} |
| |
| # Generate the web page |
| $App->generatePage("Nova", $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html); |
| } |
| if($_format == "plain") { |
| include("content/en_mir_list_plain.php"); |
| } |
| if($_format == "xml") { |
| $app->sendXMLHeader(); |
| include("content/en_mir_list_xml.php"); |
| } |
| } |
| else { |
| if($_format == "html") { |
| if($_send_404) { |
| header("HTTP/1.0 404 Not Found"); |
| echo "<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1></body></html>"; |
| } |
| else { |
| include("content/en_mir_download_invalid_file.php"); |
| } |
| } |
| if($_format == "xml") { |
| $app->sendXMLHeader(); |
| include("content/en_mir_list_xml.php"); |
| } |
| } |
| } |
| |
| |
| |
| $dbc_RW->disconnect(); # disconnects all pending DB connections |
| $rs = null; |
| $dbh_RW = null; |
| $dbc_RW = null; |
| $dbh = null; |
| $dbc = null; |
| |
| |
| |
| |
| |
| function getPath($_cur_drop_id, $_drop_id, $_rel_path_override, $_our_path, $_our_path2) { |
| global $_file; |
| global $app; |
| global $_debug; |
| |
| $path = ""; |
| if($_cur_drop_id == $_drop_id) { |
| if($_rel_path_override != "") { |
| $path = $_rel_path_override; |
| } |
| else { |
| $path = $_our_path; |
| } |
| } |
| else { |
| if($_rel_path_override != "") { |
| # Build path |
| $our_path2 = $app->str_replace_count($_our_path, $_rel_path_override, $_our_path2, 1); |
| |
| $path = $our_path2; |
| } |
| else { |
| $path = $_our_path2; |
| } |
| } |
| |
| if($_file != "") { |
| # remove path from file, and append to path |
| $_file_tmp = $app->str_replace_count($_our_path2, "", $_file, 1); |
| $path .= $_file_tmp; |
| |
| } |
| |
| $path = str_replace("//", "/", $path); |
| |
| if($_debug == 1) { |
| echo "FINAL PATH: $path<br><br>"; |
| } |
| |
| return $path; |
| } |
| |
| /** |
| * |
| * @param $filename - file name portion (relative to http://download.eclipse.org) to inspect |
| * @param $trainname - optional name of train to limit search to |
| * @return string - name of package (jee|java|cpp|modeling|reporting|rcp|php|pulsar|sdk) or the empty string |
| * @author Denis Roy |
| * @example getPackageFromFilename("/technology/epp/downloads/release/galileo/R/eclipse-rcp-galileo-R-win32.zip", "galileo") |
| * @since June 2009 |
| * @ |
| */ |
| function getPackageFromFilename($filename, $trainname=".*") { |
| $rValue = ""; |
| |
| $packageList = "automotive|jee|java|cpp|modeling|reporting|rcp|scout|testing|soa|javascript|parallel"; |
| |
| # /technology/epp/downloads/release/galileo/R/eclipse-rcp-galileo-RC4-win32.zip |
| # /eclipse/downloads/drops/R-3.4-200806172000/eclipse-SDK-3.4-solaris-gtk.zip |
| |
| if(preg_match(",^/technology/epp/downloads/release/($trainname)/SR1/eclipse-($packageList)-($trainname),", $filename, $matches)) { |
| $rValue = $matches[2]; |
| } |
| elseif(preg_match(",^/eclipse/downloads/drops4/R-4.2.1-201209141800/eclipse-SDK-,", $filename)) { |
| $rValue = "sdk"; |
| } |
| return $rValue; |
| } |
| |
| function getOSFromFilename($filename) { |
| $rValue = ""; |
| |
| $osList = "win32|macosx-cocoa|linux-gtk-x86_64|linux-gtk.tar"; |
| |
| # /technology/epp/downloads/release/galileo/R/eclipse-rcp-galileo-RC4-win32.zip |
| # /eclipse/downloads/drops/R-3.4-200806172000/eclipse-SDK-3.4-solaris-gtk.zip |
| |
| if(preg_match(",($osList),", $filename, $matches)) { |
| $rValue = $matches[1]; |
| } |
| |
| switch($rValue) { |
| case "linux-gtk-x86_64": $rValue = "LINUX64"; break; |
| case "linux-gtk.tar": $rValue = "LINUX32"; break; |
| case "macosx-cocoa-x86_64": $rValue = "MACCOCOA64"; break; |
| case "macosx-cocoa": $rValue = "MACCOCOA"; break; |
| } |
| |
| return $rValue; |
| } |
| |
| function logDownload($in_file_id, $in_mirror_id) { |
| |
| global $dbh_RW, $log_download_table, $client_hostname, $_country_code, $_debug; |
| |
| $ip = $_SERVER['REMOTE_ADDR']; |
| |
| if ($in_file_id != "") { |
| $sql = "INSERT DELAYED INTO $log_download_table (file_id, download_date, remote_host, remote_addr, mirror_id, ccode) |
| VALUES ( $in_file_id, NOW(), '$client_hostname', '$ip', $in_mirror_id, '$_country_code') "; |
| if($_debug == 1) { |
| echo $sql . "<br />"; |
| } |
| mysql_query($sql, $dbh_RW); |
| |
| $sql = "UPDATE LOW_PRIORITY download_file_index SET download_count = download_count + 1 WHERE file_id = " . $in_file_id; |
| mysql_query($sql, $dbh_RW); |
| } |
| } |
| |
| function addFileToIndex($in_file) { |
| global $app, $dbh_RW, $filetime, $_debug; |
| |
| # Add this file to the file index |
| if($in_file != "") { |
| $sql = "INSERT INTO download_file_index (file_id, file_name, download_count, timestamp_disk) |
| VALUES (NULL, '" . $app->sqlSanitize($in_file, $dbc_RW) . "', 0, $filetime)"; |
| $rs = mysql_query($sql, $dbh_RW); |
| return mysql_insert_id($dbh_RW); |
| } |
| else { |
| return 0; |
| } |
| } |
| |
| ?> |