Skip to content

Instantly share code, notes, and snippets.

@dan-manges
Created July 16, 2009 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dan-manges/148099 to your computer and use it in GitHub Desktop.
Save dan-manges/148099 to your computer and use it in GitHub Desktop.
unless ARGV.size == 1
$stderr.puts "Usage: #{$0} 1password_text_export"
exit 1
end
def escape(text)
text.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;").gsub("\"", "&quot;")
end
puts <<-END
<!DOCTYPE KEEPASSX_DATABASE>
<database>
<group>
<title>Internet</title>
<icon>1</icon>
END
File.read(ARGV[0]).split("\n").each do |line|
fields = line.split("\t")
next if fields[0,3] == %w[title notes contentsHash] # header row
puts <<-END
<entry>
<title>#{escape(fields[0])}</title>
<username>#{escape(fields[4])}</username>
<password>#{escape(fields[5])}</password>
<url>#{escape(fields[6])}</url>
<comment>#{escape(fields[1])}</comment>
<icon>0</icon>
<creation>#{Time.now.strftime("%Y-%m-%dT%H:%M:%S")}</creation>
<lastaccess>#{Time.now.strftime("%Y-%m-%dT%H:%M:%S")}</lastaccess>
<lastmod>#{Time.now.strftime("%Y-%m-%dT%H:%M:%S")}</lastmod>
<expire>Never</expire>
</entry>
END
end
puts <<-END
</group>
</database>
END
__END__
["title", "notes", "contentsHash", "passwordHistory", "username", "password", "URL/Location", "account_type", "cellphone_local", "zip", "state", "address1", "birthdate_dd", "address2", "homephone_exchange", "birthdate_mm", "sex", "country", "homephone_local", "homephone_area", "city", "lastname", "birthdate_yy", "cellphone_exchange", "cellphone_area", "firstname", "bank", "phoneTollFree", "ccnum", "expiry_yy", "cvv", "type", "expiry_mm", "cardholder", "pin", "creditLimit", "validFrom_mm", "validFrom_yy", "htmlName", "htmlMethod", "htmlID", "htmlAction", "location", "keyHash", "securityLevel"]
<!DOCTYPE KEEPASSX_DATABASE>
<database>
<group>
<title>Internet</title>
<icon>1</icon>
<entry>
<title>title</title>
<username>username</username>
<password>password</password>
<url>http://www.url.com</url>
<comment>comment</comment>
<icon>0</icon>
<creation>2009-07-15T20:11:13</creation>
<lastaccess>2009-07-15T20:12:42</lastaccess>
<lastmod>2009-07-15T20:12:42</lastmod>
<expire>2010-01-01T00:00:00</expire>
</entry>
</group>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment