rockbox/www/index.cgi
Björn Stenberg 3cb3c7599f Changed mirror location
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@52 a1c6a512-1295-4272-9138-f99709370657
2002-03-28 13:38:40 +00:00

41 lines
857 B
Perl
Executable file

#!/usr/bin/perl
# A very simple load balancing script:
# If more than $nlim hits in under $tlim seconds, redirect to $mirror.
#
# 2002-01-24 Björn Stenberg <bjorn@haxx.se>
# redirect is triggered by more than:
$nlim = 10; # accesses in...
$tlim = 10; # seconds
$mirror = "http://rockbox.sourceforge.net/rockbox/";
open FILE, "+<.load" or die "Can't open .load: $!";
flock FILE, LOCK_EX;
@a = <FILE>;
if ( scalar @a > $nlim ) {
$first = shift @a;
}
else {
$first = $a[0];
}
$now = time();
@a = ( @a, "$now\n" );
truncate FILE, 0;
seek FILE, 0, 0;
for ( @a ) {
print FILE $_;
}
flock FILE, LOCK_UN;
close FILE;
$diff = $now - $first;
if ( $diff < $tlim ) {
print "Location: $mirror\n\n";
}
else {
print "Content-Type: text/html\n\n";
open FILE, "<main.html" or die "Can't open main.html: $!\n";
print <FILE>;
close FILE;
}