[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.3 and 1.12

version 1.3, 2007/01/31 04:17:15 version 1.12, 2009/12/16 22:54:55
Line 1 
Line 1 
 #!/usr/bin/perl  #!/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 <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 Palm::PDB;  use Palm::PDB;
 use Palm::Keyring;  use Palm::Keyring;
   
Line 14 
Line 24 
 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 32 
         "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,
 );  );
Line 32 
Line 44 
 if ($Action_List) {  if ($Action_List) {
         show_list();          show_list();
 } elsif ($Action_Show) {  } elsif ($Action_Show) {
           push @{ $Names }, @ARGV;
         show_items($Names);          show_items($Names);
 } elsif (defined $Categories) {  } elsif (defined $Categories) {
         show_categories();          show_categories();
Line 45 
Line 58 
 sub show_list  sub show_list
 {  {
         print "Showing List\n";          print "Showing List\n";
         foreach (0..$#{ $pdb->{'records'} }) {          foreach my $r (@{ $pdb->{records} }) {
         next if $_ == 0;  
         my $r = $pdb->{'records'}->[$_];  
                 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 }) {
Line 61 
Line 72 
                 next if ( @{ $Categories } || @{ $Names } ) && not $matched;                  next if ( @{ $Categories } || @{ $Names } ) && not $matched;
   
                 # XXX Fix up formatting                  # XXX Fix up formatting
                 print $r->{'name'} .                  print $r->{plaintext}->{0}->{data} .
                         ":" .                          ":" .
                         $r->{'category'} .                          $r->{category} .
                         ":" .                          ":" .
                         $category .                          $category .
                         "\n";                          "\n";
Line 83 
Line 94 
 sub show_items  sub show_items
 {  {
         get_password() || die "Couldn't decrypt file!";          get_password() || die "Couldn't decrypt file!";
   
         foreach (0..$#{ $pdb->{'records'} }) {          foreach (0..$#{ $pdb->{'records'} }) {
         next if $_ == 0;                  my $r = $pdb->{'records'}->[$_];
         my $r = $pdb->{'records'}->[$_];  
   
                 my $category =                  my $category =
                         $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};                          $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
   
Line 96 
Line 104 
                         $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->{'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);                  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->{'name'} .  "\n\t" .                  print $a->{0}->{data} .  "\n\t" .
                         "Category: " . $category .  "\n\t" .                          "Category: " . $category .  "\n\t" .
                         "Account:  " . $a->{'account'} .  "\n\t" .                          "Account:  " . $a->{1}->{data} .  "\n\t" .
                         "Password: " . $a->{'password'} .  "\n";                          "Password: " . $a->{2}->{data} .  "\n";
                         print "\tNotes: " . $a->{'notes'} . "\n" if $a->{'notes'};                          print "\tNotes: " . $a->{255}->{data} . "\n" if $a->{255}->{data};
         }          }
   
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.12

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