summaryrefslogtreecommitdiff
path: root/contrib/importers
diff options
context:
space:
mode:
authorDavid Francoeur <dfrancoeur04@gmail.com>2015-10-20 21:32:33 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2016-02-06 20:56:47 +0100
commiteafeb73852880260e14da4cf1a65515396332d5d (patch)
tree8bad294183135adaaa29071a5beb14d211c49b04 /contrib/importers
parent35f7f2eaf307fd9f563623ceaaf88ce939cde282 (diff)
downloadpass-eafeb73852880260e14da4cf1a65515396332d5d.tar.gz
pass-eafeb73852880260e14da4cf1a65515396332d5d.tar.bz2
pass-eafeb73852880260e14da4cf1a65515396332d5d.zip
keepass2csv2pass
The CSV is generated by KeePassX 2.0 on Mac OSX
Diffstat (limited to 'contrib/importers')
-rwxr-xr-xcontrib/importers/keepass2csv2pass.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/importers/keepass2csv2pass.py b/contrib/importers/keepass2csv2pass.py
new file mode 100755
index 0000000..47e787f
--- /dev/null
+++ b/contrib/importers/keepass2csv2pass.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+
+# Copyright 2015 David Francoeur <dfrancoeur04@gmail.com>
+# This file is licensed under the GPLv2+. Please see COPYING for more information.
+
+# KeePassX 2+ on Mac allows export to CSV. The CSV contains the following headers :
+# "Group","Title","Username","Password","URL","Notes"
+# Group and Title are used to build the path, @see prepareForInsertion
+# Password is the first line and the url and the notes are appended after
+#
+# Usage: ./csv_to_pass.py test.csv
+
+import csv
+import itertools
+import sys
+from subprocess import Popen, PIPE
+
+def pass_import_entry(path, data):
+ """ Import new password entry to password-store using pass insert command """
+ proc = Popen(['pass', 'insert', '--multiline', path], stdin=PIPE, stdout=PIPE)
+ proc.communicate(data.encode('utf8'))
+ proc.wait()
+
+def readFile(filename):
+ """ Read the file and proccess each entry """
+ with open(filename, 'rU') as csvIN:
+ next(csvIN)
+ outCSV=(line for line in csv.reader(csvIN, dialect='excel'))
+ #for row in itertools.islice(outCSV, 0, 1):
+ for row in outCSV:
+ #print("Length: ", len(row), row)
+ prepareForInsertion(row)
+
+
+def prepareForInsertion(row):
+ """ prepare each CSV entry into an insertable string """
+ keyFolder = escape(row[0][4:])
+ keyName = escape(row[1])
+ username = row[2]
+ password = row[3]
+ url = row[4]
+ notes = row[5]
+
+ path = keyFolder+"/"+keyName+"/"+username
+ data = password + "\n" if password else "\n"
+ data = "%s%s: %s\n" % (data, "url:", url+"\n")
+ data = "%s%s: %s\n" % (data, "notes:", notes+"\n")
+ pass_import_entry(path,data)
+ print(path+" imported!")
+
+def escape(strToEscape):
+ """ escape the list """
+ return strToEscape.replace(" ", "-").replace("&","and").replace("[","").replace("]","")
+
+
+def main(argv):
+ inputFile = sys.argv[1]
+ print("File to read: " + inputFile)
+ readFile(inputFile)
+
+
+main(sys.argv)
s='deletions'>-5/+1 2008-07-03Updated setup.py to install the correct set of pluginsRené 'Necoro' Neumann1-3/+2 2008-07-03Ported etc-proposals pluginRené 'Necoro' Neumann3-50/+43 2008-07-03Ported gpytage pluginRené 'Necoro' Neumann2-16/+14 2008-07-03Ported Notify pluginRené 'Necoro' Neumann4-37/+51 2008-07-03Remove xsd and -x cmdline optionRené 'Necoro' Neumann2-107/+1 2008-07-03Ported completelyRené 'Necoro' Neumann3-548/+54 2008-07-03Should show dependencies nowRené 'Necoro' Neumann2-82/+128 2008-07-03Use __slots__ for the PkgData class to save memoryRené 'Necoro' Neumann1-2/+3 2008-07-03New plugin system - first hackRené 'Necoro' Neumann2-420/+683 2008-06-30Now the new design is able to do the same as the old oneRené 'Necoro' Neumann3-168/+182 2008-06-30First draft of the new plugin windowRené 'Necoro' Neumann1-8/+172 2008-06-30Added stuff to plugin.pyRené 'Necoro' Neumann1-2/+24 2008-06-30Beautified some dialogsRené 'Necoro' Neumann1-6/+8 2008-06-30Only add a package to mergequeue if everything went fineRené 'Necoro' Neumann1-1/+1 2008-06-26Removed '__find_resolved_unresolved' as it is quite useless.René 'Necoro' Neumann3-53/+29 Also removed the "find_packages::ws" and moved the content into "world" and "system" to prepare for exchangebility. 2008-06-26Added very basic set queryingRené 'Necoro' Neumann3-0/+27 2008-06-25Now load 22 versions when running the correct portageRené 'Necoro' Neumann4-8/+18 2008-06-25Added Package_22 and System_22René 'Necoro' Neumann4-5/+63