Skip to content

Commit 29328ed

Browse files
updated modules
1 parent 11ea656 commit 29328ed

File tree

842 files changed

+27557
-127301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

842 files changed

+27557
-127301
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
PORTA=8080
22
email_server="@gmail.com"
33
emai_password=""
4-
DISCORD_LOGS_WEBHOOK_URL=https://discord.com/api/webhooks/1256601355548889131/saIXqCXKWKh-xE4CkjsjiP8MCbH3aXsXJlLCtBCnMnbxWqMUK1vAmvejCh1-z3hk83fT
4+
DISCORD_LOGS_WEBHOOK_URL=https://discord.com/api/webhooks/1043621229858390098/F9agt1QAvY853mnVJrGdtmC5TKtDqXnX_CTyJ6XzT57mCoPPaxMLsmOu_fjLyNyoHbF0

config.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"WSS":false
66
},
77
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
8-
"key":"key1",
9-
"key2":"key2",
10-
"keyApp":"key For &application",
8+
"defaultKeys":["ROOT:admnin","ROOT:apiUser"],
119
"blockedRoutes": [
1210
"/my-private-route"
1311
],

modules/checkHeaderMiddleware.js

+44-35
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,52 @@ const filesServer = __dirname + "/src/";
66
const path_pages = filesServer + "pages/";
77
const forbiddenFilePath = path.join(path_pages, "forbidden.html");
88

