Created
June 6, 2012 02:25
-
-
Save jonyesno/2879471 to your computer and use it in GitHub Desktop.
Convert pwman XML to KeePassX XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'pp' | |
xin = Nokogiri::XML(STDIN) | |
xout = Nokogiri::XML::Builder.new do |x| | |
x.database { | |
xin.css('PwList').each do |list| | |
group = list['name'] | |
next if group == 'Main' | |
next if list.css('PwItem').nil? | |
x.group { | |
x.title group | |
x.icon 0 | |
list.css('PwItem').each do |item| | |
x.entry { | |
# this stuff is just cleans up the title based on some | |
# conventions used in the pwman entries | |
name = item.css('name').inner_text | |
if name == 'Access' | |
name = nil | |
end | |
if name == 'Unix' | |
name = 'unix user' | |
end | |
if name == 'MySQL' | |
name = 'MySQL user' | |
end | |
if name.nil? || name == '' | |
title = item.css('user').inner_text | |
else | |
title = "#{item.css('user').inner_text} (#{name})" | |
end | |
x.title title | |
x.username item.css('user').inner_text | |
x.password item.css('passwd').inner_text | |
x.url item.css('host').inner_text | |
x.<< "<comment>imported from pwman</comment>" # nokogiri 1.5.3 uses #comment to insert <!-- foo --> | |
} # entry | |
end # item | |
} # group | |
end # list | |
} # database | |
end # builder | |
puts xout.to_xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment