mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add security loop
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import type { } from '#ui/types/tabs'
|
||||
|
||||
definePageMeta({ layout: 'dashboard' });
|
||||
const activeProjectId = useActiveProjectId();
|
||||
|
||||
|
||||
3
security/.env.example
Normal file
3
security/.env.example
Normal file
@@ -0,0 +1,3 @@
|
||||
MONGO_CONNECTION_STRING=
|
||||
EMAIL_SERVICE=
|
||||
BREVO_API_KEY=
|
||||
1
security/.gitignore
vendored
1
security/.gitignore
vendored
@@ -5,3 +5,4 @@ dist
|
||||
start_dev.js
|
||||
package-lock.json
|
||||
build_all.bat
|
||||
.env
|
||||
@@ -1,4 +1,4 @@
|
||||
import { anomalyCheckAll, AnomalyReport, findAnomalies } from "./AnomalyService";
|
||||
import { anomalyLoop } from "./AnomalyService";
|
||||
import { connectDatabase } from '@services/DatabaseService'
|
||||
import { requireEnv } from '@utils/requireEnv'
|
||||
|
||||
@@ -10,37 +10,18 @@ import { UserModel } from "@schema/UserSchema";
|
||||
EmailService.init(requireEnv('BREVO_API_KEY'));
|
||||
connectDatabase(requireEnv('MONGO_CONNECTION_STRING'));
|
||||
|
||||
anomalyCheckAll(async report => {
|
||||
|
||||
|
||||
anomalyLoop(async report => {
|
||||
if (report.visits.length > 0 || report.events.length > 0 || report.dns.length > 0) {
|
||||
|
||||
const project = await ProjectModel.findById(report.pid);
|
||||
if (!project) return { ok: false, error: 'Cannot find project with id ' + report.pid.toString() }
|
||||
const user = await UserModel.findById(project.owner);
|
||||
if (!user) return { ok: false, error: 'Cannot find user with id ' + project.owner.toString() }
|
||||
|
||||
if (report.visits.length > 0 || report.events.length > 0) {
|
||||
|
||||
await EmailService.sendAnomalyVisitsEventsEmail(
|
||||
user.email,
|
||||
project.name,
|
||||
{ visits: report.visits, events: report.events }
|
||||
);
|
||||
|
||||
await EmailService.sendAnomalyVisitsEventsEmail(user.email, project.name, { visits: report.visits, events: report.events });
|
||||
}
|
||||
|
||||
if (report.visits.length > 0) {
|
||||
|
||||
await EmailService.sendAnomalyDomainEmail(
|
||||
user.email,
|
||||
project.name,
|
||||
report.dns
|
||||
);
|
||||
|
||||
await EmailService.sendAnomalyDomainEmail(user.email, project.name, report.dns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user