|
1 | 1 | import Promise from 'bluebird'; |
2 | 2 | import logger from 'lib/logger'; |
| 3 | +import defaultTo from 'lodash/defaultTo'; |
3 | 4 |
|
4 | | -const scanError = err => ( |
5 | | - new Error(`Something went wrong when scanning the file. ${err.message}`) |
6 | | -); |
7 | 5 | const virusError = () => ( |
8 | 6 | new Error('This file has not passed the virus scan and will be deleted.') |
9 | 7 | ); |
10 | 8 | export default filePath => new Promise((resolve, reject) => { |
11 | | - if (!process.env.CLAMSCAN_BINARY) { |
12 | | - logger.warn('CLAMSCAN NOT INSTALLED, SEE DOCS FOR FURTHER INFORMATION.'); |
| 9 | + if (!process.env.CLAMDSCAN_BINARY) { |
| 10 | + logger.warn('CLAMDSCAN NOT INSTALLED, SEE DOCS FOR FURTHER INFORMATION.'); |
13 | 11 | return resolve(filePath); |
14 | 12 | } |
15 | 13 | try { |
16 | 14 | const clam = require('clamscan')({ |
17 | 15 | remove_infected: true, |
18 | | - clamscan: { |
19 | | - path: process.env.CLAMSCAN_BINARY, |
| 16 | + clamdscan: { |
| 17 | + path: process.env.CLAMDSCAN_BINARY, |
| 18 | + config_file: defaultTo(process.env.CLAMDSCAN_CONF, '/etc/clamav/clamd.conf') |
20 | 19 | }, |
21 | | - preference: 'clamscan', |
| 20 | + preference: 'clamdscan', |
22 | 21 | }); |
23 | 22 |
|
24 | 23 | clam.is_infected(filePath, (err, file, isInfected) => { |
25 | | - if (err) return reject(scanError(err)); |
| 24 | + if (err) { |
| 25 | + logger.warn('ERROR SCANNING FILE WITH CLAMD - ', err); |
| 26 | + return resolve(filePath); |
| 27 | + } |
26 | 28 | if (isInfected) return reject(virusError()); |
27 | 29 | return resolve(filePath); |
28 | 30 | }); |
29 | 31 | } catch (err) { |
30 | | - return reject(scanError(err)); |
| 32 | + logger.warn('ERROR SCANNING FILE WITH CLAMD - ', err); |
| 33 | + return resolve(filePath); |
31 | 34 | } |
32 | 35 | }); |
0 commit comments