Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 137 lines (112 sloc) 5.514 kb
319e300 @linuxsquad adding converter.py
authored
1 #!/usr/bin/env python
2 """
3 Convert SplashID DB (v3) into KeepassX XML
4
5 ASSUMPTION:
6 keePassX <Last Access> and <Last Modified> time stamp filled with a date and time of conversion
7 SplashID <Description> and <Company> fields merge into keePassX <title>
8 All SplashID fields that does not match main keePassX ones, added to the keePassX <comments>
9 SplashID Creation Date is expected in the following format <November 28, 2009>
10
11 TODO:
12 Some characters have to be replaced (for instance, &) since keePassX refuses to import them
13 If SplashID has no username, check <comment> section for <account> data to substitute
14
15 From SplashID website:
16 You may also import and export SplashID records in CSV format.
17 CSV stands for Comma Separated Values, and is a common file format
18 readable by most spreadsheets, databases and word processors.
19 If you wish to import a CSV file, the data must be in the following format:
20
21 Type, Field 1, Field 2, Field 3, Field 4, Field 5, Field 6, Field 7, Field 8, Field 9, Date Modified, Notes, Category
22
23 It is easy to create the above format in Excel by creating a spreadsheet
24 with 13 columns (as designated above) with one record per row.
25 Then save the splashid_export_f in CSV format.
26
27 Note: When importing data, if the type field is blank the record
28 will be placed in Unfiled. If there is a type name and it
29 does not match an existing type a new type will be created.
30 """
31
32 import sys
33 import csv
34 import time
35 from time import gmtime, strftime
36
37 TODAY = strftime("%Y-%m-%dT%X",gmtime())
38
39 splashid_type = {}
40 splashid_value = []
41 splashid_type_prev = '0'
42 SPLASHID_2_KEEPASSX = {'DESCRIPTION': 'title', 'COMPANY': 'title', 'USERNAME': 'username',
43 'PASSWORD': 'password', 'PIN': 'password', 'URL': 'url'}
44 xml_entry = {'title': [1,''], 'username': [2,''], 'password': [3,''], 'url': [4,''], 'comment': [5,''], 'icon': [6, '67'],
45 'creation': [7,''], 'lastaccess': [8,TODAY],'lastmod': [9,TODAY], 'expire': [91,'Never']}
46 xml_group = {'title': ''}
47
48 if (len(sys.argv) > 1):
49 splashid_export_f = sys.argv[1]
50 else:
51 print "Please supply splashid_export_f name"
52 quit(1)
53
54
55
56 with open(splashid_export_f, 'rb') as csv_file:
57 csv_imported_splashid = csv.reader(csv_file)
58 with open(splashid_export_f+".log", 'w') as log_file:
59 for i, row in enumerate(csv_imported_splashid):
60 csv_entry = [ item for item in row ]
61 try:
62 if csv_entry[0] == 'T':
63 try:
64 if csv_entry[1] in splashid_type:
65 pass
66 else:
67 splashid_type[csv_entry[1]] = csv_entry[2:]
68 log_file.write(" INFO: Group Name ="+csv_entry[2]+", Group ID ="+csv_entry[1]+"\n")
69 splashid_type_prev = csv_entry[1]
70 except IndexError, name:
71 pass
72 if csv_entry[0] == 'F':
73 if csv_entry[1] != splashid_type_prev:
74 log_file.write(" WARN: Unrecognized Group ID F="+csv_entry[1]+", Guessing a correct one T="+splashid_type_prev+"\n")
75 csv_entry[1] = splashid_type_prev
76 splashid_value.append(csv_entry[1:])
77 except IndexError, name:
78 pass
79
80 splashid_value.sort()
81
82 print "<!DOCTYPE KEEPASSX_DATABASE>"
83 print "<database>"
84
85 group_name_prev = ""
86
87 for single_record in splashid_value:
88 if len(single_record) > 0:
89 if single_record[0] in splashid_type:
90 field_names = splashid_type[single_record[0]]
91
92
93 xml_entry['comment'][1] = ''
94
95 for i, item in enumerate(field_names[1:-3]):
96 j = i + 1
97 try:
98 index = item.strip('0123456789 ').upper()
99 if index in SPLASHID_2_KEEPASSX :
100 if SPLASHID_2_KEEPASSX[index] == "title":
101 xml_entry[SPLASHID_2_KEEPASSX[index]][1] = single_record[j]+" ("+single_record[-2]+")"
102 else:
103 xml_entry[SPLASHID_2_KEEPASSX[index]][1] = single_record[j]
104 else:
105 xml_entry['comment'][1] += item+": "+single_record[j]+" <br/>"
106 except IndexError, name:
107 print "Index ERROR", name
108
109 if single_record[10] != "":
110 date_format = "%B %d, %Y"
111 try:
112 time_tuple = time.strptime(single_record[10], date_format)
113 xml_entry['creation'][1] = strftime("%Y-%m-%dT%X", time_tuple)
114 except TypeError, name:
115 print " ERR: ", name
116 quit(1)
117
118 xml_entry['comment'][1] += "Notes: "+single_record[-1]
119
120 if field_names[0] != group_name_prev:
121 if group_name_prev != "":
122 print " </group>"
123 print " <group>\n <title>{}</title>\n <icon>1</icon>".format(field_names[0])
124 group_name_prev = field_names[0]
125
126 print " <entry>"
127 for item in sorted( (value,field) for (field,value) in xml_entry.items() ):
128 print " <{0}>{1}</{0}>".format(item[1],item[0][1])
129 print " </entry>"
130 else:
131 print single_record, " Not Found"
132 else:
133 print single_record
134
135 print " </group>"
136 print "</database>"
137 quit(0)
Something went wrong with that request. Please try again.