Advertisement
theanonym

bump-wipe.pl

Dec 14th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.20 KB | None | 0 0
  1. #!/usr/bin/perl -X
  2. # Кодировка: utf-8
  3. # Требуется пакет libgtk2-perl
  4. use strict;
  5. use autodie;
  6. use Gtk2 -init;
  7. use LWP::UserAgent;
  8. use File::Temp qw/tempfile/;
  9. use utf8;
  10. $| = 1;
  11.  
  12. #--------------------------------------------------------------------------
  13.  
  14. my $board  = "b"; # Доска
  15. my $page   = 60;  # Стартовая страница, с которой бампать треды
  16.  
  17. my $file    = "pedal.jpg"; # Файл
  18. my $timeout = 15; # Сколько ждать ответ сервера
  19.  
  20. #--------------------------------------------------------------------------
  21.  
  22. my $lwp = new LWP::UserAgent;
  23. $lwp->agent("Opera/9.80 (X11; Linux i686; U; en) Presto/2.10.229 Version/11.60");
  24. $lwp->default_header("Referer" => "http://iichan.ru/");
  25. $lwp->timeout($timeout);
  26.  
  27. while(1) {
  28.    foreach my $thread (keys %{find_threads()}) {
  29.       print "Выбран тред: $thread\n";
  30.       my $file = get_captcha($thread);
  31.       my $captcha = display_captcha($file);
  32.       send_post($thread, $captcha);
  33.       unlink($file);
  34.       print "-" x 30, "\n";
  35.    }
  36.    $page--;
  37. }
  38.  
  39. sub find_threads {
  40.    my %threads;
  41.    while($page >= 0) {
  42.       print "Поиск подходящих тредов (страница: $page): ";
  43.       %threads = $lwp->get("http://iichan.ru/$board/$page.html")->decoded_content()
  44.          =~ /(\d+)\.html">Ответ.*?Пропущено (\d+) сообщений/gs;
  45.       die("Что-то пошло не так.\n") unless(%threads);
  46.       for(keys %threads) {
  47.          delete $threads{$_} if($threads{$_} >= 490);
  48.       }
  49.       if(%threads) {
  50.          printf("%d найдено.\n", scalar(keys %threads));
  51.          last;
  52.       } else {
  53.          print "Все треды на странице в бамплимите.\n";
  54.          $page--;
  55.       }
  56.    }
  57.    die "подходящие треды не найдены.\n" unless(%threads);
  58.    return \%threads;
  59. }
  60.  
  61. sub get_captcha {
  62.    my($thread) = @_;
  63.    my $script = ($board ne "b") ? "captcha.pl" : "captcha1.pl";
  64.    for(1..3) {
  65.       print "Капча: ";
  66.       my $response = $lwp->get("http://iichan.ru/cgi-bin/$script/$board/?key=res$thread&dummy=");
  67.       if($response->{_headers}->{"content-type"} eq "image/gif") {
  68.          print "Успешно\n";
  69.          my($fh, $file) = tempfile();
  70.          binmode $fh;
  71.          print $fh $response->content();
  72.          return $file;
  73.       } else {
  74.          printf("Ошибка соединения (%s)\n", substr($response->status_line(), 0, 20));
  75.       }
  76.    }
  77.    die "Не удалось скачать капчу.\n";
  78. }
  79.  
  80. sub send_post {
  81.    my($thread, $captcha) = @_;
  82.    #----------------------------------------
  83.    my $image;
  84.    open(my $fh, $file);
  85.    my $buffer;
  86.    $image .= $buffer
  87.       while(sysread($fh, $buffer, (stat($fh))[7]));
  88.    $image .= substr(rand, -6);
  89.    #----------------------------------------
  90.    print "Пост: ";
  91.    my $response = $lwp->post("http://iichan.ru/cgi-bin/wakaba.pl/$board/",
  92.       Content_Type => "form-data",
  93.       Content => [
  94.          task   => "post",
  95.          parent => $thread || "",
  96.          nya3   => "", # Subject
  97.          nya4   => "", # Message
  98.          file   => [undef, $file,
  99.                       Content_Type => "*/*",
  100.                       Content => $image],
  101.          captcha  => $captcha,
  102.          password => "",
  103.       ]
  104.    );
  105.    #----------------------------------------
  106.    if($response->headers_as_string() =~ /Location:/) {
  107.       print "Успешно\n";
  108.       return 1;
  109.    } elsif($response->code() == 200) {
  110.       printf("Ошибка (%s)\n", parse_error($response));
  111.    } else {
  112.       printf("Ошибка соединения (%s)\n", substr($response->status_line(), 0, 20));
  113.    }
  114.    return 0;
  115. }
  116.  
  117. sub parse_error {
  118.    my($response) = @_;
  119.    my($error) = $response->decoded_content() =~ /(Введён неверный код подтверждения|Код подтверждения не найден в базе|Тред не существует|Изображение слишком большое|Введён неверный пароль для удаления|Флуд|Строка отклонена)/;
  120.    return $error || "Неизвестная ошибка движка";
  121. }
  122.  
  123. sub display_captcha {
  124.    my($filename) = @_;
  125.    my $return_text;
  126.    die(qq/Bad file "$filename"/)
  127.       unless(-B $filename);
  128.    #----------------------------------------
  129.    my $main_window = new Gtk2::Window("toplevel");
  130.    $main_window->set_position("center");
  131.    $main_window->set_title("Капча");
  132.    $main_window->signal_connect(destroy => sub { Gtk2->main_quit() });
  133.    #----------------------------------------
  134.    my $vbox = new Gtk2::VBox;
  135.    my $image = Gtk2::Image->new_from_file($filename);
  136.    my $entry = new Gtk2::Entry;
  137.    $entry->signal_connect(
  138.       activate => sub {
  139.          $return_text = $entry->get_text();
  140.          $main_window->destroy();
  141.          Gtk2->main_quit();
  142.       },
  143.    );
  144.    #----------------------------------------
  145.    $vbox->pack_start($image, 0, 0, 20);
  146.    $vbox->pack_start($entry, 0, 0, 0);
  147.    $main_window->add($vbox);
  148.    $main_window->show_all();
  149.    #----------------------------------------
  150.    Gtk2->main();
  151.    return $return_text;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement