[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.10

version 1.1, 2007/01/28 16:17:54 version 1.10, 2008/03/05 22:04:46
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
   # $RedRiver: example3.pl,v 1.9 2008/02/28 00:17:33 andrew Exp $
   ########################################################################
   # palmkeyring.pl *** a command line client for Keyring databases.
   #
   # 2007.02.10 #*#*# andrew fresh <andrew@cpan.org>
   ########################################################################
   # 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 strict;
 use warnings;  use warnings;
   
 use Getopt::Long;  use Getopt::Long;
 Getopt::Long::Configure('bundling');  Getopt::Long::Configure('bundling');
 use Term::ReadLine;  use Term::ReadLine;
   
 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';
 my $PDBFile;  my $PDBFile;
 my $Categories;  my $Categories;
 my $Names;  my $Names;
   my $Accounts;
 my $Action_List;  my $Action_List;
 my $Action_Show;  my $Action_Show;
   
Line 21 
Line 34 
         "file|f=s"        => \$PDBFile,          "file|f=s"        => \$PDBFile,
         "categories|c:s@" => \$Categories,          "categories|c:s@" => \$Categories,
         "name|n=s@"       => \$Names,          "name|n=s@"       => \$Names,
           "account|a=s@"    => \$Accounts,
         "list|l"          => \$Action_List,          "list|l"          => \$Action_List,
         "show|s"          => \$Action_Show,          "show|s"          => \$Action_Show,
 );  );
   
 $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 56 
 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 my $r (@{ $pdb->{records} }) {
                 next unless $r->{'plaintext'};  
                 my $category =                  my $category =
                         $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};                          $pdb->{appinfo}->{categories}->[ $r->{category} ]->{name};
   
                 my $matched = 0;                  my $matched = 0;
                 foreach my $cat (@{ $Categories }) {                  foreach my $cat (@{ $Categories }) {
                         $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->{'name'}) 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->{plaintext}->{0}->{data} .
                         ":" .                          ":" .
                         $r->{'category'} .                          $r->{category} .
                         ":" .                          ":" .
                         $category .                          $category .
                         "\n";                          "\n";
Line 100 
Line 94 
   
 sub show_items  sub show_items
 {  {
         decrypt() || die "Couldn't decrypt file!";          get_password() || die "Couldn't decrypt file!";
           foreach (0..$#{ $pdb->{'records'} }) {
         foreach my $r (@{ $pdb->{'records'} }) {                  my $r = $pdb->{'records'}->[$_];
                 next unless $r->{'plaintext'};  
                 my $category =                  my $category =
                         $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};                          $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
   
Line 112 
Line 105 
                         $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->{plaintext}->{0}->{data}) eq uc($name);
                 }                  }
                 next if ( @{ $Categories } || @{ $Names } ) && not $matched;                  next if ( @{ $Categories } || @{ $Names } ) && not $matched;
   
                   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                  # XXX Fix up formatting
                 print $r->{'plaintext'}->{'name'} .                  print $a->{0}->{data} .  "\n\t" .
                         "\n\t" .                          "Category: " . $category .  "\n\t" .
                         "Category: " . $category .                          "Account:  " . $a->{1}->{data} .  "\n\t" .
                         "\n\t" .                          "Password: " . $a->{2}->{data} .  "\n";
                         "Account:  " . $r->{'plaintext'}->{'account'} .                          print "\tNotes: " . $a->{255}->{data} . "\n" if $a->{255}->{data};
                         "\n\t" .  
                         "Password: " . $r->{'plaintext'}->{'password'} .  
                         "\n";  
                         print "\tDescription: " . $r->{'plaintext'}->{'description'} . "\n"  
                                 if $r->{'plaintext'}->{'description'};  
   
         }          }
   
 }  }
Line 142 
Line 137 
         die "not implemented!";          die "not implemented!";
 }  }
   
 sub decrypt  sub get_password
 {  {
         while (1) {          while (1) {
                 print "Enter Password: ";                  print "Enter Password: ";
Line 156 
Line 151 
                 $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.10

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