=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/example3.pl,v retrieving revision 1.1 retrieving revision 1.6 diff -u -r1.1 -r1.6 --- palm/Palm-Keyring/examples/example3.pl 2007/01/28 16:17:54 1.1 +++ palm/Palm-Keyring/examples/example3.pl 2007/09/12 04:59:37 1.6 @@ -1,13 +1,25 @@ #!/usr/bin/perl +# $RedRiver: example3.pl,v 1.5 2007/08/10 04:13:31 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'; @@ -26,7 +38,7 @@ ); $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 +54,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 +92,12 @@ sub show_items { - decrypt() || die "Couldn't decrypt file!"; + get_password() || die "Couldn't decrypt file!"; - foreach my $r (@{ $pdb->{'records'} }) { - next unless $r->{'plaintext'}; + foreach (0..$#{ $pdb->{'records'} }) { + next if $_ == 0; + my $r = $pdb->{'records'}->[$_]; + my $category = $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'}; @@ -112,22 +106,18 @@ $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; + my $a = $pdb->Decrypt($r); + # 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 +132,7 @@ die "not implemented!"; } -sub decrypt +sub get_password { while (1) { print "Enter Password: "; @@ -156,7 +146,7 @@ $read =~ s/\s*$//; #return 1 if - $pdb->Decrypt($read) && return 1; + $pdb->Password($read) && return 1; #print Dump $read, $pdb; #exit; }