1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-06-30 06:30:11 +02:00

feat: allow to configure clamav with environment variables

This commit is contained in:
Elias Schneider 2023-05-09 08:45:56 +02:00
parent 2dc0fc9332
commit 1df5c7123e
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C
3 changed files with 14 additions and 10 deletions

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
/backend/src/constants.ts

View File

@ -1,21 +1,22 @@
import { Injectable } from "@nestjs/common";
import { Injectable, Logger } from "@nestjs/common";
import * as NodeClam from "clamscan";
import * as fs from "fs";
import { FileService } from "src/file/file.service";
import { PrismaService } from "src/prisma/prisma.service";
import { SHARE_DIRECTORY } from "../constants";
import { CLAMAV_HOST, CLAMAV_PORT, SHARE_DIRECTORY } from "../constants";
const clamscanConfig = {
clamdscan: {
host: process.env.NODE_ENV == "docker" ? "clamav" : "127.0.0.1",
port: 3310,
host: CLAMAV_HOST,
port: CLAMAV_PORT,
localFallback: false,
},
preference: "clamdscan",
};
@Injectable()
export class ClamScanService {
private readonly logger = new Logger(ClamScanService.name);
constructor(
private fileService: FileService,
private prisma: PrismaService
@ -24,11 +25,11 @@ export class ClamScanService {
private ClamScan: Promise<NodeClam | null> = new NodeClam()
.init(clamscanConfig)
.then((res) => {
console.log("ClamAV is active");
this.logger.log("ClamAV is active");
return res;
})
.catch(() => {
console.log("ClamAV is not active");
this.logger.log("ClamAV is not active");
return null;
});
@ -47,7 +48,7 @@ export class ClamScanService {
const { isInfected } = await clamScan
.isInfected(`${SHARE_DIRECTORY}/${shareId}/${fileId}`)
.catch(() => {
console.log("ClamAV is not active");
this.logger.log("ClamAV is not active");
return { isInfected: false };
});
@ -79,7 +80,7 @@ export class ClamScanService {
},
});
console.log(
this.logger.warn(
`Share ${shareId} deleted because it contained ${infectedFiles.length} malicious file(s)`
);
}

View File

@ -1,3 +1,5 @@
export const DATA_DIRECTORY = process.env.DATA_DIRECTORY || "./data";
export const SHARE_DIRECTORY = `${DATA_DIRECTORY}/uploads/shares`
export const DATABASE_URL = process.env.DATABASE_URL || "file:../data/pingvin-share.db?connection_limit=1";
export const DATABASE_URL = process.env.DATABASE_URL || "file:../data/pingvin-share.db?connection_limit=1";
export const CLAMAV_HOST = process.env.CLAMAV_HOST || (process.env.NODE_ENV == "docker" ? "clamav" : "127.0.0.1");
export const CLAMAV_PORT = parseInt(process.env.CLAMAV_PORT) || 3310;