|
From: Ian S. <ian...@ni...> - 2009-02-05 20:28:34
|
I have the following Perl script which I used in exporting my Keyring db
to (eventually) 1Password on my iPhone. It dumps to CSV format.
#!/usr/bin/perl
use Palm::PDB;
use Palm::Keyring;
use Term::ReadKey;
use Text::CSV;
use strict;
my $file = shift or die "Usage: dump-keys.pl <keys file>\n";
print STDERR "password: ";
ReadMode('noecho');
my $password = ReadLine(0);
ReadMode('normal');
print "\n";
chomp $password;
my $pdb = new Palm::PDB;
$pdb->Load($file);
if ($pdb->{version} == 4) {
print STDERR "v4\n";
}
if ($pdb->{options}->{v4compatible}) {
print STDERR "v4compatible\n";
}
my $csv = Text::CSV->new ({ always_quote => 1,
binary => 1,
});
for my $i (0 .. $#{ $pdb->{records} }) {
# skip the password record for version 4 databases
next if $i == 0 and $pdb->{version} == 4;
my $rec = $pdb->{records}->[$i];
my $data = $pdb->Decrypt($rec, $password);
my @columns = ();
push @columns, $rec->{name};
push @columns, $data->{account};
push @columns, ($data->{lastchange}{month} + 1) . "/" .
$data->{lastchange}{day} . "/" .
($data->{lastchange}{year} + 1900);
push @columns, $data->{password};
push @columns, $data->{notes};
my $status = $csv->combine(@columns);
if (!$status) { print $csv->error_input(); }
print $csv->string(), "\n";
}
|