verteilen-core 1.2.4 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/analysis.d.ts +35 -0
- package/dist/client/analysis.js +382 -0
- package/dist/client/client.d.ts +25 -0
- package/dist/client/client.js +227 -0
- package/dist/client/cluster.d.ts +1 -0
- package/dist/{src/client → client}/cluster.js +1 -2
- package/dist/client/database.d.ts +13 -0
- package/dist/client/database.js +37 -0
- package/dist/client/execute.d.ts +24 -0
- package/dist/{src/client → client}/execute.js +61 -51
- package/dist/client/http.d.ts +7 -0
- package/dist/client/http.js +40 -0
- package/dist/client/javascript.d.ts +47 -0
- package/dist/{src/client → client}/javascript.js +110 -136
- package/dist/client/job_database.d.ts +10 -0
- package/dist/client/job_database.js +34 -0
- package/dist/client/job_execute.d.ts +20 -0
- package/dist/client/job_execute.js +173 -0
- package/dist/client/os.d.ts +29 -0
- package/dist/client/os.js +197 -0
- package/dist/client/resource.d.ts +7 -0
- package/dist/client/resource.js +107 -0
- package/dist/client/shell.d.ts +16 -0
- package/dist/client/shell.js +122 -0
- package/dist/computed.d.ts +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -3
- package/dist/interface/base.d.ts +70 -0
- package/dist/interface/bus.d.ts +90 -0
- package/dist/interface/enum.d.ts +143 -0
- package/dist/interface/execute.d.ts +20 -0
- package/dist/interface/record.d.ts +93 -0
- package/dist/interface/server.d.ts +76 -0
- package/dist/interface/struct.d.ts +182 -0
- package/dist/interface/table.d.ts +20 -0
- package/dist/interface/ui.d.ts +29 -0
- package/dist/interface.d.ts +29 -0
- package/dist/plugins/i18n.d.ts +1666 -0
- package/dist/script/console_manager.d.ts +18 -0
- package/dist/script/console_manager.js +131 -0
- package/dist/script/console_server_manager.d.ts +13 -0
- package/dist/script/console_server_manager.js +40 -0
- package/dist/script/execute/base.d.ts +45 -0
- package/dist/script/execute/base.js +200 -0
- package/dist/script/execute/feedback.d.ts +12 -0
- package/dist/script/execute/feedback.js +179 -0
- package/dist/script/execute/interface.d.ts +8 -0
- package/dist/script/execute/region_job.d.ts +5 -0
- package/dist/{src/script → script}/execute/region_job.js +1 -0
- package/dist/script/execute/region_project.d.ts +10 -0
- package/dist/{src/script → script}/execute/region_project.js +4 -0
- package/dist/script/execute/region_subtask.d.ts +5 -0
- package/dist/{src/script → script}/execute/region_subtask.js +1 -0
- package/dist/script/execute/region_task.d.ts +10 -0
- package/dist/{src/script → script}/execute/region_task.js +4 -0
- package/dist/script/execute/runner.d.ts +14 -0
- package/dist/script/execute/runner.js +264 -0
- package/dist/script/execute/util_parser.d.ts +14 -0
- package/dist/script/execute/util_parser.js +135 -0
- package/dist/script/execute_manager.d.ts +25 -0
- package/dist/script/execute_manager.js +297 -0
- package/dist/script/socket_manager.d.ts +31 -0
- package/dist/script/socket_manager.js +263 -0
- package/dist/script/webhook_manager.d.ts +3 -0
- package/dist/script/webhook_server_manager.d.ts +13 -0
- package/dist/script/webhook_server_manager.js +133 -0
- package/dist/server/detail.d.ts +72 -0
- package/dist/server/detail.js +451 -0
- package/dist/server/io.d.ts +46 -0
- package/dist/{src/server → server}/io.js +42 -51
- package/dist/server/plugin.d.ts +18 -0
- package/dist/{src/server → server}/plugin.js +45 -54
- package/dist/server/server.d.ts +27 -0
- package/dist/server/server.js +53 -0
- package/dist/server.d.ts +4 -0
- package/dist/util/console_handle.d.ts +20 -0
- package/dist/util/console_handle.js +244 -0
- package/dist/util/log_handle.d.ts +23 -0
- package/dist/util/log_handle.js +224 -0
- package/index.ts +1 -6
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/test/TEST.d.ts +1 -0
- package/test/TEST.js +88 -0
- package/test/client/execute.test.d.ts +1 -0
- package/{dist/test → test}/client/execute.test.js +6 -15
- package/test/client/javascript.test.d.ts +1 -0
- package/{dist/test → test}/client/javascript.test.js +21 -30
- package/test/client/server.test.d.ts +1 -0
- package/test/client/task.test.d.ts +1 -0
- package/{dist/test → test}/client/task.test.js +1 -1
- package/test/script/parser.test.d.ts +1 -0
- package/test/script/socket.test.d.ts +1 -0
- package/tsconfig.json +8 -4
- package/dist/jest.config.js +0 -8
- package/dist/src/client/analysis.js +0 -383
- package/dist/src/client/client.js +0 -233
- package/dist/src/client/database.js +0 -36
- package/dist/src/client/http.js +0 -37
- package/dist/src/client/job_database.js +0 -36
- package/dist/src/client/job_execute.js +0 -171
- package/dist/src/client/job_parameter.js +0 -36
- package/dist/src/client/os.js +0 -202
- package/dist/src/client/parameter.js +0 -36
- package/dist/src/client/resource.js +0 -118
- package/dist/src/client/shell.js +0 -118
- package/dist/src/script/console_manager.js +0 -125
- package/dist/src/script/console_server_manager.js +0 -37
- package/dist/src/script/execute/base.js +0 -197
- package/dist/src/script/execute/feedback.js +0 -188
- package/dist/src/script/execute/runner.js +0 -274
- package/dist/src/script/execute/util_parser.js +0 -137
- package/dist/src/script/execute_manager.js +0 -309
- package/dist/src/script/socket_manager.js +0 -260
- package/dist/src/script/webhook_server_manager.js +0 -140
- package/dist/src/server/detail.js +0 -428
- package/dist/src/server/server.js +0 -51
- package/dist/src/util/console_handle.js +0 -248
- package/dist/src/util/log_handle.js +0 -230
- package/dist/src/util/server/console_handle.js +0 -248
- package/dist/src/util/server/log_handle.js +0 -230
- package/dist/test/TEST.js +0 -105
- /package/dist/{src/computed.js → computed.js} +0 -0
- /package/dist/{src/interface → interface}/base.js +0 -0
- /package/dist/{src/interface → interface}/bus.js +0 -0
- /package/dist/{src/interface → interface}/enum.js +0 -0
- /package/dist/{src/interface → interface}/execute.js +0 -0
- /package/dist/{src/interface → interface}/record.js +0 -0
- /package/dist/{src/interface → interface}/server.js +0 -0
- /package/dist/{src/interface → interface}/struct.js +0 -0
- /package/dist/{src/interface → interface}/table.js +0 -0
- /package/dist/{src/interface → interface}/ui.js +0 -0
- /package/dist/{src/interface.js → interface.js} +0 -0
- /package/dist/{src/lan → lan}/en.json +0 -0
- /package/dist/{src/lan → lan}/zh_TW.json +0 -0
- /package/dist/{src/plugins → plugins}/i18n.js +0 -0
- /package/dist/{src/script → script}/execute/interface.js +0 -0
- /package/dist/{src/script → script}/webhook_manager.js +0 -0
- /package/dist/{src/server.js → server.js} +0 -0
- /package/{dist/test → test}/client/server.test.js +0 -0
- /package/{dist/test → test}/script/parser.test.js +0 -0
- /package/{dist/test → test}/script/socket.test.js +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecuteManager = void 0;
|
|
4
|
+
const interface_1 = require("../interface");
|
|
5
|
+
const runner_1 = require("./execute/runner");
|
|
6
|
+
class ExecuteManager extends runner_1.ExecuteManager_Runner {
|
|
7
|
+
Update = () => {
|
|
8
|
+
if (this.state != interface_1.ExecuteState.RUNNING)
|
|
9
|
+
return;
|
|
10
|
+
else if (this.current_p == undefined && this.current_projects.length > 0) {
|
|
11
|
+
this.current_p = this.current_projects[0];
|
|
12
|
+
this.messager_log(`[Execute] Project Start ${this.current_p.uuid}`);
|
|
13
|
+
this.proxy?.executeProjectStart([this.current_p, 0]);
|
|
14
|
+
this.SyncDatabase(this.current_p);
|
|
15
|
+
}
|
|
16
|
+
else if (this.current_p != undefined) {
|
|
17
|
+
if (this.first)
|
|
18
|
+
this.first = false;
|
|
19
|
+
this.ExecuteProject(this.current_p);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
Stop = () => {
|
|
23
|
+
this.current_nodes.forEach(x => {
|
|
24
|
+
const h = {
|
|
25
|
+
name: 'stop_job',
|
|
26
|
+
message: 'Stop All Jobs',
|
|
27
|
+
data: {}
|
|
28
|
+
};
|
|
29
|
+
x.websocket.send(JSON.stringify(h));
|
|
30
|
+
});
|
|
31
|
+
this.jobstack = 0;
|
|
32
|
+
this.current_nodes.forEach(x => x.current_job = []);
|
|
33
|
+
};
|
|
34
|
+
Register = (lib) => {
|
|
35
|
+
this.current_projects = this.record.projects;
|
|
36
|
+
this.current_nodes = [];
|
|
37
|
+
this.record.nodes.forEach(x => {
|
|
38
|
+
const n = this.websocket_manager.targets.find(y => y.uuid == x.uuid);
|
|
39
|
+
if (n != undefined)
|
|
40
|
+
this.current_nodes.push(n);
|
|
41
|
+
});
|
|
42
|
+
this.messager_log(`[Execute] Start executing, Project count: ${this.current_projects.length}, Node count: ${this.current_nodes.length}`);
|
|
43
|
+
if (this.state == interface_1.ExecuteState.RUNNING) {
|
|
44
|
+
this.messager_log(`[Execute] Init error, There are projects being execute right now`);
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
if (this.current_nodes.length == 0) {
|
|
48
|
+
this.messager_log(`[Execute] Node count should be bigger than one`);
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
if (this.current_projects.map(x => x.task.length).reduce((acc, cur) => acc + cur, 0) == 0) {
|
|
52
|
+
this.messager_log(`[Execute] No task can be executing`);
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
if (!this.validation(this.current_projects)) {
|
|
56
|
+
this.messager_log(`[Execute] Init failed, Format checking error`);
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
if (lib != undefined)
|
|
60
|
+
this.libs = this.filter_lib(this.record.projects, lib);
|
|
61
|
+
else
|
|
62
|
+
this.libs = { libs: [] };
|
|
63
|
+
this.state = interface_1.ExecuteState.RUNNING;
|
|
64
|
+
this.messager_log(`[Execute] Init successfully, Enter process right now, length: ${this.current_projects.length}`);
|
|
65
|
+
let i = 0;
|
|
66
|
+
for (const x of this.current_projects) {
|
|
67
|
+
if (x.task.length > 0) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return i;
|
|
75
|
+
};
|
|
76
|
+
Clean = () => {
|
|
77
|
+
this.current_projects = [];
|
|
78
|
+
this.current_p = undefined;
|
|
79
|
+
this.current_t = undefined;
|
|
80
|
+
this.current_cron = [];
|
|
81
|
+
this.current_job = [];
|
|
82
|
+
this.current_nodes = [];
|
|
83
|
+
this.current_multithread = 1;
|
|
84
|
+
this.state = interface_1.ExecuteState.NONE;
|
|
85
|
+
};
|
|
86
|
+
Release = () => {
|
|
87
|
+
this.current_nodes.forEach(x => this.release(x));
|
|
88
|
+
};
|
|
89
|
+
NewConnection = (source) => {
|
|
90
|
+
if (this.state == interface_1.ExecuteState.RUNNING && this.localPara != undefined) {
|
|
91
|
+
this.sync_para(this.localPara, source);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
Disconnect = (source) => {
|
|
95
|
+
if (this.current_p == undefined)
|
|
96
|
+
return;
|
|
97
|
+
if (this.current_t == undefined)
|
|
98
|
+
return;
|
|
99
|
+
if (this.current_job.length > 0) {
|
|
100
|
+
const singleContainIt = this.current_job.filter(x => x.uuid == source.uuid && x.state == interface_1.ExecuteState.RUNNING);
|
|
101
|
+
singleContainIt.forEach((x, index) => {
|
|
102
|
+
x.uuid = '';
|
|
103
|
+
x.state = interface_1.ExecuteState.NONE;
|
|
104
|
+
});
|
|
105
|
+
this.proxy?.executeSubtaskUpdate([this.current_t, 0, '', interface_1.ExecuteState.NONE]);
|
|
106
|
+
}
|
|
107
|
+
else if (this.current_cron.length > 0) {
|
|
108
|
+
const cronContainIt = this.current_cron.filter(x => x.work.filter(y => y.state == interface_1.ExecuteState.RUNNING && y.uuid == source.uuid).length > 0);
|
|
109
|
+
cronContainIt.forEach(element => {
|
|
110
|
+
element.work.forEach(x => {
|
|
111
|
+
x.uuid = '';
|
|
112
|
+
x.state = interface_1.ExecuteState.NONE;
|
|
113
|
+
});
|
|
114
|
+
this.proxy?.executeSubtaskUpdate([this.current_t, element.id - 1, '', interface_1.ExecuteState.NONE]);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
source.current_job = [];
|
|
118
|
+
};
|
|
119
|
+
ClearState = (task_index) => {
|
|
120
|
+
if (this.current_p == undefined)
|
|
121
|
+
return;
|
|
122
|
+
if (this.current_t == undefined)
|
|
123
|
+
return;
|
|
124
|
+
if (this.current_job.length > 0) {
|
|
125
|
+
this.current_job = [];
|
|
126
|
+
this.proxy?.executeSubtaskUpdate([this.current_t, 0, '', interface_1.ExecuteState.NONE]);
|
|
127
|
+
}
|
|
128
|
+
else if (this.current_cron.length > 0) {
|
|
129
|
+
const target = this.current_cron[task_index];
|
|
130
|
+
target.work.forEach(x => {
|
|
131
|
+
x.uuid = '';
|
|
132
|
+
x.state = interface_1.ExecuteState.NONE;
|
|
133
|
+
});
|
|
134
|
+
this.proxy?.executeSubtaskUpdate([this.current_t, target.id - 1, '', interface_1.ExecuteState.NONE]);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
SkipProject = () => {
|
|
138
|
+
return this.jumpProject(true);
|
|
139
|
+
};
|
|
140
|
+
PreviousProject = () => {
|
|
141
|
+
return this.jumpProject(false);
|
|
142
|
+
};
|
|
143
|
+
SkipTask = () => {
|
|
144
|
+
return this.jumpTask(true);
|
|
145
|
+
};
|
|
146
|
+
PreviousTask = () => {
|
|
147
|
+
return this.jumpTask(false);
|
|
148
|
+
};
|
|
149
|
+
SkipSubTask = (v) => {
|
|
150
|
+
if (this.current_p == undefined) {
|
|
151
|
+
console.error("No project exist, Skip failed");
|
|
152
|
+
return -2;
|
|
153
|
+
}
|
|
154
|
+
if (this.current_t == undefined) {
|
|
155
|
+
console.error("Project has no task, Skip failed");
|
|
156
|
+
return -2;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (!this.current_t.cronjob) {
|
|
160
|
+
return this.SkipTask();
|
|
161
|
+
}
|
|
162
|
+
const min = Math.min(v, this.current_cron.length);
|
|
163
|
+
for (let i = 0; i < min; i++) {
|
|
164
|
+
const ps = this.current_cron[i].work.filter(y => y.state != interface_1.ExecuteState.FINISH && y.state != interface_1.ExecuteState.ERROR);
|
|
165
|
+
ps.forEach(x => x.state = interface_1.ExecuteState.FINISH);
|
|
166
|
+
}
|
|
167
|
+
return min;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
jumpProject = (forward) => {
|
|
171
|
+
if (this.current_projects.length == 0) {
|
|
172
|
+
console.error("There is no project exists");
|
|
173
|
+
return -2;
|
|
174
|
+
}
|
|
175
|
+
if (this.current_p == undefined) {
|
|
176
|
+
return forward ? this.skipProjectFirst() : -2;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return this._jumpProject(forward);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
jumpTask = (forward) => {
|
|
183
|
+
if (this.current_p == undefined)
|
|
184
|
+
return -2;
|
|
185
|
+
if (this.current_t == undefined) {
|
|
186
|
+
return forward ? this.skipTaskFirst() : this.previousTaskFirst();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
return forward ? this.skipTask() : this.previousTask();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
skipProjectFirst = () => {
|
|
193
|
+
this.current_p = this.current_projects[1];
|
|
194
|
+
this.proxy?.executeProjectStart([this.current_p, 1]);
|
|
195
|
+
this.SyncDatabase(this.current_p);
|
|
196
|
+
this.state = interface_1.ExecuteState.RUNNING;
|
|
197
|
+
return 1;
|
|
198
|
+
};
|
|
199
|
+
_jumpProject = (forward) => {
|
|
200
|
+
const index = this.current_projects.findIndex(x => x.uuid == this.current_p.uuid);
|
|
201
|
+
if (forward)
|
|
202
|
+
this.proxy?.executeProjectFinish([this.current_p, index]);
|
|
203
|
+
const atend = forward ? index == this.current_projects.length - 1 : index == 0;
|
|
204
|
+
if (atend) {
|
|
205
|
+
if (forward) {
|
|
206
|
+
this.current_p = undefined;
|
|
207
|
+
this.current_t = undefined;
|
|
208
|
+
this.state = interface_1.ExecuteState.FINISH;
|
|
209
|
+
this.messager_log(`[Execute] Skip project to Finish !`);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.current_p = this.current_projects[0];
|
|
213
|
+
this.current_t = undefined;
|
|
214
|
+
this.state = interface_1.ExecuteState.RUNNING;
|
|
215
|
+
this.messager_log(`[Execute] Previous project to Begining !`);
|
|
216
|
+
}
|
|
217
|
+
return -1;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const next = forward ? this.current_projects[index + 1] : this.current_projects[index - 1];
|
|
221
|
+
this.current_p = next;
|
|
222
|
+
this.current_t = undefined;
|
|
223
|
+
this.state = interface_1.ExecuteState.RUNNING;
|
|
224
|
+
if (forward) {
|
|
225
|
+
this.messager_log(`[Execute] Skip project ${index}. ${this.current_p.uuid}`);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
this.messager_log(`[Execute] Previous project ${index}. ${this.current_p.uuid}`);
|
|
229
|
+
}
|
|
230
|
+
this.proxy?.executeProjectStart([this.current_p, index + (forward ? 1 : -1)]);
|
|
231
|
+
this.SyncDatabase(this.current_p);
|
|
232
|
+
return index;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
skipTaskFirst = () => {
|
|
236
|
+
if (this.current_p.task.length > 0) {
|
|
237
|
+
this.current_t = this.current_p.task[0];
|
|
238
|
+
const taskCount = this.get_task_state_count(this.current_t);
|
|
239
|
+
if (this.current_t.cronjob) {
|
|
240
|
+
this.Init_CronContainer(this.current_t, taskCount);
|
|
241
|
+
}
|
|
242
|
+
this.t_state = interface_1.ExecuteState.NONE;
|
|
243
|
+
this.proxy?.executeTaskStart([this.current_t, taskCount]);
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
console.error("Project has no task, Skip failed");
|
|
248
|
+
return -2;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
previousTaskFirst = () => {
|
|
252
|
+
const index = this.current_projects.findIndex(x => x.uuid == this.current_p.uuid);
|
|
253
|
+
if (index == 0) {
|
|
254
|
+
this.current_t = undefined;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.current_p = this.current_projects[index - 1];
|
|
258
|
+
this.messager_log(`[Execute] Previous task ${index}. Jump Project: ${this.current_p.uuid}`);
|
|
259
|
+
}
|
|
260
|
+
this.current_job = [];
|
|
261
|
+
this.t_state = interface_1.ExecuteState.NONE;
|
|
262
|
+
return index;
|
|
263
|
+
};
|
|
264
|
+
skipTask = () => {
|
|
265
|
+
const index = this.current_p.task.findIndex(x => x.uuid == this.current_t.uuid);
|
|
266
|
+
if (index == this.current_p.task.length - 1) {
|
|
267
|
+
this.proxy?.executeTaskFinish(this.current_t);
|
|
268
|
+
this.current_t = undefined;
|
|
269
|
+
this.messager_log(`[Execute] Skip task to Finish !`);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this.proxy?.executeTaskFinish(this.current_t);
|
|
273
|
+
this.current_t = this.current_p.task[index + 1];
|
|
274
|
+
this.messager_log(`[Execute] Skip task ${index}. ${this.current_t.uuid}`);
|
|
275
|
+
const taskCount = this.get_task_state_count(this.current_t);
|
|
276
|
+
if (this.current_t.cronjob) {
|
|
277
|
+
this.Init_CronContainer(this.current_t, taskCount);
|
|
278
|
+
}
|
|
279
|
+
this.proxy?.executeTaskStart([this.current_t, taskCount]);
|
|
280
|
+
}
|
|
281
|
+
this.current_job = [];
|
|
282
|
+
this.t_state = interface_1.ExecuteState.NONE;
|
|
283
|
+
return index;
|
|
284
|
+
};
|
|
285
|
+
previousTask = () => {
|
|
286
|
+
const index = this.current_p.task.findIndex(x => x.uuid == this.current_t.uuid);
|
|
287
|
+
this.current_t = this.current_p.task[index - 1];
|
|
288
|
+
const taskCount = this.get_task_state_count(this.current_t);
|
|
289
|
+
if (this.current_t.cronjob) {
|
|
290
|
+
this.Init_CronContainer(this.current_t, taskCount);
|
|
291
|
+
}
|
|
292
|
+
this.t_state = interface_1.ExecuteState.NONE;
|
|
293
|
+
this.proxy?.executeTaskStart([this.current_t, taskCount]);
|
|
294
|
+
return 0;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
exports.ExecuteManager = ExecuteManager;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Node, NodeProxy, NodeTable, WebsocketPack } from "../interface";
|
|
2
|
+
import * as ws from 'ws';
|
|
3
|
+
export declare class WebsocketManager {
|
|
4
|
+
targets: Array<WebsocketPack>;
|
|
5
|
+
newConnect: Function;
|
|
6
|
+
disconnect: Function;
|
|
7
|
+
onAnalysis: Function;
|
|
8
|
+
proxy: NodeProxy;
|
|
9
|
+
private messager_log;
|
|
10
|
+
constructor(_newConnect: Function, _disconnect: Function, _onAnalysis: Function, _messager_log: Function, _proxy: NodeProxy);
|
|
11
|
+
server_start: (url: string, id: string) => WebSocket | ws.WebSocket | undefined;
|
|
12
|
+
server_stop: (uuid: string, reason?: string) => void;
|
|
13
|
+
server_update: () => Array<NodeTable>;
|
|
14
|
+
server_record: (ns: Array<Node>) => void;
|
|
15
|
+
shell_open: (uuid: string) => void;
|
|
16
|
+
shell_enter: (uuid: string, text: string) => void;
|
|
17
|
+
shell_close: (uuid: string) => void;
|
|
18
|
+
shell_folder: (uuid: string, path: string) => void;
|
|
19
|
+
private serverconnect;
|
|
20
|
+
private analysis;
|
|
21
|
+
private socket_analysis;
|
|
22
|
+
private sendUpdate;
|
|
23
|
+
private removeByUUID;
|
|
24
|
+
private update;
|
|
25
|
+
private shell_reply;
|
|
26
|
+
private shell_folder_reply;
|
|
27
|
+
private system_info;
|
|
28
|
+
private node_info;
|
|
29
|
+
private pong;
|
|
30
|
+
private plugin_info_reply;
|
|
31
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WebsocketManager = void 0;
|
|
37
|
+
const uuid_1 = require("uuid");
|
|
38
|
+
const interface_1 = require("../interface");
|
|
39
|
+
const jsEnv = __importStar(require("browser-or-node"));
|
|
40
|
+
const ws = __importStar(require("ws"));
|
|
41
|
+
const https = __importStar(require("https"));
|
|
42
|
+
function isRenderer() {
|
|
43
|
+
if (typeof process === 'undefined')
|
|
44
|
+
return true;
|
|
45
|
+
if (!process)
|
|
46
|
+
return true;
|
|
47
|
+
if (!process.type)
|
|
48
|
+
return false;
|
|
49
|
+
return process.type === 'renderer';
|
|
50
|
+
}
|
|
51
|
+
console.log("isRenderer", isRenderer());
|
|
52
|
+
class WebsocketManager {
|
|
53
|
+
targets = [];
|
|
54
|
+
newConnect;
|
|
55
|
+
disconnect;
|
|
56
|
+
onAnalysis;
|
|
57
|
+
proxy;
|
|
58
|
+
messager_log;
|
|
59
|
+
constructor(_newConnect, _disconnect, _onAnalysis, _messager_log, _proxy) {
|
|
60
|
+
this.newConnect = _newConnect;
|
|
61
|
+
this.disconnect = _disconnect;
|
|
62
|
+
this.onAnalysis = _onAnalysis;
|
|
63
|
+
this.messager_log = _messager_log;
|
|
64
|
+
this.proxy = _proxy;
|
|
65
|
+
setInterval(this.update, 1000);
|
|
66
|
+
}
|
|
67
|
+
server_start = (url, id) => this.serverconnect(url, id);
|
|
68
|
+
server_stop = (uuid, reason) => this.removeByUUID(uuid, reason);
|
|
69
|
+
server_update = () => this.sendUpdate();
|
|
70
|
+
server_record = (ns) => {
|
|
71
|
+
ns.forEach(x => {
|
|
72
|
+
this.serverconnect(x.url, x.uuid);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
shell_open = (uuid) => {
|
|
76
|
+
const p = this.targets.find(x => x.uuid == uuid && x.websocket.readyState == interface_1.SocketState.OPEN);
|
|
77
|
+
if (p == undefined) {
|
|
78
|
+
this.messager_log(`[Shell] Error cannot find the node by ID: ${uuid}`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const d = {
|
|
82
|
+
name: "open_shell",
|
|
83
|
+
data: 0
|
|
84
|
+
};
|
|
85
|
+
p.websocket.send(JSON.stringify(d));
|
|
86
|
+
};
|
|
87
|
+
shell_enter = (uuid, text) => {
|
|
88
|
+
const p = this.targets.find(x => x.uuid == uuid && x.websocket.readyState == interface_1.SocketState.OPEN);
|
|
89
|
+
if (p == undefined) {
|
|
90
|
+
this.messager_log(`[Shell] Error cannot find the node by ID: ${uuid}`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const d = {
|
|
94
|
+
name: "enter_shell",
|
|
95
|
+
data: text
|
|
96
|
+
};
|
|
97
|
+
p.websocket.send(JSON.stringify(d));
|
|
98
|
+
};
|
|
99
|
+
shell_close = (uuid) => {
|
|
100
|
+
const p = this.targets.find(x => x.uuid == uuid && x.websocket.readyState == interface_1.SocketState.OPEN);
|
|
101
|
+
if (p == undefined) {
|
|
102
|
+
this.messager_log(`[Shell] Error cannot find the node by ID: ${uuid}`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const d = {
|
|
106
|
+
name: "close_shell",
|
|
107
|
+
data: 0
|
|
108
|
+
};
|
|
109
|
+
p.websocket.send(JSON.stringify(d));
|
|
110
|
+
};
|
|
111
|
+
shell_folder = (uuid, path) => {
|
|
112
|
+
const p = this.targets.find(x => x.uuid == uuid && x.websocket.readyState == interface_1.SocketState.OPEN);
|
|
113
|
+
if (p == undefined) {
|
|
114
|
+
this.messager_log(`[Shell] Error cannot find the node by ID: ${uuid}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const d = {
|
|
118
|
+
name: "shell_folder",
|
|
119
|
+
data: path
|
|
120
|
+
};
|
|
121
|
+
p.websocket.send(JSON.stringify(d));
|
|
122
|
+
};
|
|
123
|
+
serverconnect = (url, uuid) => {
|
|
124
|
+
if (this.targets.findIndex(x => x.websocket.url.slice(0, -1) == url) != -1)
|
|
125
|
+
return;
|
|
126
|
+
if (this.targets.findIndex(x => x.uuid == uuid) != -1)
|
|
127
|
+
return;
|
|
128
|
+
let client = undefined;
|
|
129
|
+
if (jsEnv.isNode)
|
|
130
|
+
client = new ws.WebSocket(url, { agent: new https.Agent(), rejectUnauthorized: false });
|
|
131
|
+
else
|
|
132
|
+
client = new WebSocket(url);
|
|
133
|
+
const t = { uuid: (uuid == undefined ? (0, uuid_1.v6)() : uuid), websocket: client, current_job: [] };
|
|
134
|
+
this.targets.push(t);
|
|
135
|
+
client.onerror = (err) => {
|
|
136
|
+
this.messager_log(`[Socket] Connect failed ${url} ${err.message}`);
|
|
137
|
+
};
|
|
138
|
+
client.onclose = (ev) => {
|
|
139
|
+
if (t.s != undefined) {
|
|
140
|
+
this.messager_log(`[Socket] Client close connection, ${ev.code}, ${ev.reason}`);
|
|
141
|
+
this.disconnect(t);
|
|
142
|
+
}
|
|
143
|
+
t.s = undefined;
|
|
144
|
+
t.current_job = [];
|
|
145
|
+
};
|
|
146
|
+
client.onopen = () => {
|
|
147
|
+
this.messager_log('[Socket] New Connection !' + client.url);
|
|
148
|
+
if (t.s == undefined) {
|
|
149
|
+
t.s = true;
|
|
150
|
+
}
|
|
151
|
+
this.sendUpdate();
|
|
152
|
+
this.newConnect(t);
|
|
153
|
+
};
|
|
154
|
+
client.onmessage = (ev) => {
|
|
155
|
+
const h = JSON.parse(ev.data.toString());
|
|
156
|
+
const c = this.targets.find(x => x.uuid == uuid);
|
|
157
|
+
this.analysis(h, c);
|
|
158
|
+
};
|
|
159
|
+
return client;
|
|
160
|
+
};
|
|
161
|
+
analysis = (h, c) => {
|
|
162
|
+
if (h == undefined) {
|
|
163
|
+
this.messager_log('[Source Analysis] Decode failed, Get value undefined');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (h.message != undefined && h.message.length > 0) {
|
|
167
|
+
this.messager_log(`[Source Analysis] ${h.message}`);
|
|
168
|
+
}
|
|
169
|
+
if (h.data == undefined)
|
|
170
|
+
return;
|
|
171
|
+
const d = { name: h.name, h: h, c: c };
|
|
172
|
+
const pass = this.socket_analysis(d);
|
|
173
|
+
if (!pass)
|
|
174
|
+
this.onAnalysis(d);
|
|
175
|
+
};
|
|
176
|
+
socket_analysis = (d) => {
|
|
177
|
+
const typeMap = {
|
|
178
|
+
'system_info': this.system_info,
|
|
179
|
+
'shell_reply': this.shell_reply,
|
|
180
|
+
'shell_folder_reply': this.shell_folder_reply,
|
|
181
|
+
'node_info': this.node_info,
|
|
182
|
+
'pong': this.pong,
|
|
183
|
+
'plugin_info_reply': this.plugin_info_reply,
|
|
184
|
+
};
|
|
185
|
+
if (typeMap.hasOwnProperty(d.name)) {
|
|
186
|
+
const castingFunc = typeMap[d.h.name];
|
|
187
|
+
castingFunc(d.h.data, d.c, d.h.meta);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
sendUpdate = () => {
|
|
195
|
+
let result = [];
|
|
196
|
+
const data = [];
|
|
197
|
+
this.targets.forEach(x => {
|
|
198
|
+
if (x.websocket.readyState == interface_1.SocketState.CLOSED) {
|
|
199
|
+
data.push({ uuid: x.uuid, url: x.websocket.url });
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
data.forEach(d => this.removeByUUID(d.uuid));
|
|
203
|
+
data.forEach(d => {
|
|
204
|
+
this.serverconnect(d.url, d.uuid);
|
|
205
|
+
});
|
|
206
|
+
result = this.targets.map(x => {
|
|
207
|
+
return {
|
|
208
|
+
s: false,
|
|
209
|
+
uuid: x.uuid,
|
|
210
|
+
state: x.websocket.readyState,
|
|
211
|
+
url: x.websocket.url,
|
|
212
|
+
connection_rate: x.ms,
|
|
213
|
+
system: x.information,
|
|
214
|
+
plugins: x.plugins
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
return result;
|
|
218
|
+
};
|
|
219
|
+
removeByUUID = (uuid, reason) => {
|
|
220
|
+
let index = this.targets.findIndex(x => x.uuid == uuid);
|
|
221
|
+
if (index != -1) {
|
|
222
|
+
if (this.targets[index].websocket.readyState == interface_1.SocketState.OPEN)
|
|
223
|
+
this.targets[index].websocket.close(1000, reason != undefined ? reason : '');
|
|
224
|
+
this.targets.splice(index, 1);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
update = () => {
|
|
228
|
+
const h = { name: 'ping', data: 0 };
|
|
229
|
+
this.targets.forEach(x => {
|
|
230
|
+
if (x.websocket.readyState != interface_1.SocketState.OPEN)
|
|
231
|
+
return;
|
|
232
|
+
x.last = Date.now();
|
|
233
|
+
x.websocket.send(JSON.stringify(h));
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
shell_reply = (data, w) => {
|
|
237
|
+
this.proxy?.shellReply(data, w);
|
|
238
|
+
};
|
|
239
|
+
shell_folder_reply = (data, w) => {
|
|
240
|
+
this.proxy?.folderReply(data, w);
|
|
241
|
+
};
|
|
242
|
+
system_info = (info, source) => {
|
|
243
|
+
if (source == undefined)
|
|
244
|
+
return;
|
|
245
|
+
source.information = info;
|
|
246
|
+
};
|
|
247
|
+
node_info = (info, source) => {
|
|
248
|
+
if (source == undefined)
|
|
249
|
+
return;
|
|
250
|
+
source.load = info;
|
|
251
|
+
};
|
|
252
|
+
pong = (info, source) => {
|
|
253
|
+
if (source == undefined || source.last == undefined)
|
|
254
|
+
return;
|
|
255
|
+
source.ms = Date.now() - source.last;
|
|
256
|
+
};
|
|
257
|
+
plugin_info_reply = (data, source) => {
|
|
258
|
+
if (source == undefined || source.last == undefined)
|
|
259
|
+
return;
|
|
260
|
+
source.plugins = data;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
exports.WebsocketManager = WebsocketManager;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Messager, Messager_log } from '../interface';
|
|
2
|
+
export declare class WebhookServerManager {
|
|
3
|
+
private httpss;
|
|
4
|
+
private server;
|
|
5
|
+
private sources;
|
|
6
|
+
private messager;
|
|
7
|
+
private messager_log;
|
|
8
|
+
constructor(_messager: Messager, _messager_log: Messager_log);
|
|
9
|
+
Init: () => Promise<void>;
|
|
10
|
+
Destroy: () => void;
|
|
11
|
+
Release: () => void;
|
|
12
|
+
private get_pem;
|
|
13
|
+
}
|