2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-14 16:50:13 +02:00
|
|
|
class ClamavService
|
2018-03-20 17:47:37 +01:00
|
|
|
def self.safe_file?(file_path)
|
2022-01-28 16:20:11 +01:00
|
|
|
return true if !Rails.configuration.x.clamav.enabled
|
2016-04-20 16:51:57 +02:00
|
|
|
|
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
|
2019-02-05 14:23:43 +01:00
|
|
|
response = client.execute(ClamAV::Commands::ScanCommand.new(file_path)).first
|
2022-01-28 16:20:11 +01:00
|
|
|
|
|
|
|
case response
|
|
|
|
when ClamAV::SuccessResponse
|
2019-02-05 14:23:43 +01:00
|
|
|
true
|
2022-01-28 16:20:11 +01:00
|
|
|
when ClamAV::VirusResponse
|
2019-02-05 14:23:43 +01:00
|
|
|
false
|
2022-01-28 16:20:11 +01:00
|
|
|
when ClamAV::ErrorResponse
|
2019-02-05 14:23:43 +01:00
|
|
|
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
|