#!/usr/bin/perl #Location and name of the Count Script on your server $CountDownLocation = 'http://www.netconfirm.de/downloads/tools/count.cgi'; # This is the directory location of the file(s) that will be downloaded $DownloadFileDir = 'http://www.netconfirm.de/downloads/tools'; # This is the counter log filename $Counter = '/srv/www/htdocs/web1/html/downloads/tools/count.log'; #This is the HTML output filename $HTMLFile = '/srv/www/htdocs/web1/html/downloads/tools/log.htm'; #This is the HTML output filename for the Top Ten List only $TopTenFile = '/srv/www/htdocs/web1/html/downloads/tools/topten.htm'; ########################################################## # No changes need to be made after these lines ########################################################## $File = $ENV{'QUERY_STRING'}; # Strip off anything up to, and including, the last "/", if present if ($File =~ /\//) { ($File) = $File =~ /^.*\/([^\/]+)$/g; } $DownloadFile = "$DownloadFileDir/$File"; # Add hit to main counter open (CNT,"+<$Counter") || &endIt; flock (CNT,2); seek (CNT,0,0); @infile = ; # This will put the hits in order from max to min for each file added $record = 0; # Starting record in the log is always 0 $correctspot = 'N'; # Tells script if this record is the one that was hit # Proceeds as long as the record number is less than the total # number of records in the file and the correct record hasn't been found yet. while (($correctspot eq 'N') && ($record <= $#infile)) { ($count,$filename,$eol) = split(/\|/,$infile[$record]); if ($filename eq $File) #if this is the right record, hit it, trip correctspot {$count++; $infile[$record] = join ("\|",$count,$filename,"\n"); $correctspot = 'Y'; } $record++; } if ($correctspot eq 'N') { $count = 1; $newrecord = join ("\|",$count,$File,"\n"); push @infile, $newrecord; } @outfile = sort {($b =~ /(\d+)/)[0] <=> ($a =~ /(\d+)/)[0]} @infile; seek (CNT,0,0); print (CNT @outfile); truncate (CNT,tell(CNT)); close (CNT); #Create HTML File - Whole List open (Out,"+>$HTMLFile") || &endIt; flock (Out,2); print {Out} < Downloads TextOut foreach (@outfile) { ($count,$filename,$eol) = split(/\|/,$_); print {Out} < TextOut } print {Out} < TextOut #Create HTML File - Top Ten List open (Out,"+>$TopTenFile") || &endIt; flock (Out,2); print {Out} < Top Ten Downloads
Downloads Datei
$count - $filename
TextOut if ($#outfile < 9) { for ($i = 0; $i <= $#outfile; $i++) { ($count,$filename,$eol) = split(/\|/,$outfile[$i]); print {Out} < TextOut } } else { for ($i = 0; $i <=9; $i++) { ($count,$filename,$eol) = split(/\|/,$outfile[$i]); print {Out} < TextOut } } print {Out} < TextOut print "Content-type: text/html\n"; print "Location: $DownloadFile\n\n"; sub endIt # exit on error { exit; } # end endIt
Downloads Datei
$count - $filename
$count - $filename