Name: Anonymous 2007-10-04 9:33
This week: write a spam bot.
parse=>sub{
my $cat=shift @ARGV or die "Category not specified";
my $resto=shift @ARGV;
(my $board_name,$resto)=($resto or "")=~/^\>*\/?([a-z]*)\/?(\d+)$/i or return undef;
my $board=Yotsuba::Boards->new($board_name or 'a') or error "No such board: $board_name";
my $self={
resto=>$resto,
board=>$board,
cat=>$cat,
};
return $self;
},
do=>sub{
my $self=shift;
my $board=$self->{board};
my $resto=$self->{resto};
my($cat,$path,$name,$issue,$issue_name)=("","","","","");
for(split /\n/,cat "$home/hijack"){
($cat,$path,$name,$issue,$issue_name)=(/(?:(?:\||^)([^\|]*))/g);
last if $cat eq $self->{cat};
}
die "$cat ne $self->{cat}" if($cat ne $self->{cat});
die "wrong path in hijack file: $path" unless -d $path;
$name||='Namelеss Fairy';
$path=~s/[\/\\]$//;
$self->{renzoku}||=RENZOKU;
$self->{renzoku}*=1000000;
my @files;
push @files,glob("$path/*.$_") foreach('jpg','jpeg','png','gif',);
exit unless @files;
unless($self->{o}){
my @fileso=@files;
@files=();
while($_=(delete $fileso[rand @fileso])){
push @files,$_;
}
}
my $text=$board->get($resto);
die "Couldnt't get page: ".$board->error if $board->error;
if(-e "$home/$issue" and not $self->{I}){
`cp "$home/$issue" "$home/issue.jpg"`;
`echo $resto>>"$home/issue.jpg"`;
$issue="$home/issue.jpg";
unshift @files,$issue;
}
my($last,$upspeed)=(0,1.0);
my $f=shift @files;
while(@files){
my($fname)=$f=~/.*\/(.*)/;
printf "$fname %.1f KB .. ",(-s $f)/1024;
my $ttp=((-s $f)/1024)*1000000/$upspeed;
my $tosleep=$self->{renzoku}-$ttp-(us()-$last);
if($tosleep>0){
printf "(sleeping %.1fs",$tosleep/1000000;
usleep($tosleep);
print ").. ";
}
my $start=us();
my $res=$board->post($resto,
email => $self->{email},
upfile => [$f,$f eq $issue?"$issue_name":sprintf "%d%03d.jpg",time-rand 65536,rand 1000],
pwd => $self->{pass},
com => $self->{com},
name => $name,
);
if($board->error){
if($res eq "500 read timeout"){
print "timeout\n";
$f=shift @files;
}
elsif($res=~/^(\d+) (.*)$/){
print "$res\n";
exit if $res=~/^(302|403)/;
}
else{
print "unknown error!\n$res\n";
}
next;
}
unless($res){
$last=us();
$upspeed=(-s $f)*1000000/1024/($last-$start);
printf "[%.0f KBps] done!\n",$upspeed;
$f=shift @files;
next;
}
for($res){
/Max limit of \d+ image replies has been reached./ and do {
print "limit reached\n";
exit;
};
/Thread specified does not exist./ and do {
print "thread doesn't exist\n";
exit;
};
/Duplicate file entry detected./ and do {
print "duplicate entry\n";
$f=shift @files;
next;
};
/File too large/ and do {
print "filesize\n";
$f=shift @files;
next;
};
/Flood detected, file discarded./ and do {
print "flood\n";
next;
};
print "error: $res\n";
}
};
},
usage=>sub{
my $self=shift;
print <<HERE;
Usage: $0 hijack CATEGORY THREAD [OPTION]...
Floods a thread with images. CATEGORY is one of the hijack sets defined in
file $home/hijack.
THREAD can be either thread number, or, if you want to use
other board than /a/, you can specify short name of board
before thread number. (ex: 123456, b1677721, >>>/z/42)
--com=COMMENT Use COMMENT as comment when posting
--email=EMAIL Use EMAIL as poster email
--name=NAME Use NAME as poster name
--pass=PASSWORD Use PASSWORD as delete password (default is random)
--path=PATH Search PATH for images instead of current directory
--renzoku=TIME Post an image every TIME seconds (default 20)
-o Alphabetical image order (default random)
-I No issue image
HERE
exit;
},
desc=> "floods a thread with images.",