This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
/
ff-pwd-exp-to-keepassx.pl
executable file
·90 lines (78 loc) · 2.27 KB
/
ff-pwd-exp-to-keepassx.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
# Convert Firefox Password Exporter to KeepassX XML format
# 2014-09-13, Updated to correct combined conversion errors with append file
my $creation_date = "2010-06-03T23:01:17";
my $lastaccess_date = "2010-06-03T23:01:33";
my $lastmod_date = "2010-06-03T23:01:33";
if ( @ARGV > 0 )
{
$data_file = $ARGV[0];
$append_file = $ARGV[1];
} else {
print "\n";
print "Firefox to KeepassX Converter v0.1beta - Wayne Moulden 2010\n";
print " Converts CSV input from the Firefox Password Exporter\n";
print " Extension to KeepassX XML format for import\n\n";
print " User may pass an optional KeepassX data file which will\n";
print " be included in the final output\n";
print " NOTE: Output is sent to stdout redirect output to file if\n";
print " saving for import\n\n";
print " Usage: $0 \<exported-firefox-csv\> \<optional-keypass-xml\>\n";
print "\n";
exit(1);
}
open(DAT, $data_file) || die("Could not open file! $data_file");
@raw_data=<DAT>;
print "<!DOCTYPE KEEPASSX_DATABASE>\n";
print "<database>\n";
print " <group>\n";
print " <title>Imported</title>\n";
print " <icon>1</icon>\n";
$i = 0;
foreach $line (@raw_data)
{
$i++;
if ( $i > 2 ) {
chomp($line);
$line =~ s/\"//g;;
my @values = split(',', $line);
print "<entry>\n";
print " <title>$values[0]</title>\n";
print " <username>$values[1]</username>\n";
print " <password>$values[2]</password>\n";
print " <url>$values[0]</url>\n";
print " <comment>Converted with $0</comment>\n";
print " <icon>0</icon>\n";
print " <creation>$creation_date</creation>\n";
print " <lastaccess>$lastaccess_date</lastaccess>\n";
print " <lastmod>$lastmod_date</lastmod>\n";
print " <expire>Never</expire>\n";
print " </entry>\n";
}
}
close(DAT);
print "</group>\n";
if ( $append_file ) {
# Append Keepass exported file contents
open(DAT, $append_file) || die("Could not open file!");
@raw_data=<DAT>;
my $total = @{raw_data};
$y,$x = 0;
foreach $line (@raw_data)
{
$y++;
if ( ( $y == "1" ) && ( ! $line =~ '/KEEPASS/' ) )
{
print "Not a Keepass Export File, will not include\n";
exit(1);
}
if ( $y > 2 ) {
if ( $x <= $total ) {
print $line;
}
$x++;
}
}
} else {
print "</database>\n"
}