#!/usr/bin/perl # General linkback stats version 1.0 # Sami Köykkä 18.5.2002 # samik @ iki.fi www.pinseri.com # # You can distribute this software freely, but I'd appreciate # a link to www.pinseri.com. Also, if you improve the software, # send me a copy! # use strict; # # CONFIGURATION # # Absolute path to the file that holds the referrer log. my $file="/home/customers/pinseri/reflog"; # How many seconds to keep referral my $expire=60*60*24; # 24 hours # How many referers to print my $show=15; # Max length of URL shown my $maxlength=35; # My domain (for filtering out internal refs) my $mydomain="pinseri.com"; # "Direct link" text my $dirlink="Kirjanmerkki tai kirjoitettu osoite"; # Exclude direct links (1 = yes, 0 = no) my $exclude=1; # # END CONFIGURATION # print "Content-type: text/html\n\n"; my $now=time; my $ref=$ENV{'HTTP_REFERER'}, "\n"; # add some security: change dangerous characters $ref=~s//%3E/g; $ref=~s/"/%22/g; # Read in the old entries my (%entries, %count, $line, $timestamp, $url); open (IN, $file) || die "File $file open error: $!"; foreach $line () { chomp $line; ($timestamp, $url)=split(' ', $line); if ($timestamp > $now-$expire) { $entries{$timestamp}=$url; $count{$url}=$count{$url}+1; } } close(IN); # Add the newest entry $entries{$now}=$ref; $count{$ref}=$count{$ref}+1; # Print results my ($counter); foreach $url (sort {$count{$b}<=>$count{$a}} keys %count) { next if ($url=~m/$mydomain/); next if ($exclude==1 && $url eq ""); if ($url eq "") { print "$dirlink ($count{$url})
\n"; } else { print "", &tidy($url), " ($count{$url})
\n"; } $counter++; last if ($counter >= $show); } # Save # (file locking not implemented, should do that sometimes) open (OUT, ">$file") || die "File $file write error: $!"; foreach $timestamp (keys %entries) { print OUT join (' ', $timestamp, $entries{$timestamp}), "\n"; } close(OUT); sub tidy { # # Tidies up the URL before showing it in the site # my $url=shift; my ($result); # # add here matches that change urls to more descriptive text # # --start-- if ($url=~m[virtual4.wysiwyg.fi/~samik/yossa]) { $result="Yössä"; } elsif ($url=~m[virtual4.wysiwyg.fi/~samik/$]) { $result="Samin kotisivu"; } elsif ($url=~m[pekkala.info/$]) { $result="Pekkaspace HQ"; } elsif ($url=~m[suodatin.com]) { $result="Suodatin"; } elsif ($url=~m[google.com]) { $result="Google-haku"; } # --end-- # # elsif (length($url)>$maxlength) { $result=substr($url, 0, $maxlength) . "..."; } else { $result=$url; } return $result; }