nodejs-poolcontroller 8.1.2 → 8.4.0
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/.eslintrc.json +36 -36
- package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -84
- package/.github/ISSUE_TEMPLATE/2-docs.md +12 -12
- package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -28
- package/.github/ISSUE_TEMPLATE/config.yml +8 -8
- package/.github/copilot-instructions.md +63 -0
- package/.github/workflows/ghcr-publish.yml +67 -0
- package/AGENTS.md +597 -0
- package/CONTRIBUTING.md +74 -74
- package/Changelog +292 -257
- package/Dockerfile +62 -19
- package/Gruntfile.js +40 -40
- package/LICENSE +661 -661
- package/README.md +318 -191
- package/anslq25/MessagesMock.ts +221 -221
- package/anslq25/boards/MockBoardFactory.ts +49 -49
- package/anslq25/boards/MockEasyTouchBoard.ts +696 -696
- package/anslq25/boards/MockSystemBoard.ts +216 -216
- package/anslq25/chemistry/MockChlorinator.ts +98 -98
- package/anslq25/pumps/MockPump.ts +83 -83
- package/app.ts +115 -115
- package/config/Config.ts +57 -7
- package/config/VersionCheck.ts +63 -35
- package/controller/Constants.ts +809 -805
- package/controller/Equipment.ts +2688 -2664
- package/controller/Errors.ts +181 -181
- package/controller/Lockouts.ts +549 -549
- package/controller/State.ts +3738 -3690
- package/controller/boards/AquaLinkBoard.ts +1003 -1003
- package/controller/boards/BoardFactory.ts +53 -53
- package/controller/boards/EasyTouchBoard.ts +3202 -3202
- package/controller/boards/IntelliCenterBoard.ts +4393 -3899
- package/controller/boards/IntelliComBoard.ts +69 -69
- package/controller/boards/IntelliTouchBoard.ts +382 -382
- package/controller/boards/NixieBoard.ts +1944 -1929
- package/controller/boards/SunTouchBoard.ts +400 -400
- package/controller/boards/SystemBoard.ts +5268 -5268
- package/controller/comms/Comms.ts +1272 -1214
- package/controller/comms/ScreenLogic.ts +1665 -1665
- package/controller/comms/messages/Messages.ts +1433 -1243
- package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -0
- package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
- package/controller/comms/messages/config/CircuitMessage.ts +0 -0
- package/controller/comms/messages/config/ConfigMessage.ts +6 -0
- package/controller/comms/messages/config/CoverMessage.ts +0 -0
- package/controller/comms/messages/config/CustomNameMessage.ts +31 -31
- package/controller/comms/messages/config/EquipmentMessage.ts +216 -210
- package/controller/comms/messages/config/ExternalMessage.ts +96 -10
- package/controller/comms/messages/config/FeatureMessage.ts +0 -0
- package/controller/comms/messages/config/GeneralMessage.ts +0 -0
- package/controller/comms/messages/config/HeaterMessage.ts +0 -0
- package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
- package/controller/comms/messages/config/OptionsMessage.ts +194 -174
- package/controller/comms/messages/config/PumpMessage.ts +0 -0
- package/controller/comms/messages/config/RemoteMessage.ts +0 -0
- package/controller/comms/messages/config/ScheduleMessage.ts +401 -390
- package/controller/comms/messages/config/SecurityMessage.ts +0 -0
- package/controller/comms/messages/config/ValveMessage.ts +0 -0
- package/controller/comms/messages/status/ChlorinatorStateMessage.ts +0 -0
- package/controller/comms/messages/status/EquipmentStateMessage.ts +1158 -822
- package/controller/comms/messages/status/HeaterStateMessage.ts +135 -135
- package/controller/comms/messages/status/IntelliChemStateMessage.ts +448 -448
- package/controller/comms/messages/status/IntelliValveStateMessage.ts +36 -36
- package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
- package/controller/comms/messages/status/RegalModbusStateMessage.ts +411 -0
- package/controller/comms/messages/status/VersionMessage.ts +103 -41
- package/controller/nixie/Nixie.ts +173 -173
- package/controller/nixie/NixieEquipment.ts +104 -104
- package/controller/nixie/bodies/Body.ts +120 -120
- package/controller/nixie/bodies/Filter.ts +135 -135
- package/controller/nixie/chemistry/ChemController.ts +2724 -2724
- package/controller/nixie/chemistry/ChemDoser.ts +806 -806
- package/controller/nixie/chemistry/Chlorinator.ts +367 -367
- package/controller/nixie/circuits/Circuit.ts +478 -478
- package/controller/nixie/heaters/Heater.ts +834 -834
- package/controller/nixie/pumps/Pump.ts +1194 -996
- package/controller/nixie/schedules/Schedule.ts +401 -401
- package/controller/nixie/valves/Valve.ts +170 -170
- package/defaultConfig.json +352 -347
- package/docker-compose.yml +32 -0
- package/logger/DataLogger.ts +448 -448
- package/logger/Logger.ts +448 -436
- package/package.json +58 -60
- package/sendSocket.js +32 -32
- package/tsconfig.json +25 -25
- package/types/express-multer.d.ts +32 -0
- package/web/Server.ts +1937 -1927
- package/web/bindings/aqualinkD.json +559 -559
- package/web/bindings/influxDB.json +1066 -1066
- package/web/bindings/mqtt.json +721 -721
- package/web/bindings/mqttAlt.json +746 -746
- package/web/bindings/rulesManager.json +54 -54
- package/web/bindings/smartThings-Hubitat.json +31 -31
- package/web/bindings/valveRelays.json +20 -20
- package/web/bindings/vera.json +25 -25
- package/web/interfaces/baseInterface.ts +188 -188
- package/web/interfaces/httpInterface.ts +148 -148
- package/web/interfaces/influxInterface.ts +283 -283
- package/web/interfaces/mqttInterface.ts +695 -695
- package/web/interfaces/ruleInterface.ts +101 -87
- package/web/services/config/Config.ts +1063 -1053
- package/web/services/config/ConfigSocket.ts +0 -0
- package/web/services/state/State.ts +0 -0
- package/web/services/state/StateSocket.ts +0 -0
- package/web/services/utilities/Utilities.ts +233 -233
- package/.github/workflows/docker-publish-njsPC-linux.yml +0 -50
package/logger/Logger.ts
CHANGED
|
@@ -1,436 +1,448 @@
|
|
|
1
|
-
/* nodejs-poolController. An application to control pool equipment.
|
|
2
|
-
Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
|
|
3
|
-
Russell Goldin, tagyoureit. russ.goldin@gmail.com
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Affero General Public License as
|
|
7
|
-
published by the Free Software Foundation, either version 3 of the
|
|
8
|
-
License, or (at your option) any later version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Affero General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
import * as path from 'path';
|
|
19
|
-
import * as fs from 'fs';
|
|
20
|
-
import * as winston from 'winston';
|
|
21
|
-
import * as os from 'os';
|
|
22
|
-
import { utils } from "../controller/Constants";
|
|
23
|
-
import { Message } from '../controller/comms/messages/Messages';
|
|
24
|
-
import { config } from '../config/Config';
|
|
25
|
-
import { webApp } from '../web/Server';
|
|
26
|
-
import { sl } from '../controller/comms/ScreenLogic';
|
|
27
|
-
|
|
28
|
-
const extend = require("extend");
|
|
29
|
-
|
|
30
|
-
class Logger {
|
|
31
|
-
constructor() {
|
|
32
|
-
if (!fs.existsSync(path.join(process.cwd(), '/logs'))) fs.mkdirSync(path.join(process.cwd(), '/logs'));
|
|
33
|
-
this.pktPath = path.join(process.cwd(), '/logs', this.getPacketPath());
|
|
34
|
-
this.captureForReplayBaseDir = path.join(process.cwd(), '/logs/', this.getLogTimestamp());
|
|
35
|
-
/* this.captureForReplayPath = path.join(this.captureForReplayBaseDir, '/packetCapture.json'); */
|
|
36
|
-
this.pkts = [];
|
|
37
|
-
this.slMessages = [];
|
|
38
|
-
}
|
|
39
|
-
private cfg;
|
|
40
|
-
private pkts: Message[];
|
|
41
|
-
private slMessages: any[];
|
|
42
|
-
private pktPath: string;
|
|
43
|
-
private consoleToFilePath: string;
|
|
44
|
-
private transports: { console: winston.transports.ConsoleTransportInstance, file?: winston.transports.FileTransportInstance, consoleFile?: winston.transports.FileTransportInstance } = {
|
|
45
|
-
console: new winston.transports.Console({ level: 'silly' })
|
|
46
|
-
};
|
|
47
|
-
private captureForReplayBaseDir: string;
|
|
48
|
-
private captureForReplayPath: string;
|
|
49
|
-
private pktTimer: NodeJS.Timeout;
|
|
50
|
-
private currentTimestamp: string;
|
|
51
|
-
private
|
|
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
|
-
if (
|
|
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
|
-
public
|
|
110
|
-
public
|
|
111
|
-
public
|
|
112
|
-
public
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
logger.
|
|
154
|
-
if (logger.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
public
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
fs.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
buf = '';
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (typeof
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
"
|
|
304
|
-
|
|
305
|
-
"
|
|
306
|
-
"
|
|
307
|
-
"
|
|
308
|
-
"
|
|
309
|
-
"
|
|
310
|
-
"
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
"
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
"
|
|
324
|
-
"
|
|
325
|
-
"
|
|
326
|
-
"
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
"
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
"
|
|
334
|
-
"
|
|
335
|
-
"
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
"
|
|
340
|
-
"
|
|
341
|
-
"
|
|
342
|
-
"
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
"
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
"
|
|
349
|
-
"
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
"
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
//
|
|
398
|
-
let
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
1
|
+
/* nodejs-poolController. An application to control pool equipment.
|
|
2
|
+
Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
|
|
3
|
+
Russell Goldin, tagyoureit. russ.goldin@gmail.com
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as
|
|
7
|
+
published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
License, or (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import * as fs from 'fs';
|
|
20
|
+
import * as winston from 'winston';
|
|
21
|
+
import * as os from 'os';
|
|
22
|
+
import { utils } from "../controller/Constants";
|
|
23
|
+
import { Message } from '../controller/comms/messages/Messages';
|
|
24
|
+
import { config } from '../config/Config';
|
|
25
|
+
import { webApp } from '../web/Server';
|
|
26
|
+
import { sl } from '../controller/comms/ScreenLogic';
|
|
27
|
+
|
|
28
|
+
const extend = require("extend");
|
|
29
|
+
|
|
30
|
+
class Logger {
|
|
31
|
+
constructor() {
|
|
32
|
+
if (!fs.existsSync(path.join(process.cwd(), '/logs'))) fs.mkdirSync(path.join(process.cwd(), '/logs'));
|
|
33
|
+
this.pktPath = path.join(process.cwd(), '/logs', this.getPacketPath());
|
|
34
|
+
this.captureForReplayBaseDir = path.join(process.cwd(), '/logs/', this.getLogTimestamp());
|
|
35
|
+
/* this.captureForReplayPath = path.join(this.captureForReplayBaseDir, '/packetCapture.json'); */
|
|
36
|
+
this.pkts = [];
|
|
37
|
+
this.slMessages = [];
|
|
38
|
+
}
|
|
39
|
+
private cfg;
|
|
40
|
+
private pkts: Message[];
|
|
41
|
+
private slMessages: any[];
|
|
42
|
+
private pktPath: string;
|
|
43
|
+
private consoleToFilePath: string;
|
|
44
|
+
private transports: { console: winston.transports.ConsoleTransportInstance, file?: winston.transports.FileTransportInstance, consoleFile?: winston.transports.FileTransportInstance } = {
|
|
45
|
+
console: new winston.transports.Console({ level: 'silly' })
|
|
46
|
+
};
|
|
47
|
+
private captureForReplayBaseDir: string;
|
|
48
|
+
private captureForReplayPath: string;
|
|
49
|
+
private pktTimer: NodeJS.Timeout;
|
|
50
|
+
private currentTimestamp: string;
|
|
51
|
+
private _captureInProgress: boolean = false;
|
|
52
|
+
private getPacketPath(): string {
|
|
53
|
+
// changed this to remove spaces from the name
|
|
54
|
+
return 'packetLog(' + this.getLogTimestamp() + ').log';
|
|
55
|
+
}
|
|
56
|
+
private getConsoleToFilePath(): string {
|
|
57
|
+
return 'consoleLog(' + this.getLogTimestamp() + ').log';
|
|
58
|
+
}
|
|
59
|
+
public getLogTimestamp(bNew: boolean = false): string {
|
|
60
|
+
if (!bNew && typeof this.currentTimestamp !== 'undefined') { return this.currentTimestamp; }
|
|
61
|
+
var ts = new Date();
|
|
62
|
+
function pad(n) { return (n < 10 ? '0' : '') + n; }
|
|
63
|
+
this.currentTimestamp = ts.getFullYear() + '-' + pad(ts.getMonth() + 1) + '-' + pad(ts.getDate()) + '_' + pad(ts.getHours()) + '-' + pad(ts.getMinutes()) + '-' + pad(ts.getSeconds());
|
|
64
|
+
return this.currentTimestamp;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private myFormat = winston.format.printf(({ level, message, label }) => {
|
|
68
|
+
return `[${new Date().toLocaleString()}] ${level}: ${message}`;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
private _logger: winston.Logger;
|
|
72
|
+
public init() {
|
|
73
|
+
this.cfg = config.getSection('log');
|
|
74
|
+
logger._logger = winston.createLogger({
|
|
75
|
+
format: winston.format.combine(winston.format.timestamp({format: 'MMMM DD YYYY'}), winston.format.colorize(), winston.format.splat(), this.myFormat),
|
|
76
|
+
transports: [this.transports.console]
|
|
77
|
+
});
|
|
78
|
+
this.transports.console.level = this.cfg.app.level;
|
|
79
|
+
// Only start capture if not already capturing (prevents duplicate transports when config watcher triggers init())
|
|
80
|
+
if (this.cfg.app.captureForReplay && !this._captureInProgress) {
|
|
81
|
+
this.startCaptureForReplay(false);
|
|
82
|
+
}
|
|
83
|
+
if (this.cfg.app.logToFile) {
|
|
84
|
+
this.transports.consoleFile = new winston.transports.File({
|
|
85
|
+
filename: path.join(process.cwd(), '/logs', this.getConsoleToFilePath()),
|
|
86
|
+
level: 'silly',
|
|
87
|
+
format: winston.format.combine(winston.format.splat(), winston.format.uncolorize(), this.myFormat)
|
|
88
|
+
});
|
|
89
|
+
this.transports.consoleFile.level = this.cfg.app.level;
|
|
90
|
+
this._logger.add(this.transports.consoleFile);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
public async stopAsync() {
|
|
94
|
+
try {
|
|
95
|
+
this.info(`Stopping logger Process.`);
|
|
96
|
+
if (this.cfg.app.captureForReplay) {
|
|
97
|
+
return await this.stopCaptureForReplayAsync();
|
|
98
|
+
}
|
|
99
|
+
// Free up the file handles. This is yet another goofiness with winston. Not sure why they
|
|
100
|
+
// need to exclusively lock the file handles when the process always appends. Just stupid.
|
|
101
|
+
if (typeof this.transports.consoleFile !== 'undefined') {
|
|
102
|
+
this._logger.remove(this.transports.consoleFile);
|
|
103
|
+
this.transports.consoleFile.close();
|
|
104
|
+
this.transports.consoleFile = undefined;
|
|
105
|
+
}
|
|
106
|
+
console.log(`Logger Process Stopped`);
|
|
107
|
+
} catch (err) { console.log(`Error shutting down logger: ${err.message}`); }
|
|
108
|
+
}
|
|
109
|
+
public get options(): any { return this.cfg; }
|
|
110
|
+
public info(...args: any[]) { logger._logger.info.apply(logger._logger, arguments); }
|
|
111
|
+
public debug(...args: any[]) { logger._logger.debug.apply(logger._logger, arguments); }
|
|
112
|
+
public warn(...args: any[]) { logger._logger.warn.apply(logger._logger, arguments); }
|
|
113
|
+
public verbose(...args: any[]) { logger._logger.verbose.apply(logger._logger, arguments); }
|
|
114
|
+
public error(...args: any[]): Error { logger._logger.error.apply(logger._logger, arguments); return new Error(arguments[0]); }
|
|
115
|
+
public silly(...args: any[]) { logger._logger.silly.apply(logger._logger, arguments); }
|
|
116
|
+
public reject(sError: string): Promise<Error> {
|
|
117
|
+
logger.error(sError);
|
|
118
|
+
return Promise.reject(new Error(sError));
|
|
119
|
+
}
|
|
120
|
+
private isIncluded(byte: number, arr: number[]): boolean {
|
|
121
|
+
if (typeof (arr) === "undefined" || !arr || arr.length === 0) return true;
|
|
122
|
+
if (arr.indexOf(byte) !== -1) return true;
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
private isExcluded(byte: number, arr: number[]): boolean {
|
|
126
|
+
if (typeof (arr) === "undefined" || !arr) return false;
|
|
127
|
+
if (arr && arr.length === 0) return false;
|
|
128
|
+
if (arr.indexOf(byte) !== -1) return true;
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
public packet(msg: Message) {
|
|
132
|
+
// Emits to clients should not be gated by logging settings.
|
|
133
|
+
// Logging-to-file/console remains gated by packet config and filters.
|
|
134
|
+
webApp.emitToChannel('msgLogger', 'logMessage', msg);
|
|
135
|
+
|
|
136
|
+
// Filter out the messages we do not want to *log*.
|
|
137
|
+
let bLog: boolean = true;
|
|
138
|
+
if (logger.cfg.packet.enabled || logger.cfg.app.captureForReplay) {
|
|
139
|
+
// A random packet may actually find its way into the throws should the bytes get messed up
|
|
140
|
+
// in a fashion where the header byte is 255, 0, 255 but we have not identified the channel.
|
|
141
|
+
// Thus far we have seen 165 and 166.
|
|
142
|
+
const cfgPacket = logger.cfg.packet[msg.protocol] || logger.cfg.packet['unidentified'];
|
|
143
|
+
if (!logger.cfg.app.captureForReplay) {
|
|
144
|
+
// Log invalid messages no matter what if the user has selected invalid message logging.
|
|
145
|
+
if (bLog && !msg.isValid) {
|
|
146
|
+
if (!logger.cfg.packet.invalid) bLog = false;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (bLog && !cfgPacket.enabled) bLog = false;
|
|
150
|
+
if (bLog && !logger.isIncluded(msg.source, cfgPacket.includeSouce)) bLog = false;
|
|
151
|
+
if (bLog && !logger.isIncluded(msg.dest, cfgPacket.includeDest)) bLog = false;
|
|
152
|
+
if (bLog && !logger.isIncluded(msg.action, cfgPacket.includeActions)) bLog = false;
|
|
153
|
+
if (bLog && logger.isExcluded(msg.source, cfgPacket.excludeSource)) bLog = false;
|
|
154
|
+
if (bLog && logger.isExcluded(msg.dest, cfgPacket.excludeDest)) bLog = false;
|
|
155
|
+
if (bLog && logger.isExcluded(msg.action, cfgPacket.excludeActions)) bLog = false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (bLog && logger.cfg.packet.logToFile) {
|
|
160
|
+
logger.pkts.push(msg);
|
|
161
|
+
if (logger.pkts.length > 5)
|
|
162
|
+
logger.flushLogs();
|
|
163
|
+
else {
|
|
164
|
+
// Attempt to ease up on the writes if we are logging a bunch of packets.
|
|
165
|
+
if (logger.pktTimer) clearTimeout(logger.pktTimer);
|
|
166
|
+
logger.pktTimer = setTimeout(logger.flushLogs, 1000);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
bLog = false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (logger.cfg.packet.logToConsole && bLog) {
|
|
175
|
+
if (msg.isValid) logger._logger.info(msg.toLog());
|
|
176
|
+
else logger._logger.warn(msg.toLog());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
public screenlogic(data: any){
|
|
180
|
+
if (logger.cfg.screenlogic.enabled || logger.cfg.app.captureForReplay){
|
|
181
|
+
if (logger.cfg.screenlogic.logToFile) {
|
|
182
|
+
logger.slMessages.push(data);
|
|
183
|
+
if (logger.slMessages.length > 5)
|
|
184
|
+
logger.flushSLLogs();
|
|
185
|
+
else {
|
|
186
|
+
// Attempt to ease up on the writes if we are logging a bunch of packets.
|
|
187
|
+
if (logger.pktTimer) clearTimeout(logger.pktTimer);
|
|
188
|
+
logger.pktTimer = setTimeout(logger.flushSLLogs, 1000);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
webApp.emitToChannel('msgLogger', 'logMessage', data);
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
if (logger.cfg.screenlogic.logToConsole){
|
|
195
|
+
logger._logger.info(sl.toLog(data));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
public logAPI(apiReq:string){
|
|
199
|
+
if (logger.cfg.app.captureForReplay){
|
|
200
|
+
// TODO: buffer this
|
|
201
|
+
fs.appendFile(logger.pktPath, apiReq, function(err) {
|
|
202
|
+
if (err) logger.error('Error writing packet to %s: %s', logger.pktPath, err);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
public clearMessages() {
|
|
208
|
+
if (fs.existsSync(logger.pktPath)) {
|
|
209
|
+
logger.info(`Clearing message log: ${ logger.pktPath }`);
|
|
210
|
+
fs.truncateSync(logger.pktPath, 0);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
public flushLogs() {
|
|
214
|
+
var p: Message[] = logger.pkts.splice(0, logger.pkts.length);
|
|
215
|
+
var buf: string = '';
|
|
216
|
+
if (logger.cfg.packet.enabled) {
|
|
217
|
+
for (let i = 0; i < p.length; i++) {
|
|
218
|
+
|
|
219
|
+
buf += (p[i].toLog() + os.EOL);
|
|
220
|
+
}
|
|
221
|
+
fs.appendFile(logger.pktPath, buf, function(err) {
|
|
222
|
+
if (err) logger.error('Error writing packet to %s: %s', logger.pktPath, err);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
buf = '';
|
|
226
|
+
}
|
|
227
|
+
public flushSLLogs() {
|
|
228
|
+
var p: any[] = logger.slMessages.splice(0, logger.slMessages.length);
|
|
229
|
+
var buf: string = '';
|
|
230
|
+
|
|
231
|
+
for (let i = 0; i < p.length; i++) {
|
|
232
|
+
buf += (p[i] + os.EOL);
|
|
233
|
+
}
|
|
234
|
+
fs.appendFile(logger.pktPath, buf, function(err) {
|
|
235
|
+
if (err) logger.error(`Error writing screenlogic message to ${logger.pktPath}: ${err.message}`);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
buf = '';
|
|
239
|
+
}
|
|
240
|
+
public setOptions(opts, c?: any) {
|
|
241
|
+
c = typeof c === 'undefined' ? this.cfg : c;
|
|
242
|
+
for (let prop in opts) {
|
|
243
|
+
let o = opts[prop];
|
|
244
|
+
if (o instanceof Array) {
|
|
245
|
+
//console.log({ o: o, c: c, prop: prop });
|
|
246
|
+
c[prop] = o; // Stop here we are replacing the array.
|
|
247
|
+
}
|
|
248
|
+
else if (typeof o === 'object') {
|
|
249
|
+
if (typeof c[prop] === 'undefined') c[prop] = {};
|
|
250
|
+
this.setOptions(o, c[prop]); // Use recursion here. Harder to follow but much less code.
|
|
251
|
+
}
|
|
252
|
+
else
|
|
253
|
+
c[prop] = opts[prop];
|
|
254
|
+
}
|
|
255
|
+
config.setSection('log', this.cfg);
|
|
256
|
+
if (utils.makeBool(this.cfg.app.logToFile)) {
|
|
257
|
+
if (typeof this.transports.consoleFile === 'undefined') {
|
|
258
|
+
this.transports.consoleFile = new winston.transports.File({
|
|
259
|
+
filename: path.join(process.cwd(), '/logs', this.getConsoleToFilePath()),
|
|
260
|
+
level: 'silly',
|
|
261
|
+
format: winston.format.combine(winston.format.splat(), winston.format.uncolorize(), this.myFormat)
|
|
262
|
+
});
|
|
263
|
+
this._logger.add(this.transports.consoleFile);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
if (typeof this.transports.consoleFile !== 'undefined') {
|
|
268
|
+
this._logger.remove(this.transports.consoleFile);
|
|
269
|
+
this.transports.consoleFile.close();
|
|
270
|
+
this.transports.consoleFile = undefined;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
for (let [key, transport] of Object.entries(this.transports)) {
|
|
274
|
+
if(typeof transport !== 'undefined') transport.level = this.cfg.app.level;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
public startCaptureForReplay(bResetLogs:boolean) {
|
|
278
|
+
this._captureInProgress = true;
|
|
279
|
+
logger.info(`Starting Replay Capture.`);
|
|
280
|
+
// start new replay directory
|
|
281
|
+
|
|
282
|
+
if (!fs.existsSync(this.captureForReplayPath)) fs.mkdirSync(this.captureForReplayBaseDir, { recursive: true });
|
|
283
|
+
|
|
284
|
+
// Create logs subdirectory for additional log files
|
|
285
|
+
let logsSubDir = path.join(this.captureForReplayBaseDir, 'logs');
|
|
286
|
+
if (!fs.existsSync(logsSubDir)) fs.mkdirSync(logsSubDir, { recursive: true });
|
|
287
|
+
if (bResetLogs){
|
|
288
|
+
if (fs.existsSync(path.join(process.cwd(), 'data/poolConfig.json'))) {
|
|
289
|
+
fs.copyFileSync(path.join(process.cwd(), 'data/poolConfig.json'), path.join(process.cwd(),'data/', `poolConfig-${this.getLogTimestamp()}.json`));
|
|
290
|
+
fs.unlinkSync((path.join(process.cwd(), 'data/poolConfig.json')));
|
|
291
|
+
}
|
|
292
|
+
if (fs.existsSync(path.join(process.cwd(), 'data/poolState.json'))) {
|
|
293
|
+
fs.copyFileSync(path.join(process.cwd(), 'data/poolState.json'), path.join(process.cwd(),'data/', `poolState-${this.getLogTimestamp()}.json`));
|
|
294
|
+
fs.unlinkSync((path.join(process.cwd(), 'data/poolState.json')));
|
|
295
|
+
}
|
|
296
|
+
this.clearMessages();
|
|
297
|
+
}
|
|
298
|
+
logger.cfg = extend(true, {}, logger.cfg, {
|
|
299
|
+
"packet": {
|
|
300
|
+
"enabled": true,
|
|
301
|
+
"logToConsole": true,
|
|
302
|
+
"logToFile": true,
|
|
303
|
+
"invalid": true,
|
|
304
|
+
"broadcast": {
|
|
305
|
+
"enabled": true,
|
|
306
|
+
"includeActions": [],
|
|
307
|
+
"includeSource": [],
|
|
308
|
+
"includeDest": [],
|
|
309
|
+
"excludeActions": [],
|
|
310
|
+
"excludeSource": [],
|
|
311
|
+
"excludeDest": []
|
|
312
|
+
},
|
|
313
|
+
"pump": {
|
|
314
|
+
"enabled": true,
|
|
315
|
+
"includeActions": [],
|
|
316
|
+
"includeSource": [],
|
|
317
|
+
"includeDest": [],
|
|
318
|
+
"excludeActions": [],
|
|
319
|
+
"excludeSource": [],
|
|
320
|
+
"excludeDest": []
|
|
321
|
+
},
|
|
322
|
+
"chlorinator": {
|
|
323
|
+
"enabled": true,
|
|
324
|
+
"includeSource": [],
|
|
325
|
+
"includeDest": [],
|
|
326
|
+
"excludeSource": [],
|
|
327
|
+
"excludeDest": []
|
|
328
|
+
},
|
|
329
|
+
"intellichem": {
|
|
330
|
+
"enabled": true,
|
|
331
|
+
"includeActions": [],
|
|
332
|
+
"exclueActions": [],
|
|
333
|
+
"includeSource": [],
|
|
334
|
+
"includeDest": [],
|
|
335
|
+
"excludeSource": [],
|
|
336
|
+
"excludeDest": []
|
|
337
|
+
},
|
|
338
|
+
"intellivalve": {
|
|
339
|
+
"enabled": true,
|
|
340
|
+
"includeActions": [],
|
|
341
|
+
"exclueActions": [],
|
|
342
|
+
"includeSource": [],
|
|
343
|
+
"includeDest": [],
|
|
344
|
+
"excludeSource": [],
|
|
345
|
+
"excludeDest": []
|
|
346
|
+
},
|
|
347
|
+
"unidentified": {
|
|
348
|
+
"enabled": true,
|
|
349
|
+
"includeSource": [],
|
|
350
|
+
"includeDest": [],
|
|
351
|
+
"excludeSource": [],
|
|
352
|
+
"excludeDest": []
|
|
353
|
+
},
|
|
354
|
+
"unknown": {
|
|
355
|
+
"enabled": true,
|
|
356
|
+
"includeSource": [],
|
|
357
|
+
"includeDest": [],
|
|
358
|
+
"excludeSource": [],
|
|
359
|
+
"excludeDest": []
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
"app": {
|
|
363
|
+
"enabled": true,
|
|
364
|
+
"level": "silly",
|
|
365
|
+
"captureForReplay": true
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
this.consoleToFilePath = path.join(this.captureForReplayBaseDir, this.getConsoleToFilePath());
|
|
369
|
+
this.transports.file = new winston.transports.File({
|
|
370
|
+
filename: this.consoleToFilePath,
|
|
371
|
+
level: 'silly',
|
|
372
|
+
format: winston.format.combine(winston.format.splat(), winston.format.uncolorize(), this.myFormat)
|
|
373
|
+
});
|
|
374
|
+
logger._logger.add(this.transports.file);
|
|
375
|
+
this.transports.console.level = 'silly';
|
|
376
|
+
}
|
|
377
|
+
public async stopCaptureForReplayAsync(remLogs?: any[]):Promise<string> {
|
|
378
|
+
return new Promise<string>(async (resolve, reject) => {
|
|
379
|
+
try {
|
|
380
|
+
// Get REM server configurations from config
|
|
381
|
+
let configData = config.getSection();
|
|
382
|
+
let remServers = [];
|
|
383
|
+
if (configData.web && configData.web.interfaces) {
|
|
384
|
+
for (let interfaceName in configData.web.interfaces) {
|
|
385
|
+
let interfaceConfig = configData.web.interfaces[interfaceName];
|
|
386
|
+
if (interfaceConfig.type === 'rem' && interfaceConfig.enabled) {
|
|
387
|
+
remServers.push({
|
|
388
|
+
name: interfaceConfig.name || interfaceName,
|
|
389
|
+
uuid: interfaceConfig.uuid,
|
|
390
|
+
host: interfaceConfig.options?.host || '',
|
|
391
|
+
backup: true
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Use the existing backup logic to create the base backup
|
|
398
|
+
let backupOptions = {
|
|
399
|
+
njsPC: true,
|
|
400
|
+
servers: remServers,
|
|
401
|
+
name: `Packet Capture ${this.currentTimestamp}`,
|
|
402
|
+
automatic: false
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
let backupFile = await webApp.backupServer(backupOptions);
|
|
406
|
+
|
|
407
|
+
// Add packet capture logs to the existing backup zip
|
|
408
|
+
let jszip = require("jszip");
|
|
409
|
+
let zip = await jszip.loadAsync(fs.readFileSync(backupFile.filePath));
|
|
410
|
+
|
|
411
|
+
// Add packet capture logs to the njsPC/logs directory
|
|
412
|
+
zip.file(`njsPC/logs/${this.getPacketPath()}`, fs.readFileSync(logger.pktPath));
|
|
413
|
+
zip.file(`njsPC/logs/${this.getConsoleToFilePath()}`, fs.readFileSync(this.consoleToFilePath));
|
|
414
|
+
|
|
415
|
+
// Add REM server logs if provided
|
|
416
|
+
if (remLogs && remLogs.length > 0) {
|
|
417
|
+
logger.info(`Adding ${remLogs.length} REM logs to backup`);
|
|
418
|
+
for (let remLog of remLogs) {
|
|
419
|
+
// Create logs directory for the REM server using the hardcoded name
|
|
420
|
+
let logPath = `Relay Equipment Manager/logs/${remLog.logFileName}`;
|
|
421
|
+
logger.info(`Adding REM log to backup: ${logPath} (size: ${remLog.logData.length} characters)`);
|
|
422
|
+
zip.file(logPath, remLog.logData);
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
logger.info(`No REM logs provided to add to backup`);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Generate the updated zip
|
|
429
|
+
await zip.generateAsync({type:'nodebuffer'}).then(content => {
|
|
430
|
+
fs.writeFileSync(backupFile.filePath, content);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Restore original logging configuration
|
|
434
|
+
this.cfg = config.getSection('log');
|
|
435
|
+
logger._logger.remove(this.transports.file);
|
|
436
|
+
this.transports.console.level = this.cfg.app.level;
|
|
437
|
+
this._captureInProgress = false;
|
|
438
|
+
|
|
439
|
+
resolve(backupFile.filePath);
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
this._captureInProgress = false;
|
|
443
|
+
reject(err.message);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
export var logger = new Logger();
|