=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/example3.pl,v retrieving revision 1.2 retrieving revision 1.12 diff -u -r1.2 -r1.12 --- palm/Palm-Keyring/examples/example3.pl 2007/01/30 04:59:55 1.2 +++ palm/Palm-Keyring/examples/example3.pl 2009/12/16 22:54:55 1.12 @@ -1,12 +1,22 @@ #!/usr/bin/perl +# $RedRiver: example3.pl,v 1.11 2008/09/17 14:49:50 andrew Exp $ +######################################################################## +# palmkeyring.pl *** a command line client for Keyring databases. +# +# 2007.02.10 #*#*# andrew fresh +######################################################################## +# Copyright (C) 2007 by Andrew Fresh +# +# This program is free software; you can redistribute it and/or modify +# it under the same terms as Perl itself. +######################################################################## use strict; use warnings; + use Getopt::Long; Getopt::Long::Configure('bundling'); use Term::ReadLine; -use YAML; - use Palm::PDB; use Palm::Keyring; @@ -14,6 +24,7 @@ my $PDBFile; my $Categories; my $Names; +my $Accounts; my $Action_List; my $Action_Show; @@ -21,6 +32,7 @@ "file|f=s" => \$PDBFile, "categories|c:s@" => \$Categories, "name|n=s@" => \$Names, + "account|a=s@" => \$Accounts, "list|l" => \$Action_List, "show|s" => \$Action_Show, ); @@ -32,6 +44,7 @@ if ($Action_List) { show_list(); } elsif ($Action_Show) { + push @{ $Names }, @ARGV; show_items($Names); } elsif (defined $Categories) { show_categories(); @@ -45,25 +58,23 @@ sub show_list { print "Showing List\n"; - foreach (0..$#{ $pdb->{'records'} }) { - next if $_ == 0; - my $r = $pdb->{'records'}->[$_]; + foreach my $r (@{ $pdb->{records} }) { my $category = - $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'}; + $pdb->{appinfo}->{categories}->[ $r->{category} ]->{name}; my $matched = 0; foreach my $cat (@{ $Categories }) { $matched++ if uc($category) eq uc($cat); } foreach my $name (@{ $Names}) { - $matched++ if uc($r->{'data'}) eq uc($name); + $matched++ if uc($r->{'name'}) eq uc($name); } next if ( @{ $Categories } || @{ $Names } ) && not $matched; # XXX Fix up formatting - print $r->{'data'} . + print $r->{plaintext}->{0}->{data} . ":" . - $r->{'category'} . + $r->{category} . ":" . $category . "\n"; @@ -83,11 +94,8 @@ sub show_items { get_password() || die "Couldn't decrypt file!"; - foreach (0..$#{ $pdb->{'records'} }) { - next if $_ == 0; - my $r = $pdb->{'records'}->[$_]; - + my $r = $pdb->{'records'}->[$_]; my $category = $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'}; @@ -96,18 +104,24 @@ $matched++ if uc($category) eq uc($cat); } foreach my $name (@{ $Names}) { - $matched++ if uc($r->{'data'}) eq uc($name); + $matched++ if uc($r->{plaintext}->{0}->{data}) eq uc($name); } next if ( @{ $Categories } || @{ $Names } ) && not $matched; - my $a = $pdb->Decrypt($r); + my $a = $pdb->Decrypt($r); + $matched = 0; + foreach my $account (@{ $Accounts }) { + $matched++ if uc($a->{1}->{data}) eq uc($account); + } + next if ( @{ $Accounts } ) && not $matched; + # XXX Fix up formatting - print $r->{'data'} . "\n\t" . + print $a->{0}->{data} . "\n\t" . "Category: " . $category . "\n\t" . - "Account: " . $a->{'account'} . "\n\t" . - "Password: " . $a->{'password'} . "\n"; - print "\tNotes: " . $a->{'notes'} . "\n" if $a->{'notes'}; + "Account: " . $a->{1}->{data} . "\n\t" . + "Password: " . $a->{2}->{data} . "\n"; + print "\tNotes: " . $a->{255}->{data} . "\n" if $a->{255}->{data}; } }