version 1.1, 2007/01/28 16:17:54 |
version 1.9, 2008/02/28 00:17:33 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
|
# $RedRiver: example3.pl,v 1.8 2008/02/27 23:54:02 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; |
|
|
|
|
"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) { |
|
|
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"; |
|
|
|
|
sub show_items |
sub show_items |
{ |
{ |
decrypt() || die "Couldn't decrypt file!"; |
foreach (0..$#{ $pdb->{'records'} }) { |
|
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'}; |
|
|
|
|
$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; |
|
|
|
get_password() || die "Couldn't decrypt file!"; |
|
|
|
my $a = $pdb->Decrypt($r); |
|
$matched = 0; |
|
|
|
foreach my $account (@{ $Accounts }) { |
|
$matched++ if uc($r->{plaintext}->{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'}; |
|
|
|
} |
} |
|
|
} |
} |
|
|
die "not implemented!"; |
die "not implemented!"; |
} |
} |
|
|
sub decrypt |
sub get_password |
{ |
{ |
while (1) { |
while (1) { |
print "Enter Password: "; |
print "Enter Password: "; |
|
|
$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; |
} |
} |