#!/usr/bin/perl -w -- # # Looks for files named .LICENSE at or closest above the current directory # level. Such a file should be a symlink to the appropriate distribution # intent from /pub/licenses. If the symlink becomes broken, the filename of # the link target will be sought in /pub/licenses. You can also simply touch a # file .LICENSE.foo, and it will look for /pub/licenses/LICENSE.foo # # This file is invoked by the rule in .htaccess in the /pub directory. # The web server virtual host must have an Alias for /licenses use CGI::Carp qw(warningsToBrowser fatalsToBrowser); print qq{

Index of $ENV{'REQUEST_URI'} on $ENV{'HTTP_HOST'}

}; my $path = ''; if ($ENV{'SERVER_NAME'} =~ /afswww.icequake.net/) { $path = $ENV{'REQUEST_URI'}; $path =~ s/^/\/pub/g; } elsif ($ENV{'SERVER_NAME'} =~ /www.icequake.net/) { $ENV{'REQUEST_URI'} =~ /.*?(\/afs\/.*)$/; $path = $1; $path =~ s/^\/afs/\/pub/g; } elsif ($ENV{'SERVER_NAME'} =~ /dbz.icequake.net/) { $ENV{'REQUEST_URI'} =~ /(\/pub\/.*)$/; $path = $1; } else { exit 0; } my $location = "/afs/icequake.net" . $path; if ($location !~ /\/$/) { $location .= "/"; } my $fh; opendir my $dir, "$location"; my @licenses = grep /^\.LICENSE/, readdir $dir; my $found = 1; while (scalar(@licenses) == 0) { closedir $dir; $location =~ s/[^\/]+\/$//; if ($location !~ /^\/afs\/icequake.net\/pub\// || $location eq '/afs/icequake.net/pub/') { $found = 0; last; } opendir my $dir, "$location"; @licenses = grep /^\.LICENSE/, readdir $dir; } if ($found) { closedir $dir; my $license = $licenses[0]; my $target = $license; $target =~ s/^\.//; if ( -l $location.$license) { my $linktgt = readlink $location.$license; if ( -r $linktgt) { $target = $location.$license; } else { # invalid symlink $linktgt =~ s/.*\/([^\/]*)$/$1/g; $target = "/afs/icequake.net/pub/licenses/".$linktgt; } } else { $target = "/afs/icequake.net/pub/licenses/".$target.".html"; } open my $fh, "<".$target; while (<$fh>) { print $_; } close $fh; } exit 0;