Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Scan files when a single server is online #42

Merged
merged 6 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions lib/discourse_antivirus/clamav.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,11 @@ def update_versions
end

def accepting_connections?
sockets = clamav_services_pool.all_tcp_sockets
available = clamav_services_pool.all_tcp_sockets.any? { |socket| target_online?(socket) }

if sockets.empty?
update_status(true)
return false
end

available = sockets.reduce(true) { |memo, socket| memo && target_online?(socket) }
update_status(!available)

available.tap do |status|
unavailable = !status
update_status(unavailable)
end
available
end

def scan_upload(upload)
Expand Down Expand Up @@ -101,7 +93,10 @@ def clean_msg(raw)
raw.gsub("1: ", "").strip
end

def with_session(socket: clamav_services_pool.tcp_socket)
def with_session(socket: nil)
socket ||= clamav_services_pool.all_tcp_sockets.shuffle.find { |s| target_online?(s) }
romanrizzi marked this conversation as resolved.
Show resolved Hide resolved
raise "no online socket found" if !socket

write_in_socket(socket, "zIDSESSION\0")

yield(socket)
Expand Down
4 changes: 0 additions & 4 deletions lib/discourse_antivirus/clamav_services_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ def self.correctly_configured?
end
end

def tcp_socket
build_socket(service_instance.targets.first)
end

def all_tcp_sockets
service_instance.targets.map { |target| build_socket(target) }
end
Expand Down
Loading