This repository was archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
177 lines (150 loc) · 6.4 KB
/
Copy pathmain.js
File metadata and controls
177 lines (150 loc) · 6.4 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const { app, BrowserWindow, Menu, ipcMain, shell } = require('electron');
const { spawn, exec } = require('child_process');
const dgram = require('dgram');
const path = require('path');
const udpSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
let clientProcess;
let serverProcess;
let sendMulticastMessageInterval;
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
icon: path.join(__dirname, './app/images/256x256.ico'),
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
//win.webContents.openDevTools();
Menu.setApplicationMenu(null);
win.loadFile('index.html');
};
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (clientProcess) {
spawn('taskkill', ['/IM', 'core.exe', '/F']);
clientProcess.kill();
clientProcess = null;
}
if (serverProcess) {
spawn('taskkill', ['/IM', 'core.exe', '/F']);
serverProcess.kill();
serverProcess = null;
}
if (sendMulticastMessageInterval) {
clearInterval(sendMulticastMessageInterval);
sendMulticastMessageInterval = null;
}
if (process.platform !== 'darwin') {
app.quit();
}
});
udpSocket.on('error', (err) => {
udpSocket.close();
});
function sendMulticastMessage() {
const message = Buffer.from('[MOTD]§eMergiLink默连局域网通道 - 双击进入[/MOTD][AD]59735[/AD]');
const multicastAddress = '224.0.2.60';
const port = 4445;
udpSocket.send(message, 0, message.length, port, multicastAddress, (err) => {
});
}
ipcMain.on('run-client', (event, token) => {
const clientUrl = `https://link.qwqo.cn/api/user.php?rp=getcconfig&token=${token}`;
const clientFilePath = 'client.toml';
const exePath = 'core.exe';
const downloadScript = `
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$url = "${clientUrl}"
$outputPath = "${clientFilePath}"
Invoke-WebRequest -Uri $url -OutFile $outputPath
`;
const runScript = `
Start-Process -FilePath "${exePath}" -ArgumentList "-c", "${clientFilePath}" -NoNewWindow -PassThru | Out-Null
`;
event.sender.send('exe-output', '开始拉取配置文件 <br>');
// Download configuration file
const downloadProcess = spawn('powershell.exe', ['-NoProfile', '-Command', downloadScript]);
downloadProcess.stdout.on('data', (data) => {
const message = data.toString();
});
downloadProcess.stderr.on('data', (data) => event.sender.send('exe-output', `stderr: ${data.toString()}`));
downloadProcess.on('close', (code) => {
event.sender.send('exe-output', `拉取配置文件结束,状态码: ${code} <br>`);
if (code === 0) {
event.sender.send('exe-output', '您现在运行的软件版本为:1.0.2<br>您现在运行的Frp内核为:0.58.1_a35ee10 <br>');
// Run core.exe after successful download
clientProcess = spawn('powershell.exe', ['-NoProfile', '-Command', runScript]);
clientProcess.stdout.on('data', (data) => event.sender.send('exe-output', data.toString()));
clientProcess.stderr.on('data', (data) => event.sender.send('exe-output', `stderr: ${data.toString()}`));
clientProcess.on('close', (code) => event.sender.send('exe-output', `软件已退出 状态码:${code} <br>`));
}
});
sendMulticastMessageInterval = setInterval(sendMulticastMessage, 5000);
});
ipcMain.on('stop-client', (event) => {
if (clientProcess) {
spawn('taskkill', ['/IM', 'core.exe', '/F']);
clientProcess.kill();
event.sender.send('exe-output', '联机进程已退出 <br>');
clientProcess = null;
}
if (sendMulticastMessageInterval) {
clearInterval(sendMulticastMessageInterval);
event.sender.send('exe-output', '局域网广播进程终止 <br>');
sendMulticastMessageInterval = null;
}
});
ipcMain.on('run-server', (event, token) => {
const serverUrl = `https://link.qwqo.cn/api/user.php?rp=getsconfig&token=${token}`;
const serverFilePath = 'server.toml'
const exePath = 'core.exe';
const downloadScript = `
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$url = "${serverUrl}"
$outputPath = "${serverFilePath}"
Invoke-WebRequest -Uri $url -OutFile $outputPath
`;
const runScript = `
Start-Process -FilePath "${exePath}" -ArgumentList "-c", "${serverFilePath}" -NoNewWindow -PassThru | Out-Null
`;
event.sender.send('exe-output', '开始拉取配置文件 <br>');
const downloadProcess = spawn('powershell.exe', ['-NoProfile', '-Command', downloadScript]);
downloadProcess.stdout.on('data', (data) => {
const message = data.toString();
});
downloadProcess.stderr.on('data', (data) => event.sender.send('exe-output', `stderr: ${data.toString()}`));
downloadProcess.on('close', (code) => {
event.sender.send('exe-output', `拉取配置文件结束状态码: ${code} <br>`);
if (code === 0) {
event.sender.send('exe-output', '您现在运行的软件版本为:1.0.2<br>您现在运行的Frp内核为:0.58.1_a35ee10 <br>');
serverProcess = spawn('powershell.exe', ['-NoProfile', '-Command', runScript]);
serverProcess.stdout.on('data', (data) => event.sender.send('exe-output', data.toString()));
serverProcess.stderr.on('data', (data) => event.sender.send('exe-output', `stderr: ${data.toString()}`));
serverProcess.on('close', (code) => event.sender.send('exe-output', `软件已退出 状态码:${code} <br>`));
}
});
});
ipcMain.on('stop-server', (event) => {
if (serverProcess) {
spawn('taskkill', ['/IM', 'core.exe', '/F']);
serverProcess.kill();
event.sender.send('exe-output', '软件进程终止 <br>');
serverProcess = null;
}
});
ipcMain.on('goonlineweb', (event) => {
exec('start https://link.qwqo.cn/')
})
udpSocket.bind(() => {
udpSocket.setMulticastTTL(128); // 设置多播TTL
udpSocket.addMembership('224.0.2.60'); // 加入多播组
});