mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-10-02 01:20:11 +02:00
feat: allow to configure clamav with environment variables
This commit is contained in:
parent
2dc0fc9332
commit
1df5c7123e
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
/backend/src/constants.ts
|
@ -1,21 +1,22 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable, Logger } from "@nestjs/common";
|
||||||
import * as NodeClam from "clamscan";
|
import * as NodeClam from "clamscan";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { FileService } from "src/file/file.service";
|
import { FileService } from "src/file/file.service";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { SHARE_DIRECTORY } from "../constants";
|
import { CLAMAV_HOST, CLAMAV_PORT, SHARE_DIRECTORY } from "../constants";
|
||||||
|
|
||||||
const clamscanConfig = {
|
const clamscanConfig = {
|
||||||
clamdscan: {
|
clamdscan: {
|
||||||
host: process.env.NODE_ENV == "docker" ? "clamav" : "127.0.0.1",
|
host: CLAMAV_HOST,
|
||||||
port: 3310,
|
port: CLAMAV_PORT,
|
||||||
localFallback: false,
|
localFallback: false,
|
||||||
},
|
},
|
||||||
preference: "clamdscan",
|
preference: "clamdscan",
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ClamScanService {
|
export class ClamScanService {
|
||||||
|
private readonly logger = new Logger(ClamScanService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private fileService: FileService,
|
private fileService: FileService,
|
||||||
private prisma: PrismaService
|
private prisma: PrismaService
|
||||||
@ -24,11 +25,11 @@ export class ClamScanService {
|
|||||||
private ClamScan: Promise<NodeClam | null> = new NodeClam()
|
private ClamScan: Promise<NodeClam | null> = new NodeClam()
|
||||||
.init(clamscanConfig)
|
.init(clamscanConfig)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log("ClamAV is active");
|
this.logger.log("ClamAV is active");
|
||||||
return res;
|
return res;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log("ClamAV is not active");
|
this.logger.log("ClamAV is not active");
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ export class ClamScanService {
|
|||||||
const { isInfected } = await clamScan
|
const { isInfected } = await clamScan
|
||||||
.isInfected(`${SHARE_DIRECTORY}/${shareId}/${fileId}`)
|
.isInfected(`${SHARE_DIRECTORY}/${shareId}/${fileId}`)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log("ClamAV is not active");
|
this.logger.log("ClamAV is not active");
|
||||||
return { isInfected: false };
|
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)`
|
`Share ${shareId} deleted because it contained ${infectedFiles.length} malicious file(s)`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
export const DATA_DIRECTORY = process.env.DATA_DIRECTORY || "./data";
|
export const DATA_DIRECTORY = process.env.DATA_DIRECTORY || "./data";
|
||||||
export const SHARE_DIRECTORY = `${DATA_DIRECTORY}/uploads/shares`
|
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;
|
Loading…
Reference in New Issue
Block a user