Created
May 22, 2014 14:31
-
-
Save gatlin/5c3295ad9b054357aa81 to your computer and use it in GitHub Desktop.
A script to convert a CSV exported from KeePass(X) to a .kdb format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.14; | |
use strict; | |
use warnings; | |
use File::KeePass; | |
use Text::CSV; | |
use Data::Dump qw(pp); | |
use Term::ReadPassword; | |
# Initialize the CSV data structures | |
my $csv = Text::CSV->new ({ binary => 0 }) | |
or die "Cannot use CSV: " . Text::CSV->error_diag (); | |
open my $fh, "<:encoding(utf8)", $ARGV[0] or die "csv: $!"; | |
my ($filename, $fileext) = split /\./, $ARGV[0]; | |
# Initialize the KeePass data structures | |
my $k = File::KeePass->new; | |
my $group = $k->add_group({ | |
title => 'Default', | |
}); | |
# Loop: parse a CSV row, add entry to database | |
while (my $row = $csv->getline($fh)) { | |
my $e = $k->add_entry({ | |
title => $row->[0], | |
username => $row->[1], | |
password => $row->[2], | |
url => $row->[3], | |
comment => $row->[4], | |
}); | |
} | |
$csv->eof or $csv->error_diag(); | |
close $fh; | |
# Acquire database password and save | |
while (1) { | |
my $password = read_password("Choose database password: "); | |
redo unless defined $password; | |
# Now generate the KeePassX database | |
$k->save_db("$filename.kdb",$password); | |
last; | |
} | |
1; | |
__END__ | |
=pod | |
=head1 NAME | |
keepassalong - read KeePass CSV files, spit out a KeePassX compatible database | |
=head1 SYNOPSIS | |
$> keepassalong somedb.csv | |
This will produce C<somedb.kdb>. | |
=head1 LICENSE | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment