Skip to content

Commit

Permalink
FIX: Scan files when a single server is online
Browse files Browse the repository at this point in the history
This commits makes sure that even when a single server is online,
the plugin is available. This commit also makes sure that a random
and online server is chosen when using with_session without any
specified socket. It used to use the first one.
  • Loading branch information
nbianca committed Aug 2, 2023
1 parent 7b70301 commit d1b2050
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
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) }
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

0 comments on commit d1b2050

Please sign in to comment.