Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commenting out clamscanand preference to supress error #35

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SERVER_PORT = 3500
CLAMD_CONFIG_FILE = null
CLAMD_MULTI_SCAN = true
CLAMD_ACTIVE = true
CLAMD_BYPASS_REST = false
CLAMD_BYPASS_TEST = false
CLAMD_SOCKET = '/tmp/clamd.sock'
CLAMD_HOST = '127.0.0.1'
CLAMD_PORT = 65615
Expand Down
45 changes: 17 additions & 28 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
require('dotenv').config();

const clamscanConfig = {
removeInfected: true, // If true, removes infected files
quarantineInfected: false, // False: Don't quarantine, Path: Moves files to this place.
scanLog: process.env.CLAM_SCAN_LOG && process.env.CLAM_SCAN_LOG != 'null'? process.env.CLAM_SCAN_LOG : null, // Path to a writeable log file to write scan results into
// removeInfected: true, // If true, removes infected files
// quarantineInfected: false, // False: Don't quarantine, Path: Moves files to this place.
// scanLog: process.env.CLAM_SCAN_LOG && process.env.CLAM_SCAN_LOG != 'null'? process.env.CLAM_SCAN_LOG : null, // Path to a writeable log file to write scan results into
debugMode: process.env.CLAM_DEBUG_MODE ? /^true$/i.test(process.env.CLAM_DEBUG_MODE) : true, // Whether or not to log info/debug/error msgs to the console
fileList: null, // path to file containing list of files to scan (for scanFiles method)
// fileList: null, // path to file containing list of files to scan (for scanFiles method)
scanRecursively: true, // If true, deep scan folders recursively
clamscan: {
path: process.env.CLAMD_PATH ? process.env.CLAMD_PATH :'/opt/homebrew/bin/clamscan', // Path to clamscan binary on your server
db: null, // Path to a custom virus definition database
scanArchives: true, // If true, scan archives (ex. zip, rar, tar, dmg, iso, etc...)
active: process.env.CLAMD_ACTIVE ? /^true$/i.test(process.env.CLAMD_ACTIVE) : true // If true, this module will consider using the clamscan binary
},
// clamscan: {
// path: process.env.CLAMD_PATH ? process.env.CLAMD_PATH :'/opt/homebrew/bin/clamscan', // Path to clamscan binary on your server
// db: null, // Path to a custom virus definition database
// scanArchives: true, // If true, scan archives (ex. zip, rar, tar, dmg, iso, etc...)
// active: process.env.CLAMD_ACTIVE ? /^true$/i.test(process.env.CLAMD_ACTIVE) : true // If true, this module will consider using the clamscan binary
// },
clamdscan: {
socket: process.env.CLAMD_SOCKET && process.env.CLAMD_SOCKET != 'null'? process.env.CLAMD_SOCKET : null, // Socket file for connecting via TCP
host: process.env.CLAMD_HOST ? process.env.CLAMD_HOST : '127.0.0.1', // IP of host to connect to TCP interface
port: process.env.CLAMD_PORT ? parseInt(process.env.CLAMD_PORT) : 65615, // Port of host to use when connecting via TCP interface
timeout: process.env.CLAMD_TIMEOUT ? parseInt(process.env.CLAMD_TIMEOUT) : 120000, // Timeout for scanning files
localFallback: false, // Do no fail over to binary-method of scanning
path: process.env.CLAMD_PATH ? process.env.CLAMD_PATH : '/opt/homebrew/bin/clamscan', // Path to the clamdscan binary on your server
configFile: process.env.CLAMD_CONFIG_FILE && process.env.CLAMD_CONFIG_FILE != 'null' ? process.env.CLAMD_CONFIG_FILE : null, // Specify config file if it's in an unusual place
// configFile: process.env.CLAMD_CONFIG_FILE && process.env.CLAMD_CONFIG_FILE != 'null' ? process.env.CLAMD_CONFIG_FILE : null, // Specify config file if it's in an unusual place
multiscan: process.env.CLAMD_MULTI_SCAN ? /^true$/i.test(process.env.CLAMD_MULTI_SCAN) : false, // Scan using all available cores! Yay!
reloadDb: false, // If true, will re-load the DB on every call (slow)
active: process.env.CLAMD_ACTIVE ? /^true$/i.test(process.env.CLAMD_ACTIVE) : true, // If true, this module will consider using the clamdscan binary
bypassRest: process.env.CLAMD_BYPASS_REST ? /^true$/i.test(process.env.CLAMD_BYPASS_REST) : false, // Check to see if socket is available when applicable
// active: process.env.CLAMD_ACTIVE ? /^true$/i.test(process.env.CLAMD_ACTIVE) : true, // If true, this module will consider using the clamdscan binary
bypassTest: process.env.CLAMD_BYPASS_TEST ? /^true$/i.test(process.env.CLAMD_BYPASS_TEST) : false, // Check to see if socket is available when applicable
},
preference: process.env.CLAM_PREFERENCE ? process.env.CLAM_PREFERENCE :'clamdscan' // If clamdscan is found and active, it will be used by default
// preference: process.env.CLAM_PREFERENCE ? process.env.CLAM_PREFERENCE :'clamdscan' // If clamdscan is found and active, it will be used by default
}

