# pornbot v0.1 # to test BAIR "AI" filter # By Declan McCullagh (declan@well.com) # background: http://www.wired.com/news/technology/0,1282,36923,00.html # global vars # also create two directories under . -- porn and nporn $totalimages = 30; $numporn = 15; $dirname = randomnum(10000); $outputdir = "/home/httpd/html/jpg/" . $dirname; $htmldir = "/jpg/" . $dirname; # create output directory print "$outputdir\n"; `/bin/mkdir $outputdir`; opendir(USERDIR, 'porn'); @filenames = readdir(USERDIR); $porncount = 0; shift(@filenames); # to get rid of dots shift(@filenames); foreach $i (@filenames) { $porncount++; $pornimage[$porncount] = $i; } close (USERDIR); print "$porncount images\n"; opendir(USERDIR, 'nporn'); @filenames = readdir(USERDIR); $nporncount = 0; shift(@filenames); shift(@filenames); foreach $i (@filenames) { $nporncount++; $npornimage[$nporncount] = $i; } close (USERDIR); print "$nporncount images\n"; # how many innocent imgs we want $numinnocent = $totalimages - $numporn; open(OUT, ">$outputdir/index.html") or die "file could not be created.\n"; print OUT "
";
# output the porn
for ($i = 0; $i<$numporn; $i++) {
$picked=randomnum($porncount);
my $j = randomnum(10000);
$filename="/bin/ln porn/$pornimage[$picked] $outputdir/" . $j . ".jpg";
`$filename`; #execute ln cmd
print "$filename\n";
push (@FinalList,$j);
}
# output the non-porn
for ($i = $numporn; $i<$totalimages; $i ++) {
$picked=randomnum($nporncount);
my $j = randomnum(10000);
$filename="/bin/ln nporn/$npornimage[$picked] $outputdir/" . $j . ".jpg";
`$filename`; #execute ln cmd
print "$filename\n";
push (@FinalList,$j);
}
# mix up the images
# (we don't want bair to block based on position in page)
@FinalList2 = sort @FinalList;
for ($i =0; $i<$totalimages; $i ++) {
$j = pop(@FinalList2);
print OUT "";
print OUT "
\n";
}
close OUT;
sub randomnum {
my $i = int (rand (pop(@_))) +1;
return $i;
}