Class: Clamby::Command
- Inherits:
-
Object
- Object
- Clamby::Command
- Defined in:
- lib/clamby/command.rb
Overview
Interface with the system. Builds and runs the command.
Constant Summary collapse
- EXECUTABLES =
%w(clamscan clamdscan freshclam)
Instance Attribute Summary collapse
-
#command ⇒ Object
Array containing the complete command line.
Class Method Summary collapse
-
.clamscan_version ⇒ Object
Show the ClamAV version.
-
.freshclam ⇒ Object
Update the virus definitions.
-
.scan(path) ⇒ Object
Perform a ClamAV scan on the given path.
-
.scan_executable ⇒ Object
Returns the appropriate scan executable, based on clamd being used.
Instance Method Summary collapse
-
#run(executable, *args) ⇒ Object
Run the given commands via a system call.
Instance Attribute Details
#command ⇒ Object
Array containing the complete command line.
7 8 9 |
# File 'lib/clamby/command.rb', line 7 def command @command end |
Class Method Details
.clamscan_version ⇒ Object
Show the ClamAV version. Also acts as a quick check if ClamAV functions.
53 54 55 |
# File 'lib/clamby/command.rb', line 53 def self.clamscan_version new.run 'clamscan', '--version' end |
.freshclam ⇒ Object
Update the virus definitions.
48 49 50 |
# File 'lib/clamby/command.rb', line 48 def self.freshclam new.run 'freshclam' end |
.scan(path) ⇒ Object
Perform a ClamAV scan on the given path.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/clamby/command.rb', line 16 def self.scan(path) return nil unless file_exists?(path) args = [path, '--no-summary'] if Clamby.config[:daemonize] args << '--fdpass' if Clamby.config[:fdpass] args << '--stream' if Clamby.config[:stream] args << "--config-file=#{Clamby.config[:config_file]}" if Clamby.config[:config_file] end new.run scan_executable, *args case $CHILD_STATUS.exitstatus when 0 return false when 2 # clamdscan returns 2 whenever error other than a detection happens if Clamby.config[:error_clamscan_client_error] && Clamby.config[:daemonize] raise Clamby::ClamscanClientError.new("Clamscan client error") end # returns true to maintain legacy behavior return true else return true unless Clamby.config[:error_file_virus] raise Clamby::VirusDetected.new("VIRUS DETECTED on #{Time.now}: #{path}") end end |
.scan_executable ⇒ Object
Returns the appropriate scan executable, based on clamd being used.
10 11 12 13 |
# File 'lib/clamby/command.rb', line 10 def self.scan_executable return 'clamdscan' if Clamby.config[:daemonize] return 'clamscan' end |
Instance Method Details
#run(executable, *args) ⇒ Object
Run the given commands via a system call. The executable must be one of the permitted ClamAV executables. The arguments will be combined with default arguments if needed. The arguments are sorted alphabetically before being passed to the system.
Examples:
run('clamscan', file, '--verbose')
run('clamscan', '-V')
65 66 67 68 69 70 71 |
# File 'lib/clamby/command.rb', line 65 def run(executable, *args) executable_full = executable_path(executable) self.command = args | default_args self.command = command.sort.unshift(executable_full) system(*self.command, ) end |