Class: Dockscan::Scan::Manage
- Inherits:
-
Object
- Object
- Dockscan::Scan::Manage
- Defined in:
- lib/dockscan/scan/manage.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
- #check_connection ⇒ Object
-
#initialize ⇒ Manage
constructor
A new instance of Manage.
- #scan(url, opts, logger) ⇒ Object
Constructor Details
#initialize ⇒ Manage
Returns a new instance of Manage.
18 19 20 21 |
# File 'lib/dockscan/scan/manage.rb', line 18 def initialize @auditoutput=Hash.new @log=Logger.new MultiDelegator.delegate(:write, :close).to(STDERR) end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
16 17 18 |
# File 'lib/dockscan/scan/manage.rb', line 16 def log @log end |
Instance Method Details
#check_connection ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dockscan/scan/manage.rb', line 23 def check_connection @log.info("Validating version specified: "+Docker.url) begin Docker.validate_version! rescue @log.error("Error connecting or validating Docker version") return false end return true end |
#scan(url, opts, logger) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/dockscan/scan/manage.rb', line 34 def scan (url, opts, logger) failed=Array.new if url != nil then Docker.url = url end @log=logger if not check_connection then return end moduledirs=Array.new if moduledirs.empty? then moduledirs.push File.("../modules", File.dirname(__FILE__)) end @log.info("Loading discovery modules...") moduledirs.each do |moduledir| @log.debug("Loading dir: #{moduledir}") Dir["#{moduledir}/discover/*.rb"].each do |f| @log.info("Loading discovery module: #{f}") begin require f rescue SyntaxError => se @log.info("Error loading audit module: #{f}") @log.debug("Error executing audit module: #{se.backtrace}") failed << f end end end @log.info("Running discovery modules...") Dockscan::Modules::DiscoverModule.modules.each do |modclass| @log.info("Running discovery module: #{modclass.name}") begin mod=modclass.new mod.scandata=@auditoutput @auditoutput[mod.class.name]=mod.run rescue Exception => e @log.info("Error executing audit module: #{modclass.name}") @log.debug("Error executing audit module: #{e.backtrace}") failed << modclass.name end # pp @auditoutput[mod.class.name] end @log.info("Loading audit modules...") moduledirs.each do |moduledir| @log.debug("Loading dir: #{moduledir}") Dir["#{moduledir}/audit/*.rb"].each do |f| @log.info("Loading audit module: #{f}") begin require f rescue SyntaxError => se @log.info("Error loading audit module: #{f}") @log.debug("Error executing audit module: #{se.backtrace}") failed << f end end end @log.info("Running audit modules...") Dockscan::Modules::AuditModule.modules.each do |modclass| @log.info("Running audit module: #{modclass.name}") begin mod=modclass.new mod.scandata=@auditoutput @auditoutput[mod.class.name]=mod.check('test') rescue Exception => e @log.info("Error executing audit module: #{modclass.name}") @log.debug("Error executing audit module: #{e.to_s} #{e.backtrace}") failed << modclass.name end # pp @auditoutput[mod.class.name] end @log.info("Loading report modules...") moduledirs.each do |moduledir| Dir["#{moduledir}/report/*.rb"].each do |f| @log.info("Loading report #{f}") begin require f rescue SyntaxError => se @log.info("Error loading report module: #{f}") @log.debug("Error executing report module: #{se.backtrace}") failed << f end end end @log.info("Running report modules...") Dockscan::Modules::ReportModule.modules.each do |modclass| @log.info("Running report module: #{modclass.name}") mod=modclass.new if opts.key?("report") then formats=opts["report"].split(",") else formats=['stdout'] end formats.each do |fmt| if fmt==mod.format then begin mod.scandata=@auditoutput output=mod.report(nil) if opts.key?("output") then reportfilename = opts["output"] reportfilename << mod.file_extension File.open(reportfilename, 'w') { |file| file.write(output) } else puts output end rescue Exception => e @log.info("Error executing report module: #{modclass.name}") @log.debug("Error executing report module: #{e.to_s} #{e.backtrace}") failed << modclass.name end @log.debug(output) else @log.debug("Skipping report module: #{modclass.name}"); end end end if failed.count > 0 failedstr="" failed.each do |f| failedstr = f + " " end @log.warn("Following modules failed: #{failedstr}") end end |