Commit c65b0571 authored by Antoine Cellerier's avatar Antoine Cellerier

Preparse the include/mirrors during make (might help reduce the load when we release).

parent 330862ab
......@@ -28,7 +28,7 @@ ifneq ($(PHP_IGNORES),)
PHP_FILES := $(filter-out $(PHP_IGNORES:%=%.php), $(PHP_FILES))
endif
TARGETS := $(PHP_FILES:%.php=%.html)
TARGETS := $(PHP_FILES:%.php=%.html) $(ROOT)/include/mirrors.php
real-all: $(TARGETS) all-recursive
......@@ -41,7 +41,7 @@ clean: clean-recursive
HERE=$(HERE)$$d/ || exit $$? ; \
done
%.html: %.php $(ROOT)Makefile $(ROOT)/include/*.php $(ROOT)/include/*.php $(ROOT)/include/mirrors $(ROOT)/include/menu/*
%.html: %.php $(ROOT)Makefile $(ROOT)/include/*.php $(ROOT)/include/*.php $(ROOT)/include/mirrors.php $(ROOT)/include/menu/*
@echo "Preprocessing $@ ..."
@rm -f $@.tmp
@cd $(ROOT) || exit 1 ; \
......@@ -53,6 +53,9 @@ clean: clean-recursive
@$(STRIP_HEADERS) < $@.tmp > $@
@rm -f $@.tmp
$(ROOT)/include/mirrors.php: $(ROOT)/include/mirrors
@echo "Processing $< ..."
awk -F '|' 'BEGIN { print "/* This file is automatically generated from the mirrors file. Do not edit */\nmirrors = {" } !/^#/{print " { \""$$1"\", \""$$2"\", \""$$3"\", \""$$4"\", \""$$5"\", "$$6" },"} END { print "};" }' $< > $<.php
.PHONY: clean all
......@@ -5,14 +5,15 @@
<!--
<?php
$mirror = $_GET["mirror"];
$mirror_url = $_GET["mirror"];
$file = $_GET["file"];
if( !isset( $file ) ) { die; }
if( !isset( $mirror ) )
if( !isset( $mirror_url ) )
{
require $_SERVER["DOCUMENT_ROOT"]."/include/continents.php";
require $_SERVER["DOCUMENT_ROOT"]."/include/mirrors.php";
$code = apache_note("GEOIP_COUNTRY_CODE");
$name = apache_note("GEOIP_COUNTRY_NAME");
......@@ -20,13 +21,6 @@ if( !isset( $mirror ) )
$continent = $continents[$code];
echo "Your continent is: $continent\n";
$listfile = $_SERVER["DOCUMENT_ROOT"]."/include/mirrors";
$fp = fopen( $listfile, "r" );
$all = fread( $fp, filesize( $listfile ) );
fclose( $fp );
$mirrors = explode( "\n", $all );
array_pop( $mirrors );
/* Country */
$cbw = 0; /* Available bandwidth in country */
$ccount = 0; /* Number of mirrors in country */
......@@ -41,10 +35,8 @@ if( !isset( $mirror ) )
foreach( $mirrors as $mirror )
{
if( substr( $mirror, 0, 1 ) == "#" ) continue;
$ex=explode("|",$mirror);
$country_short = $ex[3];
$bw = $ex[5];
$country_short = $mirror[3];
$bw = $mirror[5];
$COUNTRY_SHORT = strtoupper( $country_short );
if( $COUNTRY_SHORT == $code )
{
......@@ -76,14 +68,11 @@ if( !isset( $mirror ) )
foreach( $mirrors as $mirror )
{
if( substr( $mirror, 0, 1 ) == "#" ) continue;
$ex=explode("|",$mirror);
$mirror_url = $ex[0];
$mirror_name = $ex[1];
$country = $ex[2];
$country_short = $ex[3];
$bw = $ex[5];
$mirror_url = $mirror[0];
$mirror_name = $mirror[1];
$country = $mirror[2];
$country_short = $mirror[3];
$bw = $mirror[5];
$COUNTRY_SHORT = strtoupper( $country_short );
/* Get the current mirror's probability of being choosen */
......
<?php
require '/home/videolan/etc/db.php';
$mirror = $_GET["mirror"];
$mirror_url = $_GET["mirror"];
$file = $_GET["file"];
if( !isset($file) ) { die; }
$listfile = $_SERVER["DOCUMENT_ROOT"]."/include/mirrors";
$file_id = fopen( $listfile, "r" );
$all = fread ( $file_id, filesize( $listfile ) );
fclose ( $file_id );
$mirrors = explode ( "\n", $all );
require $_SERVER["DOCUMENT_ROOT"]."/include/mirrors";
if ( isset($mirror) )
if( isset($mirror_url) )
{
$len = sizeof( $mirrors );
for ( $i = 0; $i < $len; $i++ ) {
$url = explode ( "|", $mirrors[$i] );
if( $mirror === $url[0] ) $found = true;
foreach( $mirrors as $mirror )
{
if( $mirror_url === $mirror[0] )
{
$found = true; break;
}
}
!$found && die;
}
else
# Pick up a random mirror
{
array_pop( $mirrors );
while( !isset( $mirror ) )
{
$index = rand( 0, sizeof( $mirrors ) - 1 );
if( substr( $mirrors[ $index] , 0, 1 ) == "#" ) continue;
$esp = strpos( $mirrors[ $index] , "|" );
$mirror = substr( $mirrors[ $index ], 0, $esp );
}
$mirror = $mirrors[$index];
$mirror_url = $mirror[0];
}
$mirror_name = $mirror[1];
$country = $mirror[2];
?>
<html>
<head>
<title>VideoLAN - Download from mirror</title>
<meta http-equiv="refresh" content="0; url=<?php echo $mirror.$file ?>" />
<meta http-equiv="refresh" content="0; url=<?php echo $url.$file ?>" />
</head>
<body>
<p>Click <a href="<?php echo $mirror.$file ?>">here</a> if your download doesn't start</p>
<p>If you want to put a direct download link on your website, please use <?php echo "http://www.videolan.org/mirror.php?file=$file.<br />Please don't use a direct link. This script allows us to distribute the network load across our mirrors. Thanks."; ?> </p>
<p>Downloading from <?php echo $mirror_name; ?>, <?php echo $country; ?>. Click <a href="<?php echo $url.$file ?>">here</a> if your download doesn't start. Refresh the page to download from another mirror.</p>
<p>If you want to put a direct download link on your website, please use <?php echo "http://www.videolan.org/mirror.php?file=$file"; ?>.<br />Please don't use a direct link. This script allows us to distribute the network load across our mirrors. Thanks."; </p>
</body>
</html>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment