Skip to content

Commit 8d45037

Browse files
updated
1 parent 2858e19 commit 8d45037

File tree

9 files changed

+371
-178
lines changed

9 files changed

+371
-178
lines changed

modules/autoFileSysModule.js

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,73 @@
11
const fs = require("fs");
2+
const path = require("path");
3+
const multer = require("multer");
4+
5+
const storagePages = multer.diskStorage({
6+
destination: (req, file, cb) => {
7+
// Especifique o diretório onde os arquivos serão salvos
8+
const destinationPath = path.join(__dirname, "src", "uploads");
9+
fs.mkdirSync(destinationPath, { recursive: true }); // Cria a pasta 'src/uploads não existir
10+
cb(null, destinationPath);
11+
},
12+
filename: (req, file, cb) => {
13+
// Use um nome de arquivo único baseado no nome original do arquivo
14+
const uniqueFilename = file.originalname;
15+
cb(null, uniqueFilename);
16+
},
17+
});
18+
19+
const saveFile = multer({
20+
storage: storagePages,
21+
limits: {
22+
fileSize: 1024 * 1024 * 256, // Limite de 256 megabytes (ajuste conforme necessário)
23+
},
24+
});
225

3-
// example: const data = fopen("./data.json")
426
function fopen(filePath) {
5-
const database = fs.readFileSync(filePath, "utf8");
6-
const data = JSON.parse(database);
27+
const database = fs.readFileSync(filePath, "utf8");
28+
const data = JSON.parse(database);
729

8-
return data;
30+
return data;
931
}
1032

11-
// example: fwrite("./data.json", data)
1233
function fwrite(filePath, data) {
13-
const formatData = JSON.stringify(data, null, 2)
14-
fs.writeFileSync(filePath, formatData, "utf8");
15-
return true;
34+
const formatData = JSON.stringify(data, null, 2);
35+
36+
fs.writeFileSync(filePath, formatData, "utf8");
37+
return true;
38+
}
39+
40+
// Função para converter uma string em uma representação binária
41+
function stringToBinary(str) {
42+
return str
43+
.split("")
44+
.map((char) => {
45+
return char.charCodeAt(0).toString(2).padStart(8, "0");
46+
})
47+
.join(" ");
48+
}
49+
50+
// Função para salvar dados JSON como binário
51+
function fwriteBin(filePath, data) {
52+
const jsonString = JSON.stringify(data);
53+
const binaryString = stringToBinary(jsonString);
54+
55+
fs.writeFileSync(filePath, binaryString, "utf8");
56+
return true;
57+
}
58+
59+
// Leitura e conversão de volta para JSON
60+
function freadBin(filePath) {
61+
const binaryString = fs.readFileSync(filePath, "utf8");
62+
const jsonString = binaryString
63+
.split(" ")
64+
.map((bin) => {
65+
return String.fromCharCode(parseInt(bin, 2));
66+
})
67+
.join("");
68+
const data = JSON.parse(jsonString);
69+
70+
return data;
1671
}
1772

18-
module.exports = { fopen, fwrite };
73+
module.exports = { fopen, fwrite, freadBin, fwriteBin, saveFile };

modules/checkHeaderMiddleware.js

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
1-
const fs = require("fs");
2-
const configs = JSON.parse(fs.readFileSync("config.json", "utf8"));
3-
const path = require("path");
1+
const {
2+
getRandomInt,
3+
getRandomBin,
4+
getRandomHex,
5+
validadeApiKey,
6+
unauthorized,
7+
forbidden,
8+
formatDate,
9+
conversorSimEnao,
10+
} = require("./utils.js");
11+
const {
12+
fopen,
13+
fwrite,
14+
freadBin,
15+
fwriteBin,
16+
} = require("./autoFileSysModule.js");
17+
const configs = fopen("config.json");
418
const xss = require("xss");
5-
const filesServer = __dirname + "/src/";
6-
const path_pages = filesServer + "pages/";
7-
const forbiddenFilePath = path.join(path_pages, "forbidden.html");
819

