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
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,233 +1,233 @@
|
|
|
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 multer from 'multer';
|
|
21
|
-
import * as express from 'express';
|
|
22
|
-
import { SsdpServer} from '../../Server';
|
|
23
|
-
import { state } from "../../../controller/State";
|
|
24
|
-
import { sys } from "../../../controller/Equipment";
|
|
25
|
-
import { webApp } from "../../Server";
|
|
26
|
-
import { config } from "../../../config/Config";
|
|
27
|
-
import { logger } from "../../../logger/Logger";
|
|
28
|
-
import { ServiceParameterError, ServiceProcessError } from "../../../controller/Errors";
|
|
29
|
-
import { BindingsFile } from "../../interfaces/baseInterface";
|
|
30
|
-
import { Utils, utils } from "../../../controller/Constants";
|
|
31
|
-
const extend = require("extend");
|
|
32
|
-
export class UtilitiesRoute {
|
|
33
|
-
|
|
34
|
-
public static initRoutes(app: express.Application) {
|
|
35
|
-
app.use('/upnp.xml', async (req, res, next) => {
|
|
36
|
-
try {
|
|
37
|
-
// Put together the upnp device description.
|
|
38
|
-
let ssdp = webApp.findServer('ssdp') as SsdpServer;
|
|
39
|
-
if (typeof ssdp === 'undefined') throw new Error(`SSDP Server not initialized. No upnp information available.`);
|
|
40
|
-
res.status(200).set('Content-Type', 'text/xml').send(ssdp.deviceXML());
|
|
41
|
-
} catch (err) { next(err); }
|
|
42
|
-
});
|
|
43
|
-
app.get('/extended/:section', (req, res) => {
|
|
44
|
-
let cfg = sys.getSection(req.params.section);
|
|
45
|
-
let st = state.getState(req.params.section);
|
|
46
|
-
let arr = [];
|
|
47
|
-
for (let i = 0; i < cfg.length; i++){
|
|
48
|
-
let p = extend(true, {}, cfg[i], st.find(s => s.id === cfg[i].id));
|
|
49
|
-
arr.push(p);
|
|
50
|
-
}
|
|
51
|
-
return res.status(200).send(arr);
|
|
52
|
-
});
|
|
53
|
-
app.put('/app/interfaces/add', async (req, res, next) => {
|
|
54
|
-
try {
|
|
55
|
-
let faces = config.getSection('web.interfaces');
|
|
56
|
-
let opts: any = {};
|
|
57
|
-
switch (req.body.type) {
|
|
58
|
-
case 'rule':
|
|
59
|
-
opts = {};
|
|
60
|
-
break;
|
|
61
|
-
case 'rem':
|
|
62
|
-
opts = {
|
|
63
|
-
options: { protocol: 'http://', host: '', port: 8080, headers: { "content-type": "application/json" } },
|
|
64
|
-
socket: {
|
|
65
|
-
transports: ['websocket'], allowEIO3: true, upgrade: false,
|
|
66
|
-
reconnectionDelay: 2000, reconnection: true, reconnectionDelayMax: 20000
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
case 'http':
|
|
71
|
-
case 'rest':
|
|
72
|
-
opts = {
|
|
73
|
-
options: { protocol: 'http://', host: '', port: 80 }
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
case 'influx':
|
|
77
|
-
case 'influxdb':
|
|
78
|
-
opts = {
|
|
79
|
-
options: {
|
|
80
|
-
version: 1,
|
|
81
|
-
protocol: 'http',
|
|
82
|
-
database: 'pool',
|
|
83
|
-
port: 8601,
|
|
84
|
-
retentionPolicy: 'autogen'
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
case 'influxdb2':
|
|
89
|
-
opts = {
|
|
90
|
-
options: {
|
|
91
|
-
version: 2,
|
|
92
|
-
protocol: 'http',
|
|
93
|
-
port: 9999,
|
|
94
|
-
database: 'pool',
|
|
95
|
-
bucket: '57ec4eed2d90a50b',
|
|
96
|
-
token: '...LuyM84JJx93Qvc7tfaXPbI_mFFjRBjaA==',
|
|
97
|
-
org: 'njsPC-org'
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
case 'mqtt':
|
|
102
|
-
opts = {
|
|
103
|
-
options: {
|
|
104
|
-
protocol: 'mqtt://', host: '', port: 1883, username: '', password: '',
|
|
105
|
-
selfSignedCertificate: false,
|
|
106
|
-
rootTopic: "pool/@bind=(state.equipment.model).replace(/ /g,'-').replace(' / ','').toLowerCase();",
|
|
107
|
-
retain: true, qos: 0, changesOnly: true
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
return Promise.reject(new ServiceParameterError(`An invalid type was specified ${req.body.type}`, 'PUT: /app/interfaces/add', 'type', req.body.type));
|
|
113
|
-
}
|
|
114
|
-
opts.uuid = utils.uuid();
|
|
115
|
-
opts.isCustom = true;
|
|
116
|
-
// Now lets create a name for the element. This would have been much easier if it were an array but alas we are stuck.
|
|
117
|
-
let name = req.body.name.replace(/^[^a-zA-Z_$]|[^0-9a-zA-Z_$]/g, '_');
|
|
118
|
-
if (name.length === 0) return Promise.reject(new ServiceParameterError(`An invalid name was specified ${req.body.name}`, 'PUT: /app/interfaces/add', 'name', req.body.name));
|
|
119
|
-
if (name.charAt(0) >= '0' && name.charAt(0) <= '9') name = 'i' + name;
|
|
120
|
-
let fnEnsureUnique = (name, ord?: number): string => {
|
|
121
|
-
let isUnique = true;
|
|
122
|
-
for (let fname in faces) {
|
|
123
|
-
if (fname === (typeof ord !== 'undefined' ? `${name}_${ord}` : name)) {
|
|
124
|
-
isUnique = false;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (!isUnique) name = fnEnsureUnique(name, typeof ord === 'undefined' ? 0 : ord++);
|
|
129
|
-
return typeof ord !== 'undefined' ? `${name}_${ord}` : name;
|
|
130
|
-
}
|
|
131
|
-
name = fnEnsureUnique(name);
|
|
132
|
-
opts = extend(true, {}, opts, req.body);
|
|
133
|
-
config.setSection(`web.interfaces.${name}`, opts);
|
|
134
|
-
res.status(200).send({ id: name, opts: opts });
|
|
135
|
-
} catch (err) { next(err); }
|
|
136
|
-
});
|
|
137
|
-
app.delete('/app/interface', async (req, res, next) => {
|
|
138
|
-
try {
|
|
139
|
-
let faces = config.getSection('web.interfaces');
|
|
140
|
-
let deleted;
|
|
141
|
-
for (let fname in faces) {
|
|
142
|
-
let iface = faces[fname];
|
|
143
|
-
if (typeof req.body.id !== 'undefined') {
|
|
144
|
-
if (fname === req.body.id) {
|
|
145
|
-
deleted = iface;
|
|
146
|
-
iface.enabled = false;
|
|
147
|
-
await webApp.updateServerInterface(iface);
|
|
148
|
-
config.removeSection(`web.interfaces.${fname}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else if (typeof req.body.uuid !== 'undefined') {
|
|
152
|
-
if (req.body.uuid.toLowerCase() === iface.uuid.toLowerCase()) {
|
|
153
|
-
deleted = iface;
|
|
154
|
-
iface.enabled = false;
|
|
155
|
-
await webApp.updateServerInterface(iface);
|
|
156
|
-
config.removeSection(`web.interfaces.${fname}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return res.status(200).send(deleted);
|
|
161
|
-
} catch (err) { next(err); }
|
|
162
|
-
});
|
|
163
|
-
app.get('/app/options/interfaces', async (req, res, next) => {
|
|
164
|
-
try {
|
|
165
|
-
// todo: move bytevaluemaps out to a proper location; add additional definitions
|
|
166
|
-
let opts = {
|
|
167
|
-
interfaces: config.getSection('web.interfaces'),
|
|
168
|
-
types: [
|
|
169
|
-
{ name: 'rule', desc: 'Rule', hasBindings: true, hasUrl: false },
|
|
170
|
-
{ name: 'rest', desc: 'Rest', hasBindings: true },
|
|
171
|
-
{ name: 'http', desc: 'Http', hasBindings: true },
|
|
172
|
-
{ name: 'rem', desc: 'Relay Equipment Manager', hasBindings: false },
|
|
173
|
-
{ name: 'mqtt', desc: 'MQTT', hasBindings: true },
|
|
174
|
-
{ name: 'influx', desc: 'InfluxDB', hasBindings: true },
|
|
175
|
-
{ name: 'influxdb2', desc: 'InfluxDB2', hasBindings: true}
|
|
176
|
-
],
|
|
177
|
-
protocols: [
|
|
178
|
-
{ val: 0, name: 'http://', desc: 'http://' },
|
|
179
|
-
{ val: 1, name: 'https://', desc: 'https://' },
|
|
180
|
-
{ val: 2, name: 'mqtt://', desc: 'mqtt://' }
|
|
181
|
-
],
|
|
182
|
-
files: []
|
|
183
|
-
}
|
|
184
|
-
// Read all the files in the custom bindings directory.
|
|
185
|
-
let cpath = path.posix.join(process.cwd(), '/web/bindings/custom/');
|
|
186
|
-
let files = fs.readdirSync(cpath);
|
|
187
|
-
for (let i = 0; i < files.length; i++) {
|
|
188
|
-
if (path.extname(files[i]) === '.json') {
|
|
189
|
-
let bf = await BindingsFile.fromFile(path.posix.join(process.cwd(), 'web/bindings/'), `custom/${files[i]}`);
|
|
190
|
-
if (typeof bf !== 'undefined') opts.files.push(bf.options);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return res.status(200).send(opts);
|
|
194
|
-
} catch (err) { next(err); }
|
|
195
|
-
});
|
|
196
|
-
app.post('/app/interfaceBindings/file', async (req, res, next) => {
|
|
197
|
-
try {
|
|
198
|
-
let file = multer({
|
|
199
|
-
limits: { fileSize: 1000000 },
|
|
200
|
-
storage: multer.memoryStorage()
|
|
201
|
-
}).single('bindingsFile');
|
|
202
|
-
file(req, res, async (err) => {
|
|
203
|
-
try {
|
|
204
|
-
if (err) { next(err); }
|
|
205
|
-
else {
|
|
206
|
-
// Validate the incoming data and save it off only if it is valid.
|
|
207
|
-
let bf = await BindingsFile.fromBuffer(req.file.originalname, req.file.buffer);
|
|
208
|
-
if (typeof bf === 'undefined') {
|
|
209
|
-
err = new ServiceProcessError(`Invalid bindings file: ${req.file.originalname}`, 'POST: app/bindings/file', 'extractBindingOptions');
|
|
210
|
-
next(err);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
if (fs.existsSync(bf.filePath))
|
|
214
|
-
return next(new ServiceProcessError(`File already exists ${req.file.originalname}`, 'POST: app/bindings/file', 'writeFile'));
|
|
215
|
-
else {
|
|
216
|
-
try {
|
|
217
|
-
fs.writeFileSync(bf.filePath, req.file.buffer);
|
|
218
|
-
} catch (e) { logger.error(`Error writing bindings file ${e.message}`); }
|
|
219
|
-
}
|
|
220
|
-
return res.status(200).send(bf);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} catch (e) {
|
|
224
|
-
err = new ServiceProcessError(`Error uploading file: ${e.message}`, 'POST: app/backup/file', 'uploadFile');
|
|
225
|
-
next(err);
|
|
226
|
-
logger.error(`File upload error: ${e.message}`);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
} catch (err) { next(err); }
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
}
|
|
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 multer from 'multer';
|
|
21
|
+
import * as express from 'express';
|
|
22
|
+
import { SsdpServer} from '../../Server';
|
|
23
|
+
import { state } from "../../../controller/State";
|
|
24
|
+
import { sys } from "../../../controller/Equipment";
|
|
25
|
+
import { webApp } from "../../Server";
|
|
26
|
+
import { config } from "../../../config/Config";
|
|
27
|
+
import { logger } from "../../../logger/Logger";
|
|
28
|
+
import { ServiceParameterError, ServiceProcessError } from "../../../controller/Errors";
|
|
29
|
+
import { BindingsFile } from "../../interfaces/baseInterface";
|
|
30
|
+
import { Utils, utils } from "../../../controller/Constants";
|
|
31
|
+
const extend = require("extend");
|
|
32
|
+
export class UtilitiesRoute {
|
|
33
|
+
|
|
34
|
+
public static initRoutes(app: express.Application) {
|
|
35
|
+
app.use('/upnp.xml', async (req, res, next) => {
|
|
36
|
+
try {
|
|
37
|
+
// Put together the upnp device description.
|
|
38
|
+
let ssdp = webApp.findServer('ssdp') as SsdpServer;
|
|
39
|
+
if (typeof ssdp === 'undefined') throw new Error(`SSDP Server not initialized. No upnp information available.`);
|
|
40
|
+
res.status(200).set('Content-Type', 'text/xml').send(ssdp.deviceXML());
|
|
41
|
+
} catch (err) { next(err); }
|
|
42
|
+
});
|
|
43
|
+
app.get('/extended/:section', (req, res) => {
|
|
44
|
+
let cfg = sys.getSection(req.params.section);
|
|
45
|
+
let st = state.getState(req.params.section);
|
|
46
|
+
let arr = [];
|
|
47
|
+
for (let i = 0; i < cfg.length; i++){
|
|
48
|
+
let p = extend(true, {}, cfg[i], st.find(s => s.id === cfg[i].id));
|
|
49
|
+
arr.push(p);
|
|
50
|
+
}
|
|
51
|
+
return res.status(200).send(arr);
|
|
52
|
+
});
|
|
53
|
+
app.put('/app/interfaces/add', async (req, res, next) => {
|
|
54
|
+
try {
|
|
55
|
+
let faces = config.getSection('web.interfaces');
|
|
56
|
+
let opts: any = {};
|
|
57
|
+
switch (req.body.type) {
|
|
58
|
+
case 'rule':
|
|
59
|
+
opts = {};
|
|
60
|
+
break;
|
|
61
|
+
case 'rem':
|
|
62
|
+
opts = {
|
|
63
|
+
options: { protocol: 'http://', host: '', port: 8080, headers: { "content-type": "application/json" } },
|
|
64
|
+
socket: {
|
|
65
|
+
transports: ['websocket'], allowEIO3: true, upgrade: false,
|
|
66
|
+
reconnectionDelay: 2000, reconnection: true, reconnectionDelayMax: 20000
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case 'http':
|
|
71
|
+
case 'rest':
|
|
72
|
+
opts = {
|
|
73
|
+
options: { protocol: 'http://', host: '', port: 80 }
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case 'influx':
|
|
77
|
+
case 'influxdb':
|
|
78
|
+
opts = {
|
|
79
|
+
options: {
|
|
80
|
+
version: 1,
|
|
81
|
+
protocol: 'http',
|
|
82
|
+
database: 'pool',
|
|
83
|
+
port: 8601,
|
|
84
|
+
retentionPolicy: 'autogen'
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case 'influxdb2':
|
|
89
|
+
opts = {
|
|
90
|
+
options: {
|
|
91
|
+
version: 2,
|
|
92
|
+
protocol: 'http',
|
|
93
|
+
port: 9999,
|
|
94
|
+
database: 'pool',
|
|
95
|
+
bucket: '57ec4eed2d90a50b',
|
|
96
|
+
token: '...LuyM84JJx93Qvc7tfaXPbI_mFFjRBjaA==',
|
|
97
|
+
org: 'njsPC-org'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case 'mqtt':
|
|
102
|
+
opts = {
|
|
103
|
+
options: {
|
|
104
|
+
protocol: 'mqtt://', host: '', port: 1883, username: '', password: '',
|
|
105
|
+
selfSignedCertificate: false,
|
|
106
|
+
rootTopic: "pool/@bind=(state.equipment.model).replace(/ /g,'-').replace(' / ','').toLowerCase();",
|
|
107
|
+
retain: true, qos: 0, changesOnly: true
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
return Promise.reject(new ServiceParameterError(`An invalid type was specified ${req.body.type}`, 'PUT: /app/interfaces/add', 'type', req.body.type));
|
|
113
|
+
}
|
|
114
|
+
opts.uuid = utils.uuid();
|
|
115
|
+
opts.isCustom = true;
|
|
116
|
+
// Now lets create a name for the element. This would have been much easier if it were an array but alas we are stuck.
|
|
117
|
+
let name = req.body.name.replace(/^[^a-zA-Z_$]|[^0-9a-zA-Z_$]/g, '_');
|
|
118
|
+
if (name.length === 0) return Promise.reject(new ServiceParameterError(`An invalid name was specified ${req.body.name}`, 'PUT: /app/interfaces/add', 'name', req.body.name));
|
|
119
|
+
if (name.charAt(0) >= '0' && name.charAt(0) <= '9') name = 'i' + name;
|
|
120
|
+
let fnEnsureUnique = (name, ord?: number): string => {
|
|
121
|
+
let isUnique = true;
|
|
122
|
+
for (let fname in faces) {
|
|
123
|
+
if (fname === (typeof ord !== 'undefined' ? `${name}_${ord}` : name)) {
|
|
124
|
+
isUnique = false;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (!isUnique) name = fnEnsureUnique(name, typeof ord === 'undefined' ? 0 : ord++);
|
|
129
|
+
return typeof ord !== 'undefined' ? `${name}_${ord}` : name;
|
|
130
|
+
}
|
|
131
|
+
name = fnEnsureUnique(name);
|
|
132
|
+
opts = extend(true, {}, opts, req.body);
|
|
133
|
+
config.setSection(`web.interfaces.${name}`, opts);
|
|
134
|
+
res.status(200).send({ id: name, opts: opts });
|
|
135
|
+
} catch (err) { next(err); }
|
|
136
|
+
});
|
|
137
|
+
app.delete('/app/interface', async (req, res, next) => {
|
|
138
|
+
try {
|
|
139
|
+
let faces = config.getSection('web.interfaces');
|
|
140
|
+
let deleted;
|
|
141
|
+
for (let fname in faces) {
|
|
142
|
+
let iface = faces[fname];
|
|
143
|
+
if (typeof req.body.id !== 'undefined') {
|
|
144
|
+
if (fname === req.body.id) {
|
|
145
|
+
deleted = iface;
|
|
146
|
+
iface.enabled = false;
|
|
147
|
+
await webApp.updateServerInterface(iface);
|
|
148
|
+
config.removeSection(`web.interfaces.${fname}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (typeof req.body.uuid !== 'undefined') {
|
|
152
|
+
if (req.body.uuid.toLowerCase() === iface.uuid.toLowerCase()) {
|
|
153
|
+
deleted = iface;
|
|
154
|
+
iface.enabled = false;
|
|
155
|
+
await webApp.updateServerInterface(iface);
|
|
156
|
+
config.removeSection(`web.interfaces.${fname}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return res.status(200).send(deleted);
|
|
161
|
+
} catch (err) { next(err); }
|
|
162
|
+
});
|
|
163
|
+
app.get('/app/options/interfaces', async (req, res, next) => {
|
|
164
|
+
try {
|
|
165
|
+
// todo: move bytevaluemaps out to a proper location; add additional definitions
|
|
166
|
+
let opts = {
|
|
167
|
+
interfaces: config.getSection('web.interfaces'),
|
|
168
|
+
types: [
|
|
169
|
+
{ name: 'rule', desc: 'Rule', hasBindings: true, hasUrl: false },
|
|
170
|
+
{ name: 'rest', desc: 'Rest', hasBindings: true },
|
|
171
|
+
{ name: 'http', desc: 'Http', hasBindings: true },
|
|
172
|
+
{ name: 'rem', desc: 'Relay Equipment Manager', hasBindings: false },
|
|
173
|
+
{ name: 'mqtt', desc: 'MQTT', hasBindings: true },
|
|
174
|
+
{ name: 'influx', desc: 'InfluxDB', hasBindings: true },
|
|
175
|
+
{ name: 'influxdb2', desc: 'InfluxDB2', hasBindings: true}
|
|
176
|
+
],
|
|
177
|
+
protocols: [
|
|
178
|
+
{ val: 0, name: 'http://', desc: 'http://' },
|
|
179
|
+
{ val: 1, name: 'https://', desc: 'https://' },
|
|
180
|
+
{ val: 2, name: 'mqtt://', desc: 'mqtt://' }
|
|
181
|
+
],
|
|
182
|
+
files: []
|
|
183
|
+
}
|
|
184
|
+
// Read all the files in the custom bindings directory.
|
|
185
|
+
let cpath = path.posix.join(process.cwd(), '/web/bindings/custom/');
|
|
186
|
+
let files = fs.readdirSync(cpath);
|
|
187
|
+
for (let i = 0; i < files.length; i++) {
|
|
188
|
+
if (path.extname(files[i]) === '.json') {
|
|
189
|
+
let bf = await BindingsFile.fromFile(path.posix.join(process.cwd(), 'web/bindings/'), `custom/${files[i]}`);
|
|
190
|
+
if (typeof bf !== 'undefined') opts.files.push(bf.options);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return res.status(200).send(opts);
|
|
194
|
+
} catch (err) { next(err); }
|
|
195
|
+
});
|
|
196
|
+
app.post('/app/interfaceBindings/file', async (req, res, next) => {
|
|
197
|
+
try {
|
|
198
|
+
let file = multer({
|
|
199
|
+
limits: { fileSize: 1000000 },
|
|
200
|
+
storage: multer.memoryStorage()
|
|
201
|
+
}).single('bindingsFile');
|
|
202
|
+
file(req, res, async (err) => {
|
|
203
|
+
try {
|
|
204
|
+
if (err) { next(err); }
|
|
205
|
+
else {
|
|
206
|
+
// Validate the incoming data and save it off only if it is valid.
|
|
207
|
+
let bf = await BindingsFile.fromBuffer(req.file.originalname, req.file.buffer);
|
|
208
|
+
if (typeof bf === 'undefined') {
|
|
209
|
+
err = new ServiceProcessError(`Invalid bindings file: ${req.file.originalname}`, 'POST: app/bindings/file', 'extractBindingOptions');
|
|
210
|
+
next(err);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
if (fs.existsSync(bf.filePath))
|
|
214
|
+
return next(new ServiceProcessError(`File already exists ${req.file.originalname}`, 'POST: app/bindings/file', 'writeFile'));
|
|
215
|
+
else {
|
|
216
|
+
try {
|
|
217
|
+
fs.writeFileSync(bf.filePath, req.file.buffer);
|
|
218
|
+
} catch (e) { logger.error(`Error writing bindings file ${e.message}`); }
|
|
219
|
+
}
|
|
220
|
+
return res.status(200).send(bf);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} catch (e) {
|
|
224
|
+
err = new ServiceProcessError(`Error uploading file: ${e.message}`, 'POST: app/backup/file', 'uploadFile');
|
|
225
|
+
next(err);
|
|
226
|
+
logger.error(`File upload error: ${e.message}`);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
} catch (err) { next(err); }
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
name: Publish Docker Image - Ubuntu
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
tags:
|
|
8
|
-
- "v*.*.*"
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
build-and-push:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- name: Docker meta
|
|
16
|
-
id: meta
|
|
17
|
-
uses: docker/metadata-action@v5
|
|
18
|
-
with:
|
|
19
|
-
# list of Docker images to use as base name for tags
|
|
20
|
-
images: |
|
|
21
|
-
tagyoureit/njspc
|
|
22
|
-
# generate Docker tags based on the following events/attributes
|
|
23
|
-
tags: |
|
|
24
|
-
type=schedule
|
|
25
|
-
type=ref,event=branch
|
|
26
|
-
type=ref,event=pr
|
|
27
|
-
type=semver,pattern={{version}}
|
|
28
|
-
type=semver,pattern={{major}}.{{minor}}
|
|
29
|
-
type=semver,pattern={{major}}
|
|
30
|
-
type=sha
|
|
31
|
-
|
|
32
|
-
- name: Set up QEMU
|
|
33
|
-
uses: docker/setup-qemu-action@v3
|
|
34
|
-
|
|
35
|
-
- name: Set up Docker Buildx
|
|
36
|
-
uses: docker/setup-buildx-action@v3
|
|
37
|
-
|
|
38
|
-
- name: Login to Docker Hub
|
|
39
|
-
uses: docker/login-action@v3
|
|
40
|
-
with:
|
|
41
|
-
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
42
|
-
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
43
|
-
|
|
44
|
-
- name: Build and push combined Docker image
|
|
45
|
-
uses: docker/build-push-action@v6
|
|
46
|
-
with:
|
|
47
|
-
push: true
|
|
48
|
-
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
49
|
-
tags: ${{ steps.meta.outputs.tags }}
|
|
50
|
-
labels: ${{ steps.meta.outputs.labels }}
|