script/wachovia.pl untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 24 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 141 SCAR 17.9
CC
2
Cov
0%
get_account_info
6.0
save_account_info
2.0
BEGIN
2.0
CRAP 6.0
1 #!/usr/local/bin/perl
2  
3 use Finance::Bank::Wachovia;
4 use Crypt::CBC;
5 use strict;
6 $| = 1;
7  
8 our $VERSION = 0.3;
9  
10 # set option defaults
11 my $opts = {
12 keyfile => $ENV{HOME}.'/.wachovia', # file that stores encrypted login info + account number
13 details => 1, # report type: balance|summary|details
14 };
15 # parse command line options -- see perldocs for info
16 for (@ARGV){
17 $opts->{lc($1)} = $2 if /--(\w+)=(.+)/g;
18 $opts->{lc($1)} = 1 if /^--(\w+)$/g;
19 }
20  
21 if( $opts->{key} ){
22 eval {
23 require Crypt::CBC;
24 import Crypt::CBC;
25 };
26 if($@){ die "Must have Crypt::CBC and Crypt::DES_PP module installed to use --key feature: $@\n" }
27  
28 # if here, then user provided key + some info, so we want to preserve whatever it is they provided
29 # while keeping whatever it is they didn't provide.
30 my $new_opts = {};
31 my $file_opts = get_account_info( $opts->{keyfile}, $opts->{key} );
32 for(keys %$opts){ $new_opts->{$_} = $opts->{$_} }
33 for(keys %$file_opts){ $new_opts->{$_} = $file_opts->{$_} unless $new_opts->{$_} }
34 $opts = $new_opts;
35 save_account_info( $opts );
36 }
37 else{
38 # if here, then the user must provide all the info them self, and they don't plan on keeping it
39 # in a key-file.
40 unless( ( $opts->{can} && $opts->{pin} && $opts->{codeword} ) || ( $opts->{userid} && $opts->{password} ) ){
41 print "Need either login info, or file-key to login. see `perldoc wachovia.pl`\n";
42 exit(1);
43 }
44 }
45 my $x;
46  
47 my %login_info = $opts->{userid}
48 ? ( user_id => $opts->{userid}, password => $opts->{password} )
49 : ( customer_access_number => $opts->{can}, pin => $opts->{pin}, code_word => $opts->{codeword} );
50
51 my $wachovia = Finance::Bank::Wachovia->new( %login_info )
52 or die Finance::Bank::Wachovia->ErrStr;
53  
54 my $account = $wachovia->account( $opts->{account} )
55 or die $wachovia->ErrStr;
56
57 print $account->available_balance, "\n" and exit if $opts->{balance};
58 print "Acct Number: ", $account->number, "\n";
59 print "Acct Name : ", $account->name, ($opts->{details}?" ( ".$account->type." )":''), "\n";
60 print "Avail. Bal.: ", $account->available_balance, "\n";
61 exit unless $opts->{details};
62 print "Posted.Bal.: ", $account->posted_balance, "\n";
63
64 my $transactions = $account->transactions
65 or die $account->ErrStr;
66  
67 my($date, $desc, $with, $deposit, $bal) = qw/Date Description Withdrawal Deposit Balance/;
68 format Transactions =
69 @<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>>
70 $date, $desc, $with, $deposit, $bal
71 .
72 $~ = 'Transactions';
73 write;
74 print <<EOF;
75 ===== ================================================= =========== =========== ===========
76 EOF
77 foreach my $t ( (reverse @$transactions)[0..10] ){
78 $date = substr $t->date, 0, 5;
79 $desc = $t->description;
80 $with = $t->withdrawal_amount ? $t->withdrawal_amount : '';
81 $deposit = $t->deposit_amount ? $t->deposit_amount : '';
82 $bal = $t->balance ? $t->balance : '';
83 write;
84 #print"Date: ", $t->date, "\n",
85 # "Action: ", $t->action, "\n",
86 # "Desc: ", $t->description, "\n",
87 # "Withdrawal", $t->withdrawal_amount, "\n",
88 # "Deposit", $t->deposit_amount, "\n",
89 # "Balance", $t->balance, "\n",
90 # "seq_no", $t->seq_no, "\n",
91 # "trans_code", $t->trans_code, "\n",
92 # "check_num", $t->check_num, "\n";
93 }
94  
95
96 #==============================================================================
97 # Fills the options hash with account info from the local .wachovia file
98 sub get_account_info {
99 my($keyfile, $key) = @_;
100 my $opts;
101 return unless -e $keyfile;
102 open( F, $keyfile ) or die "Can't open ".$keyfile." for reading: $!";
103 my $cipher = Crypt::CBC->new({
104 'key'=> $key,
105 'cipher'=> 'DES_PP',
106 'iv'=> '%_j,!z"{'
107 });
108 my $plaintext = $cipher->decrypt( <F> );
109 my @opts = split( /\//, $plaintext );
110 for( @opts ){
111 my($k, $v) = split(/=>/);
112 $opts->{$k} = $v;
113 }
114 return $opts;
115 }
116  
117 # Writes an MD5 hash for the hash info.
118 sub save_account_info {
119 my $opts = shift;
120 open( F, '>', $opts->{keyfile} ) or die "Can't open ".$opts->{keyfile}." for writing: $!";
121 my $cipher = Crypt::CBC->new({
122 'key'=> $opts->{key},
123 'cipher'=> 'DES_PP',
124 'iv'=> '%_j,!z"{'
125 });
126 my $ciphertext = $cipher->encrypt( join('/', (map { "$_=>".$opts->{$_} } keys %$opts) ) );
127 print F $ciphertext;
128 close( F );
129 return 1;
130 }
131  
132  
133  
134 __END__