#dbfix, Copyright 2000 Boutell.Com, Inc. # #Recreates database.dat files based on data found in Wusage 6 #and Wusage 7 reports for individual time periods. #This script assumes you have not altered your #report formatting too drastically. If you have, you will #need to make adjustments. TBB 02/02/00 # #DON'T RUN THIS if your historical charts are fine! #Only customers who used Wusage 7.0 P11 are likely to need this. #7.0 P11 was only available for download for about 24 hours. # #Your old database.dat files will be backed up to #database.bak, just in case you ran this program by mistake. #Please note that database.bak can be overwritten if you run it twice. # #TO USE: # #1. VERIFY THAT YOU EVER HAD 7.0 P11, WHICH WAS ONLY AVAILABLE #ON 1/31/00 FOR 24 HOURS, OR THAT YOUR HISTORICAL TOTALS GRAPHS #ARE COMPLETELY ZEROED OUT FOR SOME OTHER REASON. # #2. Type "perl dbfix /path/to/my/conf/file" # #3. If you don't get good results, please send your configuration #file to us for analysis, and explain that you were trying to use #dbfix and did not get the expected results. # # #END OF INSTRUCTIONS @frequencies = ( "daily", "weekly", "monthly", "quarterly", "annual" ); @hashes = ( "documents", "notfound", "sites", "proxysites", "useragents", "referers", "referrers", "referringsites", "searchkeywords", "authusers", "domains", "proxydomains", "os", "types", "visits", "trails" ); $found = 0; $conf = $ARGV[0]; if ($conf eq "") { die "Usage: perlfix /path/to/my/conf/file\n"; } open(IN, $conf) || die "Can't open configuration file $conf\n"; while ($line = ) { if ($line =~ /^reportorder/) { while ($line = ) { if ($line =~ /^end/) { last; } } } if ($line =~ /^reportdir\s+(\S+)/) { $reportDir = $1; } if (($line =~ /^totals\s*$/) || ($line =~ /^totalsgroup\s*$/)) { while ($line = ) { if ($line =~ /^end/) { last; } $hashes = join('|', @hashes); if ($line =~ /^($hashes) /i) { $hash = $1; } else { $hash = "documents"; } $line =~ s/^((function|nograph|nototal|yeartoyear) )+//; if ($line =~ /^((?:$hashes )?(?:(?:\{.*?\})|[^\s\{\}]+)+)\s+(.*)\s*$/) { ($pattern, $title) = ($1, $2); $pattern = "$hash $pattern"; $patterns{$title} = $pattern; $titles{$pattern} = $title; push @patterns, $pattern; } } } } close(IN); for $f (@frequencies) { opendir(DIR, "$reportDir/$f") || next; if (open(IN, "$reportDir/$f/database.dat")) { open(OUT, ">$reportDir/$f/database.bak"); while ($line = ) { print OUT $line; } close(IN); close(OUT); } open(OUT, ">$reportDir/$f/database.dat"); print OUT "Date\tDays"; for $p (@patterns) { print OUT "\t$p accesses\t$p bytes\t$p visits"; } print OUT "\n"; $found++; %accesses = ( ); %bytes = ( ); %visits = ( ); for ($year = 1990; ($year < 2010); $year++) { opendir(YDIR, "$reportDir/$f/$year") || next; closedir(YDIR); for ($month = 1; ($month <= 12); $month++) { $month = sprintf("%02d", $month); opendir(MDIR, "$reportDir/$f/$year/$month") || next; closedir(MDIR); for ($day = 1; ($day <= 31); $day++) { $day = sprintf("%02d", $day); opendir(DDIR, "$reportDir/$f/$year/$month/$day") || next; closedir(DDIR); if (!(open(IN, "$reportDir/$f/$year/$month/$day/exec.html") || open(IN, "$reportDir/$f/$year/$month/$day/exec.htm") || open(IN, "$reportDir/$f/$year/$month/$day/index.html") || open(IN, "$reportDir/$f/$year/$month/$day/index.htm"))) { next; } $data = ""; while ($line = ) { $data .= $line; } close(IN); $data =~ s/\,//g; # Wusage 6 style if ($data =~ /\Totals\<\/h3\>\s+\(.*?)\<\/table\>/is) { $data = $1; while ($data =~ /\(.*?)\<\/td\>\s+\\s*([\d\,\.]+)\s*\<\/td\>\s+\\s*([\d\,\.]+)\s*\<\/td\>(.*)$/is) { ($title, $accesses, $bytes, $data) = ($1, $2, $3, $4); $title =~ s/^\s+//; $title =~ s/\s+$//; $accesses{$title} = $accesses; $bytes{$title} = $bytes; } next; } # Wusage 7 style while ($data =~ /\\s+\(.*?)\<\/td\>\s+\\s*([\d\,\.]+)\s*\<\/td\>\s+\\s*([\d\,\.]+)\s*\<\/td\>\s+\\s*([\d\,\.]+)\s*\<\/td\>(.*)$/is) { ($title, $accesses, $bytes, $visits, $data) = ($1, $2, $3, $4, $5); $title =~ s/^\s+//; $title =~ s/\s+$//; $accesses{$title} = $accesses; $bytes{$title} = $bytes; $visits{$title} = $visits; } print OUT "$month/$day/$year\t", &length($f, $month, $day, $year); for $p (@patterns) { $a = $accesses{$titles{$p}}; $b = $bytes{$titles{$p}}; $v = $visits{$titles{$p}}; $a = sprintf("%20.02f", $a); $b = sprintf("%20.02f", $b); $v = sprintf("%20.02f", $v); print OUT "\t$a\t$b\t$v"; } print OUT "\n"; } } } close(OUT); closedir(DIR); } if (!$found) { die "Didn't find any of the report subdirectories. You are probably\n" . "not in your report directory. cd there first.\n"; } sub length { my($f, $month, $day, $year) = @_; if ($f eq "daily") { return 1; } elsif ($f eq "weekly") { return 7; } elsif ($f eq "monthly") { return 31; } elsif ($f eq "quarterly") { return 93; } elsif ($f eq "annual") { return 365; } }