| 1 | package Finance::Bank::Commerzbank; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | our $VERSION = '0.29'; | ||
| 5 | |||
| 6 | 1 | ▶ | use WWW::Mechanize; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use WWW::Mechanize::FormFiller; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use URI::URL; | ||
| 9 | our $ua = WWW::Mechanize->new( autocheck => 1 ); | ||
| 10 | our $formfiller = WWW::Mechanize::FormFiller->new(); | ||
| 11 | use Time::localtime; | ||
| 12 | |||
| 13 | sub check_balance { | ||
| 14 | my ($class, %opts) = @_; | ||
| 15 | my %HashOfAccounts; | ||
| 16 | croak "Must provide a Teilnehmernummer" | ||
| 17 | unless exists $opts{Teilnehmernummer}; | ||
| 18 | croak "Must provide a PIN" | ||
| 19 | unless exists $opts{PIN}; | ||
| 20 | my $self = bless { %opts }, $class; | ||
| 21 | |||
| 22 | $ua->env_proxy(); | ||
| 23 | $ua->get('https://portal01.commerzbanking.de/P-Portal/XML/IFILPortal/pgf.html?Tab=1'); | ||
| 24 | $ua->form(1) if $ua->forms and scalar @{$ua->forms}; | ||
| 25 | $ua->form_number(4); | ||
| 26 | { | ||
| 27 | local $^W; $ua->current_form->value('PltLogin_8_txtTeilnehmernummer', $opts{Teilnehmernummer}); | ||
| 28 | } | ||
| 29 | ; | ||
| 30 | { | ||
| 31 | local $^W; $ua->current_form->value('PltLogin_8_txtPIN', $opts{PIN}); | ||
| 32 | } | ||
| 33 | ; | ||
| 34 | $ua->click('PltLogin_8_btnLogin'); | ||
| 35 | my @links=$ua->find_all_links(); | ||
| 36 | my $n; | ||
| 37 | for ($n=0;$n<$#links;$n++) { | ||
| 38 | my ($url,$title)=@{$links[$n]}; | ||
| 39 | if ($opts{"debug"} eq "1") { | ||
| 40 | print "LINK------>".$n." - ".$title."\n"; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | if (0) { | ||
| 44 | $ua->follow_link(text=>"Kontoübersicht"); | ||
| 45 | my $Overview=$ua->content; | ||
| 46 | my $Konto; | ||
| 47 | while (index($Overview,"PltViewAccountOverview_8_STR_KontoNummer")>-1) { | ||
| 48 | $Konto=substr ($Overview,index($Overview,"PltViewAccountOverview_8_STR_KontoNummer")+46,15); | ||
| 49 | $Overview=substr ($Overview,index($Overview,"PltViewAccountOverview_8_STR_KontoNummer")+46); | ||
| 50 | if ($opts{"debug"} eq "1") { | ||
| 51 | print $Konto."\n"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | $ua->follow_link(text => "Kontoumsätze"); | ||
| 56 | @links=$ua->find_all_links(); | ||
| 57 | for ($n=0;$n<$#links;$n++) { | ||
| 58 | my ($url,$title)=@{$links[$n]}; | ||
| 59 | print "LINK------>".$n." - ".$title."\n"; | ||
| 60 | } | ||
| 61 | |||
| 62 | if ($opts{"debug"} eq "1") { | ||
| 63 | write_file($ua->content,"/tmp/Commerzbank-0"); | ||
| 64 | } | ||
| 65 | if ( $ua->form_number(5)) { | ||
| 66 | if ($opts{"debug"} eq "1") { | ||
| 67 | write_file($ua->content,"/tmp/Commerzbank-1"); | ||
| 68 | } | ||
| 69 | { | ||
| 70 | local $^W; $ua->current_form->value('PltViewAccountTransactions_8_STR_CodeZeitrahmen', '90 Tage'); | ||
| 71 | local $^W; $ua->current_form->value('PltViewAccountTransactions_8_STR_KontoNr', $opts{Kontonummer}); | ||
| 72 | } | ||
| 73 | ; | ||
| 74 | my $response= $ua->click('PltViewAccountTransactions_8_btnAnzeigen'); | ||
| 75 | write_file($ua->content,"/tmp/Account"); | ||
| 76 | $ua->form_number(4); | ||
| 77 | $ua->click('PltHomeTeaser_3_btnLogout'); | ||
| 78 | } else { | ||
| 79 | print "Could not log on - wait timeout detected..\n"; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | use HTML::TableContentParser; | ||
| 85 | my $p = HTML::TableContentParser->new(); | ||
| 86 | |||
| 87 | open(IN,"</tmp/Account"); | ||
| 88 | my $Data; | ||
| 89 | my $go; | ||
| 90 | while (<IN>) { | ||
| 91 | if (index($_,"Buchungstag")>-1) { | ||
| 92 | $go=1; | ||
| 93 | } | ||
| 94 | if ($go) { | ||
| 95 | $Data.=$_; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | if ( ($opts{"debug"} ne "1") && ( -r "/tmp/Account" )) { | ||
| 99 | # We remove the temporary file only in non-debug mode... | ||
| 100 | `rm /tmp/Account`; | ||
| 101 | } | ||
| 102 | |||
| 103 | my $tables = $p->parse($Data); | ||
| 104 | my $t; | ||
| 105 | my $r; | ||
| 106 | my @accounts; | ||
| 107 | for $t (@$tables) { | ||
| 108 | my $j=0; | ||
| 109 | for $r (@{$t->{rows}}) { | ||
| 110 | my $i=0; | ||
| 111 | my $IsOk=0; | ||
| 112 | my $c; | ||
| 113 | my @line; | ||
| 114 | for $c (@{$r->{cells}}) { | ||
| 115 | # print "CELL :$i\n"; | ||
| 116 | my $Data; | ||
| 117 | if (($i == 1 ) || ($i == 5 )|| ($i == 7 ) ) { | ||
| 118 | |||
| 119 | $Data=substr($c->{data},index($c->{data},"tablehead1")+12,1000); | ||
| 120 | $Data =~ s/<\/span><br>//g; | ||
| 121 | $Data =~s/<BR>/#/g; | ||
| 122 | my $year=localtime->year()+1900; | ||
| 123 | my $year_before=localtime->year()+1900-1; | ||
| 124 | if (($i ==1 ) && ( (index($Data,$year)>-1) || (index($Data,$year_before)>-1))) { | ||
| 125 | $IsOk=1; | ||
| 126 | $j++; | ||
| 127 | # print "Transaction - $j:"; | ||
| 128 | } | ||
| 129 | if ($IsOk) { | ||
| 130 | push @line,$Data; | ||
| 131 | # print "Push IsOK".$Data.";"; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | if ($i == 10) { | ||
| 135 | # print "[$c->{data}]"; | ||
| 136 | if (index($c->{data},'"red">')> -1) { | ||
| 137 | $Data=substr($c->{data},index($c->{data},"red")+5,1000); | ||
| 138 | } | ||
| 139 | if (index($c->{data},'"green">')> -1) { | ||
| 140 | $Data=substr($c->{data},index($c->{data},"green")+7,1000); | ||
| 141 | } | ||
| 142 | $Data =~ s/<\/span><br>//g; | ||
| 143 | if ($IsOk) { | ||
| 144 | $Data =~ s/\.//g; | ||
| 145 | push @line,$Data; | ||
| 146 | push @accounts, (bless { | ||
| 147 | TradeDate => $line[0], | ||
| 148 | Description => $line[1], | ||
| 149 | ValueDate => $line[2], | ||
| 150 | Amount => $line[3], | ||
| 151 | parent => $self | ||
| 152 | }, "Finance::Bank::Commerzbank::Account"); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | $i++; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | return @accounts; | ||
| 160 | } | ||
| 161 | |||
| 162 | sub money_transfer { | ||
| 163 | my ($class, %opts) = @_; | ||
| 164 | #Checking all necessary InputParameters | ||
| 165 | croak "Must provide : Teilnehmernummer" | ||
| 166 | unless exists $opts{Teilnehmernummer}; | ||
| 167 | croak "Must provide : PIN" | ||
| 168 | unless exists $opts{PIN}; | ||
| 169 | croak "Must provide : TANPIN" | ||
| 170 | unless exists $opts{TANPIN}; | ||
| 171 | croak "Must provide : EmpfaengerName" | ||
| 172 | unless exists $opts{EmpfaengerName}; | ||
| 173 | croak "Must provide : EmpfaengerKtoNr" | ||
| 174 | unless exists $opts{EmpfaengerKtoNr}; | ||
| 175 | croak "Must provide : EmpfaengerBLZ" | ||
| 176 | unless exists $opts{EmpfaengerBLZ}; | ||
| 177 | croak "Must provide : Betrag_Eingabe" | ||
| 178 | unless exists $opts{Betrag_Eingabe}; | ||
| 179 | |||
| 180 | my $self = bless { %opts }, $class; | ||
| 181 | |||
| 182 | $ua->env_proxy(); | ||
| 183 | |||
| 184 | $ua->get('https://portal01.commerzbanking.de/P-Portal/XML/IFILPortal/pgf.html?Tab=1'); | ||
| 185 | $ua->form(1) if $ua->forms and scalar @{$ua->forms}; | ||
| 186 | $ua->form_number(4); | ||
| 187 | { | ||
| 188 | local $^W; $ua->current_form->value('PltLogin_8_txtTeilnehmernummer', $opts{Teilnehmernummer}); | ||
| 189 | } | ||
| 190 | ; | ||
| 191 | { | ||
| 192 | local $^W; $ua->current_form->value('PltLogin_8_txtPIN', $opts{PIN}); | ||
| 193 | } | ||
| 194 | ; | ||
| 195 | $ua->click('PltLogin_8_btnLogin'); | ||
| 196 | my @links=$ua->find_all_links(); | ||
| 197 | my $n; | ||
| 198 | for ($n=0;$n<$#links;$n++) { | ||
| 199 | my ($url,$title)=@{$links[$n]}; | ||
| 200 | print "LINK------>".$n." - ".$title."\n"; | ||
| 201 | |||
| 202 | } | ||
| 203 | $ua->follow_link(text => "Inlandsüberweisung"); | ||
| 204 | @links=$ua->find_all_links(); | ||
| 205 | for ($n=0;$n<$#links;$n++) { | ||
| 206 | my ($url,$title)=@{$links[$n]}; | ||
| 207 | print "LINK------>".$n." - ".$title."\n"; | ||
| 208 | |||
| 209 | } | ||
| 210 | if ($opts{"debug"} eq "1") { | ||
| 211 | write_file($ua->content,"/tmp/Commerzbank-0"); | ||
| 212 | } | ||
| 213 | if ( $ua->form_number(5)) { | ||
| 214 | if ($opts{"debug"} eq "1") { | ||
| 215 | write_file($ua->content,"/tmp/Commerzbank-1"); | ||
| 216 | } | ||
| 217 | { | ||
| 218 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_EmpfaengerName', $opts{EmpfaengerName}); | ||
| 219 | } | ||
| 220 | ; | ||
| 221 | { | ||
| 222 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_EmpfaengerKtoNr', $opts{EmpfaengerKtoNr}); | ||
| 223 | } | ||
| 224 | ; | ||
| 225 | { | ||
| 226 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_EmpfaengerBLZ', $opts{EmpfaengerBLZ}); | ||
| 227 | } | ||
| 228 | ; | ||
| 229 | { | ||
| 230 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_DBL_Betrag_Eingabe',$opts{Betrag_Eingabe}); | ||
| 231 | } | ||
| 232 | ; | ||
| 233 | { | ||
| 234 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_Verwendungszweck1', $opts{Verwendungszweck1}); | ||
| 235 | } | ||
| 236 | ; | ||
| 237 | { | ||
| 238 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_Verwendungszweck2', $opts{Verwendungszweck2}); | ||
| 239 | } | ||
| 240 | ; | ||
| 241 | { | ||
| 242 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_Verwendungszweck3', $opts{Verwendungszweck3}); | ||
| 243 | } | ||
| 244 | ; | ||
| 245 | { | ||
| 246 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_Verwendungszweck4', $opts{Verwendungszweck4}); | ||
| 247 | } | ||
| 248 | ; | ||
| 249 | { | ||
| 250 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_CBO_Konten', $opts{Auftragskonto}); | ||
| 251 | } | ||
| 252 | ; | ||
| 253 | print "Empfaenger :".$opts{EmpfaengerName}."\n"; | ||
| 254 | print "Empfaenger Kto :".$opts{EmpfaengerKtoNr}."\n"; | ||
| 255 | print "Empfaenger BLZ :".$opts{EmpfaengerBLZ}."\n"; | ||
| 256 | print "Empfaenger Betrag:".$opts{Betrag_Eingabe}."\n"; | ||
| 257 | print "VZ 1 :".$opts{Verwendungszweck1}."\n"; | ||
| 258 | print "VZ 2 :".$opts{Verwendungszweck2}."\n"; | ||
| 259 | print "VZ 3 :".$opts{Verwendungszweck3}."\n"; | ||
| 260 | print "VZ 4 :".$opts{Verwendungszweck4}."\n"; | ||
| 261 | my $response= $ua->click('PltManageDomesticTransfer_8_btnPruefenDomestic'); | ||
| 262 | #$ua->click('PltManageDomesticTransfer_8_btnPruefenDomestic'); | ||
| 263 | sleep(3); | ||
| 264 | $ua->form_number(5); | ||
| 265 | { | ||
| 266 | local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_STR_FECAF5D9B9AF914896', $opts{TANPIN}); | ||
| 267 | #The Form has changed.... below the old input for the tan | ||
| 268 | #local $^W; $ua->current_form->value('PltManageDomesticTransfer_8_txtTANPIN', $opts{TANPIN}); | ||
| 269 | } | ||
| 270 | ; | ||
| 271 | $ua->click('PltManageDomesticTransfer_8_btnFreigebenDomestic'); | ||
| 272 | $ua->form_number(4); | ||
| 273 | |||
| 274 | |||
| 275 | if ($opts{"debug"} eq "1") { | ||
| 276 | write_file($ua->content,"/tmp/Commerzbank-2"); | ||
| 277 | } | ||
| 278 | $ua->form_number(4); | ||
| 279 | $ua->click('PltHomeTeaser_3_btnLogout'); | ||
| 280 | } else { | ||
| 281 | print "Could not log on - wait timeout detected..\n"; | ||
| 282 | } | ||
| 283 | |||
| 284 | |||
| 285 | } | ||
| 286 | |||
| 287 | sub write_file { | ||
| 288 | my ($Data,$FileName)=@_; | ||
| 289 | open( OUT , ">".$FileName); | ||
| 290 | print OUT $Data; | ||
| 291 | close(OUT); | ||
| 292 | } | ||
| 293 | |||
| 294 | |||
| 295 | |||
| 296 | |||
| 297 | package Finance::Bank::Commerzbank::Account; | ||
| 298 | # Basic OO smoke | ||
| 299 | no strict; | ||
| 300 | sub AUTOLOAD { my $self=shift; $AUTOLOAD =~ s/.*:://; $self->{$AUTOLOAD} } | ||
| 301 | |||
| 302 | __END__ | ||