summaryrefslogtreecommitdiff
path: root/contrib/importers/fpm2pass.pl
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 12:01:52 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 12:03:12 -0600
commit47fed2c5d47a03fad7b91bfb890eed257e9c1b2d (patch)
tree46666ba401340524ab9c217a062c366f6e5ec818 /contrib/importers/fpm2pass.pl
parent414bab7d973b50431854496811608c549fb541e1 (diff)
downloadpass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.tar.gz
pass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.tar.bz2
pass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.zip
Makefile: do not use recursion and organize
Diffstat (limited to 'contrib/importers/fpm2pass.pl')
-rwxr-xr-xcontrib/importers/fpm2pass.pl79
1 files changed, 79 insertions, 0 deletions
diff --git a/contrib/importers/fpm2pass.pl b/contrib/importers/fpm2pass.pl
new file mode 100755
index 0000000..d1a0908
--- /dev/null
+++ b/contrib/importers/fpm2pass.pl
@@ -0,0 +1,79 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2012 Jeffrey Ratcliffe <jeffrey.ratcliffe@gmail.com>. All Rights Reserved.
+# This file is licensed under the GPLv2+. Please see COPYING for more information.
+
+use warnings;
+use strict;
+use XML::Simple;
+use Getopt::Long;
+use Pod::Usage;
+
+my ($help, $man);
+my @args = ('help' => \$help,
+ 'man' => \$man,);
+GetOptions (@args) or pod2usage(2);
+pod2usage(1) if ($help);
+pod2usage(-exitstatus => 0, -verbose => 2) if $man;
+pod2usage(
+ -msg => "Syntax error: must specify a file to read.",
+ -exitval => 2,
+ -verbose => 1
+)
+ if (@ARGV != 1);
+
+# Grab the XML to a perl structure
+my $xs = XML::Simple->new();
+my $doc = $xs->XMLin(shift);
+
+for (@{$doc->{PasswordList}{PasswordItem}}) {
+ my $name;
+ if (ref($_->{category}) eq 'HASH') {
+ $name = escape($_->{title});
+ }
+ else {
+ $name = escape($_->{category})."/".escape($_->{title});
+ }
+ my $contents = '';
+ $contents .= "$_->{password}\n" unless (ref($_->{password}) eq 'HASH');
+ $contents .= "user $_->{user}\n" unless (ref($_->{user}) eq 'HASH');
+ $contents .= "url $_->{url}\n" unless (ref($_->{url}) eq 'HASH');
+ unless (ref($_->{notes}) eq 'HASH') {
+ $_->{notes} =~ s/\n/\n /g;
+ $contents .= "notes:\n $_->{notes}\n";
+ }
+ my $cmd = "pass insert -f -m $name";
+ my $pid = open(my $fh, "| $cmd") or die "Couldn't fork: $!\n";
+ print $fh $contents;
+ close $fh;
+}
+
+# escape inverted commas, spaces, ampersands and brackets
+sub escape {
+ my ($s) = @_;
+ $s =~ s/\//-/g;
+ $s =~ s/(['\(\) &])/\\$1/g;
+ return $s;
+}
+
+=head1 NAME
+
+ fpm2pass.pl - imports an .xml exported by fpm2 into pass
+
+=head1 SYNOPSIS
+
+=head1 USAGE
+
+ fpm2pass.pl [--help] [--man] <xml>
+
+The following options are available:
+
+=over
+
+=item --help
+
+=item --man
+
+=back
+
+=cut