Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
// todo: unsure if can handle filenames that are URLs?
// handy constant to compute file size in megabytes
function fileSizeInMegs($filename) {
$onemeg=1024*1024;
$zipfilesize=filesize($filename);
$zipfilesize=round($zipfilesize/$onemeg, 0);
return $zipfilesize;
}
function fileSizeForDisplay($filename) {
$onekilo=1024;
$onemeg=$onekilo * $onekilo;
$criteria = 10 * $onemeg;
$scaleChar = "M";
if (file_exists($filename)) {
$zipfilesize=filesize($filename);
if ($zipfilesize > $criteria) {
$zipfilesize=round($zipfilesize/$onemeg, 0);
$scaleChar = "M";
}
else {
$zipfilesize=round($zipfilesize/$onekilo, 0);
$scaleChar = "K";
}
}
else {
$zipfilesize = 0;
}
$result = "(" . $zipfilesize . $scaleChar . ")";
return $result;
}
function displayFileLine($downloadprefix, $filename, $zipfilesize, $fileShortDescription) {
echo "<td align=\"right\" valign=\"top\" width=\"30%\">";
echo "<a href=\"$downloadprefix$filename\">" . $fileShortDescription . "</a>";
echo "</td><td align=\"right\" valign=\"top\" width=\"3%\">";
echo $zipfilesize;
echo "</td>";
echo "<td align=\"right\" valign=\"top\" width=\"2%\">";
echo "[<a href=\"checksum/$filename.md5\">md5</a>]";
echo "</td>";
}
function resourceExist($url, $mirrorPrefixuri, $prereqfilename, $eclipseFSpathPrefix)
{
$result = false;
$allowURLopen = ini_get('allow_url_fopen');
if ($allowURLopen && stream_last_modified($url)) {
$result = true;
}
else {
// TODO: for now, we'll do a raw check on the whole file name, since enable_url_open
// is off. better would be to check if we are on build.eclipse.org or download.eclipse.org?
$wholePath = trim($eclipseFSpathPrefix) . "/" . trim($mirrorPrefixuri) . "/" . trim($prereqfilename);
if (file_exists($wholePath)) {
$result = true;
}
}
return $result;
}
function stream_last_modified($url)
{
if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') > 0)
{
if (!($fp = @fopen($url, 'r')))
return NULL;
$meta = stream_get_meta_data($fp);
for ($j = 0; isset($meta['wrapper_data'][$j]); $j++)
{
if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified'))
{
$modtime = substr($meta['wrapper_data'][$j], 15);
break;
}
}
fclose($fp);
}
else
{
$parts = parse_url($url);
$host = $parts['host'];
$path = $parts['path'];
if (!($fp = @fsockopen($host, 80)))
return NULL;
$req = "HEAD $path HTTP/1.0\r\nUser-Agent: PHP/".phpversion()."\r\nHost: $host:80\r\nAccept: */*\r\n\r\n";
fputs($fp, $req);
while (!feof($fp))
{
$str = fgets($fp, 4096);
if (strstr(strtolower($str), 'last-modified'))
{
$modtime = substr($str, 15);
break;
}
}
fclose($fp);
}
return isset($modtime) ? strtotime($modtime) : time();
}
function isMirrored($uriToCheck) {
global $debugScript;
global $debugFunctions;
$localuri = $uriToCheck;
$debugMirrorList = false;
if ($debugScript) {
echo "uriToCheck: " . $localuri . "<br />";
}
$xmlcount = 0;
/* This method true and accurate method of parsing mirror results
* may be expensive, and would
* likely cause artificially high counts of "downloads".
* Could maybe use if somehow only checked once ever 5 minutes or something.
// turn off warnings, as sometimes HTML is returned, which causes lots of warnings
$holdLevel = error_reporting(E_ERROR);
$mirrorsxml=simplexml_load_file(rawurlencode($localuri) . urlencode("&format=xml"));
error_reporting($holdLevel);
if ($mirrorsxml) {
if ($debugFunctions) {
echo "root node: " . $mirrorsxml->getName() . "<br />";
}
if (strcmp($mirrorsxml->getName(), "mirrors") == 0) {
foreach ($mirrorsxml->children() as $mirror) {
if (strcmp($mirror->getName(),"mirror") == 0) {
$xmlcount=$xmlcount+1;
}
if ($debugMirrorList) {
print_r($mirror);
echo "<br />";
}
}
}
if ($debugFunctions) {
echo "Mirror count: " . $xmlcount . "<br />";
}
}
*/
/*
* Use simple heuristic based on pattern
* in the URI ... if it contains "/downloads/" then assume it's mirrored
*/
if (strpos($uriToCheck, "webtools/downloads/") > 0) {
$xmlcount = 1;
}
return ($xmlcount > 0);
}
// TODO: replace with Phoenix variables
function getPlatform () {
global $debugScript;
global $debugFunctions;
// getBrowser is expensive, so cache the data
static $browser;
$platform = "unknown";
if(ini_get("browscap")) {
if(!isset($browser)){
$browser = get_browser(null, true);
}
if ($browser) {
$rawPlatform = $browser['platform'];
if ($debugFunctions) {
echo "browser platfrom: " . $rawPlatform . "<br />" ;
}
if ($debugFunctions) {
$browserKeys = array_keys($browser);
foreach ($browserKeys as $key) {
echo $key . ": " . $browser[$key] . "<br />";
}
}
}
if (strpos($rawPlatform, "Win") === 0) {
$platform="windows";
} else if (strpos($rawPlatform, "Linux") === 0) {
$platform="linux";
} else if (strpos($rawPlatform, "Mac") === 0) {
$platform="mac";
}
}
return $platform;
}
function getPrereqReferenceOrName($eclipseMirrorScript, $mirrorPrefixuri, $prerequrl, $prereqfilename, $eclipseFSpathPrefix) {
// todo: we really only need "if exists" so could make a bit more efficient
// I tried "file_exists" but is didn't seem to work on my test server
// For these pre-reqs, we assume if they exist, they are mirrored. This is true
// 99% of the time.
if (resourceExist($prerequrl, $mirrorPrefixuri, $prereqfilename, $eclipseFSpathPrefix)) {
$reflink="<a href=\"" . $eclipseMirrorScript . $mirrorPrefixuri . "/" . $prereqfilename . "\">" . $prereqfilename . "</a>";
} else {
$reflink=$prereqfilename;
}
return $reflink;
}
?>