#!/usr/bin/perl
use LWP::UserAgent;
use HTML::TreeBuilder;
use Data::Dumper;
use HTTP::Cookies;
my $forumURL="http://board.com"; # place Board address here like http://board.com
my $login="login"; # your login
my $passwd="secretpassword"; # password
my $forunePath="/home/user/MyFortune/" # path to fortune data files
my $boardEncoding="cp1251" # encoding used by the board
################################################################################3
my $ua = LWP::UserAgent->new;
my $jar = HTTP::Cookies->new(autosave => 1, file => '/tmp/SignChangeCookies.jar');
$ua->cookie_jar($jar);
my $res = $ua->get($forumURL);
die "request fails" if ! $res->is_success;
my $h = HTML::TreeBuilder->new();
$h->parse($res->content);
my @forms = $h->find_by_tag_name('form');
my $loginAction = undef;
foreach (@forms) {
if( $_->attr('action') =~ /Login/){
$loginAction = $_->attr('action');
};
}
if( defined $loginAction) {;
# already logged in
$res = $ua->post($loginAction, [{ UserName => $login, 'PassWord' => $passwd}]);
$h->parse($res->content);
my @metas = $h->find_by_tag_name('meta');
my $refreshURL = undef;
foreach (@metas){
if ( $_->attr('http-equiv') =~ /refresh/i){
$refreshURL = $_->attr('content');
$refreshURL =~ s/.*url=(.*)$/$1/;
}
}
die "No refresh URL found. Failed login?" if ! defined $refreshURL;
sleep 1;
$res = $ua->get($refreshURL);
$h->parse($res->content);
}
my @links = $h->find_by_tag_name('a');
my $cplink = undef;
foreach (@links){
if ($_->attr('href') =~ /act=UserCP.*CODE=00/i){
$cplink = $_->attr('href');
$cplink =~ s/CODE=\d+/CODE=22/;
}
}
if (! defined $cplink) {
die "No CPLINK URL found."
};
$res = $ua->get($cplink);
$h->parse($res->content);
my $form = $h->find_by_attribute('name','REPLIER');
die "No REPLIER form found." if ! $form;
my %vals = {};
my $formURL = $form->attr('action');
foreach ($form->find_by_tag_name('input')) {
$vals{$_->attr('name')} = $_->attr('value');
}
$vals{'Post'} = `fortune $forunePath | recode utf8..$boardEncoding`;
$res = $ua->post($formURL,\%vals);
# By Constantine Deribin
# Feel free to use it and have fun!