920
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();
19-
});
20-
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;
21+
// Middleware para configurar o tipo de conteúdo como JSON
22+
app.all("/api/*name", (req, res, next) => {
23+
if (!req.headers["authorization"]) {
24+
forbidden(res);
25+
}
26+
res.set("Content-Type", "application/json");
27+
next();
28+
});
3429

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-
}
30+
app.all("/*name", (req, res, next) => {
31+
const origin = req.headers.referer || req.headers.referrer;
32+
const keyHeader = req.headers["authorization"];
33+
const blockedRoutes = configs.blockedRoutes || [];
34+
const blockRoutesPresent = blockedRoutes.some((route) => {
35+
// Trata rotas com curingas
36+
const regex = new RegExp(`^${route.replace(/\*/g, ".*")}$`);
37+
return regex.test(req.path);
5338
});
54-
}
39+
const payload = JSON.stringify(req.body, null, 2);
40+
const keys = [
41+
"snve072509ç$",
42+
"snve072509ç$",
43+
"snve072509&Aplication",
44+
"ROOT:keyBypass",
45+
];
46+
const validKey = keys.some((key) => keyHeader === key);
47+
const auth = blockRoutesPresent && !validKey;
5548

56-
function forbidden(res) {
57-
res.status(403);
58-
res.sendFile(forbiddenFilePath);
59-
}
60-
61-
function conversorSimEnao(value) {
62-
if (value) {
63-
return "✔Voce foi autorizado, esta tudo correto";
49+
console.log("-------------------------");
50+
console.log("SISTEMA <CHECK> <OBTER>: " + req.url);
51+
console.log("SISTEMA <ORIGEM>: " + origin);
52+
console.log("SISTEMA <PAYLOAD>: " + payload);
53+
keys.forEach((key) => {
54+
const auth = keyHeader === key;
55+
print(keyHeader, key, auth);
56+
});
57+
for (const key in req.body) {
58+
req.body[key] = xss(req.body[key]);
59+
}
60+
if (auth) {
61+
// Se estiver solicitando das rotas bloqueadas E não conter key, bloquea a solicitação
62+
forbidden(res);
63+
} else {
64+
// Cabeçalho "solicitador" presente ou rota não bloqueada, permite o acesso
65+
next();
6466
}
65-
return "⚠Esta faltando algo ou não foi autorizado!";
67+
});
6668
}
6769

6870
// functions basicas
6971
function print(keyHeader, key, auth) {
70-
console.log("SISTEMA <VERIFICAÇÃO>: " + keyHeader + " == " + key);
71-
console.log("SISTEMA <AUTORIZAÇÃO>: " + conversorSimEnao(!auth));
72-
console.log("----------------------------");
72+
console.log("SISTEMA <VERIFICAÇÃO>: " + keyHeader + " == " + key);
73+
console.log("SISTEMA <AUTORIZAÇÃO>: " + conversorSimEnao(!auth));
74+
console.log("----------------------------");
7375
}
7476

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

modules/ddosModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const ddos = require("ddos");
22

