# Copyright (c) 2010-2016 Arxopia LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the Arxopia LLC nor the names of its contributors
#     	may be used to endorse or promote products derived from this software
#     	without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

module Risu
	module Templates
		class ExploitablitySummary < Risu::Base::TemplateBase
			include TemplateHelper

			#
			def initialize ()
				@template_info =
				{
					:name => "exploitablity_summary",
					:author => "hammackj",
					:version => "0.0.1",
					:renderer => "PDF",
					:description => "Generates a Exploitablity Summary NessusReport"
				}
			end

			# Generates a report with 4 Tables of findings showing which exploit
			# framework has a exploit for the vulnerable finding.
			def render(output)
				report_classification

				report_title NessusReport.title
				report_subtitle "Exploitablity Summary NessusReport"
				report_author "This report was prepared by\n#{NessusReport.author}"

				@output.text "\n\n\n"

				@output.text "Scan Date:", :style => :bold
				@output.text "#{NessusReport.scan_date}"
				@output.text "\n"

				headers = ["Vulnerability", "Total", "Core", "Metasploit", "Canvas", "ExploitHub", "d2"]
				header_widths = {0 => 230, 1 => 38, 2 => 38, 3 => 64, 4 => 48, 5 => 62, 6 => 32}

				heading1 "Critical Findings"
				table headers, header_widths, Item.exploitablity_matrix(Item.critical_risks_unique_sorted)
				new_page

				heading1 "High Findings"
				table headers, header_widths, Item.exploitablity_matrix(Item.high_risks_unique_sorted)
				new_page

				heading1 "Medium Findings"
				table headers, header_widths, Item.exploitablity_matrix(Item.medium_risks_unique_sorted)
				new_page

				heading1 "Low Findings"
				table headers, header_widths, Item.exploitablity_matrix(Item.low_risks_unique_sorted)
				new_page

				@output.number_pages "<page> of <total>", :at => [output.bounds.right - 75, 0], :width => 150, :page_filter => :all
			end
		end
	end
end
