[BACK]Return to example3.pl CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / examples

Diff for /palm/Palm-Keyring/examples/example3.pl between version 1.1 and 1.2

version 1.1, 2007/01/28 16:17:54 version 1.2, 2007/01/30 04:59:55
Line 7 
Line 7 
   
 use YAML;  use YAML;
   
 use lib 'lib';  use Palm::PDB;
 use Palm::Keyring;  use Palm::Keyring;
   
 my $Default_File = $ENV{'HOME'} . '/.jpilot/Keys-Gtkr.pdb';  my $Default_File = $ENV{'HOME'} . '/.jpilot/Keys-Gtkr.pdb';
Line 26 
Line 26 
 );  );
   
 $PDBFile ||= $Default_File;  $PDBFile ||= $Default_File;
 my $pdb = new Palm::Keyring();  my $pdb = new Palm::PDB();
 $pdb->Load($PDBFile) || die "Couldn't load '$PDBFile': $!";  $pdb->Load($PDBFile) || die "Couldn't load '$PDBFile': $!";
   
 if ($Action_List) {  if ($Action_List) {
Line 42 
Line 42 
 exit;  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  sub show_list
 {  {
         print "Showing List\n";          print "Showing List\n";
         foreach my $r (@{ $pdb->{'records'} }) {          foreach (0..$#{ $pdb->{'records'} }) {
                 next unless $r->{'plaintext'};          next if $_ == 0;
           my $r = $pdb->{'records'}->[$_];
                 my $category =                  my $category =
                         $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};                          $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
   
Line 74 
Line 56 
                         $matched++ if uc($category) eq uc($cat);                          $matched++ if uc($category) eq uc($cat);
                 }                  }
                 foreach my $name (@{ $Names}) {                  foreach my $name (@{ $Names}) {
                         $matched++ if uc($r->{'plaintext'}->{'name'}) eq uc($name);                          $matched++ if uc($r->{'data'}) eq uc($name);
                 }                  }
                 next if ( @{ $Categories } || @{ $Names } ) && not $matched;                  next if ( @{ $Categories } || @{ $Names } ) && not $matched;
   
                 # XXX Fix up formatting                  # XXX Fix up formatting
                 print $r->{'plaintext'}->{'name'} .                  print $r->{'data'} .
                         ":" .                          ":" .
                         $r->{'category'} .                          $r->{'category'} .
                         ":" .                          ":" .
Line 100 
Line 82 
   
 sub show_items  sub show_items
 {  {
         decrypt() || die "Couldn't decrypt file!";          get_password() || die "Couldn't decrypt file!";
   
         foreach my $r (@{ $pdb->{'records'} }) {          foreach (0..$#{ $pdb->{'records'} }) {
                 next unless $r->{'plaintext'};          next if $_ == 0;
           my $r = $pdb->{'records'}->[$_];
   
                 my $category =                  my $category =
                         $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};                          $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
   
Line 112 
Line 96 
                         $matched++ if uc($category) eq uc($cat);                          $matched++ if uc($category) eq uc($cat);
                 }                  }
                 foreach my $name (@{ $Names}) {                  foreach my $name (@{ $Names}) {
                         $matched++ if uc($r->{'plaintext'}->{'name'}) eq uc($name);                          $matched++ if uc($r->{'data'}) eq uc($name);
                 }                  }
                 next if ( @{ $Categories } || @{ $Names } ) && not $matched;                  next if ( @{ $Categories } || @{ $Names } ) && not $matched;
   
           my $a = $pdb->Decrypt($r);
   
                 # XXX Fix up formatting                  # XXX Fix up formatting
                 print $r->{'plaintext'}->{'name'} .                  print $r->{'data'} .  "\n\t" .
                         "\n\t" .                          "Category: " . $category .  "\n\t" .
                         "Category: " . $category .                          "Account:  " . $a->{'account'} .  "\n\t" .
                         "\n\t" .                          "Password: " . $a->{'password'} .  "\n";
                         "Account:  " . $r->{'plaintext'}->{'account'} .                          print "\tNotes: " . $a->{'notes'} . "\n" if $a->{'notes'};
                         "\n\t" .  
                         "Password: " . $r->{'plaintext'}->{'password'} .  
                         "\n";  
                         print "\tDescription: " . $r->{'plaintext'}->{'description'} . "\n"  
                                 if $r->{'plaintext'}->{'description'};  
   
         }          }
   
 }  }
Line 142 
Line 122 
         die "not implemented!";          die "not implemented!";
 }  }
   
 sub decrypt  sub get_password
 {  {
         while (1) {          while (1) {
                 print "Enter Password: ";                  print "Enter Password: ";
Line 156 
Line 136 
                 $read =~ s/\s*$//;                  $read =~ s/\s*$//;
   
                 #return 1 if                  #return 1 if
                 $pdb->Decrypt($read) && return 1;                  $pdb->Password($read) && return 1;
                 #print Dump $read, $pdb;                  #print Dump $read, $pdb;
                 #exit;                  #exit;
         }          }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>