script/wachovia_summary.pl untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 46 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 170 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 };
13  
14 # parse command line options -- see perldocs for info
15 for (@ARGV){
16 $opts->{lc($1)} = $2 if /--(\w+)=(.+)/g;
17 $opts->{lc($1)} = 1 if /^--(\w+)$/g;
18 }
19  
20 # Since I can never remember myself which one of these it is, then
21 # why not make them all valid?
22 my $userid;
23 my $password;
24 $opts->{user_id} = $userid if( $userid = $opts->{userid}
25 || $opts->{user_id}
26 || $opts->{user}
27 || $opts->{login}
28 || $opts->{'user-id'}
29 || $opts->{id}
30 || $opts->{name}
31 );
32
33 $opts->{password} = $password if( $password = $opts->{password}
34 || $opts->{pass}
35 || $opts->{pw}
36 );
37  
38 if( $opts->{key} ){
39 eval {
40 require Crypt::CBC;
41 import Crypt::CBC;
42 };
43 if($@){ die "Must have Crypt::CBC and Crypt::DES_PP module installed to use --key feature: $@\n" }
44  
45 # if here, then user provided key + some info, so we want to preserve whatever it is they provided
46 # while keeping whatever it is they didn't provide.
47 my $new_opts = {};
48 my $file_opts = get_account_info( $opts->{keyfile}, $opts->{key} );
49 for(keys %$opts){ $new_opts->{$_} = $opts->{$_} }
50 for(keys %$file_opts){ $new_opts->{$_} = $file_opts->{$_} unless $new_opts->{$_} }
51 $opts = $new_opts;
52 save_account_info( $opts );
53 }
54 else{
55 # if here, then the user must provide all the info them self, and they don't plan on keeping it
56 # in a key-file.
57 unless( ( $opts->{can} && $opts->{pin} && $opts->{codeword} ) || ( $opts->{userid} && $opts->{password} ) ){
58 print "Need either login info, or file-key to login. see `perldoc wachovia.pl`\n";
59 exit(1);
60 }
61 }
62 my $x;
63  
64 my %login_info = $opts->{userid}
65 ? ( user_id => $opts->{userid}, password => $opts->{password} )
66 : ( customer_access_number => $opts->{can}, pin => $opts->{pin}, code_word => $opts->{codeword} );
67
68 my $wachovia = Finance::Bank::Wachovia->new( %login_info )
69 or die Finance::Bank::Wachovia->ErrStr;
70  
71 my @account_nums = $wachovia->account_numbers();
72  
73 die $wachovia->ErrStr()
74 if $wachovia->ErrStr;
75  
76 my($num, $name, $type, $bal) = qw/Number Name Type Balance/;
77 format Summary =
78 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>
79 $num, $name, $bal
80 .
81 $~ = 'Summary';
82 write;
83 print <<EOF;
84 ================= ========================= ===========
85 EOF
86  
87 foreach $num ( @account_nums ){
88 my $a = $wachovia->account( $num );
89 $name = $a->name or die $a->ErrStr;
90 #$type = $a->type or die $a->ErrStr;
91 $bal = $a->balance or die $a->ErrStr;
92 write;
93 }
94  
95  
96  
97 #==============================================================================
98 # Fills the options hash with account info from the local .wachovia file
99 sub get_account_info {
100 my($keyfile, $key) = @_;
101 my $opts;
102 return unless -e $keyfile;
103 open( F, $keyfile ) or die "Can't open ".$keyfile." for reading: $!";
104 my $cipher = Crypt::CBC->new({
105 'key'=> $key,
106 'cipher'=> 'DES_PP',
107 'iv'=> '%_j,!z"{'
108 });
109 my $plaintext = $cipher->decrypt( <F> );
110 my @opts = split( /\//, $plaintext );
111 for( @opts ){
112 my($k, $v) = split(/=>/);
113 $opts->{$k} = $v;
114 }
115 return $opts;
116 }
117  
118 # Writes an MD5 hash for the hash info.
119 sub save_account_info {
120 my $opts = shift;
121 open( F, '>', $opts->{keyfile} ) or die "Can't open ".$opts->{keyfile}." for writing: $!";
122 my $cipher = Crypt::CBC->new({
123 'key'=> $opts->{key},
124 'cipher'=> 'DES_PP',
125 'iv'=> '%_j,!z"{'
126 });
127 my $ciphertext = $cipher->encrypt( join('/', (map { "$_=>".$opts->{$_} } keys %$opts) ) );
128 print F $ciphertext;
129 close( F );
130 return 1;
131 }
132  
133  
134 __END__