Skip to content

Instantly share code, notes, and snippets.

@cjp
Last active August 29, 2015 13:56
Show Gist options
  • Save cjp/9081280 to your computer and use it in GitHub Desktop.
Save cjp/9081280 to your computer and use it in GitHub Desktop.
Convert XCCDF to Markdown
#!/usr/bin/env ruby
require 'rubygems'
require 'xmlsimple'
# stolen from facets, thanks to dharple for the suggestion
def word_wrap(text, col_width=80)
text.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
text.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
text
end
xml = ARGF.read
data = XmlSimple.xml_in(xml, { 'KeyAttr' => 'id' , 'GroupTags' => { 'Group' => 'Rule' }})
# data = XmlSimple.xml_in('rhel6.xml', { 'KeyAttr' => 'id' , 'GroupTags' => { 'Group' => 'Rule' }})
data['Group'].each do |ok, ov|
ov['Rule'].each do |ik, iv|
print "## #{iv['title'][0]}\n"
print "Severity: _#{iv['severity']}_\n"
desc = iv['description'][0].gsub /<VulnDiscussion>(.*)<\/VulnDiscussion>.*/m, '\1'
desc = word_wrap desc, 72
desc = desc.gsub /\n/m, "\n> "
print "### Description\n> #{desc}\n"
print "\n\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment