diff options
Diffstat (limited to 'www/index.cgi')
-rwxr-xr-x | www/index.cgi | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/www/index.cgi b/www/index.cgi new file mode 100755 index 0000000000..a340a2e5ac --- /dev/null +++ b/www/index.cgi | |||
@@ -0,0 +1,41 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # A very simple load balancing script: | ||
4 | # If more than $nlim hits in under $tlim seconds, redirect to $mirror. | ||
5 | # | ||
6 | # 2002-01-24 Björn Stenberg <bjorn@haxx.se> | ||
7 | |||
8 | # redirect is triggered by more than: | ||
9 | $nlim = 10; # accesses in... | ||
10 | $tlim = 10; # seconds | ||
11 | $mirror = "http://rockbox.sourceforge.net/bjorn.haxx.se/rockbox/"; | ||
12 | |||
13 | open FILE, "+<.load" or die "Can't open .load: $!"; | ||
14 | flock FILE, LOCK_EX; | ||
15 | @a = <FILE>; | ||
16 | if ( scalar @a > $nlim ) { | ||
17 | $first = shift @a; | ||
18 | } | ||
19 | else { | ||
20 | $first = $a[0]; | ||
21 | } | ||
22 | $now = time(); | ||
23 | @a = ( @a, "$now\n" ); | ||
24 | truncate FILE, 0; | ||
25 | seek FILE, 0, 0; | ||
26 | for ( @a ) { | ||
27 | print FILE $_; | ||
28 | } | ||
29 | flock FILE, LOCK_UN; | ||
30 | close FILE; | ||
31 | |||
32 | $diff = $now - $first; | ||
33 | if ( $diff < $tlim ) { | ||
34 | print "Location: $mirror\n\n"; | ||
35 | } | ||
36 | else { | ||
37 | print "Content-Type: text/html\n\n"; | ||
38 | open FILE, "<main.html" or die "Can't open main.html: $!\n"; | ||
39 | print <FILE>; | ||
40 | close FILE; | ||
41 | } | ||