=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/example3.pl,v retrieving revision 1.1 retrieving revision 1.9 diff -u -r1.1 -r1.9 --- palm/Palm-Keyring/examples/example3.pl 2007/01/28 16:17:54 1.1 +++ palm/Palm-Keyring/examples/example3.pl 2008/02/28 00:17:33 1.9 @@ -1,19 +1,32 @@ #!/usr/bin/perl +# $RedRiver: example3.pl,v 1.8 2008/02/27 23:54:02 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 lib 'lib'; +use Palm::PDB; use Palm::Keyring; my $Default_File = $ENV{'HOME'} . '/.jpilot/Keys-Gtkr.pdb'; my $PDBFile; my $Categories; my $Names; +my $Accounts; my $Action_List; my $Action_Show; @@ -21,12 +34,13 @@ "file|f=s" => \$PDBFile, "categories|c:s@" => \$Categories, "name|n=s@" => \$Names, + "account|a=s@" => \$Accounts, "list|l" => \$Action_List, "show|s" => \$Action_Show, ); $PDBFile ||= $Default_File; -my $pdb = new Palm::Keyring(); +my $pdb = new Palm::PDB(); $pdb->Load($PDBFile) || die "Couldn't load '$PDBFile': $!"; if ($Action_List) { @@ -42,46 +56,26 @@ exit; -#$pdb->Decrypt('12345'); -#print Dump $pdb; - -#-------------------------------------------------- -# my $new_record = $pdb->append_Record(); -# -# $new_record->{plaintext} = { -# name => 'Test3', -# account => 'anothertestaccount', -# password => 'adifferentmypass', -# description => 'now that really roxorZ!', -# }; -# -#$pdb->Encrypt('12345'); -# -#$pdb->Write("Keys-GtkrNEW.PDB"); -#-------------------------------------------------- - - sub show_list { print "Showing List\n"; - foreach my $r (@{ $pdb->{'records'} }) { - next unless $r->{'plaintext'}; + 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->{'plaintext'}->{'name'}) eq uc($name); + $matched++ if uc($r->{'name'}) eq uc($name); } next if ( @{ $Categories } || @{ $Names } ) && not $matched; # XXX Fix up formatting - print $r->{'plaintext'}->{'name'} . + print $r->{plaintext}->{0}->{data} . ":" . - $r->{'category'} . + $r->{category} . ":" . $category . "\n"; @@ -100,10 +94,9 @@ sub show_items { - decrypt() || die "Couldn't decrypt file!"; + foreach (0..$#{ $pdb->{'records'} }) { + my $r = $pdb->{'records'}->[$_]; - foreach my $r (@{ $pdb->{'records'} }) { - next unless $r->{'plaintext'}; my $category = $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'}; @@ -112,22 +105,26 @@ $matched++ if uc($category) eq uc($cat); } foreach my $name (@{ $Names}) { - $matched++ if uc($r->{'plaintext'}->{'name'}) eq uc($name); + $matched++ if uc($r->{plaintext}->{0}->{data}) eq uc($name); } next if ( @{ $Categories } || @{ $Names } ) && not $matched; + get_password() || die "Couldn't decrypt file!"; + + my $a = $pdb->Decrypt($r); + $matched = 0; + + foreach my $account (@{ $Accounts }) { + $matched++ if uc($r->{plaintext}->{1}->{data}) eq uc($account); + } + next if ( @{ $Accounts } ) && not $matched; + # XXX Fix up formatting - print $r->{'plaintext'}->{'name'} . - "\n\t" . - "Category: " . $category . - "\n\t" . - "Account: " . $r->{'plaintext'}->{'account'} . - "\n\t" . - "Password: " . $r->{'plaintext'}->{'password'} . - "\n"; - print "\tDescription: " . $r->{'plaintext'}->{'description'} . "\n" - if $r->{'plaintext'}->{'description'}; - + print $a->{0}->{data} . "\n\t" . + "Category: " . $category . "\n\t" . + "Account: " . $a->{1}->{data} . "\n\t" . + "Password: " . $a->{2}->{data} . "\n"; + print "\tNotes: " . $a->{255}->{data} . "\n" if $a->{255}->{data}; } } @@ -142,7 +139,7 @@ die "not implemented!"; } -sub decrypt +sub get_password { while (1) { print "Enter Password: "; @@ -156,7 +153,7 @@ $read =~ s/\s*$//; #return 1 if - $pdb->Decrypt($read) && return 1; + $pdb->Password($read) && return 1; #print Dump $read, $pdb; #exit; }