#!/usr/bin/perl
require 'settings.conf';
require 'exclude.conf';
require 'include.conf';
$data = "";
$template_file = "template.txt";
@html_file = @pages;
print "Content-type: text/html\n\n";
print "Updating the HTML file(s)
;\n";
print "Please Hold\n";
$|=1;
$time = time();
if ($uniqe eq '1') {
open(SESAME,"$referer_log.backup") || die "Could not open Referer Log";
@filecontents = ;
close(SESAME);
@hash{@filecontents}=();
@filecontents=keys %hash;
open(SESAME,">$referer_log.backup") || die "Could not open Referer Log";
foreach $line(@filecontents){ print SESAME "$line";}
close(SESAME);
chmod (0666, "$referer_log.backup");
}
open(LOG,"$referer_log.backup") || die "Could not open Referer Log";
while(){
$ref = $_;
foreach$skip(@skip_pages) {
if($ref =~ /$skip/) {
$bad =1;
}
}
if(!$bad) {
($test,$testbogus) = split(/\|/,$ref);
study($test);
$test =~ s/:80//g;
$test =~ s/%7E/~/g;
$sitecount ="0";
foreach $line(@siteurl) {
if($test =~ /$line/) {
$test = "$sitedesc[$sitecount]";
$test .= "||$sitename[$sitecount]";
}
$sitecount++;
}
$HASH{"$test"}++;
$grandtotal++;
}
undef($bad);
print ".\n";
}
close(LOG);
sub bynumber { $b <=> $a; }
foreach$key(keys %HASH) {
$line = "$HASH{$key}\::$key";
push(@array,$line);
}
undef(%HASH);
@array = sort bynumber @array;
$time = time() - $time;
open(SESAME,"header.txt");
@filecontents = ;
close(SESAME);
foreach $line(@filecontents) {
$line =~ s/\"/\"/;
$line =~ s/\#/\#/;
$line =~ s/\?/\?/;
$header .= "$line"; }
open(SESAME,"footer.txt");
@filecontents = ;
close(SESAME);
foreach $line(@filecontents) {
$line =~ s/\"/\"/;
$line =~ s/\#/\#/;
$line =~ s/\?/\?/;
$footer .= "$line"; }
$antal ="0";
$rank ="1";
while ($antal < $top) {
$part = @array[$antal];
($total,$referer) = split(/::/,$part);
if($total >= $minumum_referals) {
if($referer !~ /^http:\/\//){
$data = "$rank";
$data .= "||$referer";
$data .= "||$total";
}
else {
$data = "$rank";
$data .= "||$referer";
$data .= "||$total";
}
push(@Ref_Info,"$data");
}
$antal++;
$rank++;
}
if ($userunners eq "1"){
$tempup = "||$runnersurl||Runners Up||?";
push(@Ref_Info,"$tempup");
}
&preview;
if ($userunners eq "1"){
$runnersrank = ($#Ref_Info + 1);
open(FH,">$runnerspath");
print FH "Runners Up\n";
print FH "\n";
print FH "Runners Up
\n";
print FH "\n";
do {print FH "
$array[$runnersrank]\n"; $runnersrank++; }
until ($runnersrank > $#array);
print FH "
\n";
close(FH);
}
print "
File(s) updated
You may close this window now..\n";
exit;
#__________________________________________________________________
sub preview {
&Get_Template;
&Get_New_Links;
foreach $pages(@html_file){
open(SESAME,"$pages");
@Old_HTML = ;
close(SESAME);
@New_HTML = ("");
do {
$temp = shift(@Old_HTML);
push(@New_HTML,"$temp");
} until ($temp =~ //);
push(@New_HTML,"$header");
push(@New_HTML,@NewLines);
do {
$temp = shift(@Old_HTML);
} until ($temp =~ //);
push(@New_HTML,"$footer");
push(@New_HTML,"$temp");
push(@New_HTML,@Old_HTML);
chmod (0666,$pages);
open(SESAME,">$pages");
print SESAME "@New_HTML";
close(SESAME);
chmod (0644,$pages);
}
}
#------------------------------
sub Get_HTML {
open(SESAME,"$html_file");
@Old_HTML = ;
close(SESAME);
}
#--------------------------------
sub Get_New_Links {
foreach $line(@Ref_Info){
@content = split(/\|\|/,"$line");
$rank = $content[0];
if ($content[3] eq ""){$content[3] = $content[2]; $content[2] = $content[1];}
$referer = "$content[2]";
$total = $content[3];
$temp = $template;
$temp =~ s//$rank/g;
$temp =~ s//$referer/g;
$temp =~ s//$total/g;
$temp .= "\n";
push(@NewLines,"$temp");
}
}
#----------------------------------
sub Get_Template {
open(SESAME,"$template_file");
@temptemplate = ;
close(SESAME);
foreach $line(@temptemplate){
$template .= "$line";
}
}
#---------------------------------------