risu 1.6.3 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -0
  3. data/Gemfile.ci +9 -9
  4. data/Gemfile.lock +118 -0
  5. data/LICENSE +1 -1
  6. data/NEWS.markdown +98 -0
  7. data/README.markdown +10 -3
  8. data/Rakefile +2 -2
  9. data/bin/risu +3 -3
  10. data/lib/risu.rb +6 -2
  11. data/lib/risu/base.rb +10 -3
  12. data/lib/risu/base/graph_template_helper.rb +71 -0
  13. data/lib/risu/base/host_template_helper.rb +75 -0
  14. data/lib/risu/base/malware_template_helper.rb +96 -0
  15. data/lib/risu/base/post_process_base.rb +210 -0
  16. data/lib/risu/base/post_process_manager.rb +120 -0
  17. data/lib/risu/base/schema.rb +10 -7
  18. data/lib/risu/base/shares_template_helper.rb +158 -0
  19. data/lib/risu/base/template_base.rb +12 -10
  20. data/lib/risu/base/template_helper.rb +105 -3
  21. data/lib/risu/base/template_manager.rb +16 -12
  22. data/lib/risu/base/templater.rb +23 -9
  23. data/lib/risu/cli.rb +1 -1
  24. data/lib/risu/cli/application.rb +23 -17
  25. data/lib/risu/cli/banner.rb +3 -3
  26. data/lib/risu/exceptions.rb +1 -1
  27. data/lib/risu/exceptions/invaliddocument.rb +1 -1
  28. data/lib/risu/models.rb +1 -1
  29. data/lib/risu/models/attachment.rb +3 -3
  30. data/lib/risu/models/familyselection.rb +3 -3
  31. data/lib/risu/models/host.rb +74 -9
  32. data/lib/risu/models/hostproperty.rb +3 -3
  33. data/lib/risu/models/individualpluginselection.rb +3 -3
  34. data/lib/risu/models/item.rb +92 -29
  35. data/lib/risu/models/patch.rb +3 -3
  36. data/lib/risu/models/plugin.rb +30 -2
  37. data/lib/risu/models/pluginspreference.rb +1 -1
  38. data/lib/risu/models/policy.rb +1 -1
  39. data/lib/risu/models/reference.rb +1 -1
  40. data/lib/risu/models/report.rb +1 -2
  41. data/lib/risu/models/serverpreference.rb +1 -1
  42. data/lib/risu/models/servicedescription.rb +3 -3
  43. data/lib/risu/models/version.rb +1 -1
  44. data/lib/risu/parsers.rb +1 -1
  45. data/lib/risu/parsers/nessus/nessus_document.rb +3 -3
  46. data/lib/risu/parsers/nessus/nessus_sax_listener.rb +23 -16
  47. data/lib/risu/parsers/nessus/postprocess.rb +3 -6
  48. data/lib/risu/parsers/nessus/postprocess/adobe_air.rb +82 -0
  49. data/lib/risu/parsers/nessus/postprocess/adobe_reader.rb +86 -0
  50. data/lib/risu/parsers/nessus/postprocess/apache.rb +67 -0
  51. data/lib/risu/parsers/nessus/postprocess/core_ftp.rb +52 -0
  52. data/lib/risu/parsers/nessus/postprocess/flash_player.rb +104 -0
  53. data/lib/risu/parsers/nessus/postprocess/flexnet.rb +53 -0
  54. data/lib/risu/parsers/nessus/postprocess/google_chrome.rb +52 -0
  55. data/lib/risu/parsers/nessus/postprocess/hp_system_mgt_homepage.rb +60 -0
  56. data/lib/risu/parsers/nessus/postprocess/java.rb +49 -198
  57. data/lib/risu/parsers/nessus/postprocess/openssh.rb +65 -0
  58. data/lib/risu/parsers/nessus/postprocess/openssl.rb +54 -0
  59. data/lib/risu/parsers/nessus/postprocess/oracle_database.rb +84 -0
  60. data/lib/risu/parsers/nessus/postprocess/php.rb +62 -0
  61. data/lib/risu/parsers/nessus/postprocess/post_process.rb +178 -0
  62. data/lib/risu/parsers/nessus/postprocess/risk_score.rb +10 -5
  63. data/lib/risu/parsers/nessus/postprocess/root_cause.rb +375 -0
  64. data/lib/risu/parsers/nessus/postprocess/servu.rb +57 -0
  65. data/lib/risu/parsers/nessus/postprocess/shockwave.rb +73 -0
  66. data/lib/risu/parsers/nessus/postprocess/windows.rb +57 -0
  67. data/lib/risu/parsers/nessus/postprocess/wireshark.rb +72 -0
  68. data/lib/risu/parsers/nexpose/nexpose_document.rb +1 -1
  69. data/lib/risu/parsers/nexpose/simple_nexpose.rb +1 -1
  70. data/lib/risu/renderers.rb +3 -1
  71. data/lib/risu/renderers/csvrenderer.rb +53 -0
  72. data/lib/risu/renderers/nilrenderer.rb +1 -1
  73. data/lib/risu/renderers/pdfrenderer.rb +57 -0
  74. data/lib/risu/templates/assets.rb +5 -4
  75. data/lib/risu/templates/cover_sheet.rb +4 -3
  76. data/lib/risu/templates/exec_summary.rb +4 -3
  77. data/lib/risu/templates/executive_summary_detailed.rb +9 -8
  78. data/lib/risu/templates/exploitablity_summary.rb +82 -0
  79. data/lib/risu/templates/failed_audits.rb +98 -0
  80. data/lib/risu/templates/finding_statistics.rb +2 -1
  81. data/lib/risu/templates/findings_host.rb +20 -22
  82. data/lib/risu/templates/findings_summary.rb +11 -9
  83. data/lib/risu/templates/findings_summary_with_pluginid.rb +31 -85
  84. data/lib/risu/templates/graphs.rb +9 -10
  85. data/lib/risu/templates/host_findings_csv.rb +67 -0
  86. data/lib/risu/templates/host_summary.rb +2 -1
  87. data/lib/risu/templates/malicious_process_detection.rb +2 -1
  88. data/lib/risu/templates/missing_root_causes.rb +162 -0
  89. data/lib/risu/templates/ms_patch_summary.rb +3 -2
  90. data/lib/risu/templates/ms_update_summary.rb +5 -4
  91. data/lib/risu/templates/ms_wsus_findings.rb +5 -4
  92. data/lib/risu/templates/notable.rb +7 -11
  93. data/lib/risu/templates/notable_detailed.rb +7 -4
  94. data/lib/risu/templates/pci_compliance.rb +5 -4
  95. data/lib/risu/templates/stig_findings_summary.rb +5 -4
  96. data/lib/risu/templates/talking_points.rb +164 -0
  97. data/lib/risu/templates/technical_findings.rb +8 -4
  98. data/lib/risu/templates/template.rb +3 -2
  99. data/lib/risu/templates/top_25.rb +115 -0
  100. data/risu.gemspec +16 -15
  101. metadata +142 -77
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2012-2014 Arxopia LLC.
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of the Arxopia LLC nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ module Risu
28
+ module Templates
29
+ module HostTemplateHelper
30
+
31
+ #
32
+ def unsupported_os(title, plugin_name)
33
+ if item_count_by_plugin_name(plugin_name) <= 0
34
+ return
35
+ end
36
+
37
+ heading2 title
38
+
39
+ headers = ["Host"]
40
+ data = Array.new
41
+
42
+ findings = Item.where(:plugin_id => Plugin.where(:plugin_name => plugin_name).first.id)
43
+
44
+ findings.each do |finding|
45
+ host = Host.find_by_id(finding.host_id)
46
+
47
+ host_string = "#{host.name}"
48
+ host_string << " (#{host.fqdn})" if host.fqdn != nil
49
+
50
+ row = Array.new
51
+ row.push host_string
52
+
53
+ data << row
54
+ end
55
+
56
+ @output.table([headers] + data, :header => true, :width => output.bounds.width) do
57
+ row(0).style(:font_style => :bold, :background_color => 'cccccc')
58
+ cells.borders = [:top, :bottom, :left, :right]
59
+ end
60
+
61
+ text "\n"
62
+
63
+ end
64
+
65
+ #
66
+ def unsupported_os_appendix_section
67
+ unsupported_os("Unsupported Windows NT Installations", "Microsoft Windows NT 4.0 Unsupported Installation Detection")
68
+ unsupported_os("Unsupported Windows 2000 Installations", "Microsoft Windows 2000 Unsupported Installation Detection")
69
+ unsupported_os("Unsupported Windows XP Installations", "Microsoft Windows XP Unsupported Installation Detection")
70
+
71
+ text "\n"
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright (c) 2012-2014 Arxopia LLC.
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of the Arxopia LLC nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ module Risu
28
+ module Templates
29
+ module MalwareTemplateHelper
30
+
31
+ #
32
+ def conficker_count
33
+ begin
34
+ return Plugin.where(:plugin_name => "Conficker Worm Detection (uncredentialed check)").count
35
+ rescue => e
36
+ return 0
37
+ end
38
+ end
39
+
40
+ #
41
+ def conficker_appendix_section
42
+ if conficker_count() <= 0
43
+ return
44
+ end
45
+
46
+ heading2 "Conficker Worm Infection"
47
+
48
+ headers = ["Host"]
49
+ data = Array.new
50
+
51
+ findings = Item.where(:plugin_id => Plugin.where(:plugin_name => "Conficker Worm Detection (uncredentialed check)").first.id)
52
+
53
+ findings.each do |finding|
54
+ host = Host.find_by_id(finding.host_id)
55
+
56
+ host_string = "#{host.name}"
57
+ host_string << " (#{host.fqdn})" if host.fqdn != nil
58
+
59
+ row = Array.new
60
+ row.push host_string
61
+
62
+ data << row
63
+ end
64
+
65
+ @output.table([headers] + data, :header => true, :width => output.bounds.width) do
66
+ row(0).style(:font_style => :bold, :background_color => 'cccccc')
67
+ cells.borders = [:top, :bottom, :left, :right]
68
+ end
69
+
70
+ text "\n"
71
+ end
72
+
73
+ #
74
+ def conficker_section
75
+ if conficker_count() <= 0
76
+ return
77
+ end
78
+
79
+ conficker_count = Item.where(:plugin_id => Plugin.where(:plugin_name => "Conficker Worm Detection (uncredentialed check)").first.id).count
80
+ heading2 "Conficker Worm Infection"
81
+ @output.text "Conficker Worm infections were found on #{conficker_count} of #{Report.title}'s computer systems. Conficker, also known as Downup, Downadup and Kido, is a computer worm targeting the Microsoft Windows operating system that was first detected in November 2008. It uses flaws in Windows software and dictionary attacks on administrator passwords to propagate while forming a botnet, and has been unusually difficult to counter because of its combined use of many advanced malware techniques. The systems of interest are detailed in the detailed findings report with remediation steps."
82
+ @output.text "\n"
83
+ end
84
+
85
+ #
86
+ def malware_section
87
+ conficker_section
88
+ end
89
+
90
+ #
91
+ def malware_appendix_section
92
+ conficker_appendix_section
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,210 @@
1
+ # Copyright (c) 2010-2014 Arxopia LLC.
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of the Arxopia LLC nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ module Risu
28
+ module Base
29
+
30
+ #
31
+ class PostProcessBase
32
+ @possible_postprocesses = Array.new
33
+
34
+ class << self
35
+ attr_reader :possible_postprocesses
36
+ end
37
+
38
+ #
39
+ attr_accessor :info
40
+
41
+ #
42
+ def self.inherited(child)
43
+ possible_postprocesses << child
44
+ end
45
+
46
+ def == (other)
47
+
48
+ if self.info == nil || self.info[:plugin_id] == nil
49
+ false
50
+ elsif other == nil || other.info == nil || other.info[:plugin_id] == nil
51
+ false
52
+ else
53
+ self.info[:plugin_id] == other.info[:plugin_id]
54
+ end
55
+ end
56
+
57
+ def <=> (other)
58
+ if self.info[:plugin_id] < other.info[:plugin_id]
59
+ -1
60
+ elsif self.info[:plugin_id] > other.info[:plugin_id]
61
+ 1
62
+ else
63
+ 0
64
+ end
65
+ end
66
+
67
+ #
68
+ #def initialize
69
+ # @info = {}
70
+ #end
71
+
72
+ #NOTE:
73
+ #looks like its working
74
+ def newest_reader_plugin
75
+ newest = DateTime.new(0001, 01, 01)
76
+ newest_plugin = nil
77
+
78
+ @info[:plugin_ids].each do |id|
79
+ plugin = Plugin.find_by_id(id)
80
+
81
+ if plugin == nil || plugin.plugin_modification_date == nil
82
+ next
83
+ end
84
+
85
+ if plugin.plugin_modification_date >= newest
86
+ newest = plugin.plugin_modification_date if plugin.plugin_modification_date != nil
87
+ newest_plugin = plugin
88
+ end
89
+ end
90
+
91
+ return newest_plugin
92
+ end
93
+
94
+ # Creates a rollup plugin based on the newest Adobe Reader
95
+ #
96
+ def create_plugin
97
+
98
+ plugin = Plugin.find_by_id(@info[:plugin_id])
99
+
100
+ newest_plugin = newest_reader_plugin()
101
+
102
+ if newest_plugin == nil
103
+ return
104
+ end
105
+
106
+ if plugin == nil
107
+ plugin = Plugin.new
108
+ end
109
+
110
+ plugin.id = @info[:plugin_id]
111
+ plugin.plugin_name = @info[:plugin_name]
112
+ plugin.family_name = "Risu Rollup Plugins"
113
+ plugin.description = newest_plugin.description || ""
114
+ plugin.plugin_version = newest_plugin.plugin_version || ""
115
+ plugin.plugin_publication_date = newest_plugin.plugin_publication_date
116
+ plugin.plugin_modification_date = newest_plugin.plugin_modification_date
117
+ plugin.vuln_publication_date = newest_plugin.vuln_publication_date
118
+ plugin.cvss_vector = newest_plugin.cvss_vector || ""
119
+ plugin.cvss_base_score = newest_plugin.cvss_base_score
120
+ plugin.cvss_temporal_score = newest_plugin.cvss_temporal_score
121
+ plugin.cvss_temporal_vector = newest_plugin.cvss_temporal_vector
122
+ plugin.risk_factor = newest_plugin.risk_factor
123
+ plugin.solution = newest_plugin.solution
124
+ plugin.synopsis = newest_plugin.synopsis
125
+ plugin.plugin_type = "Rollup"
126
+ plugin.rollup = true
127
+
128
+ plugin.save
129
+ end
130
+
131
+ #
132
+ def create_item(host_id, severity)
133
+ item = Item.new
134
+
135
+ item.host_id = host_id
136
+ item.plugin_id = @info[:plugin_id]
137
+ item.plugin_output = nil
138
+ item.port = 0
139
+ item.severity = severity
140
+ item.plugin_name = @info[:item_name]
141
+
142
+ item.save
143
+ end
144
+
145
+ #
146
+ def has_reader_findings
147
+ @info[:plugin_ids].each do |plugin_id|
148
+ if Item.where(:plugin_id => plugin_id)
149
+ return true
150
+ end
151
+ end
152
+
153
+ return false
154
+ end
155
+
156
+ def has_host_reader_findings (host_id)
157
+ @info[:plugin_ids].each do |plugin_id|
158
+ if Item.where(:plugin_id => plugin_id).where(:host_id => host_id).count >= 1
159
+ return true
160
+ end
161
+ end
162
+
163
+ return false
164
+ end
165
+
166
+ #
167
+ def calculate_severity current_severity, severity
168
+ if severity >= current_severity
169
+ return severity
170
+ else
171
+ return current_severity
172
+ end
173
+ end
174
+
175
+ #
176
+ def run
177
+ if !has_reader_findings()
178
+ return
179
+ end
180
+
181
+ #Create the dummy plugin
182
+ create_plugin()
183
+
184
+ Host.all.each do |host|
185
+ if !has_host_reader_findings(host.id)
186
+ next
187
+ end
188
+
189
+ #puts "Found host with reader finding #{host.ip}"
190
+
191
+ finding_severity = 0
192
+
193
+ @info[:plugin_ids].each do |plugin_id|
194
+ Item.where(:plugin_id => plugin_id).each do |item|
195
+ severity = item.severity
196
+ item.real_severity = severity
197
+ item.severity = -1
198
+ item.save
199
+
200
+ finding_severity = calculate_severity(finding_severity, severity)
201
+ end
202
+ end
203
+
204
+ create_item(host.id, finding_severity)
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+
@@ -0,0 +1,120 @@
1
+ # Copyright (c) 2010-2014 Arxopia LLC.
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of the Arxopia LLC nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ module Risu
28
+ module Base
29
+
30
+ class PostProcessManager
31
+ attr_accessor :registered_postprocesses
32
+
33
+ # Creates new instance of TemplateManager
34
+ #
35
+ # @param path Path relative to the base_dir of risu
36
+ #
37
+ # @return New instance of the template manager with templates loaded.
38
+ def initialize (path)
39
+ @registered_postprocesses = Array.new
40
+ @postprocesses = Array.new
41
+
42
+ base_dir = __FILE__.gsub("risu/base/post_process_manager.rb", "")
43
+
44
+ load_postprocesses(base_dir + path)
45
+ load_postprocesses(Dir.pwd, false)
46
+ load_postprocesses(File.expand_path(USER_TEMPLATES_DIR)) if File.exists?(File.expand_path(USER_TEMPLATES_DIR)) && File.directory?(File.expand_path(USER_TEMPLATES_DIR))
47
+
48
+ sort
49
+ end
50
+
51
+ def sort
52
+ @postprocesses.each do |klass|
53
+ k = klass.new
54
+ @registered_postprocesses << k
55
+ end
56
+
57
+ @registered_postprocesses.sort! do |a,b|
58
+ a <=> b
59
+ end
60
+ end
61
+
62
+ # Loads templates from a specific path
63
+ #
64
+ # @param path Path to templates to load
65
+ def load_postprocesses(path, recursive=true)
66
+ begin
67
+
68
+ search_path = "#{path}/**/*.rb" if recursive == true
69
+ search_path = "#{path}/*.rb" if recursive == false
70
+
71
+ Dir[search_path].each do |x|
72
+ begin
73
+ require x
74
+ rescue => e
75
+ #puts e.inspect
76
+ #puts e.backtrace
77
+ next
78
+ end
79
+ end
80
+
81
+ PostProcessBase.possible_postprocesses.each do |p|
82
+ if validate(p) == true
83
+ @postprocesses << p if @postprocesses.include?(p) == false
84
+ end
85
+ end
86
+ rescue => e
87
+ puts "[!] Invalid post processing path"
88
+ puts e.inspect
89
+ puts e.backtrace
90
+ end
91
+ end
92
+
93
+ # Validates that a template is a valid template
94
+ #
95
+ # @todo look at refactoring this to valid?(template)
96
+ #
97
+ # @param template The template to validate
98
+ #
99
+ # @return [Boolean] If the template is valid
100
+ def validate(template)
101
+ t = template.new
102
+
103
+ return false if t == nil
104
+ return t.instance_variable_defined?("@info")
105
+ end
106
+
107
+ # Displays a list of all the templates to STDOUT
108
+ def display_postprocesses
109
+ puts "Available Post Processing"
110
+ @registered_postprocesses.each do |p|
111
+ if p.info[:plugin_id] != nil
112
+ puts "\t#{p.info[:description]} (#{p.info[:plugin_id]})\n"
113
+ else
114
+ puts "\t#{p.info[:description]}"
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end