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),) ...@@ -28,7 +28,7 @@ ifneq ($(PHP_IGNORES),)
PHP_FILES := $(filter-out $(PHP_IGNORES:%=%.php), $(PHP_FILES)) PHP_FILES := $(filter-out $(PHP_IGNORES:%=%.php), $(PHP_FILES))
endif endif
TARGETS := $(PHP_FILES:%.php=%.html) TARGETS := $(PHP_FILES:%.php=%.html) $(ROOT)/include/mirrors.php
real-all: $(TARGETS) all-recursive real-all: $(TARGETS) all-recursive
...@@ -41,7 +41,7 @@ clean: clean-recursive ...@@ -41,7 +41,7 @@ clean: clean-recursive
HERE=$(HERE)$$d/ || exit $$? ; \ HERE=$(HERE)$$d/ || exit $$? ; \
done 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 $@ ..." @echo "Preprocessing $@ ..."
@rm -f $@.tmp @rm -f $@.tmp
@cd $(ROOT) || exit 1 ; \ @cd $(ROOT) || exit 1 ; \
...@@ -53,6 +53,9 @@ clean: clean-recursive ...@@ -53,6 +53,9 @@ clean: clean-recursive
@$(STRIP_HEADERS) < $@.tmp > $@ @$(STRIP_HEADERS) < $@.tmp > $@
@rm -f $@.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 .PHONY: clean all
...@@ -5,14 +5,15 @@ ...@@ -5,14 +5,15 @@
<!-- <!--
<?php <?php
$mirror = $_GET["mirror"]; $mirror_url = $_GET["mirror"];
$file = $_GET["file"]; $file = $_GET["file"];
if( !isset( $file ) ) { die; } if( !isset( $file ) ) { die; }
if( !isset( $mirror ) ) if( !isset( $mirror_url ) )
{ {
require $_SERVER["DOCUMENT_ROOT"]."/include/continents.php"; require $_SERVER["DOCUMENT_ROOT"]."/include/continents.php";
require $_SERVER["DOCUMENT_ROOT"]."/include/mirrors.php";
$code = apache_note("GEOIP_COUNTRY_CODE"); $code = apache_note("GEOIP_COUNTRY_CODE");
$name = apache_note("GEOIP_COUNTRY_NAME"); $name = apache_note("GEOIP_COUNTRY_NAME");
...@@ -20,13 +21,6 @@ if( !isset( $mirror ) ) ...@@ -20,13 +21,6 @@ if( !isset( $mirror ) )
$continent = $continents[$code]; $continent = $continents[$code];
echo "Your continent is: $continent\n"; 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 */ /* Country */
$cbw = 0; /* Available bandwidth in country */ $cbw = 0; /* Available bandwidth in country */
$ccount = 0; /* Number of mirrors in country */ $ccount = 0; /* Number of mirrors in country */
...@@ -41,10 +35,8 @@ if( !isset( $mirror ) ) ...@@ -41,10 +35,8 @@ if( !isset( $mirror ) )
foreach( $mirrors as $mirror ) foreach( $mirrors as $mirror )
{ {
if( substr( $mirror, 0, 1 ) == "#" ) continue; $country_short = $mirror[3];
$ex=explode("|",$mirror); $bw = $mirror[5];
$country_short = $ex[3];
$bw = $ex[5];
$COUNTRY_SHORT = strtoupper( $country_short ); $COUNTRY_SHORT = strtoupper( $country_short );
if( $COUNTRY_SHORT == $code ) if( $COUNTRY_SHORT == $code )
{ {
...@@ -76,14 +68,11 @@ if( !isset( $mirror ) ) ...@@ -76,14 +68,11 @@ if( !isset( $mirror ) )
foreach( $mirrors as $mirror ) foreach( $mirrors as $mirror )
{ {
if( substr( $mirror, 0, 1 ) == "#" ) continue; $mirror_url = $mirror[0];
$mirror_name = $mirror[1];
$ex=explode("|",$mirror); $country = $mirror[2];
$mirror_url = $ex[0]; $country_short = $mirror[3];
$mirror_name = $ex[1]; $bw = $mirror[5];
$country = $ex[2];
$country_short = $ex[3];
$bw = $ex[5];
$COUNTRY_SHORT = strtoupper( $country_short ); $COUNTRY_SHORT = strtoupper( $country_short );
/* Get the current mirror's probability of being choosen */ /* Get the current mirror's probability of being choosen */
......
<?php <?php
require '/home/videolan/etc/db.php'; require '/home/videolan/etc/db.php';
$mirror = $_GET["mirror"]; $mirror_url = $_GET["mirror"];
$file = $_GET["file"]; $file = $_GET["file"];
if( !isset($file) ) { die; } if( !isset($file) ) { die; }
$listfile = $_SERVER["DOCUMENT_ROOT"]."/include/mirrors"; require $_SERVER["DOCUMENT_ROOT"]."/include/mirrors";
$file_id = fopen( $listfile, "r" );
$all = fread ( $file_id, filesize( $listfile ) );
fclose ( $file_id );
$mirrors = explode ( "\n", $all );
if ( isset($mirror) ) if( isset($mirror_url) )
{ {
$len = sizeof( $mirrors ); foreach( $mirrors as $mirror )
for ( $i = 0; $i < $len; $i++ ) { {
$url = explode ( "|", $mirrors[$i] ); if( $mirror_url === $mirror[0] )
if( $mirror === $url[0] ) $found = true; {
} $found = true; break;
}
}
!$found && die;
}
else
# Pick up a random mirror
{
$index = rand( 0, sizeof( $mirrors ) - 1 );
$mirror = $mirrors[$index];
$mirror_url = $mirror[0];
}
!$found && die; $mirror_name = $mirror[1];
} $country = $mirror[2];
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 );
}
}
?> ?>
<html> <html>
<head> <head>
<title>VideoLAN - Download from mirror</title> <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> </head>
<body> <body>
<p>Click <a href="<?php echo $mirror.$file ?>">here</a> if your download doesn't start</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> <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> </body>
</html> </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