Skip to content
Snippets Groups Projects
Commit eb518993 authored by aurieh's avatar aurieh
Browse files

First version

parent 8eb166fc
No related branches found
No related tags found
No related merge requests found
{
"extends": "standard",
"installedESLint": true,
"plugins": [
"standard",
"promise"
],
"rules": {
"semi": "always"
}
}
\ No newline at end of file
{
"eslint.enable": true
}
\ No newline at end of file
module.exports = {
getFile: require('./lib/getfile'),
scanner: require('./lib/scanner'),
refreshclam: require('./lib/refreshclam')
}
\ No newline at end of file
module.exports = function getFile(S3, key) {
return new Promise((resolve, reject) => {
S3.getObject({
Bucket: `${process.env.SERVICE}-filestore-${process.env.STAGE}-1`,
Key: key
}, (err, file) => {
if (err) return void reject(err);
resolve(file);
});
});
}
\ No newline at end of file
const exec = require('child_process').exec;
const debug = require("debug")("scanner");
module.exports = function refresh() {
return new Promise((resolve, reject) => {
debug('Updating virus database')
const proc = exec('freshclam', [], {stdio: 'inherit'});
proc.on('error', reject);
proc.on('exit', code => {
if (code !== 0) return void reject(new Error(`Clamscan exited with code ${code}`));
debug('Finished updating');
resolve();
})
});
}
\ No newline at end of file
const clam = require('clamscan')();
const fs = require('fs');
const path = require('path');
const getFile = require('./getfile');
module.exports = function scanFile(notif, S3) {
return new Promise((resolve, reject) => {
const key = notif.Records[0].s3.object.key;
getFile(S3, key).then(file => {
const filepath = path.resolve(path.join(__dirname, '/files/', key));
fs.writeFile(filepath, file.body, (err) => {
if (err) return void reject(err);
clam.is_infected(filepath, (err, _, is_infected) => {
fs.unlink(filepath, (unlinkErr) => {
if (err || unlinkErr) return void reject(err || unlinkErr);
resolve({infected: is_infected});
});
});
});
}, reject);
});
}
\ No newline at end of file
{
"name": "whats-a-virus",
"version": "0.0.1",
"description": "Whats this, a virus? Scanner built for whats-th.is file uploader.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/whats-this/scanner.git"
},
"keywords": [
"av",
"antivirus",
"clamscan",
"clamav"
],
"author": "aurieh",
"license": "MIT",
"bugs": {
"url": "https://github.com/whats-this/scanner/issues"
},
"homepage": "https://github.com/whats-this/scanner#readme",
"devDependencies": {
"eslint": "^3.12.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment