-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
159 lines (147 loc) · 5.99 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const childProcess = require('child_process');
let child = childProcess.fork(path.join(__dirname, 'create_bot.js'));
let logWindow = null;
let inventoryWindow = null;
const janelasCaptcha = {};
process.on('uncaughtException', (err) => {
process.send({ type: 'error', data: `Exceção não tratada capturada: ${err.message}` });
process.send({ type: 'error', data: `Stack: ${err.stack}` });
});
function createLogWindow() {
logWindow = new BrowserWindow({
width: 800,
height: 600,
show: true,
resizable: true,
autoHideMenuBar: true,
icon: path.join(__dirname, '/assetsUBBOT/icone.png'),
webPreferences: { nodeIntegration: true, contextIsolation: false }
});
logWindow.loadFile('logs.html');
logWindow.setMenu(null);
}
function redirectConsoleToLogWindow() {
const originalConsoleLog = console.log;
console.log = (...args) => {
originalConsoleLog(...args);
if (logWindow) logWindow.webContents.send('log', args.join(' '));
};
const originalConsoleError = console.error;
console.error = (...args) => {
originalConsoleError(...args);
if (logWindow) logWindow.webContents.send('log', `[ERROR] ${args.join(' ')}`);
};
}
function createWindow() {
global.mainWindow = new BrowserWindow({
width: 1400,
height: 600,
show: true,
resizable: false,
autoHideMenuBar: true,
titleBarStyle: 'hidden',
icon: path.join(__dirname, '/assetsUBBOT/icone.png'),
webPreferences: { nodeIntegration: true, contextIsolation: false }
});
global.mainWindow.loadFile('index.html');
global.mainWindow.setMenu(null);
}
app.whenReady().then(() => {
createWindow();
createLogWindow();
redirectConsoleToLogWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createLogWindow();
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.on('form-data-changed-fallcheck', (event, data) => child.send({ event: 'form-data-changed-fallcheck', data }));
ipcMain.on('form-data-changed-reconnect', (event, data) => child.send({ event: 'form-data-changed-reconnect', data }));
ipcMain.on('log', (event, message) => console.log(message));
ipcMain.on('send-message-all', (event, message) => global.mainWindow.webContents.send('bot-message-all', message));
ipcMain.on('send-message-for-all-threads', (event, message) => child.send({ event: 'send-message-for-all-threads', message }));
ipcMain.on('connect-bot', (event, data) => child.send({ event: 'connect-bot', data }));
ipcMain.on('captcha-input-janela1', (event, data) => child.send({ event: 'captcha-input-janela1', data }));
ipcMain.on('send-message', (event, data) => child.send({ event: 'send-message', data }));
ipcMain.on('remove-bot', (event, botUsername) => child.send({ event: 'remove-bot', data: botUsername }));
ipcMain.on('reco-bot', (event, data) => {
console.log(data);
child.send({ event: 'reco-bot', data });
});
child.on('message', (message) => {
if (message.type === 'webcontents') {
global.mainWindow.webContents.send(message.event, message.data);
} else if (message.type === 'ipcMain') {
ipcMain.emit(message.event, null, message.data);
} else if (message.type === 'electron') {
if (message.action === 'createCaptchaWindow') {
const { botusername, captchaImage } = message.data;
if (janelasCaptcha[botusername]) {
janelasCaptcha[botusername].close();
delete janelasCaptcha[botusername];
}
janelasCaptcha[botusername] = new BrowserWindow({
width: 300,
height: 300,
show: true,
resizable: false,
autoHideMenuBar: true,
titleBarStyle: 'hidden',
webPreferences: { nodeIntegration: true, contextIsolation: false }
});
janelasCaptcha[botusername].loadFile(path.join(__dirname, '/assetsUBBOT/captcha.html'));
janelasCaptcha[botusername].setMenu(null);
janelasCaptcha[botusername].webContents.on('did-finish-load', () => {
janelasCaptcha[botusername].webContents.send('bot-janela-1', botusername, captchaImage);
});
} else if (message.action === 'createWebInventoryWindow') {
const botusername = message.data.bot;
inventoryWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: true },
frame: false
});
inventoryWindow.loadURL('http://localhost:9531');
inventoryWindow.setMenu(null);
inventoryWindow.on('closed', () => {
global.mainWindow.webContents.send('bot-message', { bot: botusername, message: "<br/><span style='color:red'>Interface fechada!</span><br><br/>" });
});
} else if (message.action === 'bot-end') {
const username = message.username;
if (janelasCaptcha[username]) {
janelasCaptcha[username].close();
delete janelasCaptcha[username];
}
if (inventoryWindow && !inventoryWindow.isDestroyed()) {
inventoryWindow.loadURL('about:blank');
inventoryWindow.close();
inventoryWindow = null;
}
} else if (message.action === 'closewindowcaptcha') {
const username = message.username;
if (janelasCaptcha[username]) {
janelasCaptcha[username].close();
delete janelasCaptcha[username];
}
} else if (message.action === 'closewindowinventory') {
if (inventoryWindow && !inventoryWindow.isDestroyed()) {
inventoryWindow.loadURL('about:blank');
inventoryWindow.close();
inventoryWindow = null;
}
} else if (message.action === 'log') {
console.log(`[BOT_INT] ${message.data}`);
} else if (message.action === 'error') {
console.error(`[BOT_INT_ERR] ${message.data}`);
}
}
});
ipcMain.on('close', (code) => console.log(`Child process exited with code ${code}`));