script/wachovia.pl untested

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