#!/usr/bin/perl -wT
use strict;
use CGI;
use LWP::Simple;
$|++;
my $q = new CGI;
my $v = $q->Vars;
my $action = $q->url;
print $q->header(-type => 'text/plain'), viewSource() and exit if $v->{view};
print $q->header, buildTop($v, $action);
exit unless $v->{start} && $v->{depth};
$v->{depth} = 25 if $v->{depth} > 25;
my $links = [$v->{start}];
my @cycleBreaker = ();
print 'Watch! The AutoSurfer is surfing!
';
my $i = 0;
do {
my $rand = randomizeArray($links);
for my $url (@$rand) {
next if grep { $_ eq $url } @cycleBreaker;
print "
Getting $url..." if $v->{verbose};
my $html = get $url;
if ($html) {
print "done." if $v->{verbose};
} else {
print "failed." if $v->{verbose};
next;
}
my $title = getTitle($html);
my $allLinks = getLinks($html);
$links = validateLinks($allLinks);
cleanLinks($links, $url);
if (@$links) {
print qq|- $title - Surf it - $url|;
$i++;
push @cycleBreaker, $url;
last;
}
}
} while ($i < $v->{depth} && @$links);
print '