demarches-normaliennes/app/services/clamav_service.rb

22 lines
580 B
Ruby
Raw Normal View History

2016-04-14 16:50:13 +02:00
class ClamavService
def self.safe_file?(file_path)
2018-12-18 21:30:02 +01:00
if Rails.env.development?
2018-11-22 00:46:49 +01:00
return true
end
2018-12-18 21:29:31 +01:00
FileUtils.chmod(0666, file_path)
2016-04-14 16:50:13 +02:00
2016-04-15 15:32:15 +02:00
client = ClamAV::Client.new
response = client.execute(ClamAV::Commands::ScanCommand.new(file_path)).first
if response.class == ClamAV::SuccessResponse
true
elsif response.class == ClamAV::VirusResponse
false
elsif response.class == ClamAV::ErrorResponse
raise "ClamAV ErrorResponse : #{response.error_str}"
else
raise "ClamAV unkown response #{response.class.name}"
end
2016-04-14 16:50:13 +02:00
end
2017-04-04 15:27:04 +02:00
end