SHARE
TWEET

lastpass_to_keepassx.rb

The_IceMan_Blog Oct 27th, 2011 274 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/ruby
  2. #
  3. # I recommend using Pocket to do the export. It works better than the browser extensions.
  4. require 'rubygems'
  5. require 'htmlentities'
  6. require 'csv'
  7. # CHANGE THIS
  8. input_file = 'passwords.csv'
  9. output_file = File.dirname(__FILE__) + '/' + input_file + '.pass.xml'
  10. coder = HTMLEntities.new
  11. csv = CSV::parse(File.open(input_file) {|f| f.read} )
  12. passwords = {}
  13. csv.each do |record|
  14.   passwords[coder.encode(record[5])] ||= []
  15.   passwords[coder.encode(record[5])] << { :username => coder.encode(record[1]),
  16.                                           :password => coder.encode(record[2]),
  17.                                           :title    => coder.encode(record[4]),
  18.                                           :comment  => coder.encode(record[3]),
  19.                                           :url      => coder.encode(record[0]) }
  20. end
  21.  
  22.  
  23. File.open(output_file, 'w') do |f|
  24.   f.puts '<!DOCTYPE KEEPASSX_DATABASE>'
  25.   f.puts '<database>'
  26.   passwords.keys.each do |key|
  27.     f.puts '  <group>'
  28.     f.puts "    <title>#{key}</title>"
  29.     passwords[key].each do |password|
  30.       f.puts "      <entry>"
  31.       f.puts "        <title>#{password[:title]}</title>"
  32.       f.puts "        <username>#{password[:username]}</username>"
  33.       f.puts "        <password>#{password[:password]}</password>"
  34.       f.puts "        <url>#{password[:url]}</url>"
  35.       f.puts "        <comment>#{password[:comment]}</comment>"
  36.       f.puts "      </entry>"
  37.     end
  38.     f.puts '  </group>'
  39.   end
  40.   f.puts '</database>'
  41. end
  42.  
  43.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top