#!/usr/bin/perl use strict; use warnings; use CGI; use Geo::Mirror; my $mf; if ($ENV{REDIRECT_URL} eq '/xonotic-0.1.0preview.zip') { $mf = 'mirrors-0.1.0preview.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.5.0.zip') { $mf = 'mirrors-0.5.0.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0.zip') { $mf = 'mirrors-0.6.0.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0-low.zip') { $mf = 'mirrors-0.6.0-low.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0-mappingsupport.zip') { $mf = 'mirrors-0.6.0-mappingsupport.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0-engine.zip') { $mf = 'mirrors-0.6.0-engine.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0-crypto.zip') { $mf = 'mirrors-0.6.0-crypto.txt'; } elsif ($ENV{REDIRECT_URL} eq '/xonotic-0.6.0-source.zip') { $mf = 'mirrors-0.6.0-source.txt'; } else { print "Content-type: text/plain\n\n File not found!\n"; exit(0); } # This script provides a way to redirect to a local mirror or a random one using a 302 header my $gm = Geo::Mirror->new(mirror_file => $mf); my $mirror = $gm->find_mirror_by_addr($ENV{REMOTE_ADDR}); open(LOG, ">>log.txt"); print LOG "$ENV{REMOTE_ADDR} redirecting to $mirror$ENV{REDIRECT_URL}\n"; close LOG; my $q = new CGI; print $q->redirect("$mirror$ENV{REDIRECT_URL}");