forked from pompelmi/pompelmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-on-malicious.js
More file actions
34 lines (27 loc) · 905 Bytes
/
delete-on-malicious.js
File metadata and controls
34 lines (27 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// delete-on-malicious.js
// Scan a file and automatically delete it if ClamAV finds malware.
// Suitable for batch jobs where infected files should be removed immediately.
// Run: node examples/delete-on-malicious.js
'use strict';
const path = require('path');
const fs = require('fs');
const { scan, Verdict } = require('pompelmi');
async function scanAndDelete(filePath) {
const resolved = path.resolve(filePath);
const result = await scan(resolved);
if (result === Verdict.Malicious) {
fs.unlinkSync(resolved);
console.log(`Deleted malicious file: ${resolved}`);
return false;
}
if (result === Verdict.ScanError) {
console.warn(`Scan incomplete, skipping: ${resolved}`);
return false;
}
console.log(`Clean: ${resolved}`);
return true;
}
(async () => {
const clean = await scanAndDelete('./uploads/attachment.zip');
process.exit(clean ? 0 : 1);
})();