33
function configureDdosMiddleware() {
44
const params = {
5-
limit: 150,
6-
maxcount: 250,
5+
limit: 20,
6+
maxcount: 150,
77
trustProxy: true,
88
includeUserAgent: true,
99
whitelist: [],

modules/emailModule.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
const nodemailer = require("nodemailer");
22
const { fopen, fwrite } = require("../modules/autoFileSysModule.js");
33
const configs = fopen("config.json");
4-
const configMail = configs.emailSystem
4+
const configMail = configs.emailSystem;
55
let transporter;
66

77
if (nodemailer.createTransport({ service: configMail.service })) {
8-
// Se o serviço estiver entre os suportados pelo Nodemailer, use createTransport com o serviço
9-
transporter = nodemailer.createTransport({
10-
service: configMail.service || "Gmail",
11-
auth: {
12-
user: process.env.email_server,
13-
pass: process.env.email_password
14-
}
15-
});
8+
// Se o serviço estiver entre os suportados pelo Nodemailer, use createTransport com o serviço
9+
transporter = nodemailer.createTransport({
10+
service: configMail.service || "Gmail",
11+
auth: {
12+
user: process.env.PINGOBRAS_SG_email_server,
13+
pass: process.env.PINGOBRAS_SG_email_password,
14+
},
15+
});
1616
} else {
17-
// Caso contrário, crie o transporte manualmente
18-
transporter = nodemailer.createTransport({
19-
host: configMail.host,
20-
port: configMail.port,
21-
secure: configMail.ssl_tls, // SSL/TLS ativado
22-
auth: {
23-
user: process.env.email_server,
24-
pass: process.env.email_password
25-
}
26-
});
17+
// Caso contrário, crie o transporte manualmente
18+
transporter = nodemailer.createTransport({
19+
host: configMail.host,
20+
port: configMail.port,
21+
secure: configMail.ssl_tls, // SSL/TLS ativado
22+
auth: {
23+
user: process.env.PINGOBRAS_SG_email_server,
24+
pass: process.env.PINGOBRAS_SG_email_password,
25+
},
26+
});
2727
}
2828

2929
function sendMail(email, subject, text, callback) {
30-
try {
31-
const mailOptions = {
32-
from: process.env.email_server, // Remetente
33-
to: email, // Destinatário
34-
subject: subject,
35-
text: text,
36-
};
37-
transporter.sendMail(mailOptions, (error, info) => {
38-
if (error) {
39-
console.log("SERVIDOR <sendMail>: Erro ao enviar o e-mail:", error);
40-
callback(error, null);
41-
} else {
42-
console.log("SERVIDOR <sendMail>: E-mail enviado:", info.response);
43-
callback(null, info);
44-
}
45-
});
46-
} catch (error) {
47-
console.error("SERVIDOR <sendMail>: Erro ao criar email: ", error);
48-
callback(error, null);
49-
}
30+
try {
31+
const mailOptions = {
32+
from: configMail.user, // Remetente
33+
to: email, // Destinatário
34+
subject: subject,
35+
text: text,
36+
};
37+
transporter.sendMail(mailOptions, (error, info) => {
38+
if (error) {
39+
console.log("SERVIDOR <sendMail>: Erro ao enviar o e-mail:", error);
40+
callback(error, null);
41+
} else {
42+
console.log("SERVIDOR <sendMail>: E-mail enviado:", info.response);
43+
callback(null, info);
44+
}
45+
});
46+
} catch (error) {
47+
console.error("SERVIDOR <sendMail>: Erro ao criar email: ", error);
48+
callback(error, null);
49+
}
5050
}
5151

5252
module.exports = sendMail;

modules/fetchModule.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function fetchGet(url, header, callback) {
3030
// Verifica o tipo de conteúdo retornado
3131
if (contentType && contentType.includes("application/json")) {
3232
// Se for JSON, retorna o JSON
33-
return response.json();
33+
return response.text();
3434
} else {
3535
// Se não for JSON, retorna o conteúdo como texto
3636
return response.text();
@@ -107,7 +107,7 @@ function discordLogs(title, mensagem) {
107107
{
108108
title: `SERVIDOR/${title}`,
109109
description: "SERVIDOR: " + mensagem,
110-
color: parseInt("FFFFFF", 16),
110+
color: parseInt("FFFFFF",16),
111111
timestamp: date, // Adiciona um timestamp atual
112112
footer: {
113113
text: `₢Todos os Direitos Reservados - ${ano}`,
@@ -124,4 +124,30 @@ function discordLogs(title, mensagem) {
124124
});
125125
}
126126

127-
module.exports = { fetchGet, fetchPost, discordLogs };
127+
function discordLogsBrasilEternity(title, mensagem) {
128+
const date = new Date();
129+
const ano = date.getFullYear();
130+
const preSet = {
131+
content: "",
132+
embeds: [
133+
{
134+
title: `SERVIDOR/${title}`,
135+
description: "SERVIDOR BRASIL ETERNITY: " + mensagem,
136+
color: parseInt("FF0000",16),
137+
timestamp: date, // Adiciona um timestamp atual
138+
footer: {
139+
text: `₢Todos os Direitos Reservados - PINGOBRAS S.A & BRASIL ETERNITY- ${ano}`,
140+
icon_url: "https://cdn.discordapp.com/attachments/952004420265205810/1258422248507969546/Brasil-Eternity-image.jpg?ex=6687fc8c&is=6686ab0c&hm=842f5fca11e4b814443ca73bac9d6b35a0d309960dbdf9548405767092bf1a07&",
141+
},
142+
},
143+
],
144+
attachments: [],
145+
};
146+
fetchPost(process.env.DISCORD_LOGS_BRASIL_ETERNITY_WEBHOOK_URL, preSet, null, (error, data) => {
147+
if (error) {
148+
console.error(error);
149+
}
150+
});
151+
}
152+
153+
module.exports = { fetchGet, fetchPost, discordLogs, discordLogsBrasilEternity };

0 commit comments

Comments
 (0)