Class: AttachFileCommand

Inherits:
AbstractCommand show all
Defined in:
lib/audit/lib/parser/command/attach_file_command.rb

Overview

A command that uploads a file from the audited host.

Constant Summary collapse

COMMAND =

Command name in the script.

"ATTACH_FILE"
@@log =
Logger.new(STDOUT)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(check, severity, args) ⇒ AttachFileCommand

Returns a new instance of AttachFileCommand.



40
41
42
43
44
45
46
47
48
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 40

def initialize(check, severity, args)
	message = args[1 .. -1].join if args.length >= 2
	super(check, severity, message)
	
	@@log.level = Logger::DEBUG
	
	@remote_path = args[0].strip if args.length >= 1 or raise ParseException.new("#{COMMAND} did not supply the file argument")
	@local_path = nil
end

Instance Attribute Details

#checkObject (readonly)

Returns the value of attribute check.



36
37
38
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 36

def check
  @check
end

#messageObject (readonly)

Returns the value of attribute message.



38
39
40
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 38

def message
  @message
end

#remote_pathObject (readonly)

Returns the value of attribute remote_path.



37
38
39
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 37

def remote_path
  @remote_path
end

#severityObject (readonly)

Returns the value of attribute severity.



35
36
37
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 35

def severity
  @severity
end

Instance Method Details

#process(parser) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 50

def process(parser)
	if parser.attachment_dir then
		filename = (/^(\/?([^\/]+\/)*)([^\/]+)$/.match(@remote_path) or {3 => nil})[3]
		@local_path = parser.attachment_dir + "/" + filename 
		parser.connection.copy_from_remote(@remote_path, @local_path)
	else
		@@log.info { "file #{@remote_path} attached, but no attachment dir specified" }
	end
end

#resultObject



60
61
62
# File 'lib/audit/lib/parser/command/attach_file_command.rb', line 60

def result()
  return AttachFileCommandResult.new(@check, @severity, @message, @local_path)
end