Бампалка: бампалка

Код бампалки. Исторически хранился в файле с названием main.pl.

#!/usr/bin/perl
 
###########################################################################
##  Haruchan autobumber, desu~
##  version #1
##
##  authors:
##    anons from haruchan.conference.jabber.jp
##
##  thanx to Chiaki for support
##
##  lisenced under GNU GPL 3.0
##
 
###########################################################################
###     bot parameters : setting defaults
###     (most of them for tirech)
####
 
# path to pictures obviously, isn't it?
my    $pictures_path = '/home/asd/Картинки/anime/touhou/flandre-scarlet'; 
 
my            $delay = 5;   # posting delay in seconds,
                            # be carefull: wipe or bump?
 
my            $count = -1;  # -1 : infinite posts;
                            #  0 : one post;
                            # >0 : corresponding number of posts
 
# this tags for error detecting are used
my  $error_tag_start = '<strong><font size="5">Ошибка: ';
my   $error_tag_stop = '</strong></font>';
 
# this strings contains captcha error messages
my       $error_captcha_wrong = 'Неверный код подтверждения.';
my $error_captcha_not_entered = 'Не введен код подтверждения.';
 
# this string contains repeated string error message
my $error_picture_repeated = 'Этот файл уже был загружен';
 
my $error_flood = 'Обнаружен флуд, файл не отправлен.';
 
# captcha file name to be saved
my $captcha_path = 'captcha.png';
 
###########################################################################
###     post parameters : setting defaults
####
 
my      $host = 'www.2-ch.ru'; # maybe www.2-ch.ru?;
my     $board = 'b';
my    $thread = '11815870';
my      $name = ''; # r u tripfag?
my      $mail = ''; # may be sage?
my   $subject = ''; # is it realy needed?
my   $message = ''; # wipe message
my   $captcha = ''; # that may be difficult, isn't it?
my  $password = ''; # for post removing ability
 
###########################################################################
###     auxiliary parameters : setting defaults
####
 
my $content_length; # post body length, useless, don't touche it
my       $boundary; # something string and random, useless, don't touche it
my           $file = 'do not forgive, do not forget'; # path to image: why does it needed for?
my         $stream; # picture file content, useless, don't touche it
 
###########################################################################
###     bot engine logic
####
 
# let's do something funny!
 
# request kavai modules itt, nipa~
use warnings;
use strict;
use Socket;
use LWP::UserAgent;
use HTTP::Request::Common;
use utf8;
use Tk;
use Tk::JPEG;
use Tk::PNG;
 
# my dolls, desu
my         $user_agent;
my            $timeout = '15'; # note, u may increase it, if it often timeout die 
my           $response;
my         $picture_id = 0;
my @pictures_filenames;
 
sub    init(); # maintain most parameters
sub    main(); # main loop
sub captcha();
sub    post(); # post machine
sub    rtfm(); # RTFM bljad!!!
 
sub next_picture_path();
 
main();
 
###########################################################################
###     initialization function
####
 
sub init() {
  my $i = 0;
  #process running arguments
  foreach(@ARGV) {
    $i++;
    if(/(-pd|--pictures-directory)/) { $pictures_path = $ARGV[$i]; }
    elsif( /(-d|--delay)/)    {    $delay = $ARGV[$i]; }
    elsif( /(-c|--count)/)    {    $count = $ARGV[$i]; }
    elsif( /(-b|--board)/)    {    $board = $ARGV[$i]; }
    elsif(  /-t|--thread/)    {   $thread = $ARGV[$i]; }
    elsif(  /-n|--name/)      {     $name = $ARGV[$i]; }
    elsif(/(-ml|--mail)/)     {     $mail = $ARGV[$i]; }
    elsif( /(-s|--subject)/)  {  $subject = $ARGV[$i]; }
    elsif( /(-m|--message)/)  {  $message = $ARGV[$i]; }
    elsif(/(-cp|--captcha)/)  {  $captcha = $ARGV[$i]; }
    elsif( /(-p|--password)/) { $password = $ARGV[$i]; }
    elsif( /(-f|--file)/)     {     $file = $ARGV[$i]; push(@pictures_filenames, $file); }
    elsif( /(-h|--help)/)     { rtfm(); exit(0); }
  }
 
  die "pictures path haven't been set\n" unless defined $pictures_path;
  die         "delay haven't been set\n" unless defined $delay;
  die         "count haven't been set\n" unless defined $count || $count < -1;
  die         "board haven't been set\n" unless defined $board;
  die        "thread haven't been set\n" unless defined $thread;
  #die "didn't set\n" unless defined $name;
  #die "didn't set\n" unless defined $mail;
  #die "didn't set\n" unless defined $subject;
  #die "didn't set\n" unless defined $message;
  #die "didn't set\n" unless defined $captcha;
  #die "didn't set\n" unless defined $password;
  #die "didn't set\n" unless defined $file;
 
  # initializeing pictures files' paths
 
  opendir(DIR, $pictures_path) || die "can't opendir $pictures_path: $!";
  push(@pictures_filenames, grep(/\.(?:png|gif|jpg)$/i,readdir(DIR)));
  closedir(DIR);
 
  die "no picture is found, desu\n" unless $#pictures_filenames;
 
  $user_agent = LWP::UserAgent->new(
        agent => 'Default Browser 0',
        timeout => $timeout
  );
 
  $user_agent->timeout($timeout) if defined $timeout;
 
  utf8::decode($error_tag_start);
  utf8::decode($error_tag_stop);
  utf8::decode($error_captcha_wrong);
  utf8::decode($error_captcha_not_entered);
  utf8::decode($error_picture_repeated);
  utf8::decode($error_flood);
}
 
