feat(services/autumn): file uploads
feat(services/autumn): deduplicate uploads feat(services/autumn): ClamAV support
This commit is contained in:
49
crates/services/autumn/src/clamav.rs
Normal file
49
crates/services/autumn/src/clamav.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use revolt_config::{config, report_internal_error};
|
||||
use revolt_result::Result;
|
||||
|
||||
/// Initialise ClamAV
|
||||
pub async fn init() {
|
||||
let config = config().await;
|
||||
|
||||
if !config.files.clamd_host.is_empty() {
|
||||
tracing::info!("Waiting for clamd to be ready...");
|
||||
|
||||
loop {
|
||||
let clamd_available =
|
||||
match revolt_clamav_client::ping_tcp(config.files.clamd_host.clone()) {
|
||||
Ok(ping_response) => ping_response == b"PONG\0",
|
||||
Err(_) => false,
|
||||
};
|
||||
|
||||
if clamd_available {
|
||||
tracing::info!("clamd is ready, virus protection enabled!");
|
||||
break;
|
||||
} else {
|
||||
tracing::error!(
|
||||
"Could not ping clamd host at {}, retrying in 10 seconds...",
|
||||
config.files.clamd_host
|
||||
);
|
||||
|
||||
std::thread::sleep(Duration::from_secs(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan for malware
|
||||
pub async fn is_malware(buf: &[u8]) -> Result<bool> {
|
||||
let config = config().await;
|
||||
if config.files.clamd_host.is_empty() {
|
||||
Ok(false)
|
||||
} else {
|
||||
let scan_response = report_internal_error!(revolt_clamav_client::scan_buffer_tcp(
|
||||
buf,
|
||||
config.files.clamd_host,
|
||||
None
|
||||
))?;
|
||||
|
||||
report_internal_error!(revolt_clamav_client::clean(&scan_response)).map(|v| !v)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user