This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (87 loc) · 3.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(async()=>{
"use strict";
require("dotenv").config()
// Dependencies
const { MongoClient } = require("mongodb")
const express = require("express")
const helmet = require("helmet")
const path = require("path")
const fs = require("fs")
// Variables
const web = express()
const port = process.env.PORT || 8080
const explore = require("./database/explore.json")
const client = new MongoClient(process.env.MONGODB_URL)
const database = client.db("nightfall")
const maliciousDomains = database.collection("maliciousDomains")
const malwareHash = database.collection("malwaresHash")
const maliciousYoutubeChannels = database.collection("maliciousYoutubeChannels")
const maliciousDiscordServers = database.collection("maliciousDiscordServers")
var SPR = {
database: {
maliciousDomains: 0,
malwareHash: 0,
maliciousYoutubeChannels: 0,
maliciousDiscordServers: 0
}
}
// Functions
function publicFiles(file){
return file ? path.join(__dirname, "public", file) : path.join(__dirname, "public")
}
async function reloadDatabase(){
SPR.database.maliciousDomains = await maliciousDomains.count()
SPR.database.malwareHash = await malwareHash.count()
SPR.database.maliciousYoutubeChannels = await maliciousYoutubeChannels.count()
SPR.database.maliciousDiscordServers = await maliciousDiscordServers.count()
}
/// Configurations
// Express
web.use(helmet({ contentSecurityPolicy: false }))
web.set("view engine", "ejs")
// Main
await client.connect()
web.use("", function(req, res, next){
if(req.path.indexOf(".html") !== -1) return res.redirect("/404")
next()
})
web.use(express.static(publicFiles()))
web.get("/", function(req, res){
res.sendFile(publicFiles("index.html"))
})
web.get("/status", function(req, res){
const SPRDatabase = SPR.database
res.render("status", {
maliciousDomains: SPRDatabase.maliciousDomains,
malwareHash: SPRDatabase.malwareHash,
maliciousYoutubeChannels: SPRDatabase.maliciousYoutubeChannels,
maliciousDiscordServers: SPRDatabase.maliciousDiscordServers
})
})
web.get("/explore", function(req, res){
res.render("explore", {
data: explore
})
})
web.get("/explore/:id", function(req, res){
const id = req.params.id
if(id){
fs.existsSync(publicFiles(`explore/${id}.md`)) ? res.render("explore-view", { id: id }) : res.redirect("/explore")
}else{
res.redirect("/404")
}
})
web.get("/404", function(req, res){
res.sendFile(publicFiles("404.html"))
})
web.use("*", function(req, res){
res.redirect("/404")
})
web.listen(port, ()=>{
reloadDatabase()
console.log(`The server is running. Port: ${port}`)
setInterval(function(){
reloadDatabase()
}, 30 * 60 * 1000)
})
})()