Module: Rclam::Helpers

Defined in:
lib/rclam/helpers.rb

Constant Summary collapse

FRESHCLAM_REGEX =
/^.+\/(\D{3}\W+\D{3}\W+\d{1,2}\W+\d{2}:\d{1,2}:\d{1,2}\W+\d{4})$/
INFECTED_FILES_REGEX =
/^Infected files: (\d+)$/
SCANNED_FILES_REGEX =
/^Scanned files: (\d+)$/
TIME_REGEX =
/^Time: .+\((\d \w{1} \d \w{1})\)$/
SIGNATURES_REGEX =
/^Known viruses: (\d+)$/

Class Method Summary collapse

Class Method Details

.clamscan_report(results) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rclam/helpers.rb', line 25

def self.clamscan_report(results)
  infected_files = first_regex_capture(INFECTED_FILES_REGEX, results).to_i
  scanned_files = first_regex_capture(SCANNED_FILES_REGEX, results)
  signatures = first_regex_capture(SIGNATURES_REGEX, results)
  result = infected_files > 0 ? "!!INFECTED!!" : "CLEAN"

  result = %Q{
    Result:         #{result}
    Infections:     #{infected_files}
    Scanned Files:  #{scanned_files}
    Signatures:     #{signatures}
  }
  
  # Remove tabs from each line
  # https://stackoverflow.com/a/31345870
  result.each_line.map(&:strip).join("\n")
end

.date_within_a_day?(date) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/rclam/helpers.rb', line 20

def self.date_within_a_day?(date)
  hours_difference = ((DateTime.now.to_time - date.to_time) / 3600).to_i
  hours_difference <= 24
end

.first_regex_capture(regex, value) ⇒ Object



9
10
11
12
13
# File 'lib/rclam/helpers.rb', line 9

def self.first_regex_capture(regex, value)
  match = regex.match(value)
  return nil if match.nil?
  match.captures.first
end

.last_signatures_updateObject



15
16
17
18
# File 'lib/rclam/helpers.rb', line 15

def self.last_signatures_update
  version_header = %x{freshclam --version}
  DateTime.parse self.first_regex_capture(FRESHCLAM_REGEX, version_header)
end