#! /usr/bin/env perl ## ---------------------------------------------------------------------------- ## "THE BEER-WARE LICENSE" (Revision 42): ## wrote this file. As long as you retain this notice you ## can do whatever you want with this stuff. If we meet some day, and you think ## this stuff is worth it, you can buy me a beer in return. Florent Thoumie ## ---------------------------------------------------------------------------- ## ## This is teh config part. ## my $acct_reg = ""; # This is your AIB registration number (9 digits) my $acct_pac = ""; # This is your Personal Access Code (5 digits) my $acct_phonehome = ""; # This is your Home Phone Number my $acct_phonework = ""; # This is your Work Phone Number ## ## Don't modify anything after this line unless you know what you're doing. ## use strict; use warnings; use WWW::Mechanize; use HTML::TokeParser; my $agent; my $stream; my $tag; my $token; my @digits; my $phone; my $version = "20090424"; $agent = WWW::Mechanize->new(); my $loginpage = "https://aibinternetbanking.aib.ie/inet/roi/login.htm"; sub get_transaction_token() { my $token; while (my $tag = $stream->get_tag("input")) { next unless exists($tag->[1]{name}); next unless ($tag->[1]{name} eq "transactionToken"); $token = $tag->[1]{value} and last; } die unless $token; return $token; } ## ## First login page (Registration number). ## $agent->get($loginpage); $stream = HTML::TokeParser->new(\$agent->{content}); $token = get_transaction_token(); $agent->submit_form( form_name => 'form1', fields => { regNumber => $acct_reg, transactionToken => $token, jsEnabled => "FALSE", "_target1" => "true", }, ); $token = ""; ## ## Second login page (personal access code, phone). ## $stream = HTML::TokeParser->new(\$agent->{content}); $token = get_transaction_token(); my $digitno; while (my $tag = $stream->get_tag("strong")) { my $text = $stream->get_trimmed_text("/strong"); if ($text =~ /^Digit/) { $digitno = $text; $digitno =~ s/.*(\d)$/$1/; push(@digits, substr($acct_pac, $digitno-1, 1)); } elsif ($text =~ /work/) { $phone = substr($acct_phonework, -4, 4) } elsif ($text =~ /home/) { $phone = substr($acct_phonehome, -4, 4) } else { next; } } # Quick sanity checks die unless ($digits[0]); die unless ($digits[1]); die unless ($digits[2]); die unless ($phone); $agent->submit_form( form_name => 'loginstep2', fields => { "pacDetails.pacDigit1" => $digits[0], "pacDetails.pacDigit2" => $digits[1], "pacDetails.pacDigit3" => $digits[2], "challengeDetails.challengeEntered" => $phone, "transactionToken" => $token, "_finish" => "true", }, ); ## ## Account summary ## $stream = HTML::TokeParser->new(\$agent->{content}); my ($name, $balance); my @header = ("Account name", "Balance"); my @sep = ("--------------------------------", "-------------"); format ACCOUNT = | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>> | $name, $balance . $~ = "ACCOUNT"; $token = get_transaction_token(); ($name, $balance) = @sep; write; ($name, $balance) = @header; write; ($name, $balance) = @sep; write; while ($tag = $stream->get_tag("span")) { my $text = $stream->get_trimmed_text("/span"); #print "$text\n"; next unless ($text =~ /\d{3}$/); $name = $text; $stream->get_tag("h3"); $balance = $stream->get_trimmed_text("/h3"); $balance =~ s/\s+.*//; write; } ($name, $balance) = @sep; write; $~ = "STDOUT"; #$agent->submit_form( # form_name => 'form1', # fields => { # transactionToken => $token, # }, #)