fix: align with clamscan v2

This commit is contained in:
Bobby 2022-04-15 15:36:50 +07:00
parent ffc82f6a2a
commit 6788dc2094
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
4 changed files with 31 additions and 12 deletions

View File

@ -401,21 +401,31 @@ module.exports = {
// Make sure maxSize is no bigger than the max size you configured for your ClamAV
maxSize: null, // Needs to be in MB
// https://github.com/kylefarris/clamscan/tree/v1.3.3#getting-started
// Breaking options (do not use): remove_infected, quarantine_infected
// Untested options (may work): scan_log, debug_mode, file_list, scan_recursively
// Supported options: clamscan, clamdscan, preference
// https://github.com/kylefarris/clamscan/tree/v2.1.2#getting-started
// Breaking options (do not use): removeInfected, quarantineInfected, fileList, scanRecursively
// Untested options (may work): scanLog
// Supported options: debugMode, clamscan, clamdscan, preference
clamOptions: {
// clamscan: {},
debugMode: false,
clamscan: {
path: '/usr/bin/clamscan',
db: null,
scanArchives: true,
active: true
},
clamdscan: {
// When both socket and host+port are specified, it will only use socket
socket: '/var/run/clamav/clamd.ctl',
host: '127.0.0.1',
port: 3310,
timeout: 1 * 60 * 1000, // 1 minute
localFallback: true,
path: '/usr/bin/clamdscan',
configFile: null,
multiscan: true,
reload_db: false,
active: true
reloadDb: false,
active: true,
bypassTest: false
},
preference: 'clamdscan'
}

View File

@ -618,6 +618,7 @@ self.scanFiles = async (req, user, infoMap) => {
}
const foundThreats = []
const unableToScan = []
const results = await Promise.all(infoMap.map(async info => {
if (utils.clamscan.whitelistExtensions && utils.clamscan.whitelistExtensions.includes(info.data.extname)) {
logger.debug(`[ClamAV]: Skipping ${info.data.filename}, extension whitelisted`)
@ -630,16 +631,24 @@ self.scanFiles = async (req, user, infoMap) => {
}
logger.debug(`[ClamAV]: Scanning ${info.data.filename}\u2026`)
const response = await utils.clamscan.instance.isInfected(info.path)
if (response.isInfected) {
logger.log(`[ClamAV]: ${info.data.filename}: ${response.viruses.join(', ')}`)
foundThreats.push(...response.viruses)
} else if (response.isInfected === null) {
logger.log(`[ClamAV]: ${info.data.filename}: Unable to scan`)
unableToScan.push(info.data.filename)
}
})).then(() => {
if (foundThreats.length) {
const more = foundThreats.length > 1
return `Threat${more ? 's' : ''} detected: ${foundThreats[0]}${more ? ', and more' : ''}.`
} else if (unableToScan.length) {
const more = unableToScan.length > 1
return `Unable to scan: ${unableToScan[0]}${more ? ', and more' : ''}.`
}
}).catch(error => {
logger.error(`[ClamAV]: ${error.toString()}`)
logger.error(`[ClamAV]: ${infoMap.map(info => info.data.filename).join(', ')}: ${error.toString()}`)
return 'An unexpected error occurred with ClamAV, please contact the site owner.'
})

View File

@ -687,7 +687,7 @@ self.stats = async (req, res, next) => {
if (self.clamscan.instance) {
try {
self.clamscan.version = await self.clamscan.instance.get_version().then(s => s.trim())
self.clamscan.version = await self.clamscan.instance.getVersion().then(s => s.trim())
} catch (error) {
logger.error(error)
self.clamscan.version = 'Errored when querying version.'

View File

@ -11,10 +11,10 @@ process.on('unhandledRejection', error => {
// Require libraries
const bodyParser = require('body-parser')
const ClamScan = require('clamscan')
const contentDisposition = require('content-disposition')
const express = require('express')
const helmet = require('helmet')
const NodeClam = require('clamscan')
const nunjucks = require('nunjucks')
const path = require('path')
const rateLimit = require('express-rate-limit')
@ -312,8 +312,8 @@ safe.use('/api', api)
logger.error('Missing object config.uploads.scan.clamOptions (check config.sample.js)')
process.exit(1)
}
utils.clamscan.instance = await new ClamScan().init(config.uploads.scan.clamOptions)
utils.clamscan.version = await utils.clamscan.instance.get_version().then(s => s.trim())
utils.clamscan.instance = await new NodeClam().init(config.uploads.scan.clamOptions)
utils.clamscan.version = await utils.clamscan.instance.getVersion().then(s => s.trim())
logger.log(`Connection established with ${utils.clamscan.version}`)
}