Module: Clamby
- Defined in:
- lib/clamby.rb,
lib/clamby/version.rb
Constant Summary collapse
- VERSION =
"1.2.5"
Class Method Summary collapse
- .clamd_executable_name(daemonize: false) ⇒ Object
- .config ⇒ Object
- .configure(opts = {}) ⇒ Object
- .daemonize? ⇒ Boolean
- .file_exists?(path) ⇒ Boolean
- .safe?(path) ⇒ Boolean
- .scanner_exists? ⇒ Boolean
-
.system_command(path) ⇒ String
Assemble the system command to be called, including optional flags.
- .update ⇒ Object
- .virus?(path) ⇒ Boolean
Class Method Details
.clamd_executable_name(daemonize: false) ⇒ Object
78 79 80 |
# File 'lib/clamby.rb', line 78 def self.clamd_executable_name(daemonize: false) daemonize? ? "clamdscan" : "clamscan" end |
.config ⇒ Object
74 75 76 |
# File 'lib/clamby.rb', line 74 def self.config @config end |
.configure(opts = {}) ⇒ Object
16 17 18 |
# File 'lib/clamby.rb', line 16 def self.configure(opts = {}) opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym} end |
.daemonize? ⇒ Boolean
82 83 84 |
# File 'lib/clamby.rb', line 82 def self.daemonize? !! @config[:daemonize] end |
.file_exists?(path) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/clamby.rb', line 58 def self.file_exists?(path) return false if path.nil? return true if File.file?(path) if @config[:error_file_missing] raise Exceptions::FileNotFound.new("File not found: #{path}") else puts "FILE NOT FOUND on #{Time.now}: #{path}" return false end end |
.safe?(path) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/clamby.rb', line 20 def self.safe?(path) value = virus?(path) return nil if value.nil? ! value end |
.scanner_exists? ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'lib/clamby.rb', line 48 def self.scanner_exists? return true unless @config[:check] scanner = system(clamd_executable_name, '-V') return true if scanner return false unless @config[:error_clamscan_missing] raise Exceptions::ClamscanMissing.new("#{clamd_executable_name} application not found. Check your installation and path.") end |
.system_command(path) ⇒ String
Assemble the system command to be called, including optional flags
29 30 31 32 33 34 35 |
# File 'lib/clamby.rb', line 29 def self.system_command(path) command = clamd_executable_name command += ' --fdpass' if @config[:fdpass] command += " #{path}" command += ' --no-summary' command end |
.update ⇒ Object
70 71 72 |
# File 'lib/clamby.rb', line 70 def self.update system("freshclam") end |
.virus?(path) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/clamby.rb', line 37 def self.virus?(path) return nil unless scanner_exists? return nil unless file_exists?(path) scanner = system(system_command(path)) return false if scanner return true unless @config[:error_file_virus] raise Exceptions::VirusDetected.new("VIRUS DETECTED on #{Time.now}: #{path}") end |