1<html>
2<head>
3<title>Eclipse Download Click Through</title>
4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5<link rel="stylesheet" href="https://download.eclipse/eclipse/default_style.css" type="text/css">
6<?php
7
8include("buildproperties.php");
9
10function computeMirrorKey ($refurl, $buildid) {
11  $dropsuffix="";
12  $edpos=strpos($refurl,"/eclipse/downloads/");
13  if ($edpos !== false) {
14    $bidpos=strrpos($refurl,$buildid);
15    if ($bidpos !== false) {
16      //echo "edpos: $edpos\n";
17      //echo "bidpos: $bidpos\n";
18      // sanity check
19      if ($bidpos > $edpos) {
20        $dropsuffix=substr($refurl,$edpos,($bidpos - $edpos -1));
21      }
22    }
23  }
24  return $dropsuffix;
25}
26
27
28if (array_key_exists("SERVER_NAME", $_SERVER)) {
29  $servername = $_SERVER["SERVER_NAME"];
30  if ($servername === "build.eclipse.org") {
31    // leave relative
32    $dlprefix="";
33  } else {
34    // if not on build.elcipse.org, assume we are on downloads.
35    // we "compute" based on matching /eclipse/downloads/*/$BUILD_ID  in the request URI.
36    // we want the /eclipse/downloads/* part, such as
37    // /eclipse/downloads/drops4, or
38    // /eclipse/downloads/drops, or
39    // function can return empty string
40    $refurl=$_SERVER["REQUEST_URI"];
41    // We expect $BUILD_ID to be defined in buildproperties.php
42    // But it can be defined several times in reference URI, such as once in directory name,
43    // and once in filename. We want the directory-like part.
44    // And to complicate things, in S and R builds, the segment is no longer BUILD_ID,
45    // but a more complicated concatination. And M builds even more complicated, since
46    // there are two types, some are "RCs", and some not.
47
48    $pos = strpos($BUILD_ID, "RC");
49    if ($pos === false) {
50      $isRC = false;
51    } else {
52      $isRC = true;
53    }
54
55    if ($BUILD_TYPE === "N" || $BUILD_TYPE === "I" || $BUILD_TYPE === "P" || $BUILD_TYPE === "U" || $BUILD_TYPE === "X" || $BUILD_TYPE === "Y" || ($BUILD_TYPE === "M" && ! $isRC)) {
56      $BUILD_DIR_NAME = $BUILD_ID;
57    } else {
58      if ($BUILD_TYPE === "R" || $BUILD_TYPE === "S" || $BUILD_TYPE === "P" || $BUILD_TYPE === "U" || $BUILD_TYPE === "X" || $BUILD_TYPE === "Y" || ($BUILD_TYPE === "M" && $isRC)) {
59        $timestamp = str_replace('-', '', $TIMESTAMP);
60        $BUILD_DIR_NAME = $BUILD_TYPE."-".$BUILD_ID."-".$timestamp;
61      } else {
62        echo "Unexpected value of BUILD_TYPE: $BUILD_TYPE. <br />";
63        // We'll make an assumption that might work.
64        $BUILD_DIR_NAME = $BUILD_ID;
65      }
66    }
67    $dlprefix=computeMirrorKey($refurl,$BUILD_DIR_NAME."/");
68  }
69}
70else {
71  // not sure what to put here (we are essentially not running on a host?)
72  // we _might_ need to assume "downloads" here, for "convert to html to work?"
73  // or, on build machine?
74  $servername=localhost;
75}
76
77$script = $_SERVER['SCRIPT_NAME'];
78$patharray = pathinfo($_SERVER['SCRIPT_NAME']);
79$path = $patharray['dirname'];
80$buildLabel = array_pop(split("/",$path,-1));
81// this script should nearly always have a query string,
82// but we check, to avoid warning when testing
83if (array_key_exists("QUERY_STRING", $_SERVER)) {
84  $qstring = $_SERVER['QUERY_STRING'];
85  $dropFile=array_pop(split("=",$qstring,-1));
86}
87
88
89$mirror=true;
90if (strstr($servername,"eclipse.org")) {
91  $mirror=false;
92  $eclipselink="https://www.eclipse.org/downloads/download.php?file="."$dlprefix/$buildLabel/$dropFile";
93} else {
94  $mirrorlink  = "https://$servername$path/$dropFile";
95}
96
97$clickFile = "clickThroughs/";
98$clickFileName = str_replace("-$BUILD_ID","",$dropFile);
99$clickFile = $clickFile.$clickFileName.".txt";
100
101if (file_exists($clickFile)) {
102  $fileHandle = fopen($clickFile, "r");
103  while (!feof($fileHandle)) {
104    $aLine = fgets($fileHandle, 4096);
105    $result = $result.$aLine;
106  }
107  fclose($fileHandle);
108} else {
109  if ($mirror) {
110    echo '<META HTTP-EQUIV="Refresh" CONTENT="0;URL='.$dropFile.'">';
111    echo '<b><font size "+4">Downloading: '.$mirrorlink.'</font></b>';
112  } else {
113    echo '<META HTTP-EQUIV="Refresh" CONTENT="0;URL='.$eclipselink.'">';
114    echo '<b><font size "+4">Downloading: '.$eclipselink.'</font></b>';
115  }
116  echo '<BR>';
117  echo '<BR>';
118  if ($mirror) {
119    echo 'If your download does not begin automatically click <a href='.$dropFile.'>here</a>.';
120  } else {
121    echo 'If your download does not begin automatically click <a href='.$eclipselink.'>here</a>.';
122  }
123}
124?>
125</head>
126
127<body bgcolor="#FFFFFF" text="#000000">
128<?php
129if (file_exists($clickFile)) {
130  echo '<p><b><font size="+4">Important Notes<BR>';
131  echo '</font></b></font></p>
132    <p>It is very important to read the following notes in order to run this version
133    of Eclipse. Once you have read the notes you can click on the Download link
134    to download the drop.</p>
135    ';
136  echo '<textarea name="textfield" cols="80" rows="18" wrap="PHYSICAL">'.$result;
137  echo '</textarea>';
138  echo '<BR>';
139  echo '<BR>';
140
141  if ($mirror) {
142    echo '<a href="'.$dropFile.'">Download</a>';
143  } else {
144    echo '<a href="'.$eclipselink.'">Download</a>';
145  }
146
147  echo "<!-- dropFile: $dropFile -->";
148  echo "<!-- eclipselink: $eclipselink -->";
149}
150?>
151</body>
152</html>
153