Init 'clamdjs' branch (#8)

Use clamdjs module instead of clam-engine. This module connects to clam daemon server.
This commit is contained in:
Bobby Wibowo 2018-09-04 22:48:24 +07:00 committed by GitHub
parent 36da76357e
commit a207c4a806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 40 deletions

View File

@ -530,7 +530,7 @@ uploadsController.formatInfoMap = (req, res, user, infoMap) => {
uploadsController.scanFiles = async (req, infoMap) => {
const dirty = await new Promise(async resolve => {
let iteration = 0
const engine = req.app.get('clam-engine')
const scanner = req.app.get('clam-scanner')
const dirty = []
for (const info of infoMap) {
@ -538,13 +538,10 @@ uploadsController.scanFiles = async (req, infoMap) => {
console.log(`ClamAV: ${info.data.filename}: ${message}.`)
}
engine.scanFile(info.path, (error, virus) => {
if (error || virus) {
if (error) { log(error.toString()) }
if (virus) { log(`${virus} detected`) }
scanner.scanFile(info.path).then(reply => {
if (!reply.includes('OK') || reply.includes('FOUND')) {
log(reply.replace(/^stream: /, ''))
dirty.push(info)
} else {
// log('OK')
}
iteration++

View File

@ -4,6 +4,7 @@ const album = require('./routes/album')
const nojs = require('./routes/nojs')
const express = require('express')
const bodyParser = require('body-parser')
const clamd = require('clamdjs')
const db = require('knex')(config.database)
const fs = require('fs')
const helmet = require('helmet')
@ -85,34 +86,30 @@ safe.use((error, req, res, next) => {
})
process.on('uncaughtException', error => {
console.error('Uncaught Exception:')
console.error(error)
console.error('Uncaught Exception:', error)
})
process.on('unhandledRejection', error => {
console.error('Unhandled Rejection (Promise):')
console.error(error)
console.error('Unhandled Rejection (Promise):', error)
})
async function start () {
if (config.uploads.scan) {
// Placing require() here so the package does not have to exist when the option is not enabled
const clam = require('clam-engine')
const created = await new Promise(resolve => {
process.stdout.write('Creating clam-engine...')
clam.createEngine(function (error, engine) {
if (error) {
process.stdout.write(' ERROR\n')
console.error(error)
return resolve(false)
}
safe.set('clam-engine', engine)
process.stdout.write(' OK\n')
console.log(`ClamAV ${engine.version} (${engine.signatures} sigs)`)
resolve(true)
})
})
if (!created) { return }
const start = async () => {
if (config.uploads.scan && config.uploads.scan.enabled) {
const created = await new Promise(async (resolve, reject) => {
if (!config.uploads.scan.ip || !config.uploads.scan.port) {
return reject(new Error('Clamd IP or Port is missing'))
}
const ping = await clamd.ping(config.uploads.scan.ip, config.uploads.scan.port).catch(reject)
if (!ping) {
return reject(new Error('Could not ping clamd'))
}
const version = await clamd.version(config.uploads.scan.ip, config.uploads.scan.port).catch(reject)
console.log(`${config.uploads.scan.ip}:${config.uploads.scan.port} ${version}`)
const scanner = clamd.createScanner(config.uploads.scan.ip, config.uploads.scan.port)
safe.set('clam-scanner', scanner)
return resolve(true)
}).catch(error => console.error(error.toString()))
if (!created) { return process.exit(1) }
}
safe.listen(config.port, () => console.log(`lolisafe started on port ${config.port}`))

View File

@ -22,7 +22,7 @@
"dependencies": {
"bcrypt": "^2.0.0",
"body-parser": "^1.18.2",
"clam-engine": "^2.0.1",
"clamdjs": "^1.0.1",
"express": "^4.16.3",
"express-rate-limit": "^2.11.0",
"fluent-ffmpeg": "^2.1.2",

View File

@ -360,11 +360,9 @@ circular-json@^0.3.1:
version "0.3.3"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
clam-engine@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/clam-engine/-/clam-engine-2.0.1.tgz#ad94dfa8e1d966d13e200dfd5d794f15425bccc5"
dependencies:
nan "^2.1.0"
clamdjs@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/clamdjs/-/clamdjs-1.0.1.tgz#335740395680217cde1327f90ae000feabab62e6"
class-utils@^0.3.5:
version "0.3.6"
@ -1764,10 +1762,6 @@ nan@2.10.0, nan@^2.9.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
nan@^2.1.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.11.0.tgz#574e360e4d954ab16966ec102c0c049fd961a099"
nan@~2.9.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.9.2.tgz#f564d75f5f8f36a6d9456cca7a6c4fe488ab7866"