const fileUploadConfig = {
Expand All @@ -35,20 +35,9 @@ const clamscanConfig = {
fileSize: process.env.FILE_SIZE_LIMIT ? parseInt(process.env.FILE_SIZE_LIMIT) : 10 * 1024 * 1024, // 10 MB
},
limitHandler: (req, res) => {
res.writeHead(413, {
Connection: 'close',
'Content-Type': 'application/json',
})
res.end(
JSON.stringify({
success: false,
data: {
error: `File size limit exceeded. Max size of uploaded file is: ${
proccess.env.FILE_SIZE_LIMIT ? parseInt(proccess.env.FILE_SIZE_LIMIT) / 1024: 10 * 1024
} KB`,
},
})
)
return res.status(413).json({
message: `File size limit exceeded. Max size of uploaded file is: ${process.env.FILE_SIZE_LIMIT ? parseInt(process.env.FILE_SIZE_LIMIT) / (1024 * 1024): 10} MB`
});
},
}

Expand Down
46 changes: 29 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ require('dotenv').config();
const app = express();
const cors = require('cors');
const fileUpload = require('express-fileupload');
const config = require('./config')
const config = require('./config');
const port = process.env.PORT && process.env.PORT !== '' ? parseInt(process.env.PORT) : 3500;

// Middleware functions
const startTime = (req, res, next) => {
const startTime = process.hrtime();
res.set(
'X-Start-Time',
startTime[0].toString() + ',' + startTime[1].toString(),
);
if (!res.headersSent) {
res.set(
'X-Start-Time',
startTime[0].toString() + ',' + startTime[1].toString(),
);
}
next();
}

Expand All @@ -26,24 +28,34 @@ const responseLogger = async function (
const originalSendFunc = res.send.bind(res);
res.send = function (body) {
const startTimeString = res.get('X-Start-Time')?.split(',');
const startTime = [
Number(startTimeString[0]),
Number(startTimeString[1]),
];
const diff = process.hrtime(startTime);
const time = diff[0] * 1e3 + diff[1] * 1e-6;
if (res.get('X-Start-Time')) {
let time;
if (startTimeString) {
const startTime = [
Number(startTimeString[0]),
Number(startTimeString[1]),
];
const diff = process.hrtime(startTime);
time = diff[0] * 1e3 + diff[1] * 1e-6;
} else {
/* In the case of 413 errors, we can't get an accurate time due to the
limit handler occuring in a library function, so set to 0 */
time = 0;
}
if (res.get('X-Start-Time') && !res.headersSent) {
res.removeHeader('X-Start-Time');
}
let reqBody = {}
if (req.files && req.files.energuide && req.files.energuide.name) reqBody = {filename: req.files.energuide.name};
if (req.files && req.files.energuide && req.files.energuide.name) reqBody = { filename: req.files.energuide.name }
else reqBody = { filename: 'Not processed' };
createAuditLog(
res.statusCode,
Number(time.toFixed(3)),
reqBody,
body,
).then(() => {});
return originalSendFunc(body);
if (!res.headersSent) {
return originalSendFunc(body);
}
};
next();
}
Expand Down Expand Up @@ -137,7 +149,7 @@ app.post('/virus-scan', async (req, res) => {

// Check for files
if (!req.files || ! req.files.energuide) {
return res.status(409).json({
return res.status(400).json({
message: 'No energuide file provided for scan'
})
}
Expand All @@ -152,10 +164,10 @@ app.post('/virus-scan', async (req, res) => {
console.log(scanResult);

if (scanResult.is_infected === true || scanFile.is_infected === null) {
return res.status(502).json({
return res.status(200).json({
filename: scanResult.filename ? scanResult.filename : null,
clean: false
})
});
}
return res.status(200).json({
filename: scanResult.filename ? scanResult.filename : null,
Expand Down