Annotation of palm/Palm-Keyring/examples/example3.pl, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl
! 2: use strict;
! 3: use warnings;
! 4: use Getopt::Long;
! 5: Getopt::Long::Configure('bundling');
! 6: use Term::ReadLine;
! 7:
! 8: use YAML;
! 9:
! 10: use lib 'lib';
! 11: use Palm::Keyring;
! 12:
! 13: my $Default_File = $ENV{'HOME'} . '/.jpilot/Keys-Gtkr.pdb';
! 14: my $PDBFile;
! 15: my $Categories;
! 16: my $Names;
! 17: my $Action_List;
! 18: my $Action_Show;
! 19:
! 20: my $result = GetOptions (
! 21: "file|f=s" => \$PDBFile,
! 22: "categories|c:s@" => \$Categories,
! 23: "name|n=s@" => \$Names,
! 24: "list|l" => \$Action_List,
! 25: "show|s" => \$Action_Show,
! 26: );
! 27:
! 28: $PDBFile ||= $Default_File;
! 29: my $pdb = new Palm::Keyring();
! 30: $pdb->Load($PDBFile) || die "Couldn't load '$PDBFile': $!";
! 31:
! 32: if ($Action_List) {
! 33: show_list();
! 34: } elsif ($Action_Show) {
! 35: show_items($Names);
! 36: } elsif (defined $Categories) {
! 37: show_categories();
! 38: } else {
! 39: help();
! 40: }
! 41:
! 42: exit;
! 43:
! 44:
! 45: #$pdb->Decrypt('12345');
! 46: #print Dump $pdb;
! 47:
! 48: #--------------------------------------------------
! 49: # my $new_record = $pdb->append_Record();
! 50: #
! 51: # $new_record->{plaintext} = {
! 52: # name => 'Test3',
! 53: # account => 'anothertestaccount',
! 54: # password => 'adifferentmypass',
! 55: # description => 'now that really roxorZ!',
! 56: # };
! 57: #
! 58: #$pdb->Encrypt('12345');
! 59: #
! 60: #$pdb->Write("Keys-GtkrNEW.PDB");
! 61: #--------------------------------------------------
! 62:
! 63:
! 64: sub show_list
! 65: {
! 66: print "Showing List\n";
! 67: foreach my $r (@{ $pdb->{'records'} }) {
! 68: next unless $r->{'plaintext'};
! 69: my $category =
! 70: $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
! 71:
! 72: my $matched = 0;
! 73: foreach my $cat (@{ $Categories }) {
! 74: $matched++ if uc($category) eq uc($cat);
! 75: }
! 76: foreach my $name (@{ $Names}) {
! 77: $matched++ if uc($r->{'plaintext'}->{'name'}) eq uc($name);
! 78: }
! 79: next if ( @{ $Categories } || @{ $Names } ) && not $matched;
! 80:
! 81: # XXX Fix up formatting
! 82: print $r->{'plaintext'}->{'name'} .
! 83: ":" .
! 84: $r->{'category'} .
! 85: ":" .
! 86: $category .
! 87: "\n";
! 88:
! 89: }
! 90: }
! 91:
! 92: sub show_categories
! 93: {
! 94: foreach my $c (sort @{ $pdb->{'appinfo'}->{'categories'} }) {
! 95: next unless $c->{'name'};
! 96: # Fix formatting
! 97: print $c->{'name'}, "\n";
! 98: }
! 99: }
! 100:
! 101: sub show_items
! 102: {
! 103: decrypt() || die "Couldn't decrypt file!";
! 104:
! 105: foreach my $r (@{ $pdb->{'records'} }) {
! 106: next unless $r->{'plaintext'};
! 107: my $category =
! 108: $pdb->{'appinfo'}->{'categories'}->[ $r->{'category'} ]->{'name'};
! 109:
! 110: my $matched = 0;
! 111: foreach my $cat (@{ $Categories }) {
! 112: $matched++ if uc($category) eq uc($cat);
! 113: }
! 114: foreach my $name (@{ $Names}) {
! 115: $matched++ if uc($r->{'plaintext'}->{'name'}) eq uc($name);
! 116: }
! 117: next if ( @{ $Categories } || @{ $Names } ) && not $matched;
! 118:
! 119: # XXX Fix up formatting
! 120: print $r->{'plaintext'}->{'name'} .
! 121: "\n\t" .
! 122: "Category: " . $category .
! 123: "\n\t" .
! 124: "Account: " . $r->{'plaintext'}->{'account'} .
! 125: "\n\t" .
! 126: "Password: " . $r->{'plaintext'}->{'password'} .
! 127: "\n";
! 128: print "\tDescription: " . $r->{'plaintext'}->{'description'} . "\n"
! 129: if $r->{'plaintext'}->{'description'};
! 130:
! 131: }
! 132:
! 133: }
! 134:
! 135: sub add_item
! 136: {
! 137: die "not implemented!";
! 138: }
! 139:
! 140: sub delete_item
! 141: {
! 142: die "not implemented!";
! 143: }
! 144:
! 145: sub decrypt
! 146: {
! 147: while (1) {
! 148: print "Enter Password: ";
! 149:
! 150: system("stty", "-echo");
! 151: chop(my $read = <STDIN>);
! 152: system("stty", "echo");
! 153: print "\n";
! 154:
! 155: $read =~ s/^\s*//;
! 156: $read =~ s/\s*$//;
! 157:
! 158: #return 1 if
! 159: $pdb->Decrypt($read) && return 1;
! 160: #print Dump $read, $pdb;
! 161: #exit;
! 162: }
! 163: return undef;
! 164: }
! 165:
! 166:
! 167: sub help
! 168: {
! 169: print STDERR "$0 [options] action\n";
! 170: exit 255;
! 171: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>