mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
fix: align with clamscan v2
This commit is contained in:
parent
ffc82f6a2a
commit
6788dc2094
@ -401,21 +401,31 @@ module.exports = {
|
|||||||
// Make sure maxSize is no bigger than the max size you configured for your ClamAV
|
// Make sure maxSize is no bigger than the max size you configured for your ClamAV
|
||||||
maxSize: null, // Needs to be in MB
|
maxSize: null, // Needs to be in MB
|
||||||
|
|
||||||
// https://github.com/kylefarris/clamscan/tree/v1.3.3#getting-started
|
// https://github.com/kylefarris/clamscan/tree/v2.1.2#getting-started
|
||||||
// Breaking options (do not use): remove_infected, quarantine_infected
|
// Breaking options (do not use): removeInfected, quarantineInfected, fileList, scanRecursively
|
||||||
// Untested options (may work): scan_log, debug_mode, file_list, scan_recursively
|
// Untested options (may work): scanLog
|
||||||
// Supported options: clamscan, clamdscan, preference
|
// Supported options: debugMode, clamscan, clamdscan, preference
|
||||||
clamOptions: {
|
clamOptions: {
|
||||||
// clamscan: {},
|
debugMode: false,
|
||||||
|
clamscan: {
|
||||||
|
path: '/usr/bin/clamscan',
|
||||||
|
db: null,
|
||||||
|
scanArchives: true,
|
||||||
|
active: true
|
||||||
|
},
|
||||||
clamdscan: {
|
clamdscan: {
|
||||||
// When both socket and host+port are specified, it will only use socket
|
// When both socket and host+port are specified, it will only use socket
|
||||||
socket: '/var/run/clamav/clamd.ctl',
|
socket: '/var/run/clamav/clamd.ctl',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 3310,
|
port: 3310,
|
||||||
timeout: 1 * 60 * 1000, // 1 minute
|
timeout: 1 * 60 * 1000, // 1 minute
|
||||||
|
localFallback: true,
|
||||||
|
path: '/usr/bin/clamdscan',
|
||||||
|
configFile: null,
|
||||||
multiscan: true,
|
multiscan: true,
|
||||||
reload_db: false,
|
reloadDb: false,
|
||||||
active: true
|
active: true,
|
||||||
|
bypassTest: false
|
||||||
},
|
},
|
||||||
preference: 'clamdscan'
|
preference: 'clamdscan'
|
||||||
}
|
}
|
||||||
|
@ -618,6 +618,7 @@ self.scanFiles = async (req, user, infoMap) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const foundThreats = []
|
const foundThreats = []
|
||||||
|
const unableToScan = []
|
||||||
const results = await Promise.all(infoMap.map(async info => {
|
const results = await Promise.all(infoMap.map(async info => {
|
||||||
if (utils.clamscan.whitelistExtensions && utils.clamscan.whitelistExtensions.includes(info.data.extname)) {
|
if (utils.clamscan.whitelistExtensions && utils.clamscan.whitelistExtensions.includes(info.data.extname)) {
|
||||||
logger.debug(`[ClamAV]: Skipping ${info.data.filename}, extension whitelisted`)
|
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`)
|
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(', ')}`)
|
logger.log(`[ClamAV]: ${info.data.filename}: ${response.viruses.join(', ')}`)
|
||||||
foundThreats.push(...response.viruses)
|
foundThreats.push(...response.viruses)
|
||||||
|
} else if (response.isInfected === null) {
|
||||||
|
logger.log(`[ClamAV]: ${info.data.filename}: Unable to scan`)
|
||||||
|
unableToScan.push(info.data.filename)
|
||||||
}
|
}
|
||||||
})).then(() => {
|
})).then(() => {
|
||||||
if (foundThreats.length) {
|
if (foundThreats.length) {
|
||||||
const more = foundThreats.length > 1
|
const more = foundThreats.length > 1
|
||||||
return `Threat${more ? 's' : ''} detected: ${foundThreats[0]}${more ? ', and more' : ''}.`
|
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 => {
|
}).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.'
|
return 'An unexpected error occurred with ClamAV, please contact the site owner.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -687,7 +687,7 @@ self.stats = async (req, res, next) => {
|
|||||||
|
|
||||||
if (self.clamscan.instance) {
|
if (self.clamscan.instance) {
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
self.clamscan.version = 'Errored when querying version.'
|
self.clamscan.version = 'Errored when querying version.'
|
||||||
|
@ -11,10 +11,10 @@ process.on('unhandledRejection', error => {
|
|||||||
|
|
||||||
// Require libraries
|
// Require libraries
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const ClamScan = require('clamscan')
|
|
||||||
const contentDisposition = require('content-disposition')
|
const contentDisposition = require('content-disposition')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const helmet = require('helmet')
|
const helmet = require('helmet')
|
||||||
|
const NodeClam = require('clamscan')
|
||||||
const nunjucks = require('nunjucks')
|
const nunjucks = require('nunjucks')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const rateLimit = require('express-rate-limit')
|
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)')
|
logger.error('Missing object config.uploads.scan.clamOptions (check config.sample.js)')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
utils.clamscan.instance = await new ClamScan().init(config.uploads.scan.clamOptions)
|
utils.clamscan.instance = await new NodeClam().init(config.uploads.scan.clamOptions)
|
||||||
utils.clamscan.version = await utils.clamscan.instance.get_version().then(s => s.trim())
|
utils.clamscan.version = await utils.clamscan.instance.getVersion().then(s => s.trim())
|
||||||
logger.log(`Connection established with ${utils.clamscan.version}`)
|
logger.log(`Connection established with ${utils.clamscan.version}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user