--- a/Smile.pm 2007-06-19 17:39:51.000000000 +0000
+++ b/Smile.pm 2011-10-26 03:08:20.464999714 +0000
@@ -27,7 +27,7 @@ sub check_balance {
if ( !exists $opts{firstSchool} ) { croak 'Must provide first school' }
- my $start_page = '
http://www.smile.co.uk/';
+ my $start_page = '
https://banking.smile.co.uk/SmileWeb/start.do';
# hackery for https proxy support
my $https_proxy = $ENV{https_proxy};
@@ -36,21 +36,42 @@ sub check_balance {
my $mech = WWW::Mechanize->new( env_proxy => 1 );
$mech->get($start_page);
- # click on "bank login"
- $mech->follow_link( n => 1 );
+ if ($DEBUG) { print $mech->content(); }
- _follow_meta_refresh($mech);
$mech->submit_form(
form_number => 1,
fields => {
sortCode => $opts{sortCode},
accountNumber => $opts{accountNumber},
- passNumber => $opts{passNumber},
}
);
# now we have to put in the secret info
my $content = $mech->content();
+ if ($DEBUG) { print $content; }
+
+ my ($first_digit, $second_digit);
+
+ if ($content =~ /enter the (first|second|third|fourth) and (first|second|third|fourth) digits of your security code and click/i) {
+ $first_digit = _get_pass_digit($1, $opts{passNumber});
+ $second_digit = _get_pass_digit($2, $opts{passNumber});
+ } else {
+ croak 'expected to be asked for two passnumber digits';
+ }
+
+ if ($DEBUG) { print "Supplying $first_digit and $second_digit\n"; }
+
+ $mech->submit_form(
+ form_number => 1,
+ fields => {
+ firstPassCodeDigit => $first_digit,
+ secondPassCodeDigit => $second_digit,
+ }
+ );
+
+ $content = $mech->content();
+ if ($DEBUG) { print $content; }
+
switch ($content) {
case /memorabledate/ {
my ( $day, $month, $year ) =
@@ -136,6 +157,24 @@ sub check_balance {
return @accounts;
}
+sub _get_pass_digit
+{
+ my ($wanted_digit_word, $passnum) = @_;
+
+ my %word2digit = (
+ first => 0,
+ second => 1,
+ third => 2,
+ fourth => 3,
+ );
+
+ if (not exists $word2digit{$wanted_digit_word}) {
+ croak "Unknown passnumber digit '$wanted_digit_word'";
+ }
+
+ return substr($passnum, $word2digit{$wanted_digit_word}, 1);
+}
+
sub _follow_meta_refresh{
my $mech = shift;
if ( $mech->response and my $refresh = $mech->response->header('Refresh') )