###########################################################################
###     main function
####
 
sub main() {
 
  init();
 
  my $condition;
 
  if($count < 0) { #infinite
    $condition = sub { return 1; };   
  }
  elsif($count > 0 ) { #n times
    $condition = sub {
      if($count > 0) { $count--; return 1; }
      else { return 0; }
    }
  }
  else { # one time
    $condition = sub {
      if($count == 0) { $count--; return 1; }
      else { return 0; }
    }
  }
 
  while(&$condition) {
  BEGIN:
    my $is_posted = 0;
 
    unless($is_posted) {
      print "trying to post, desu\n";
      my $response = post();
      if($response =~ /$error_tag_start([\S ]+)$error_tag_stop/) {
        my $error_message = $1;
        if($error_message =~ $error_captcha_not_entered) {
          print "the captcha requested, desu. enter captcha in the form, desu\n";
          captcha();
          goto BEGIN;
        } elsif($error_message =~ $error_captcha_wrong) {
          print "the captcha wrong, desu. enter captcha in the form, desu\n";
          captcha();
          goto BEGIN;
        } elsif($error_message =~ $error_picture_repeated) {
          print "the picture was posted, trying next, desu\n";
          next_picture_path();
          goto BEGIN;
        } elsif($error_message =~ $error_flood) {
          print "the server sad that i'm flooding, trying next, desu\n";
          next_picture_path();
          goto BEGIN;
        } else {
          utf8::encode($error_message);
          die "can't post: $error_message\n";
        }
      } else {
        $is_posted = 1;
        next_picture_path();
        print "the picture seems to be posted, desu. sleeping, desu\n";
        sleep $delay;
      }
    }
  }
 
  exit(0);
}
 
###########################################################################
###     captcha function
####
 
sub captcha() {
  my $response = $user_agent->get(
    "http://$host/$board/captcha.png?key=res$thread&dummy=161053819&color=000000"
  );
 
  die "can't get captcha" unless $response->is_success();
 
  my $content = $response->decoded_content();
 
  open(OUTPUT, '>', $captcha_path);
  print(OUTPUT $content);
  close(OUTPUT);
 
  my $main_window = MainWindow->new(-title => '~desu');
 
  my $label_captcha = $main_window->Label(
    -image => $main_window->Canvas()->Photo('IMG', -file => $captcha_path),
  );
 
  my $entry_captcha = $main_window->Entry(
    -background => 'white', -foreground => 'black',
  );
 
  my $button_ok = $main_window->Button(
    -command => sub { $captcha = $entry_captcha->get(); $main_window->destroy(); },
    -text => 'OK',
  );
 
  $button_ok->pack(-side => 'right', -fill => 'both',);
  $label_captcha->pack(-anchor => 'e', -side => 'top', -fill => 'both');
  $entry_captcha->pack(-side => 'bottom', -fill => 'both');
 
  MainLoop();
}
 
###########################################################################
###     post function
####
 
sub post() {
  my $picture_path = $pictures_path.'/'.$pictures_filenames[ $picture_id ];
  my $response;
    $response = $user_agent->request(POST "http://$host/$board/wakaba.pl",
              Content_Type => 'multipart/form-data',
              referer => "http://$host/$board/res/$thread.html",
              Content => [ 
              task => 'post',
              akane => $name,
        name => '',
        link => '',
        nabiki => $mail,
        kasumi => $subject,
        shampoo => $message,
        gb2 => '',
        captcha => $captcha,
        password => $password,
        parent => $thread,
        file => [ $picture_path => $picture_path => "application/octet-stream" ]
             ]
      );
  return $response->decoded_content();
}
 
###########################################################################
###     rtfm function
####
 
sub rtfm() {
  print "Available parameters:\n"
."-pd \"<parameter>\"\n"
."--pictures-directory \"<parameter>\"\n"
."\tset post pictures source path\n"
."-d \"<parameter>\"\n"
."--delay \"<parameter>\"\n"
."\tset delay time between posts\n"
."-c \"<parameter>\"\n"
."--count \"<parameter>\"\n"
."\tset post count:\n"
."\t\t-1 : inifinite posts\n"
."\t\t 0 : one post\n"
."\t\t n : n posts\n"
."-b \"<parameter>\"\n"
."--board \"<parameter>\"\n"
."\tset board url\n"
."-t \"<parameter>\"\n"
."--thread \"<parameter>\"\n"
."\tset thread id\n"
."-n \"<parameter>\"\n"
."--name \"<parameter>\"\n"
."\tset message name\n"
."-ml \"<parameter>\"\n"
."--mail \"<parameter>\"\n"
."\tset message mail\n"
."-s \"<parameter>\"\n"
."--subject \"<parameter>\"\n"
."\tset message subject\n"
."-m \"<parameter>\"\n"
."--message \"<parameter>\"\n"
."\tset message\n"
."-cp \"<parameter>\"\n"
."--captcha \"<parameter>\"\n"
."\tset message capcha value\n"
."-p \"<parameter>\"\n"
."--password \"<parameter>\"\n"
."\tset message password\n"
."-f \"<parameter>\"\n"
."--file \"<parameter>\"\n"
."\tset one post picture path\n"
."-h\n"
."--help\n"
."\tshows this help\n";
}
 
###########################################################################
###     get_next_picture_path function
####
 
sub next_picture_path() {
  if($picture_id > $#pictures_filenames) { $picture_id = 0; }
  else { $picture_id++; }
}
 
1;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License