Use GeoIP-based mirror selection.

pull/193/head
Michael R Sweet 16 years ago
parent 13204f395b
commit 6788efa5ce
  1. 64
      www/phplib/mirrors.php
  2. 44
      www/software.php

@ -0,0 +1,64 @@
<?php
//
// "$Id$"
//
// Mirror selection functions (depends on GeoIP PECL interface).
//
// Contents:
//
// mirror_closest() - Return the closest mirror to the current IP.
//
//
// List of download servers...
//
$MIRRORS = array(
"http://ftp.easysw.com/pub" => array("California, USA", 37.7898, -122.3942),
"http://ftp2.easysw.com/pub" => array("New Jersey, USA", 40.4619, -74.3561),
"http://ftp.funet.fi/pub/mirrors/ftp.easysw.com/pub" => array("Espoo, Finland", 60.2167, 24.6667),
"http://ftp.rz.tu-bs.de/pub/mirror/ftp.easysw.com/ftp/pub" => array("Braunschweig, Germany", 52.2667, 10.5333),
);
//
// 'mirror_closest()' - Return the closest mirror to the current IP.
//
function // O - Closest mirror
mirror_closest()
{
global $_SERVER, $MIRRORS;
// Get the current longitude for the client...
$current = geoip_record_by_name($_SERVER["REMOTE_ADDR"]);
$lon = $current["longitude"];
// Loop through the mirrors to find the closest one, currently just using
// the longitude...
$closest_mirror = "";
$closest_distance = 999;
reset($MIRRORS);
foreach ($MIRRORS as $mirror => $data)
{
$distance = abs($lon - $data[2]);
if ($distance > 180)
$distance = 360 - $distance;
if ($distance < $closest_distance)
{
$closest_mirror = $mirror;
$closest_distance = $distance;
}
}
return ($closest_mirror);
}
//
// End of "$Id$".
//
?>

@ -10,16 +10,7 @@
//
include_once "phplib/html.php";
// List of download servers...
$sitelist = array(
"ftp://ftp.easysw.com/pub" => "California, USA via FTP",
"http://ftp.easysw.com/pub" => "California, USA via HTTP",
"http://ftp.funet.fi/pub/mirrors/ftp.easysw.com/pub" => "Espoo, Finland via HTTP",
"ftp://ftp.funet.fi/pub/mirrors/ftp.easysw.com/pub" => "Espoo, Finland via FTP",
);
include_once "phplib/mirrors.php";
// Get the list of software files...
$fp = fopen("data/software.md5", "r");
@ -42,10 +33,10 @@ if (array_key_exists("SITE", $_GET))
setcookie("SITE", $site, time() + 90 * 86400, "/");
}
else if (array_key_exists("SITE", $_COOKIE) &&
array_key_exists($_COOKIE["SITE"], $sitelist))
array_key_exists($_COOKIE["SITE"], $MIRRORS))
$site = $_COOKIE["SITE"];
else
$site = "";
$site = mirror_closest();
if (array_key_exists("VERSION", $_GET))
$version = $_GET["VERSION"];
@ -86,38 +77,27 @@ if ($file != "")
{
print("<h1>Download</h1>\n");
if ($site != "")
print("<p>Your download should begin shortly. If not, please "
."<a href='$site/$file'>click here</a> to download the file "
."from the current mirror.</p>\n");
else
print("<p>Please select a mirror site below to begin the download.</p>\n");
print("<form action='$PHP_SELF' method='GET' name='download'>\n"
print("<p>Your download should begin shortly. If not, please "
."<a href='$site/$file'>click here</a> to download the file "
."from the current mirror.</p>\n"
."<form action='$PHP_SELF' method='GET' name='download'>\n"
."<input type='hidden' name='FILE' value='"
. htmlspecialchars($file, ENT_QUOTES) . "'>\n"
."<input type='hidden' name='VERSION' value='"
. htmlspecialchars($version, ENT_QUOTES) . "'>\n");
if ($site == "")
print("<input type='radio' name='SITE' value='' checked>None<br>\n");
reset($sitelist);
while (list($key, $val) = each($sitelist))
reset($MIRRORS);
while (list($key, $val) = each($MIRRORS))
{
print("<input type='radio' name='SITE' value='$key' "
."onClick='document.download.submit();'");
if ($site == $key)
print(" checked");
print(">$val<br>\n");
print(">$val[0]<br>\n");
}
if ($site != "")
print("<p><input type='submit' value='Change Mirror Site'>\n");
else
print("<p><input type='submit' value='Select Mirror Site'>\n");
print("</form>\n");
print("<p><input type='submit' value='Change Mirror Site'>\n"
."</form>\n");
}
else
{

Loading…
Cancel
Save