#!/usr/bin/perl -w use strict; use CGI qw/:standard/; $|=1; my $DIR = param('d') || './'; # default dir my $FILE = param('f') || 'xyz.zip'; # default file my @HOSTS = ( 'www.myotherhost.com', '10.0.0.2', 'www.myhost.com', '10.0.0.1', ); print header('text/plain'), "No access to $FILE" unless DownloadFile($DIR, $FILE, \@HOSTS); exit 0; sub DownloadFile { my ($dir, $filename, $hosts) = @_; my $remote = remote_host(); #### the following is bad because it is not an exact #### match nor is it anchored #### return(0) unless grep /$remote/, @$hosts; # the following suggested by [merlyn] return 0 unless grep $remote eq $_, @$hosts; my $filesize = -s "$dir/$filename"; # print full header print "Content-disposition: filename=$filename\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/octet-stream\n\n"; # open in binmode open(READ,$filename) || die; binmode READ; # stream it out binmode STDOUT; while () { print; } close(READ); # should always return true return(1); }