| <?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) 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 | |
| *******************************************************************************/ | |
| header("Cache-control: no-cache"); | |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection.class.php"; | |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php"; | |
| $_type = $App->getHTTPParameter("type"); | |
| $_debug = $App->getHTTPParameter("debug"); | |
| $_file = $App->getHTTPParameter("file"); | |
| if($_debug == 1) { | |
| error_reporting(E_ALL); | |
| ini_set("display_errors", true); | |
| } | |
| # make sure some incoming params are sane | |
| if($_type != "md5" && $_type != "sha1") { | |
| $_type = "sha1"; | |
| } | |
| # strip potentially bad characters from file | |
| $_file = str_replace("\%", "", $_file); | |
| $_file = str_replace("../", "", $_file); | |
| $_file = str_replace("'", "", $_file); | |
| $filename_fileonly = substr($_file, strrpos($_file, "/") + 1); # filename portion only | |
| # Connect to databases | |
| # dbc is a read-only database (good for slave servers) | |
| $dbc = new DBConnection(); | |
| $dbh = $dbc->connect(); | |
| $app = new App(); | |
| if($_file != "") { | |
| # locate file on download.eclipse.org to ensure it's valid | |
| $file_id = 0; | |
| $filetime = 0; | |
| $md5sum = 0; | |
| $sha1sum = 0; | |
| # 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(($md5sum == "" || $sha1sum == "") && $file_id > 0) { | |
| # compute immediately | |
| $md5sum = md5_file($App->getDownloadBasePath() . $_file); | |
| $sha1sum = sha1_file($App->getDownloadBasePath() . $_file); | |
| if(!$md5sum || !$sha1sum) { | |
| $md5sum = md5_file("/home/data2/httpd/archive.eclipse.org" . $_file); | |
| $sha1sum = sha1_file("/home/data2/httpd/archive.eclipse.org" . $_file); | |
| } | |
| if($md5sum && $sha1sum) { | |
| $dbc_RW = new DBConnectionRW(); | |
| $dbh_RW = $dbc_RW->connect(); | |
| $sql = "UPDATE download_file_index SET md5sum = '$md5sum', sha1sum = '$sha1sum' WHERE file_id = " . $file_id; | |
| mysql_query($sql, $dbh_RW); | |
| if($_debug == 1) { | |
| echo $sql . "<br />"; | |
| } | |
| } | |
| else { | |
| echo "Unable to retrieve or compute sums for " . $_file; | |
| } | |
| } | |
| header("Content-type: text/plain"); | |
| if($_type == "md5") { | |
| echo $md5sum . " " . $filename_fileonly; | |
| } | |
| if($_type == "sha1") { | |
| echo $sha1sum . " " . $filename_fileonly; | |
| } | |
| } | |
| $dbc->disconnect(); # disconnects all pending DB connections | |
| $rs = null; | |
| $dbh_RW = null; | |
| $dbc_RW = null; | |
| $dbh = null; | |
| $dbc = null; | |
| ?> |