| 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 | }; | ||
| 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_nums = $wachovia->account_numbers(); | ||
| 55 | |||
| 56 | my($num, $name, $type, $bal) = qw/Number Name Type Balance/; | ||
| 57 | format Summary = | ||
| 58 | @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>> | ||
| 59 | $num, $name, $bal | ||
| 60 | . | ||
| 61 | $~ = 'Summary'; | ||
| 62 | write; | ||
| 63 | print <<EOF; | ||
| 64 | ================= ========================= =========== | ||
| 65 | EOF | ||
| 66 | |||
| 67 | foreach $num ( @account_nums ){ | ||
| 68 | my $a = $wachovia->account( $num ); | ||
| 69 | $name = $a->name or die $a->ErrStr; | ||
| 70 | #$type = $a->type or die $a->ErrStr; | ||
| 71 | $bal = $a->balance or die $a->ErrStr; | ||
| 72 | write; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | #============================================================================== | ||
| 78 | # Fills the options hash with account info from the local .wachovia file | ||
| 79 | sub get_account_info { | ||
| 80 | my($keyfile, $key) = @_; | ||
| 81 | my $opts; | ||
| 82 | return unless -e $keyfile; | ||
| 83 | open( F, $keyfile ) or die "Can't open ".$keyfile." for reading: $!"; | ||
| 84 | my $cipher = Crypt::CBC->new({ | ||
| 85 | 'key'=> $key, | ||
| 86 | 'cipher'=> 'DES_PP', | ||
| 87 | 'iv'=> '%_j,!z"{' | ||
| 88 | }); | ||
| 89 | my $plaintext = $cipher->decrypt( <F> ); | ||
| 90 | my @opts = split( /\//, $plaintext ); | ||
| 91 | for( @opts ){ | ||
| 92 | my($k, $v) = split(/=>/); | ||
| 93 | $opts->{$k} = $v; | ||
| 94 | } | ||
| 95 | return $opts; | ||
| 96 | } | ||
| 97 | |||
| 98 | # Writes an MD5 hash for the hash info. | ||
| 99 | sub save_account_info { | ||
| 100 | my $opts = shift; | ||
| 101 | open( F, '>', $opts->{keyfile} ) or die "Can't open ".$opts->{keyfile}." for writing: $!"; | ||
| 102 | my $cipher = Crypt::CBC->new({ | ||
| 103 | 'key'=> $opts->{key}, | ||
| 104 | 'cipher'=> 'DES_PP', | ||
| 105 | 'iv'=> '%_j,!z"{' | ||
| 106 | }); | ||
| 107 | my $ciphertext = $cipher->encrypt( join('/', (map { "$_=>".$opts->{$_} } keys %$opts) ) ); | ||
| 108 | print F $ciphertext; | ||
| 109 | close( F ); | ||
| 110 | return 1; | ||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 | __END__ |