#!/usr/bin/perl -w # # VW - track v0.1 # by f roque # #follows the path a user took through the website # #todo: #output to various file types. currently only multiple png's are printed. #i'd rather be making flash animations. use strict; use DBI; use Time::Local; use GD; require('/home/httpd/bin/parse-logs'); require("/home/frisco/bin/dbgeneric"); $|=1; use constant MONTH => { 'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11 }; my $map_run = shift; my $whost = shift; my $imgdir = shift; my $width = 1190; my $height = 653; my $logfile = "/usr/local/apache/logs/blackant-access_log"; my @hits = (); my $lpage = 'NULL'; print STDERR "Connecting to db..."; print $main::webdb.' '.$main::user.' '.$main::password."\n" if 0; my $dbh = DBI->connect("dbi:mysql:".$main::webdb, $main::user, $main::password); my $sql = "SELECT x,y FROM map_pages WHERE page = ? AND map_run=$map_run AND "; $sql .= "x IS NOT NULL AND y IS NOT NULL "; my $sth = $dbh->prepare($sql); print STDERR "...done.", $/; print STDERR "Running through logfile..."; open(LOG, '< '.$logfile) or die "Error opening $logfile: $!"; while () { next unless /^$whost /; my %parts = getparts($_); my $referer = $parts{'referer'}; $referer =~ s/^http:\/\/www.blackant.net//i; $sth->execute($parts{'page'}); my $coords = $sth->fetchrow_arrayref() or next; $parts{'date'} =~ m/^\[(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)\s+/; if ($lpage ne 'NULL' && $referer ne $lpage && $referer ne '-') { print STDERR $referer, $/; $sth->execute($referer); my $coords2; push @hits, { 'page' => [ $referer, $$coords2[0], $$coords2[1] ], 'date' => timelocal($6,$5,$4,$1,MONTH->{$2},$3), 'referer' => 1, } if $coords2 = $sth->fetchrow_arrayref(); } push @hits, { 'page' => [ $parts{'page'}, $$coords[0], $$coords[1] ], 'date' => timelocal($6,$5,$4,$1,MONTH->{$2},$3), 'referer' => 0, }; $lpage = $parts{'page'}; } close(LOG); print STDERR "...done", $/; print STDERR "Creating images..."; my $basetime = 0; my $imgfile = '/tmp/out.png'; # HELP ME my $px = -1; my $py = -1; my $brush = new GD::Image(5,5); my $white = $brush->colorAllocate(255,255,255); my $owhite = $brush->colorAllocate(255,255,254); my $yellow = $brush->colorAllocate(255, 255, 0); my $blue = $brush->colorAllocate(0,0,255); $brush->transparent($white); $brush->arc(0,0,4,4,0,360,$yellow); $brush->fill(0,0,$yellow); for (my $n=0; $n<=$#hits; $n++) { my $im = GD::Image->newFromPng($imgfile); my $white = $im->colorAllocate(255,255,255); my $owhite = $im->colorAllocate(255,255,254); my $yellow = $im->colorAllocate(255,255,0); my $blue = $im->colorAllocate(0,0,255); $im->setBrush($brush); $im->transparent($owhite); #$im->rectangle(0,$height-20,$width-1,$height-1,$white); #$im->fill(1,$height-10,$white); for my $size ($height-20..$height-1) { $im->line(0, $size, $width-1, $size, $white); } my $page = ${$hits[$n]}{'page'}[0]; my $x = ${$hits[$n]}{'page'}[1]; my $y = ${$hits[$n]}{'page'}[2]; my $date = ${$hits[$n]}{'date'}; $basetime = $date if $basetime == 0; my $reltime = $date - $basetime; $reltime = 0 if $reltime < 0; $im->arc($x, $y, 5, 5, 0, 360, $yellow); $im->fill($x, $y, $yellow); $im->string(gdSmallFont,10,$height-15,$page,$blue); $im->string(gdSmallFont,$width-100,$height-15,$reltime,$blue); unless ($px == -1 || $py == -1) { $im->line($px+2, $py+2, $x+2, $y+2, gdBrushed); } $px = $x; $py = $y; my $num = $n; for (1..length($#hits+1)-length($n)) { $num = '0'.$num; } $imgfile = "$imgdir/$num.png"; my $simgfile = "$imgdir/$num-s.png"; open (OUT, "> $imgfile") or die "Error opening $imgfile: $!"; print OUT $im->png(); close(OUT); my ($w,$h) = $im->getBounds(); my $sim = GD::Image->new(300,($h*300/$w)); $sim->copyResized($im,0,0,0,0,299,($h*300/$w),$w,$h); open (OUT, "> $simgfile") or die "Error opening $simgfile: $!"; print OUT $sim->png(); close(OUT); } print STDERR "...done", $/; $dbh->disconnect();