Sha256: 7eac73c47317061c47da95c6146f2a18e56bfef497bf53d90e2e4ba5e5eca175

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require "clamby/version"
require "clamby/exception"
module Clamby

  @config = {
    :check => true,
    :error_clamscan_missing => true,
    :error_file_missing => true,
    :error_file_virus => true
  }

  @valid_config_keys = @config.keys

  def self.configure(opts = {})
    opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
  end

  def self.scan(path)
    if self.scanner_exists?
      if file_exists?(path)
        scanner = system("clamscan #{path} --no-summary")
        if scanner
          return true
        elsif not scanner
          if @config[:error_file_virus]
            raise Exceptions::VirusDetected.new("VIRUS DETECTED on #{Time.now}: #{path}")
          else
            puts "VIRUS DETECTED on #{Time.now}: #{path}"
            return false
          end
        end
      end
    end
  end

  def self.scanner_exists?
    if @config[:check]
      scanner = system('clamscan -V')
      if not scanner
        if @config[:error_clamscan_missing]
          raise Exceptions::ClamscanMissing.new("Clamscan application not found. Check your installation and path.")
        else
          puts "CLAMSCAN NOT FOUND"
          return false
        end
      else
        return true
      end
    else
      return true
    end
  end

  def self.file_exists?(path)
    if File.file?(path)
      return true
    else
      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
  end

  def self.update
    system("freshclam")
  end

  def self.config
    @config
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clamby-1.0.4 lib/clamby.rb