9-
const checkHeaderMiddleware = (req, res, next) => {
10-
const origin = req.headers.referer || req.headers.referrer;
11-
const keyHeader = req.headers["authorization"];
12-
const blockedRoutes = configs.blockedRoutes || []
13-
const blockRoutesPresent = blockedRoutes.some((route) => {
14-
// Trata rotas com curingas
15-
const regex = new RegExp(`^${route.replace(/\*/g, ".*")}$`);
16-
return regex.test(req.path);
9+
function checkHeaderMiddleware(app) {
10+
// Middleware para configurar o tipo de conteúdo como JSON
11+
app.all("/api/*", (req, res, next) => {
12+
if (!req.headers["authorization"]) {
13+
return res.status(403).send(
14+
JSON.stringify({ error: "Unauthorized" })
15+
);
16+
}
17+
res.set("Content-Type", "application/json");
18+
next();
1719
});
18-
const payload = JSON.stringify(req.body, null, 2);
19-
const keys = [
20-
configs.key,
21-
configs.key2,
22-
configs.keyApp
23-
];
24-
const validKey = keys.some((key) => keyHeader === key);
25-
const auth = blockRoutesPresent && !validKey;
2620

27-
console.log("-------------------------");
28-
console.log("SISTEMA <CHECK> <OBTER>: " + req.url);
29-
console.log("SISTEMA <ORIGEM>: " + origin);
30-
console.log("SISTEMA <PAYLOAD>: " + payload);
31-
keys.forEach((key) => {
32-
const auth = keyHeader === key;
33-
print(keyHeader, key, auth);
21+
app.all("/*", (req, res, next) => {
22+
const origin = req.headers.referer || req.headers.referrer;
23+
const keyHeader = req.headers["authorization"];
24+
const blockedRoutes = configs.blockedRoutes || [];
25+
const blockRoutesPresent = blockedRoutes.some((route) => {
26+
// Trata rotas com curingas
27+
const regex = new RegExp(`^${route.replace(/\*/g, ".*")}$`);
28+
return regex.test(req.path);
29+
});
30+
const payload = JSON.stringify(req.body, null, 2);
31+
const keys = configs.defaultKeys;
32+
const validKey = keys.some((key) => keyHeader === key);
33+
const auth = blockRoutesPresent && !validKey;
34+
35+
console.log("-------------------------");
36+
console.log("SISTEMA <CHECK> <OBTER>: " + req.url);
37+
console.log("SISTEMA <ORIGEM>: " + origin);
38+
console.log("SISTEMA <PAYLOAD>: " + payload);
39+
keys.forEach((key) => {
40+
const auth = keyHeader === key;
41+
print(keyHeader, key, auth);
42+
});
43+
for (const key in req.body) {
44+
req.body[key] = xss(req.body[key]);
45+
}
46+
if (auth) {
47+
// Se estiver solicitando das rotas bloqueadas E não conter key, bloquea a solicitação
48+
forbidden(res);
49+
} else {
50+
// Cabeçalho "solicitador" presente ou rota não bloqueada, permite o acesso
51+
next();
52+
}
3453
});
35-
for (const key in req.body) {
36-
req.body[key] = xss(req.body[key]);
37-
}
38-
if (auth) {
39-
// Se estiver solicitando das rotas bloqueadas E não conter key, bloquea a solicitação
40-
forbidden(res);
41-
} else {
42-
// Cabeçalho "solicitador" presente ou rota não bloqueada, permite o acesso
43-
next();
44-
}
45-
};
54+
}
4655

4756
function forbidden(res) {
4857
res.status(403);
@@ -63,4 +72,4 @@ function print(keyHeader, key, auth) {
6372
console.log("----------------------------");
6473
}
6574

66-
module.exports = checkHeaderMiddleware
75+
module.exports = checkHeaderMiddleware;

modules/fetchModule.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ function fetchPost(url, payload, header, callback) {
6565
}
6666

6767
console.log("FETCH POST", url);
68-
console.log("FETCH POST PAYLOAD: ", requestOptions.body);
6968
fetch(url, requestOptions)
7069
.then((response) => {
7170
console.log("Status da resposta:", response.status, response.statusText);
@@ -100,13 +99,20 @@ function fetchPost(url, payload, header, callback) {
10099
}
101100

102101
function discordLogs(title, mensagem) {
102+
const date = new Date();
103+
const ano = date.getFullYear();
103104
const preSet = {
104105
content: "",
105106
embeds: [
106107
{
107108
title: `SERVIDOR/${title}`,
108109
description: "SERVIDOR: " + mensagem,
109-
color: 16711935,
110+
color: parseInt("FFFFFF", 16),
111+
timestamp: date, // Adiciona um timestamp atual
112+
footer: {
113+
text: `₢Todos os Direitos Reservados - ${ano}`,
114+
icon_url: "",
115+
},
110116
},
111117
],
112118
attachments: [],
@@ -118,4 +124,4 @@ function discordLogs(title, mensagem) {
118124
});
119125
}
120126

121-
module.exports = { fetchGet, fetchPost, discordLogs };
127+
module.exports = { fetchGet, fetchPost, discordLogs };

modules/httpsSecurity.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const cors = require("cors");
2+
const helmet = require("helmet");
3+
4+
function httpsSecurityMiddleware(req, res, next) {
5+
console.log("executando https security");
6+
const corsOptions = {
7+
origin: [
8+
/^https:\/\/.+/,
9+
/^http:\/\/.+/,
10+
"https://discord.com"
11+
],
12+
methods: "GET,PUT,POST,DELETE",
13+
allowedHeaders: ["Content-Type", "authorization", "id", "key"],
14+
optionsSuccessStatus: 204,
15+
};
16+
const hstsOptions = {
17+
maxAge: 365 * 24 * 60 * 60,
18+
includeSubDomains: true,
19+
preload: true,
20+
};
21+
22+
// Chamando o middleware cors
23+
cors(corsOptions)(req, res, () => {
24+
// Configurar cabeçalhos de resposta para OPTIONS
25+
if (req.method === "OPTIONS") {
26+
res.set("Access-Control-Allow-Origin", corsOptions.origin);
27+
res.set("Access-Control-Allow-Methods", corsOptions.methods);
28+
res.set("Access-Control-Allow-Headers", corsOptions.allowedHeaders);
29+
}
30+
31+
// Chamando o middleware helmet
32+
helmet.hsts(hstsOptions)(req, res, next);
33+
});
34+
}
35+
36+
module.exports = httpsSecurityMiddleware;

modules/httpsSecurityMiddleware.js

-19
This file was deleted.

modules/postgreSQLModule.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { Pool } = require("pg");
2+
const {fetchGet,fetchPost, discordLogs} = require("./fetchModule.js");
3+
4+
async function connect() {
5+
try{
6+
if (global.connection) {
7+
return global.connection.connect();
8+
}
9+
const config = {
10+
user: "nodeJS",
11+
password: process.env.SQL_SENHA,
12+
host: process.env.SQL_HOST||"localhost",
13+
port: process.env.SQL_PORT||"5432",
14+
database: process.env.SQL_DATABASE,
15+
ssl: false
16+
};
17+
const pool = new Pool(config);
18+
const client = await pool.connect();
19+
20+
console.log("Estamos conectado!");
21+
discordLogs("SQL",`
22+
Estamos conectado!
23+
Client: ${client}
24+
`)
25+
const res = await client.query("select now()");
26+
console.log(res.rows[0]);
27+
discordLogs("SQL",`
28+
Query: select now()
29+
res: ${JSON.stringify(res.rows[0])}
30+
`)
31+
client.release();
32+
33+
global.connection = pool;
34+
return client;
35+
}catch (err){
36+
discordLogs("SQL ERROR",err)
37+
setTimeout(()=>{
38+
connect()
39+
},15000);
40+
discordLogs("SQL TRY","TENTANDO RECONECTAR!");
41+
}
42+
}
43+
44+
// connect();

node_modules/.bin/yaml2json node_modules/.bin/js-yaml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/nopt.cmd node_modules/.bin/js-yaml.cmd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@opencensus/core/node_modules/.bin/uuid.ps1 node_modules/.bin/js-yaml.ps1

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/json2yaml

-16
This file was deleted.

node_modules/.bin/json2yaml.cmd

-17
This file was deleted.

node_modules/.bin/json2yaml.ps1

-28
This file was deleted.

node_modules/.bin/nopt

-16
This file was deleted.

0 commit comments

Comments
 (0)