Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Web Confidential to KeePassX
#!/usr/bin/env ruby
# Usage:
# 1) Save as something.rb on Desktop. Optionally update the date on the line
# that beings with "time = " if you want the creation date to be correct in
# KeePassX.
# 2) Run in Terminal: chmod 777 ~/Desktop/something.rb
# 3) Run in Terminal: ~/Desktop/something.rb web_confidential_export.txt
# 4) Import the resulting export.xml into KeePassX
# 5) Use the "srm" command to delete the plaintext files containing passwords
# (the Web Confidential export and the file you imported into KeePassX).
# For more information on "srm", run "man srm".
require 'rubygems'
require 'htmlentities'
coder = HTMLEntities.new
passwords = ARGF.read
passwords = passwords.split("\r")
passwords.each_with_index {|p,i| passwords[i] = p.split("\t")}
time = "2010-06-14T19:21:00"
xml = <<EOF
<group>
<title>Imported</title>
<icon>1</icon>
EOF
count = 1
passwords.each do |p|
(1..5).each {|i| p[i] = coder.encode(p[i]) || ""}
entry = <<EOF
<entry>
<title>#{p[1]}</title>
<username>#{p[3]}</username>
<password>#{p[4]}</password>
<url>#{p[2]}</url>
<comment>#{p[5]}</comment>
<icon>1</icon>
<creation>#{time}</creation>
<lastaccess>#{time}</lastaccess>
<lastmod>#{time}</lastmod>
<expire>Never</expire>
</entry>
EOF
xml = xml + entry
count = count + 1
end
xml = xml + "</group>"
File.open("export.xml", 'w') {|f| f.write(xml)}
puts "#{count} exported"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment