@iobroker/js-controller-common-db 7.2.3 → 8.0.0-alpha.1-20260921-e5941ca8a
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/build/cjs/index.js +3 -3
- package/build/cjs/lib/common/aliasProcessing.js +6 -0
- package/build/cjs/lib/common/aliasProcessing.js.map +2 -2
- package/build/cjs/lib/common/interview.js +2 -0
- package/build/cjs/lib/common/interview.js.map +1 -1
- package/build/cjs/lib/common/logger.d.ts +34 -1
- package/build/cjs/lib/common/logger.js +37 -37
- package/build/cjs/lib/common/logger.js.map +2 -2
- package/build/cjs/lib/common/maybeCallback.js +4 -0
- package/build/cjs/lib/common/maybeCallback.js.map +1 -1
- package/build/cjs/lib/common/password.d.ts +9 -0
- package/build/cjs/lib/common/password.js +8 -6
- package/build/cjs/lib/common/password.js.map +2 -2
- package/build/cjs/lib/common/session.js +10 -5
- package/build/cjs/lib/common/session.js.map +2 -2
- package/build/cjs/lib/common/tools.d.ts +164 -59
- package/build/cjs/lib/common/tools.js +497 -476
- package/build/cjs/lib/common/tools.js.map +3 -3
- package/build/esm/lib/common/aliasProcessing.d.ts.map +1 -1
- package/build/esm/lib/common/aliasProcessing.js +5 -0
- package/build/esm/lib/common/aliasProcessing.js.map +1 -1
- package/build/esm/lib/common/logger.d.ts +34 -1
- package/build/esm/lib/common/logger.d.ts.map +1 -1
- package/build/esm/lib/common/logger.js +45 -49
- package/build/esm/lib/common/logger.js.map +1 -1
- package/build/esm/lib/common/password.d.ts +9 -0
- package/build/esm/lib/common/password.d.ts.map +1 -1
- package/build/esm/lib/common/password.js +5 -0
- package/build/esm/lib/common/password.js.map +1 -1
- package/build/esm/lib/common/session.d.ts.map +1 -1
- package/build/esm/lib/common/session.js +6 -6
- package/build/esm/lib/common/session.js.map +1 -1
- package/build/esm/lib/common/tools.d.ts +164 -59
- package/build/esm/lib/common/tools.d.ts.map +1 -1
- package/build/esm/lib/common/tools.js +535 -586
- package/build/esm/lib/common/tools.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -18
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name in all)
|
|
10
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,6 +46,7 @@ __export(tools_exports, {
|
|
|
45
46
|
encrypt: () => encrypt,
|
|
46
47
|
ensureDNSOrder: () => ensureDNSOrder,
|
|
47
48
|
execAsync: () => execAsync,
|
|
49
|
+
execFileAsync: () => execFileAsync,
|
|
48
50
|
findIPs: () => findIPs,
|
|
49
51
|
formatAliasValue: () => formatAliasValue,
|
|
50
52
|
generateDefaultCertificates: () => generateDefaultCertificates,
|
|
@@ -85,6 +87,7 @@ __export(tools_exports, {
|
|
|
85
87
|
isDevInstallation: () => isDevInstallation,
|
|
86
88
|
isDevServerInstallation: () => isDevServerInstallation,
|
|
87
89
|
isDocker: () => isDocker,
|
|
90
|
+
isForeignProcess: () => isForeignProcess,
|
|
88
91
|
isGithubPathname: () => isGithubPathname,
|
|
89
92
|
isHostRunning: () => isHostRunning,
|
|
90
93
|
isIoBrokerInstalledAsSystemd: () => isIoBrokerInstalledAsSystemd,
|
|
@@ -92,6 +95,7 @@ __export(tools_exports, {
|
|
|
92
95
|
isLocalAddress: () => isLocalAddress,
|
|
93
96
|
isLogLevel: () => isLogLevel,
|
|
94
97
|
isObject: () => isObject,
|
|
98
|
+
isProcessRunning: () => isProcessRunning,
|
|
95
99
|
isShortGithubUrl: () => isShortGithubUrl,
|
|
96
100
|
isSingleHost: () => isSingleHost,
|
|
97
101
|
isValidPattern: () => isValidPattern,
|
|
@@ -119,33 +123,32 @@ __export(tools_exports, {
|
|
|
119
123
|
});
|
|
120
124
|
module.exports = __toCommonJS(tools_exports);
|
|
121
125
|
var __import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
122
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
123
126
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
124
127
|
var import_semver = __toESM(require("semver"), 1);
|
|
125
128
|
var import_node_os = __toESM(require("node:os"), 1);
|
|
126
|
-
var
|
|
127
|
-
var import_deep_clone = __toESM(require("deep-clone"), 1);
|
|
128
|
-
var import_promisify_child_process = require("promisify-child-process");
|
|
129
|
+
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
129
130
|
var import_node_readline = require("node:readline");
|
|
130
131
|
var import_node_stream = require("node:stream");
|
|
131
|
-
var import_pak = require("@alcalzone/pak");
|
|
132
|
-
var import_exitCodes = require("../../lib/common/exitCodes.js");
|
|
133
132
|
var import_node_zlib = __toESM(require("node:zlib"), 1);
|
|
134
|
-
var import_password = require("../../lib/common/password.js");
|
|
135
|
-
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
136
|
-
var import_axios = __toESM(require("axios"), 1);
|
|
137
|
-
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
138
133
|
var import_node_child_process = require("node:child_process");
|
|
139
134
|
var import_node_url = require("node:url");
|
|
140
135
|
var import_node_events = __toESM(require("node:events"), 1);
|
|
141
|
-
var import_maybeCallback = require("../../lib/common/maybeCallback.js");
|
|
142
|
-
var import_node = __toESM(require("node.extend"), 1);
|
|
143
136
|
var import_node_dns = require("node:dns");
|
|
144
|
-
var import_aliasProcessing = require("../../lib/common/aliasProcessing.js");
|
|
145
137
|
var url = __toESM(require("node:url"), 1);
|
|
146
138
|
var import_node_module = require("node:module");
|
|
139
|
+
var import_node_forge = __toESM(require("node-forge"), 1);
|
|
140
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
141
|
+
var import_deep_clone = __toESM(require("deep-clone"), 1);
|
|
142
|
+
var import_pak = require("@alcalzone/pak");
|
|
143
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
144
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
145
|
+
var import_node = __toESM(require("node.extend"), 1);
|
|
146
|
+
var import_exitCodes = require("../../lib/common/exitCodes.js");
|
|
147
|
+
var import_password = require("../../lib/common/password.js");
|
|
148
|
+
var import_aliasProcessing = require("../../lib/common/aliasProcessing.js");
|
|
147
149
|
var import_constants = require("../../lib/common/constants.js");
|
|
148
150
|
__reExport(tools_exports, require("../../lib/common/maybeCallback.js"), module.exports);
|
|
151
|
+
const HASH_TEXT = "hash";
|
|
149
152
|
const thisDir = url.fileURLToPath(new URL(".", __import_meta_url || `file://${__filename}`));
|
|
150
153
|
const require2 = (0, import_node_module.createRequire)(__import_meta_url || `file://${__filename}`);
|
|
151
154
|
var ERRORS;
|
|
@@ -189,6 +192,7 @@ function copyAttributes(oldObj, newObj, originalObj, isNonEdit) {
|
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
194
|
}
|
|
195
|
+
__name(copyAttributes, "copyAttributes");
|
|
192
196
|
function checkNonEditable(oldObject, newObject) {
|
|
193
197
|
if (!oldObject) {
|
|
194
198
|
return true;
|
|
@@ -237,31 +241,51 @@ function checkNonEditable(oldObject, newObject) {
|
|
|
237
241
|
}
|
|
238
242
|
return true;
|
|
239
243
|
}
|
|
244
|
+
__name(checkNonEditable, "checkNonEditable");
|
|
240
245
|
function upToDate(repoVersion, installedVersion) {
|
|
241
246
|
return import_semver.default.gte(installedVersion, repoVersion);
|
|
242
247
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
decipher.on("error", (error) => {
|
|
254
|
-
console.error(`Cannot decode secret: ${error.message}`);
|
|
255
|
-
callback(null);
|
|
256
|
-
});
|
|
257
|
-
decipher.on("end", () => callback(decrypted));
|
|
258
|
-
decipher.write(data, "hex");
|
|
259
|
-
decipher.end();
|
|
260
|
-
} catch (e) {
|
|
261
|
-
console.error(`Cannot decode secret: ${e.message}`);
|
|
262
|
-
callback(null);
|
|
248
|
+
__name(upToDate, "upToDate");
|
|
249
|
+
function evpBytesToKeyMD5(password2, keyLen, ivLen) {
|
|
250
|
+
const passwordBuffer = Buffer.from(password2, "utf8");
|
|
251
|
+
let material = Buffer.alloc(0);
|
|
252
|
+
let block = Buffer.alloc(0);
|
|
253
|
+
while (material.length < keyLen + ivLen) {
|
|
254
|
+
block = import_node_crypto.default.createHash("md5").update(Buffer.concat([block, passwordBuffer])).digest();
|
|
255
|
+
material = Buffer.concat([material, block]);
|
|
263
256
|
}
|
|
257
|
+
return {
|
|
258
|
+
key: material.subarray(0, keyLen),
|
|
259
|
+
iv: material.subarray(keyLen, keyLen + ivLen)
|
|
260
|
+
};
|
|
264
261
|
}
|
|
262
|
+
__name(evpBytesToKeyMD5, "evpBytesToKeyMD5");
|
|
263
|
+
function decryptPhrase(password2, data) {
|
|
264
|
+
const { key, iv } = evpBytesToKeyMD5(password2, 24, 16);
|
|
265
|
+
const decipher = import_node_crypto.default.createDecipheriv("aes-192-cbc", key, iv);
|
|
266
|
+
return new Promise((resolve) => {
|
|
267
|
+
try {
|
|
268
|
+
let decrypted = "";
|
|
269
|
+
decipher.on("readable", () => {
|
|
270
|
+
const data2 = decipher.read();
|
|
271
|
+
if (data2) {
|
|
272
|
+
decrypted += data2.toString("utf8");
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
decipher.on("error", (error) => {
|
|
276
|
+
console.error(`Cannot decode secret: ${error.message}`);
|
|
277
|
+
resolve(null);
|
|
278
|
+
});
|
|
279
|
+
decipher.on("end", () => resolve(decrypted));
|
|
280
|
+
decipher.write(data, "hex");
|
|
281
|
+
decipher.end();
|
|
282
|
+
} catch (e) {
|
|
283
|
+
console.error(`Cannot decode secret: ${e.message}`);
|
|
284
|
+
resolve(null);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
__name(decryptPhrase, "decryptPhrase");
|
|
265
289
|
async function isSingleHost(objects) {
|
|
266
290
|
const res = await objects.getObjectList({
|
|
267
291
|
startkey: "system.host.",
|
|
@@ -270,6 +294,7 @@ async function isSingleHost(objects) {
|
|
|
270
294
|
const hostObjs = res.rows.filter((obj) => obj.value && obj.value.type === "host");
|
|
271
295
|
return hostObjs.length <= 1;
|
|
272
296
|
}
|
|
297
|
+
__name(isSingleHost, "isSingleHost");
|
|
273
298
|
async function isHostRunning(objects, states) {
|
|
274
299
|
const res = await objects.getObjectList({
|
|
275
300
|
startkey: "system.host.",
|
|
@@ -278,21 +303,24 @@ async function isHostRunning(objects, states) {
|
|
|
278
303
|
res.rows = res.rows.filter((obj) => obj.value?.type === "host");
|
|
279
304
|
for (const hostObj of res.rows) {
|
|
280
305
|
const state = await states.getState(`${hostObj.id}.alive`);
|
|
281
|
-
if (state
|
|
306
|
+
if (state?.val) {
|
|
282
307
|
return true;
|
|
283
308
|
}
|
|
284
309
|
}
|
|
285
310
|
return false;
|
|
286
311
|
}
|
|
312
|
+
__name(isHostRunning, "isHostRunning");
|
|
287
313
|
function isDevInstallation() {
|
|
288
314
|
return import_fs_extra.default.pathExistsSync(`${getControllerDir()}/../../packages/controller`);
|
|
289
315
|
}
|
|
316
|
+
__name(isDevInstallation, "isDevInstallation");
|
|
290
317
|
function getAppName() {
|
|
291
318
|
if (isDevInstallation()) {
|
|
292
319
|
return "ioBroker";
|
|
293
320
|
}
|
|
294
321
|
return "iobroker";
|
|
295
322
|
}
|
|
323
|
+
__name(getAppName, "getAppName");
|
|
296
324
|
const appNameLowerCase = "iobroker";
|
|
297
325
|
const appName = getAppName();
|
|
298
326
|
function findIPs() {
|
|
@@ -310,6 +338,7 @@ function findIPs() {
|
|
|
310
338
|
}
|
|
311
339
|
return ownIpArr;
|
|
312
340
|
}
|
|
341
|
+
__name(findIPs, "findIPs");
|
|
313
342
|
function findPath(path2, url2) {
|
|
314
343
|
if (!url2) {
|
|
315
344
|
return "";
|
|
@@ -325,6 +354,7 @@ function findPath(path2, url2) {
|
|
|
325
354
|
}
|
|
326
355
|
return `${thisDir}/../${path2}${url2}`;
|
|
327
356
|
}
|
|
357
|
+
__name(findPath, "findPath");
|
|
328
358
|
async function getMac() {
|
|
329
359
|
const macRegex = /(?:[a-z0-9]{2}[:-]){5}[a-z0-9]{2}/gi;
|
|
330
360
|
const zeroRegex = /(?:[0]{2}[:-]){5}[0]{2}/;
|
|
@@ -334,7 +364,7 @@ async function getMac() {
|
|
|
334
364
|
throw new Error(stderr);
|
|
335
365
|
}
|
|
336
366
|
if (typeof stdout !== "string") {
|
|
337
|
-
throw new Error(`Unexpected stdout: ${stdout
|
|
367
|
+
throw new Error(`Unexpected stdout: ${typeof stdout}`);
|
|
338
368
|
}
|
|
339
369
|
let macAddress;
|
|
340
370
|
let match;
|
|
@@ -355,12 +385,14 @@ ${stdout}`);
|
|
|
355
385
|
}
|
|
356
386
|
return result.replace(/-/g, ":").toLowerCase();
|
|
357
387
|
}
|
|
388
|
+
__name(getMac, "getMac");
|
|
358
389
|
async function getNewestDockerImageVersion() {
|
|
359
390
|
const res = await import_axios.default.get(DOCKER_INFO_URL);
|
|
360
391
|
const dockerResult = res.data.results[0];
|
|
361
392
|
const isNew = new Date(dockerResult.last_updated).getTime() > new Date(process.env.BUILD).getTime() + DOCKER_HUB_BUILD_TIME_MS;
|
|
362
393
|
return { version: dockerResult.name, lastUpdated: dockerResult.last_updated, isNew };
|
|
363
394
|
}
|
|
395
|
+
__name(getNewestDockerImageVersion, "getNewestDockerImageVersion");
|
|
364
396
|
function getDockerInformation() {
|
|
365
397
|
try {
|
|
366
398
|
const versionString = import_fs_extra.default.readFileSync(OFFICIAL_DOCKER_FILE, { encoding: "utf-8" }).trim();
|
|
@@ -369,6 +401,7 @@ function getDockerInformation() {
|
|
|
369
401
|
}
|
|
370
402
|
return { isDocker: isDocker(), isOfficial: false };
|
|
371
403
|
}
|
|
404
|
+
__name(getDockerInformation, "getDockerInformation");
|
|
372
405
|
function isControllerUiUpgradeSupported() {
|
|
373
406
|
const dockerInfo = getDockerInformation();
|
|
374
407
|
if (dockerInfo.isDocker) {
|
|
@@ -382,6 +415,7 @@ function isControllerUiUpgradeSupported() {
|
|
|
382
415
|
}
|
|
383
416
|
return !["win32", "darwin"].includes(import_node_os.default.platform());
|
|
384
417
|
}
|
|
418
|
+
__name(isControllerUiUpgradeSupported, "isControllerUiUpgradeSupported");
|
|
385
419
|
function isDocker() {
|
|
386
420
|
try {
|
|
387
421
|
import_fs_extra.default.statSync("/.dockerenv");
|
|
@@ -404,39 +438,39 @@ function isDocker() {
|
|
|
404
438
|
return false;
|
|
405
439
|
}
|
|
406
440
|
}
|
|
441
|
+
__name(isDocker, "isDocker");
|
|
407
442
|
async function uuid(givenMac) {
|
|
408
|
-
givenMac
|
|
443
|
+
givenMac ??= "";
|
|
409
444
|
const _isDocker = isDocker();
|
|
410
445
|
if (require2("ci-info").isCI) {
|
|
411
446
|
return "55travis-pipe-line-cior-githubaction";
|
|
412
447
|
}
|
|
413
|
-
let mac = givenMac !== null ? givenMac || "" : null;
|
|
414
448
|
let u;
|
|
415
|
-
if (!_isDocker &&
|
|
449
|
+
if (!_isDocker && !givenMac) {
|
|
416
450
|
const ifaces = import_node_os.default.networkInterfaces();
|
|
417
451
|
for (const iface of Object.values(ifaces)) {
|
|
418
452
|
if (iface) {
|
|
419
453
|
for (const entry of iface) {
|
|
420
454
|
if (entry.mac !== "00:00:00:00:00:00") {
|
|
421
|
-
|
|
455
|
+
givenMac = entry.mac;
|
|
422
456
|
break;
|
|
423
457
|
}
|
|
424
458
|
}
|
|
425
459
|
}
|
|
426
|
-
if (
|
|
460
|
+
if (givenMac) {
|
|
427
461
|
break;
|
|
428
462
|
}
|
|
429
463
|
}
|
|
430
464
|
}
|
|
431
|
-
if (!_isDocker &&
|
|
432
|
-
const
|
|
433
|
-
return uuid(
|
|
465
|
+
if (!_isDocker && !givenMac) {
|
|
466
|
+
const mac = await getMac();
|
|
467
|
+
return uuid(mac);
|
|
434
468
|
}
|
|
435
|
-
if (!_isDocker &&
|
|
469
|
+
if (!_isDocker && givenMac) {
|
|
436
470
|
const md5sum = import_node_crypto.default.createHash("md5");
|
|
437
|
-
md5sum.update(
|
|
438
|
-
|
|
439
|
-
u = `${
|
|
471
|
+
md5sum.update(givenMac);
|
|
472
|
+
givenMac = md5sum.digest("hex");
|
|
473
|
+
u = `${givenMac.substring(0, 8)}-${givenMac.substring(8, 12)}-${givenMac.substring(12, 16)}-${givenMac.substring(16, 20)}-${givenMac.substring(20)}`;
|
|
440
474
|
} else {
|
|
441
475
|
let a;
|
|
442
476
|
let b;
|
|
@@ -448,6 +482,7 @@ async function uuid(givenMac) {
|
|
|
448
482
|
}
|
|
449
483
|
return u;
|
|
450
484
|
}
|
|
485
|
+
__name(uuid, "uuid");
|
|
451
486
|
async function updateUuid(newUuid, _objects) {
|
|
452
487
|
let _uuid = await uuid("");
|
|
453
488
|
_uuid = newUuid || _uuid;
|
|
@@ -485,6 +520,7 @@ async function updateUuid(newUuid, _objects) {
|
|
|
485
520
|
}
|
|
486
521
|
return _uuid;
|
|
487
522
|
}
|
|
523
|
+
__name(updateUuid, "updateUuid");
|
|
488
524
|
async function createUuid(objects) {
|
|
489
525
|
const userObj = await objects.getObject("system.user.admin");
|
|
490
526
|
if (!userObj) {
|
|
@@ -523,7 +559,7 @@ async function createUuid(objects) {
|
|
|
523
559
|
if (!PROBLEM_UUIDS.includes(obj.native.uuid)) {
|
|
524
560
|
return;
|
|
525
561
|
}
|
|
526
|
-
const licObj = objects.getObject("system.adapter.vis.0");
|
|
562
|
+
const licObj = await objects.getObject("system.adapter.vis.0");
|
|
527
563
|
if (!licObj || !licObj.native || !licObj.native.license) {
|
|
528
564
|
return updateUuid("", objects);
|
|
529
565
|
}
|
|
@@ -542,7 +578,8 @@ async function createUuid(objects) {
|
|
|
542
578
|
console.warn(`Your iobroker.vis license must be updated. Please contact info@iobroker.net to get a new license!`);
|
|
543
579
|
console.warn(`Provide following information in email: ${data.email}, invoice: ${data.invoice}`);
|
|
544
580
|
}
|
|
545
|
-
|
|
581
|
+
__name(createUuid, "createUuid");
|
|
582
|
+
async function getFile(urlOrPath, fileName) {
|
|
546
583
|
if (urlOrPath.substring(0, "http://".length) === "http://" || urlOrPath.substring(0, "https://".length) === "https://") {
|
|
547
584
|
const tmpFile = `${thisDir}/../tmp/${fileName || `${Math.floor(Math.random() * 268435454)}.zip`}`;
|
|
548
585
|
try {
|
|
@@ -553,122 +590,92 @@ async function getFile(urlOrPath, fileName, callback) {
|
|
|
553
590
|
"Accept-Encoding": "gzip"
|
|
554
591
|
}
|
|
555
592
|
});
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
callback && callback(tmpFile);
|
|
593
|
+
await new Promise((resolve, reject) => {
|
|
594
|
+
res.data.pipe(import_fs_extra.default.createWriteStream(tmpFile)).on("close", resolve).on("error", reject);
|
|
559
595
|
});
|
|
596
|
+
console.log(`downloaded ${tmpFile}`);
|
|
560
597
|
} catch (e) {
|
|
561
598
|
console.log(`Cannot download "${tmpFile}": ${e.message}`);
|
|
562
|
-
callback && callback(tmpFile);
|
|
563
599
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
} else {
|
|
573
|
-
console.log(`File not found: ${urlOrPath}`);
|
|
574
|
-
process.exit(import_exitCodes.EXIT_CODES.FILE_NOT_FOUND);
|
|
575
|
-
}
|
|
576
|
-
} catch (err) {
|
|
577
|
-
console.log(`File "${urlOrPath}" could no be read: ${err.message}`);
|
|
578
|
-
process.exit(import_exitCodes.EXIT_CODES.FILE_NOT_FOUND);
|
|
600
|
+
return tmpFile;
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
if (import_fs_extra.default.existsSync(urlOrPath)) {
|
|
604
|
+
return urlOrPath;
|
|
605
|
+
}
|
|
606
|
+
if (import_fs_extra.default.existsSync(`${thisDir}/../${urlOrPath}`)) {
|
|
607
|
+
return `${thisDir}/../${urlOrPath}`;
|
|
579
608
|
}
|
|
609
|
+
if (import_fs_extra.default.existsSync(`${thisDir}/../tmp/${urlOrPath}`)) {
|
|
610
|
+
return `${thisDir}/../tmp/${urlOrPath}`;
|
|
611
|
+
}
|
|
612
|
+
console.log(`File not found: ${urlOrPath}`);
|
|
613
|
+
process.exit(import_exitCodes.EXIT_CODES.FILE_NOT_FOUND);
|
|
614
|
+
} catch (err) {
|
|
615
|
+
console.log(`File "${urlOrPath}" could no be read: ${err.message}`);
|
|
616
|
+
process.exit(import_exitCodes.EXIT_CODES.FILE_NOT_FOUND);
|
|
580
617
|
}
|
|
581
618
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
619
|
+
__name(getFile, "getFile");
|
|
620
|
+
async function getJson(urlOrPath, agent) {
|
|
621
|
+
agent ||= "";
|
|
622
|
+
let result = {};
|
|
623
|
+
if (!urlOrPath) {
|
|
624
|
+
console.log("Empty url!");
|
|
625
|
+
return null;
|
|
586
626
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
627
|
+
if (urlOrPath.substring(0, "http://".length) === "http://" || urlOrPath.substring(0, "https://".length) === "https://") {
|
|
628
|
+
try {
|
|
629
|
+
const res = await import_axios.default.get(urlOrPath, {
|
|
630
|
+
headers: { "Accept-Encoding": "gzip", timeout: 1e4, "User-Agent": agent }
|
|
631
|
+
});
|
|
632
|
+
if (res.status !== 200 || !res.data) {
|
|
633
|
+
throw new Error(`Invalid response, body: ${res.data}, status code: ${res.status}`);
|
|
634
|
+
}
|
|
635
|
+
result = res.data;
|
|
636
|
+
return result;
|
|
637
|
+
} catch (e) {
|
|
638
|
+
console.warn(`Cannot download json from ${urlOrPath}. Error: ${e.message}`);
|
|
639
|
+
return null;
|
|
592
640
|
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
641
|
+
}
|
|
642
|
+
if (import_fs_extra.default.existsSync(urlOrPath)) {
|
|
643
|
+
try {
|
|
644
|
+
result = import_fs_extra.default.readJSONSync(urlOrPath);
|
|
645
|
+
} catch (e) {
|
|
646
|
+
console.log(`Cannot parse json file from ${urlOrPath}. Error: ${e.message}`);
|
|
647
|
+
return null;
|
|
597
648
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
sources = res.data;
|
|
608
|
-
if (callback) {
|
|
609
|
-
callback(sources, urlOrPath);
|
|
610
|
-
}
|
|
611
|
-
} catch (e) {
|
|
612
|
-
console.warn(`Cannot download json from ${urlOrPath}. Error: ${e.message}`);
|
|
613
|
-
if (callback) {
|
|
614
|
-
callback(null, urlOrPath);
|
|
615
|
-
}
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
} else {
|
|
619
|
-
if (import_fs_extra.default.existsSync(urlOrPath)) {
|
|
620
|
-
try {
|
|
621
|
-
sources = import_fs_extra.default.readJSONSync(urlOrPath);
|
|
622
|
-
} catch (e) {
|
|
623
|
-
console.log(`Cannot parse json file from ${urlOrPath}. Error: ${e.message}`);
|
|
624
|
-
if (callback) {
|
|
625
|
-
callback(null, urlOrPath);
|
|
626
|
-
}
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
if (callback) {
|
|
630
|
-
callback(sources, urlOrPath);
|
|
631
|
-
}
|
|
632
|
-
} else if (import_fs_extra.default.existsSync(`${thisDir}/../${urlOrPath}`)) {
|
|
633
|
-
try {
|
|
634
|
-
sources = import_fs_extra.default.readJSONSync(`${thisDir}/../${urlOrPath}`);
|
|
635
|
-
} catch (e) {
|
|
636
|
-
console.log(`Cannot parse json file from ${thisDir}/../${urlOrPath}. Error: ${e.message}`);
|
|
637
|
-
if (callback) {
|
|
638
|
-
callback(null, urlOrPath);
|
|
639
|
-
}
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
if (callback) {
|
|
643
|
-
callback(sources, urlOrPath);
|
|
644
|
-
}
|
|
645
|
-
} else if (import_fs_extra.default.existsSync(`${thisDir}/../tmp/${urlOrPath}`)) {
|
|
646
|
-
try {
|
|
647
|
-
sources = import_fs_extra.default.readJSONSync(`${thisDir}/../tmp/${urlOrPath}`);
|
|
648
|
-
} catch (e) {
|
|
649
|
-
console.log(`Cannot parse json file from ${thisDir}/../tmp/${urlOrPath}. Error: ${e.message}`);
|
|
650
|
-
if (callback) {
|
|
651
|
-
callback(null, urlOrPath);
|
|
652
|
-
}
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
if (callback) {
|
|
656
|
-
callback(sources, urlOrPath);
|
|
657
|
-
}
|
|
658
|
-
} else {
|
|
659
|
-
if (callback) {
|
|
660
|
-
callback(null, urlOrPath);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
649
|
+
return result;
|
|
650
|
+
}
|
|
651
|
+
if (import_fs_extra.default.existsSync(`${thisDir}/../${urlOrPath}`)) {
|
|
652
|
+
try {
|
|
653
|
+
result = import_fs_extra.default.readJSONSync(`${thisDir}/../${urlOrPath}`);
|
|
654
|
+
} catch (e) {
|
|
655
|
+
console.log(`Cannot parse json file from ${thisDir}/../${urlOrPath}. Error: ${e.message}`);
|
|
656
|
+
return null;
|
|
663
657
|
}
|
|
658
|
+
return result;
|
|
664
659
|
}
|
|
660
|
+
if (import_fs_extra.default.existsSync(`${thisDir}/../tmp/${urlOrPath}`)) {
|
|
661
|
+
try {
|
|
662
|
+
result = import_fs_extra.default.readJSONSync(`${thisDir}/../tmp/${urlOrPath}`);
|
|
663
|
+
} catch (e) {
|
|
664
|
+
console.log(`Cannot parse json file from ${thisDir}/../tmp/${urlOrPath}. Error: ${e.message}`);
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
return result;
|
|
668
|
+
}
|
|
669
|
+
return null;
|
|
665
670
|
}
|
|
671
|
+
__name(getJson, "getJson");
|
|
666
672
|
async function getJsonAsync(urlOrPath, agent) {
|
|
667
|
-
agent
|
|
673
|
+
agent ||= "";
|
|
668
674
|
let sources = {};
|
|
669
675
|
if (urlOrPath && typeof urlOrPath === "object") {
|
|
670
676
|
return urlOrPath;
|
|
671
|
-
}
|
|
677
|
+
}
|
|
678
|
+
if (!urlOrPath) {
|
|
672
679
|
console.log("Empty url!");
|
|
673
680
|
return null;
|
|
674
681
|
}
|
|
@@ -677,7 +684,7 @@ async function getJsonAsync(urlOrPath, agent) {
|
|
|
677
684
|
const result = await (0, import_axios.default)(urlOrPath, {
|
|
678
685
|
timeout: 1e4,
|
|
679
686
|
headers: { "User-Agent": agent },
|
|
680
|
-
validateStatus: (status) => status !== 200
|
|
687
|
+
validateStatus: /* @__PURE__ */ __name((status) => status !== 200, "validateStatus")
|
|
681
688
|
});
|
|
682
689
|
return result.data;
|
|
683
690
|
} catch (e) {
|
|
@@ -713,6 +720,7 @@ async function getJsonAsync(urlOrPath, agent) {
|
|
|
713
720
|
return null;
|
|
714
721
|
}
|
|
715
722
|
}
|
|
723
|
+
__name(getJsonAsync, "getJsonAsync");
|
|
716
724
|
function scanDirectory(dirName, list, regExp) {
|
|
717
725
|
if (import_fs_extra.default.existsSync(dirName)) {
|
|
718
726
|
let dirs;
|
|
@@ -754,6 +762,7 @@ function scanDirectory(dirName, list, regExp) {
|
|
|
754
762
|
}
|
|
755
763
|
}
|
|
756
764
|
}
|
|
765
|
+
__name(scanDirectory, "scanDirectory");
|
|
757
766
|
function getInstalledInfo(hostRunningVersion) {
|
|
758
767
|
const result = {};
|
|
759
768
|
const fullPath = getControllerDir();
|
|
@@ -791,305 +800,169 @@ function getInstalledInfo(hostRunningVersion) {
|
|
|
791
800
|
scanDirectory(import_node_path.default.join(fullPath, ".."), result, regExp);
|
|
792
801
|
return result;
|
|
793
802
|
}
|
|
794
|
-
|
|
803
|
+
__name(getInstalledInfo, "getInstalledInfo");
|
|
804
|
+
async function getNpmVersion(adapter) {
|
|
795
805
|
adapter = adapter ? `${appName}.${adapter}` : appName;
|
|
796
806
|
adapter = adapter.toLowerCase();
|
|
797
807
|
const cliCommand = `npm view ${adapter}@latest version`;
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
} else if (stdout) {
|
|
806
|
-
version = import_semver.default.valid(stdout.trim());
|
|
807
|
-
}
|
|
808
|
-
if (typeof callback === "function") {
|
|
809
|
-
callback(null, version);
|
|
810
|
-
}
|
|
811
|
-
});
|
|
808
|
+
const result = await execAsync(cliCommand, { timeout: 2e3, windowsHide: true });
|
|
809
|
+
let version;
|
|
810
|
+
if (result?.stdout) {
|
|
811
|
+
version = import_semver.default.valid(result.stdout.trim());
|
|
812
|
+
}
|
|
813
|
+
return version || "";
|
|
812
814
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
815
|
+
__name(getNpmVersion, "getNpmVersion");
|
|
816
|
+
async function getIoPack(sources, name, failCounter) {
|
|
817
|
+
let packSource = sources[name];
|
|
818
|
+
try {
|
|
819
|
+
const ioPack = await getJson(packSource.meta);
|
|
820
|
+
const packUrl = packSource.meta.replace("io-package.json", "package.json");
|
|
816
821
|
if (!ioPack) {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
if (callback) {
|
|
821
|
-
callback(sources, name);
|
|
822
|
-
}
|
|
823
|
-
} else {
|
|
824
|
-
setImmediate(() => {
|
|
825
|
-
getJson(packUrl, "", (pack) => {
|
|
826
|
-
const version = sources[name].version;
|
|
827
|
-
const type = sources[name].type;
|
|
828
|
-
if (sources[name].url && name !== "js-controller") {
|
|
829
|
-
if (ioPack && ioPack.common) {
|
|
830
|
-
sources[name] = (0, import_node.default)(true, sources[name], ioPack.common);
|
|
831
|
-
if (type) {
|
|
832
|
-
sources[name].type = type;
|
|
833
|
-
}
|
|
834
|
-
if (pack && pack.licenses && pack.licenses.length) {
|
|
835
|
-
if (!sources[name].license) {
|
|
836
|
-
sources[name].license = pack.licenses[0].type;
|
|
837
|
-
}
|
|
838
|
-
if (!sources[name].licenseUrl) {
|
|
839
|
-
sources[name].licenseUrl = pack.licenses[0].url;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
if (callback) {
|
|
844
|
-
callback(sources, name);
|
|
845
|
-
}
|
|
846
|
-
} else {
|
|
847
|
-
if (ioPack && ioPack.common) {
|
|
848
|
-
sources[name] = (0, import_node.default)(true, sources[name], ioPack.common);
|
|
849
|
-
if (pack && pack.licenses && pack.licenses.length) {
|
|
850
|
-
if (!sources[name].license) {
|
|
851
|
-
sources[name].license = pack.licenses[0].type;
|
|
852
|
-
}
|
|
853
|
-
if (!sources[name].licenseUrl) {
|
|
854
|
-
sources[name].licenseUrl = pack.licenses[0].url;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
if (type) {
|
|
859
|
-
sources[name].type = type;
|
|
860
|
-
}
|
|
861
|
-
if (version) {
|
|
862
|
-
sources[name].version = version;
|
|
863
|
-
if (callback) {
|
|
864
|
-
callback(sources, name);
|
|
865
|
-
}
|
|
866
|
-
} else {
|
|
867
|
-
if (sources[name].meta.substring(0, "http://".length) === "http://" || sources[name].meta.substring(0, "https://".length) === "https://") {
|
|
868
|
-
getNpmVersion(name, (_err, version2) => {
|
|
869
|
-
if (version2) {
|
|
870
|
-
sources[name].version = version2;
|
|
871
|
-
} else {
|
|
872
|
-
sources[name].version = "npm error";
|
|
873
|
-
}
|
|
874
|
-
if (callback) {
|
|
875
|
-
callback(sources, name);
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
} else {
|
|
879
|
-
if (callback) {
|
|
880
|
-
callback(sources, name);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
});
|
|
822
|
+
failCounter.push(name);
|
|
823
|
+
return;
|
|
887
824
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
count++;
|
|
898
|
-
}
|
|
899
|
-
sources._helper = { failCounter: [] };
|
|
900
|
-
sources._helper.timeout = setTimeout(() => {
|
|
901
|
-
if (sources._helper) {
|
|
902
|
-
delete sources._helper;
|
|
903
|
-
for (const __name of Object.keys(sources)) {
|
|
904
|
-
if (sources[__name].processed !== void 0) {
|
|
905
|
-
delete sources[__name].processed;
|
|
906
|
-
}
|
|
825
|
+
const pack = await getJson(packUrl);
|
|
826
|
+
const version = packSource.version;
|
|
827
|
+
const type = packSource.type;
|
|
828
|
+
if (packSource.url && name !== "js-controller") {
|
|
829
|
+
if (ioPack?.common) {
|
|
830
|
+
sources[name] = (0, import_node.default)(true, packSource, ioPack.common);
|
|
831
|
+
packSource = sources[name];
|
|
832
|
+
if (type) {
|
|
833
|
+
packSource.type = type;
|
|
907
834
|
}
|
|
908
|
-
if (
|
|
909
|
-
|
|
835
|
+
if (pack?.licenses?.length) {
|
|
836
|
+
packSource.license ||= pack.licenses[0].type;
|
|
837
|
+
packSource.licenseUrl ||= pack.licenses[0].url;
|
|
910
838
|
}
|
|
911
|
-
callback = void 0;
|
|
912
839
|
}
|
|
913
|
-
}, count * 1e3);
|
|
914
|
-
}
|
|
915
|
-
for (const name of Object.keys(sources)) {
|
|
916
|
-
if (sources[name].processed || name === "_helper") {
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
sources[name].processed = true;
|
|
920
|
-
if (sources[name].url) {
|
|
921
|
-
sources[name].url = findPath(path2, sources[name].url);
|
|
922
|
-
}
|
|
923
|
-
if (sources[name].meta) {
|
|
924
|
-
sources[name].meta = findPath(path2, sources[name].meta);
|
|
925
|
-
}
|
|
926
|
-
if (sources[name].icon) {
|
|
927
|
-
sources[name].icon = findPath(path2, sources[name].icon);
|
|
928
|
-
}
|
|
929
|
-
if (!sources[name].name && sources[name].meta) {
|
|
930
|
-
getIoPack(sources, name, (_ignore) => {
|
|
931
|
-
if (sources._helper) {
|
|
932
|
-
if (sources._helper.failCounter.length > 10) {
|
|
933
|
-
clearTimeout(sources._helper.timeout);
|
|
934
|
-
delete sources._helper;
|
|
935
|
-
for (const _name of Object.keys(sources)) {
|
|
936
|
-
if (sources[_name].processed !== void 0) {
|
|
937
|
-
delete sources[_name].processed;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (callback) {
|
|
941
|
-
callback(new Error("Looks like there is no internet."), sources);
|
|
942
|
-
}
|
|
943
|
-
callback = void 0;
|
|
944
|
-
} else {
|
|
945
|
-
setImmediate(() => _getRepositoryFile(sources, path2, callback));
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
});
|
|
949
840
|
return;
|
|
950
841
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
clearTimeout(sources._helper.timeout);
|
|
958
|
-
delete sources._helper;
|
|
959
|
-
for (const __name of Object.keys(sources)) {
|
|
960
|
-
if (sources[__name].processed !== void 0) {
|
|
961
|
-
delete sources[__name].processed;
|
|
842
|
+
if (ioPack?.common) {
|
|
843
|
+
sources[name] = (0, import_node.default)(true, packSource, ioPack.common);
|
|
844
|
+
packSource = sources[name];
|
|
845
|
+
if (pack?.licenses?.length) {
|
|
846
|
+
packSource.license ||= pack.licenses[0].type;
|
|
847
|
+
packSource.licenseUrl ||= pack.licenses[0].url;
|
|
962
848
|
}
|
|
963
849
|
}
|
|
964
|
-
if (
|
|
965
|
-
|
|
850
|
+
if (type) {
|
|
851
|
+
packSource.type = type;
|
|
966
852
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
async function _checkRepositoryFileHash(urlOrPath, additionalInfo, callback) {
|
|
971
|
-
if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
|
|
972
|
-
urlOrPath = urlOrPath.replace(/\.json$/, "-hash.json");
|
|
973
|
-
let json = null;
|
|
974
|
-
try {
|
|
975
|
-
const res = await import_axios.default.get(urlOrPath, { headers: { "Accept-Encoding": "gzip", timeout: 1e4 } });
|
|
976
|
-
if (!res.data || res.status !== 200) {
|
|
977
|
-
throw new Error(`Invalid response, body: ${res.data}, status code: ${res.status}`);
|
|
978
|
-
}
|
|
979
|
-
json = res.data;
|
|
980
|
-
} catch (e) {
|
|
981
|
-
console.warn(`Cannot download json from ${urlOrPath}. Error: ${e.message}`);
|
|
853
|
+
if (version) {
|
|
854
|
+
packSource.version = version;
|
|
855
|
+
return;
|
|
982
856
|
}
|
|
983
|
-
if (
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
857
|
+
if (packSource.meta.substring(0, "http://".length) === "http://" || packSource.meta.substring(0, "https://".length) === "https://") {
|
|
858
|
+
try {
|
|
859
|
+
const version2 = await getNpmVersion(name);
|
|
860
|
+
if (version2) {
|
|
861
|
+
packSource.version = version2;
|
|
862
|
+
} else {
|
|
863
|
+
packSource.version = "npm error";
|
|
864
|
+
}
|
|
865
|
+
} catch {
|
|
866
|
+
packSource.version = "npm error";
|
|
990
867
|
}
|
|
991
|
-
} else {
|
|
992
|
-
console.log("failed to download new sources, use cached sources");
|
|
993
|
-
callback(null, additionalInfo.sources, "");
|
|
994
868
|
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
} else if (!urlOrPath) {
|
|
1016
|
-
try {
|
|
1017
|
-
const controllerDir = getControllerDir();
|
|
1018
|
-
if (controllerDir) {
|
|
1019
|
-
sources = import_fs_extra.default.readJSONSync(import_node_path.default.join(controllerDir, getDefaultDataDir(), "sources.json"));
|
|
869
|
+
} catch (e) {
|
|
870
|
+
console.error(`Cannot prepare repository entry for ${name}: ${e.message}`);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
__name(getIoPack, "getIoPack");
|
|
874
|
+
async function _getRepositoryFile(sources, path2 = "") {
|
|
875
|
+
const names = Object.keys(sources).filter((name) => name !== "_helper");
|
|
876
|
+
const failCounter = [];
|
|
877
|
+
let aborted = false;
|
|
878
|
+
let timeout;
|
|
879
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
880
|
+
timeout = setTimeout(() => {
|
|
881
|
+
aborted = true;
|
|
882
|
+
resolve(new Error(`Timeout by read all package.json (${names.length}) seconds`));
|
|
883
|
+
}, names.length * 1e4);
|
|
884
|
+
});
|
|
885
|
+
const processPromise = (async () => {
|
|
886
|
+
for (const name of names) {
|
|
887
|
+
if (aborted) {
|
|
888
|
+
return null;
|
|
1020
889
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
try {
|
|
1025
|
-
const controllerDir = getControllerDir();
|
|
1026
|
-
if (controllerDir) {
|
|
1027
|
-
const sourcesDist = import_fs_extra.default.readJSONSync(import_node_path.default.join(controllerDir, "conf", "sources-dist.json"));
|
|
1028
|
-
sources = (0, import_node.default)(true, sourcesDist, sources);
|
|
890
|
+
const source = sources[name];
|
|
891
|
+
if (source.url) {
|
|
892
|
+
source.url = findPath(path2, source.url);
|
|
1029
893
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
for (const s of Object.keys(sources)) {
|
|
1033
|
-
if (additionalInfo[s] && additionalInfo[s].published) {
|
|
1034
|
-
sources[s].published = additionalInfo[s].published;
|
|
894
|
+
if (source.meta) {
|
|
895
|
+
source.meta = findPath(path2, source.meta);
|
|
1035
896
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
if (err) {
|
|
1039
|
-
console.error(`[${(/* @__PURE__ */ new Date()).toString()}] ${err.message}`);
|
|
897
|
+
if (source.icon) {
|
|
898
|
+
source.icon = findPath(path2, source.icon);
|
|
1040
899
|
}
|
|
1041
|
-
if (
|
|
1042
|
-
|
|
900
|
+
if (!source.name && source.meta) {
|
|
901
|
+
await getIoPack(sources, name, failCounter);
|
|
902
|
+
if (failCounter.length > 10) {
|
|
903
|
+
return new Error("Looks like there is no internet.");
|
|
904
|
+
}
|
|
1043
905
|
}
|
|
1044
|
-
});
|
|
1045
|
-
} else {
|
|
1046
|
-
let agent = "";
|
|
1047
|
-
if (additionalInfo) {
|
|
1048
|
-
agent = `${additionalInfo.name}, RND: ${additionalInfo.randomID || randomID}, Node:${additionalInfo.node}, V:${additionalInfo.controller}`;
|
|
1049
906
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
for (const s of Object.keys(sources3)) {
|
|
1057
|
-
if (additionalInfo[s] && additionalInfo[s].published) {
|
|
1058
|
-
sources3[s].published = additionalInfo[s].published;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
setImmediate(() => _getRepositoryFile(sources3, _path, (err2) => {
|
|
1062
|
-
err2 && console.error(`[${(/* @__PURE__ */ new Date()).toString()}] ${err2.message}`);
|
|
1063
|
-
typeof callback === "function" && callback(err2, sources3, actualSourcesHash);
|
|
1064
|
-
}));
|
|
1065
|
-
} else {
|
|
1066
|
-
console.log(`failed to download new sources, ${additionalInfo.sources ? "use cached sources" : "no cached sources available"}`);
|
|
1067
|
-
return (0, import_maybeCallback.maybeCallbackWithError)(callback, `Cannot read "${urlOrPath}"`, additionalInfo.sources, "");
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
});
|
|
907
|
+
return failCounter.length ? new Error(`Following packages cannot be read: ${failCounter.join(", ")}`) : null;
|
|
908
|
+
})();
|
|
909
|
+
try {
|
|
910
|
+
return await Promise.race([processPromise, timeoutPromise]);
|
|
911
|
+
} finally {
|
|
912
|
+
clearTimeout(timeout);
|
|
1072
913
|
}
|
|
1073
914
|
}
|
|
915
|
+
__name(_getRepositoryFile, "_getRepositoryFile");
|
|
916
|
+
async function getRepositoryFile() {
|
|
917
|
+
let sources = {};
|
|
918
|
+
let controllerDir;
|
|
919
|
+
try {
|
|
920
|
+
controllerDir = getControllerDir();
|
|
921
|
+
if (controllerDir) {
|
|
922
|
+
sources = import_fs_extra.default.readJSONSync(import_node_path.default.join(controllerDir, getDefaultDataDir(), "sources.json"));
|
|
923
|
+
}
|
|
924
|
+
} catch {
|
|
925
|
+
sources = {};
|
|
926
|
+
}
|
|
927
|
+
try {
|
|
928
|
+
if (controllerDir) {
|
|
929
|
+
const sourcesDist = import_fs_extra.default.readJSONSync(import_node_path.default.join(controllerDir, "conf", "sources-dist.json"));
|
|
930
|
+
sources = (0, import_node.default)(true, sourcesDist, sources);
|
|
931
|
+
}
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
const error = await _getRepositoryFile(sources);
|
|
935
|
+
if (error) {
|
|
936
|
+
console.error(`[${(/* @__PURE__ */ new Date()).toString()}] ${error.message}`);
|
|
937
|
+
}
|
|
938
|
+
if (!error || Object.keys(sources).length > 0) {
|
|
939
|
+
return sources;
|
|
940
|
+
}
|
|
941
|
+
throw error;
|
|
942
|
+
}
|
|
943
|
+
__name(getRepositoryFile, "getRepositoryFile");
|
|
1074
944
|
async function getRepositoryFileAsync(url2, hash, force, _actualRepo) {
|
|
1075
|
-
let
|
|
1076
|
-
let data;
|
|
945
|
+
let hashResponse;
|
|
946
|
+
let data = null;
|
|
1077
947
|
if (url2.startsWith("http://") || url2.startsWith("https://")) {
|
|
1078
948
|
try {
|
|
1079
|
-
|
|
949
|
+
hashResponse = await (0, import_axios.default)({
|
|
950
|
+
url: url2.replace(/\.json$/, `-${HASH_TEXT}.json`),
|
|
951
|
+
timeout: 1e4
|
|
952
|
+
});
|
|
1080
953
|
} catch {
|
|
1081
954
|
}
|
|
1082
|
-
if (_actualRepo && !force && hash &&
|
|
955
|
+
if (_actualRepo && !force && hash && hashResponse?.data?.hash === hash) {
|
|
1083
956
|
data = _actualRepo;
|
|
1084
957
|
} else {
|
|
1085
958
|
const agent = `${appName}, RND: ${randomID}, Node:${process.version}, V:${require2("@iobroker/js-controller-common/package.json").version}`;
|
|
1086
959
|
try {
|
|
1087
|
-
|
|
960
|
+
const response = await (0, import_axios.default)({
|
|
1088
961
|
url: url2,
|
|
1089
962
|
timeout: 1e4,
|
|
1090
963
|
headers: { "User-Agent": agent }
|
|
1091
964
|
});
|
|
1092
|
-
data =
|
|
965
|
+
data = response.data;
|
|
1093
966
|
} catch (e) {
|
|
1094
967
|
throw new Error(`Cannot download repository file from "${url2}": ${e.message}`);
|
|
1095
968
|
}
|
|
@@ -1107,10 +980,11 @@ async function getRepositoryFileAsync(url2, hash, force, _actualRepo) {
|
|
|
1107
980
|
}
|
|
1108
981
|
return {
|
|
1109
982
|
json: data,
|
|
1110
|
-
changed:
|
|
1111
|
-
hash:
|
|
983
|
+
changed: hashResponse?.data ? hash !== hashResponse.data.hash : true,
|
|
984
|
+
hash: hashResponse?.data ? hashResponse.data.hash : ""
|
|
1112
985
|
};
|
|
1113
986
|
}
|
|
987
|
+
__name(getRepositoryFileAsync, "getRepositoryFileAsync");
|
|
1114
988
|
async function sendDiagInfo(obj) {
|
|
1115
989
|
const objStr = JSON.stringify(obj);
|
|
1116
990
|
console.log(`Send diag info: ${objStr}`);
|
|
@@ -1126,6 +1000,7 @@ async function sendDiagInfo(obj) {
|
|
|
1126
1000
|
console.log(`Cannot send diag info: ${e.message}`);
|
|
1127
1001
|
}
|
|
1128
1002
|
}
|
|
1003
|
+
__name(sendDiagInfo, "sendDiagInfo");
|
|
1129
1004
|
function getAdapterDir(adapter) {
|
|
1130
1005
|
if (adapter.toLowerCase().startsWith(`${appNameLowerCase}.`)) {
|
|
1131
1006
|
adapter = adapter.substring(appName.length + 1);
|
|
@@ -1157,6 +1032,7 @@ function getAdapterDir(adapter) {
|
|
|
1157
1032
|
parts.pop();
|
|
1158
1033
|
return parts.join("/");
|
|
1159
1034
|
}
|
|
1035
|
+
__name(getAdapterDir, "getAdapterDir");
|
|
1160
1036
|
function getHostName() {
|
|
1161
1037
|
if (process.env.IOB_HOSTNAME) {
|
|
1162
1038
|
return process.env.IOB_HOSTNAME;
|
|
@@ -1169,42 +1045,21 @@ function getHostName() {
|
|
|
1169
1045
|
return import_node_os.default.hostname();
|
|
1170
1046
|
}
|
|
1171
1047
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1048
|
+
__name(getHostName, "getHostName");
|
|
1049
|
+
async function getSystemNpmVersion() {
|
|
1174
1050
|
const newEnv = Object.assign({}, process.env);
|
|
1175
|
-
newEnv.PATH = (newEnv.PATH || newEnv.Path || newEnv.path).split(import_node_path.default.delimiter).filter((dir) => {
|
|
1051
|
+
newEnv.PATH = (newEnv.PATH || newEnv.Path || newEnv.path || "").split(import_node_path.default.delimiter).filter((dir) => {
|
|
1176
1052
|
dir = dir.toLowerCase();
|
|
1177
1053
|
return !dir.includes("iobroker") || !dir.includes(import_node_path.default.join("node_modules", ".bin"));
|
|
1178
1054
|
}).join(import_node_path.default.delimiter);
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
callback(new Error("timeout"));
|
|
1184
|
-
callback = void 0;
|
|
1185
|
-
}
|
|
1186
|
-
}, 1e4);
|
|
1187
|
-
exec2("npm -v", { encoding: "utf8", env: newEnv, windowsHide: true }, (error, stdout) => {
|
|
1188
|
-
if (timeout) {
|
|
1189
|
-
clearTimeout(timeout);
|
|
1190
|
-
timeout = null;
|
|
1191
|
-
}
|
|
1192
|
-
if (stdout) {
|
|
1193
|
-
stdout = import_semver.default.valid(stdout.trim());
|
|
1194
|
-
}
|
|
1195
|
-
if (callback) {
|
|
1196
|
-
callback(error, stdout);
|
|
1197
|
-
callback = void 0;
|
|
1198
|
-
}
|
|
1199
|
-
});
|
|
1200
|
-
} catch (e) {
|
|
1201
|
-
if (callback) {
|
|
1202
|
-
callback(e);
|
|
1203
|
-
callback = void 0;
|
|
1204
|
-
}
|
|
1055
|
+
const result = await execAsync("npm -v", { env: newEnv, timeout: 1e4 });
|
|
1056
|
+
let version;
|
|
1057
|
+
if (result.stdout) {
|
|
1058
|
+
version = import_semver.default.valid(result.stdout.trim());
|
|
1205
1059
|
}
|
|
1060
|
+
return version || null;
|
|
1206
1061
|
}
|
|
1207
|
-
|
|
1062
|
+
__name(getSystemNpmVersion, "getSystemNpmVersion");
|
|
1208
1063
|
async function detectPackageManagerWithFallback(cwd) {
|
|
1209
1064
|
try {
|
|
1210
1065
|
return await (0, import_pak.detectPackageManager)(typeof cwd === "string" ? (
|
|
@@ -1224,6 +1079,7 @@ async function detectPackageManagerWithFallback(cwd) {
|
|
|
1224
1079
|
pak.cwd = cwd || ioBrokerRootDir;
|
|
1225
1080
|
return pak;
|
|
1226
1081
|
}
|
|
1082
|
+
__name(detectPackageManagerWithFallback, "detectPackageManagerWithFallback");
|
|
1227
1083
|
async function installNodeModule(npmUrl, options = {}) {
|
|
1228
1084
|
const pak = await detectPackageManagerWithFallback(options.cwd);
|
|
1229
1085
|
if (!options.debug) {
|
|
@@ -1247,6 +1103,7 @@ async function installNodeModule(npmUrl, options = {}) {
|
|
|
1247
1103
|
}
|
|
1248
1104
|
return pak.install([npmUrl], installOpts);
|
|
1249
1105
|
}
|
|
1106
|
+
__name(installNodeModule, "installNodeModule");
|
|
1250
1107
|
async function uninstallNodeModule(packageName, options = {}) {
|
|
1251
1108
|
const pak = await detectPackageManagerWithFallback(options.cwd);
|
|
1252
1109
|
if (!options.debug) {
|
|
@@ -1263,6 +1120,7 @@ async function uninstallNodeModule(packageName, options = {}) {
|
|
|
1263
1120
|
}
|
|
1264
1121
|
return pak.uninstall([packageName]);
|
|
1265
1122
|
}
|
|
1123
|
+
__name(uninstallNodeModule, "uninstallNodeModule");
|
|
1266
1124
|
async function rebuildNodeModules(options = {}) {
|
|
1267
1125
|
const pak = await detectPackageManagerWithFallback(options.cwd);
|
|
1268
1126
|
if (!options.debug) {
|
|
@@ -1279,6 +1137,7 @@ async function rebuildNodeModules(options = {}) {
|
|
|
1279
1137
|
}
|
|
1280
1138
|
return pak.rebuild(options.module ? [options.module] : void 0);
|
|
1281
1139
|
}
|
|
1140
|
+
__name(rebuildNodeModules, "rebuildNodeModules");
|
|
1282
1141
|
async function getDiskInfo() {
|
|
1283
1142
|
const platform = process.platform;
|
|
1284
1143
|
if (diskusage) {
|
|
@@ -1323,6 +1182,7 @@ async function getDiskInfo() {
|
|
|
1323
1182
|
}
|
|
1324
1183
|
return null;
|
|
1325
1184
|
}
|
|
1185
|
+
__name(getDiskInfo, "getDiskInfo");
|
|
1326
1186
|
function getCertificateInfo(cert) {
|
|
1327
1187
|
let info = null;
|
|
1328
1188
|
if (!cert) {
|
|
@@ -1357,6 +1217,7 @@ function getCertificateInfo(cert) {
|
|
|
1357
1217
|
return null;
|
|
1358
1218
|
}
|
|
1359
1219
|
}
|
|
1220
|
+
__name(getCertificateInfo, "getCertificateInfo");
|
|
1360
1221
|
const MAX_CERT_VALIDITY = 365 * 24 * 60 * 60 * 1e3;
|
|
1361
1222
|
function generateDefaultCertificates() {
|
|
1362
1223
|
const pki = import_node_forge.default.pki;
|
|
@@ -1429,6 +1290,7 @@ function generateDefaultCertificates() {
|
|
|
1429
1290
|
defaultPublic: pem_cert
|
|
1430
1291
|
};
|
|
1431
1292
|
}
|
|
1293
|
+
__name(generateDefaultCertificates, "generateDefaultCertificates");
|
|
1432
1294
|
function makeid(length) {
|
|
1433
1295
|
let result = "";
|
|
1434
1296
|
const characters = "abcdef0123456789";
|
|
@@ -1438,6 +1300,7 @@ function makeid(length) {
|
|
|
1438
1300
|
}
|
|
1439
1301
|
return result;
|
|
1440
1302
|
}
|
|
1303
|
+
__name(makeid, "makeid");
|
|
1441
1304
|
async function getHostInfo(objects) {
|
|
1442
1305
|
if (!diskusage) {
|
|
1443
1306
|
try {
|
|
@@ -1450,11 +1313,11 @@ async function getHostInfo(objects) {
|
|
|
1450
1313
|
const allRepos = {};
|
|
1451
1314
|
if (systemRepos?.native?.repositories && systemConfig) {
|
|
1452
1315
|
const repos = Array.isArray(systemConfig.common.activeRepo) ? systemConfig.common.activeRepo : [systemConfig.common.activeRepo];
|
|
1453
|
-
repos.filter((repo) => systemRepos.native.repositories[repo]
|
|
1316
|
+
repos.filter((repo) => systemRepos.native.repositories[repo]?.json).forEach((repo) => Object.assign(allRepos, systemRepos.native.repositories[repo].json));
|
|
1454
1317
|
}
|
|
1455
1318
|
if (!npmVersion) {
|
|
1456
1319
|
try {
|
|
1457
|
-
npmVersion = await
|
|
1320
|
+
npmVersion = await getSystemNpmVersion() || "";
|
|
1458
1321
|
} catch (e) {
|
|
1459
1322
|
console.error(`Cannot get NPM version: ${e.message}`);
|
|
1460
1323
|
}
|
|
@@ -1474,7 +1337,7 @@ async function getHostInfo(objects) {
|
|
|
1474
1337
|
time: dateObj.getTime(),
|
|
1475
1338
|
timeOffset: dateObj.getTimezoneOffset(),
|
|
1476
1339
|
NPM: npmVersion,
|
|
1477
|
-
"adapters count": Object.keys(allRepos).length
|
|
1340
|
+
"adapters count": Object.keys(allRepos).filter((id) => id !== "_repoInfo").length
|
|
1478
1341
|
};
|
|
1479
1342
|
if (data.Platform === "win32") {
|
|
1480
1343
|
data.Platform = "Windows";
|
|
@@ -1494,6 +1357,7 @@ async function getHostInfo(objects) {
|
|
|
1494
1357
|
}
|
|
1495
1358
|
return data;
|
|
1496
1359
|
}
|
|
1360
|
+
__name(getHostInfo, "getHostInfo");
|
|
1497
1361
|
function getControllerDir() {
|
|
1498
1362
|
const possibilities = ["iobroker.js-controller", "ioBroker.js-controller"];
|
|
1499
1363
|
for (const pkg of possibilities) {
|
|
@@ -1525,12 +1389,15 @@ function getControllerDir() {
|
|
|
1525
1389
|
}
|
|
1526
1390
|
throw new Error("Could not determine controller directory");
|
|
1527
1391
|
}
|
|
1392
|
+
__name(getControllerDir, "getControllerDir");
|
|
1528
1393
|
function getRootDir() {
|
|
1529
1394
|
return import_node_path.default.join(getControllerDir(), "..", "..");
|
|
1530
1395
|
}
|
|
1396
|
+
__name(getRootDir, "getRootDir");
|
|
1531
1397
|
function isDevServerInstallation() {
|
|
1532
1398
|
return !!require2.main?.path.includes(`${import_node_path.default.sep}.dev-server${import_node_path.default.sep}`);
|
|
1533
1399
|
}
|
|
1400
|
+
__name(isDevServerInstallation, "isDevServerInstallation");
|
|
1534
1401
|
function getDefaultDataDir() {
|
|
1535
1402
|
let envDataDir = process.env[`${appName.toUpperCase()}_DATA_DIR`];
|
|
1536
1403
|
if (envDataDir) {
|
|
@@ -1544,6 +1411,7 @@ function getDefaultDataDir() {
|
|
|
1544
1411
|
}
|
|
1545
1412
|
return import_node_path.default.join("..", "..", `${appNameLowerCase}-data/`);
|
|
1546
1413
|
}
|
|
1414
|
+
__name(getDefaultDataDir, "getDefaultDataDir");
|
|
1547
1415
|
function getConfigFileName() {
|
|
1548
1416
|
let envDataDir = process.env[`${appName.toUpperCase()}_DATA_DIR`];
|
|
1549
1417
|
if (envDataDir) {
|
|
@@ -1569,6 +1437,7 @@ function getConfigFileName() {
|
|
|
1569
1437
|
}
|
|
1570
1438
|
return prodConfigFile;
|
|
1571
1439
|
}
|
|
1440
|
+
__name(getConfigFileName, "getConfigFileName");
|
|
1572
1441
|
function sliceArgs(argsObj, startIndex = 0) {
|
|
1573
1442
|
if (startIndex === null || startIndex === void 0) {
|
|
1574
1443
|
startIndex = 0;
|
|
@@ -1579,6 +1448,7 @@ function sliceArgs(argsObj, startIndex = 0) {
|
|
|
1579
1448
|
}
|
|
1580
1449
|
return ret;
|
|
1581
1450
|
}
|
|
1451
|
+
__name(sliceArgs, "sliceArgs");
|
|
1582
1452
|
function promisify(fn, context, returnArgNames) {
|
|
1583
1453
|
return function() {
|
|
1584
1454
|
const args = sliceArgs(arguments);
|
|
@@ -1618,6 +1488,7 @@ function promisify(fn, context, returnArgNames) {
|
|
|
1618
1488
|
});
|
|
1619
1489
|
};
|
|
1620
1490
|
}
|
|
1491
|
+
__name(promisify, "promisify");
|
|
1621
1492
|
function promisifyNoError(fn, context, returnArgNames) {
|
|
1622
1493
|
return function() {
|
|
1623
1494
|
const args = sliceArgs(arguments);
|
|
@@ -1650,6 +1521,7 @@ function promisifyNoError(fn, context, returnArgNames) {
|
|
|
1650
1521
|
});
|
|
1651
1522
|
};
|
|
1652
1523
|
}
|
|
1524
|
+
__name(promisifyNoError, "promisifyNoError");
|
|
1653
1525
|
async function _setQualityForStates(states, keys, quality) {
|
|
1654
1526
|
for (const key of keys) {
|
|
1655
1527
|
try {
|
|
@@ -1658,6 +1530,7 @@ async function _setQualityForStates(states, keys, quality) {
|
|
|
1658
1530
|
}
|
|
1659
1531
|
}
|
|
1660
1532
|
}
|
|
1533
|
+
__name(_setQualityForStates, "_setQualityForStates");
|
|
1661
1534
|
function setQualityForInstance(objects, states, namespace, q) {
|
|
1662
1535
|
return new Promise((resolve, reject) => {
|
|
1663
1536
|
objects.getObjectView("system", "state", {
|
|
@@ -1687,6 +1560,7 @@ function setQualityForInstance(objects, states, namespace, q) {
|
|
|
1687
1560
|
});
|
|
1688
1561
|
});
|
|
1689
1562
|
}
|
|
1563
|
+
__name(setQualityForInstance, "setQualityForInstance");
|
|
1690
1564
|
function pattern2RegEx(pattern) {
|
|
1691
1565
|
pattern = (pattern || "").toString();
|
|
1692
1566
|
if (!isValidPattern(pattern)) {
|
|
@@ -1697,10 +1571,12 @@ function pattern2RegEx(pattern) {
|
|
|
1697
1571
|
pattern = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, ".*");
|
|
1698
1572
|
return (startsWithWildcard ? "" : "^") + pattern + (endsWithWildcard ? "" : "$");
|
|
1699
1573
|
}
|
|
1574
|
+
__name(pattern2RegEx, "pattern2RegEx");
|
|
1700
1575
|
function isValidPattern(pattern) {
|
|
1701
1576
|
pattern = pattern.replace(/\*/g, "");
|
|
1702
1577
|
return !FORBIDDEN_CHARS.test(pattern);
|
|
1703
1578
|
}
|
|
1579
|
+
__name(isValidPattern, "isValidPattern");
|
|
1704
1580
|
function captureStackTrace(wrapperName) {
|
|
1705
1581
|
if (typeof wrapperName !== "string") {
|
|
1706
1582
|
wrapperName = "captureStackTrace";
|
|
@@ -1721,6 +1597,7 @@ function captureStackTrace(wrapperName) {
|
|
|
1721
1597
|
}
|
|
1722
1598
|
return "";
|
|
1723
1599
|
}
|
|
1600
|
+
__name(captureStackTrace, "captureStackTrace");
|
|
1724
1601
|
function appendStackTrace(str) {
|
|
1725
1602
|
if (typeof str !== "string") {
|
|
1726
1603
|
str = String(str);
|
|
@@ -1730,6 +1607,7 @@ function appendStackTrace(str) {
|
|
|
1730
1607
|
}
|
|
1731
1608
|
return str + captureStackTrace("appendStackTrace");
|
|
1732
1609
|
}
|
|
1610
|
+
__name(appendStackTrace, "appendStackTrace");
|
|
1733
1611
|
function encryptLegacy(key, value) {
|
|
1734
1612
|
let result = "";
|
|
1735
1613
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -1737,6 +1615,7 @@ function encryptLegacy(key, value) {
|
|
|
1737
1615
|
}
|
|
1738
1616
|
return result;
|
|
1739
1617
|
}
|
|
1618
|
+
__name(encryptLegacy, "encryptLegacy");
|
|
1740
1619
|
function decryptLegacy(key, value) {
|
|
1741
1620
|
let result = "";
|
|
1742
1621
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -1744,6 +1623,7 @@ function decryptLegacy(key, value) {
|
|
|
1744
1623
|
}
|
|
1745
1624
|
return result;
|
|
1746
1625
|
}
|
|
1626
|
+
__name(decryptLegacy, "decryptLegacy");
|
|
1747
1627
|
function encrypt(key, value) {
|
|
1748
1628
|
if (!/^[0-9a-f]{48}$/.test(key)) {
|
|
1749
1629
|
return encryptLegacy(key, value);
|
|
@@ -1753,6 +1633,7 @@ function encrypt(key, value) {
|
|
|
1753
1633
|
const encrypted = Buffer.concat([cipher.update(value), cipher.final()]);
|
|
1754
1634
|
return `$/aes-192-cbc:${iv.toString("hex")}:${encrypted.toString("hex")}`;
|
|
1755
1635
|
}
|
|
1636
|
+
__name(encrypt, "encrypt");
|
|
1756
1637
|
function decrypt(key, value) {
|
|
1757
1638
|
if (!value.startsWith(`$/aes-192-cbc:`) || !/^[0-9a-f]{48}$/.test(key)) {
|
|
1758
1639
|
return decryptLegacy(key, value);
|
|
@@ -1764,12 +1645,15 @@ function decrypt(key, value) {
|
|
|
1764
1645
|
const decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
|
|
1765
1646
|
return decrypted.toString();
|
|
1766
1647
|
}
|
|
1648
|
+
__name(decrypt, "decrypt");
|
|
1767
1649
|
function isObject(it) {
|
|
1768
1650
|
return Object.prototype.toString.call(it) === "[object Object]";
|
|
1769
1651
|
}
|
|
1652
|
+
__name(isObject, "isObject");
|
|
1770
1653
|
function isArray(it) {
|
|
1771
1654
|
return Array.isArray(it);
|
|
1772
1655
|
}
|
|
1656
|
+
__name(isArray, "isArray");
|
|
1773
1657
|
function measureEventLoopLag(ms, cb) {
|
|
1774
1658
|
let start = hrtime();
|
|
1775
1659
|
let timeout = setTimeout(check, ms);
|
|
@@ -1777,16 +1661,19 @@ function measureEventLoopLag(ms, cb) {
|
|
|
1777
1661
|
function check() {
|
|
1778
1662
|
clearTimeout(timeout);
|
|
1779
1663
|
const t = hrtime();
|
|
1780
|
-
cb
|
|
1664
|
+
cb?.(Math.max(0, t - start - ms));
|
|
1781
1665
|
start = t;
|
|
1782
1666
|
timeout = setTimeout(check, ms);
|
|
1783
1667
|
timeout.unref();
|
|
1784
1668
|
}
|
|
1669
|
+
__name(check, "check");
|
|
1785
1670
|
function hrtime() {
|
|
1786
1671
|
const t = process.hrtime();
|
|
1787
1672
|
return t[0] * 1e3 + t[1] / 1e6;
|
|
1788
1673
|
}
|
|
1674
|
+
__name(hrtime, "hrtime");
|
|
1789
1675
|
}
|
|
1676
|
+
__name(measureEventLoopLag, "measureEventLoopLag");
|
|
1790
1677
|
function formatAliasValue(options) {
|
|
1791
1678
|
const { sourceCommon, sourceId, targetCommon, targetId, state, logger } = options;
|
|
1792
1679
|
const logNamespace = options.logNamespace ? `${options.logNamespace} ` : "";
|
|
@@ -1837,10 +1724,9 @@ function formatAliasValue(options) {
|
|
|
1837
1724
|
state.val = (0, import_aliasProcessing.applyAliasAutoScaling)({ state, sourceCommon, targetCommon });
|
|
1838
1725
|
return state;
|
|
1839
1726
|
}
|
|
1727
|
+
__name(formatAliasValue, "formatAliasValue");
|
|
1840
1728
|
async function removeIdFromAllEnums(objects, id, allEnums) {
|
|
1841
|
-
|
|
1842
|
-
allEnums = await getAllEnums(objects);
|
|
1843
|
-
}
|
|
1729
|
+
allEnums ||= await getAllEnums(objects);
|
|
1844
1730
|
let error = null;
|
|
1845
1731
|
for (const [enumId, enumObj] of Object.entries(allEnums)) {
|
|
1846
1732
|
const idx = enumObj.common.members ? enumObj.common.members.indexOf(id) : -1;
|
|
@@ -1850,9 +1736,7 @@ async function removeIdFromAllEnums(objects, id, allEnums) {
|
|
|
1850
1736
|
await objects.setObjectAsync(enumId, enumObj);
|
|
1851
1737
|
allEnums[enumId] = enumObj;
|
|
1852
1738
|
} catch (err) {
|
|
1853
|
-
|
|
1854
|
-
error = err;
|
|
1855
|
-
}
|
|
1739
|
+
error ||= err;
|
|
1856
1740
|
}
|
|
1857
1741
|
}
|
|
1858
1742
|
}
|
|
@@ -1860,6 +1744,7 @@ async function removeIdFromAllEnums(objects, id, allEnums) {
|
|
|
1860
1744
|
throw error;
|
|
1861
1745
|
}
|
|
1862
1746
|
}
|
|
1747
|
+
__name(removeIdFromAllEnums, "removeIdFromAllEnums");
|
|
1863
1748
|
function parseDependencies(dependencies) {
|
|
1864
1749
|
let adapters = {};
|
|
1865
1750
|
if (Array.isArray(dependencies)) {
|
|
@@ -1877,6 +1762,7 @@ function parseDependencies(dependencies) {
|
|
|
1877
1762
|
}
|
|
1878
1763
|
return adapters;
|
|
1879
1764
|
}
|
|
1765
|
+
__name(parseDependencies, "parseDependencies");
|
|
1880
1766
|
function validateGeneralObjectProperties(obj, extend2) {
|
|
1881
1767
|
if (!obj || obj.type === void 0 && !extend2) {
|
|
1882
1768
|
throw new Error(`obj.type has to exist`);
|
|
@@ -1944,8 +1830,9 @@ function validateGeneralObjectProperties(obj, extend2) {
|
|
|
1944
1830
|
throw new Error(`obj.common.min (${obj.common.min}) needs to be less than or equal to obj.common.max (${obj.common.max})`);
|
|
1945
1831
|
}
|
|
1946
1832
|
}
|
|
1947
|
-
if (obj.common.def
|
|
1948
|
-
if (!(obj.common.type === "mixed" && typeof obj.common.def !== "object" || obj.common.type !== "object" && obj.common.type === typeof obj.common.def || obj.common.type === "array" && typeof obj.common.def === "string" ||
|
|
1833
|
+
if (obj.common.def != null) {
|
|
1834
|
+
if (!(obj.common.type === "mixed" && typeof obj.common.def !== "object" || obj.common.type !== "object" && obj.common.type === typeof obj.common.def || obj.common.type === "array" && typeof obj.common.def === "string" || // @ts-expect-error deprecated
|
|
1835
|
+
obj.common.type === "json" && typeof obj.common.def === "string" || obj.common.type === "object" && typeof obj.common.def === "string")) {
|
|
1949
1836
|
if (["object", "json", "array"].includes(obj.common.type)) {
|
|
1950
1837
|
throw new Error(`Default value has to be stringified but received type "${typeof obj.common.def}"`);
|
|
1951
1838
|
} else {
|
|
@@ -1967,14 +1854,15 @@ function validateGeneralObjectProperties(obj, extend2) {
|
|
|
1967
1854
|
if (obj.common.desc !== void 0 && typeof obj.common.desc !== "string" && typeof obj.common.desc !== "object") {
|
|
1968
1855
|
throw new Error(`obj.common.desc has an invalid type! Expected "string" or "object", received "${typeof obj.common.desc}"`);
|
|
1969
1856
|
}
|
|
1970
|
-
if (obj.type === "state" && obj.common.custom
|
|
1857
|
+
if (obj.type === "state" && obj.common.custom != null && !isObject(obj.common.custom)) {
|
|
1971
1858
|
throw new Error(`obj.common.custom has an invalid type! Expected "object", received "${typeof obj.common.custom}"`);
|
|
1972
1859
|
}
|
|
1973
|
-
if (obj.common.states
|
|
1974
|
-
|
|
1860
|
+
if (obj.common.states != null && // we allow null for deletion TODO: implement https://github.com/ioBroker/ioBroker.js-controller/issues/1735
|
|
1861
|
+
!isObject(obj.common.states) && !Array.isArray(obj.common.states)) {
|
|
1975
1862
|
throw new Error(`obj.common.states has an invalid type! Expected "object", received "${typeof obj.common.states}"`);
|
|
1976
1863
|
}
|
|
1977
1864
|
}
|
|
1865
|
+
__name(validateGeneralObjectProperties, "validateGeneralObjectProperties");
|
|
1978
1866
|
async function getAllInstances(adapters, objects) {
|
|
1979
1867
|
const instances = [];
|
|
1980
1868
|
for (let i = 0; i < adapters.length; i++) {
|
|
@@ -1988,14 +1876,13 @@ async function getAllInstances(adapters, objects) {
|
|
|
1988
1876
|
instances.push(inst[j]);
|
|
1989
1877
|
}
|
|
1990
1878
|
}
|
|
1991
|
-
} else {
|
|
1992
|
-
|
|
1993
|
-
instances.push(adapters[i]);
|
|
1994
|
-
}
|
|
1879
|
+
} else if (!instances.includes(adapters[i])) {
|
|
1880
|
+
instances.push(adapters[i]);
|
|
1995
1881
|
}
|
|
1996
1882
|
}
|
|
1997
1883
|
return instances;
|
|
1998
1884
|
}
|
|
1885
|
+
__name(getAllInstances, "getAllInstances");
|
|
1999
1886
|
async function getAllEnums(objects) {
|
|
2000
1887
|
const allEnums = {};
|
|
2001
1888
|
const res = await objects.getObjectViewAsync("system", "enum", {
|
|
@@ -2009,6 +1896,7 @@ async function getAllEnums(objects) {
|
|
|
2009
1896
|
}
|
|
2010
1897
|
return allEnums;
|
|
2011
1898
|
}
|
|
1899
|
+
__name(getAllEnums, "getAllEnums");
|
|
2012
1900
|
async function getInstances(adapter, objects, withObjects) {
|
|
2013
1901
|
const arr = await objects.getObjectListAsync({
|
|
2014
1902
|
startkey: `system.adapter.${adapter}.`,
|
|
@@ -2029,6 +1917,7 @@ async function getInstances(adapter, objects, withObjects) {
|
|
|
2029
1917
|
}
|
|
2030
1918
|
return instances;
|
|
2031
1919
|
}
|
|
1920
|
+
__name(getInstances, "getInstances");
|
|
2032
1921
|
function execAsync(command, execOptions) {
|
|
2033
1922
|
const defaultOptions = {
|
|
2034
1923
|
// we do not want to show the node.js window on Windows
|
|
@@ -2036,8 +1925,45 @@ function execAsync(command, execOptions) {
|
|
|
2036
1925
|
// And we want to capture stdout/stderr
|
|
2037
1926
|
encoding: "utf8"
|
|
2038
1927
|
};
|
|
2039
|
-
return (
|
|
1928
|
+
return new Promise((resolve, reject) => {
|
|
1929
|
+
(0, import_node_child_process.exec)(command, { ...defaultOptions, ...execOptions }, (error, stdout, stderr) => {
|
|
1930
|
+
if (error) {
|
|
1931
|
+
reject(stderr ? new Error(stderr.toString()) : error);
|
|
1932
|
+
} else {
|
|
1933
|
+
resolve({
|
|
1934
|
+
stderr: stderr?.toString(),
|
|
1935
|
+
stdout: stdout?.toString()
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
__name(execAsync, "execAsync");
|
|
1942
|
+
function execFileAsync(file, args, execOptions) {
|
|
1943
|
+
const defaultOptions = {
|
|
1944
|
+
// we do not want to show the node.js window on Windows
|
|
1945
|
+
windowsHide: true,
|
|
1946
|
+
// And we want to capture stdout/stderr
|
|
1947
|
+
encoding: "utf8"
|
|
1948
|
+
};
|
|
1949
|
+
return new Promise((resolve, reject) => {
|
|
1950
|
+
(0, import_node_child_process.execFile)(file, [...args], { ...defaultOptions, ...execOptions }, (error, stdout, stderr) => {
|
|
1951
|
+
if (error) {
|
|
1952
|
+
const failure = error;
|
|
1953
|
+
if (stderr) {
|
|
1954
|
+
failure.message = stderr.toString();
|
|
1955
|
+
}
|
|
1956
|
+
reject(failure);
|
|
1957
|
+
} else {
|
|
1958
|
+
resolve({
|
|
1959
|
+
stderr: stderr?.toString(),
|
|
1960
|
+
stdout: stdout?.toString()
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
});
|
|
2040
1965
|
}
|
|
1966
|
+
__name(execFileAsync, "execFileAsync");
|
|
2041
1967
|
function pipeLinewise(input, output) {
|
|
2042
1968
|
const rl = (0, import_node_readline.createInterface)({
|
|
2043
1969
|
input,
|
|
@@ -2052,6 +1978,7 @@ function pipeLinewise(input, output) {
|
|
|
2052
1978
|
rl.on("error", () => {
|
|
2053
1979
|
});
|
|
2054
1980
|
}
|
|
1981
|
+
__name(pipeLinewise, "pipeLinewise");
|
|
2055
1982
|
async function isAdapterEsmModule(adapter) {
|
|
2056
1983
|
const adapterDir = getAdapterDir(adapter);
|
|
2057
1984
|
if (!adapterDir) {
|
|
@@ -2060,6 +1987,7 @@ async function isAdapterEsmModule(adapter) {
|
|
|
2060
1987
|
const packJson = await import_fs_extra.default.readJSON(import_node_path.default.join(adapterDir, "package.json"), { encoding: "utf-8" });
|
|
2061
1988
|
return packJson.type === "module";
|
|
2062
1989
|
}
|
|
1990
|
+
__name(isAdapterEsmModule, "isAdapterEsmModule");
|
|
2063
1991
|
async function resolveAdapterMainFile(adapter) {
|
|
2064
1992
|
const adapterDir = getAdapterDir(adapter);
|
|
2065
1993
|
if (!adapterDir) {
|
|
@@ -2088,6 +2016,7 @@ async function resolveAdapterMainFile(adapter) {
|
|
|
2088
2016
|
}
|
|
2089
2017
|
throw new Error(`Could not find main file of ${adapter}`);
|
|
2090
2018
|
}
|
|
2019
|
+
__name(resolveAdapterMainFile, "resolveAdapterMainFile");
|
|
2091
2020
|
function getDefaultNodeArgs(mainFile) {
|
|
2092
2021
|
const ret = [];
|
|
2093
2022
|
if (mainFile.endsWith(".ts")) {
|
|
@@ -2098,6 +2027,7 @@ function getDefaultNodeArgs(mainFile) {
|
|
|
2098
2027
|
}
|
|
2099
2028
|
return ret;
|
|
2100
2029
|
}
|
|
2030
|
+
__name(getDefaultNodeArgs, "getDefaultNodeArgs");
|
|
2101
2031
|
function getDefaultRequireResolvePaths(callerModule) {
|
|
2102
2032
|
const ret = [
|
|
2103
2033
|
// This is the default for require.resolve
|
|
@@ -2108,10 +2038,12 @@ function getDefaultRequireResolvePaths(callerModule) {
|
|
|
2108
2038
|
}
|
|
2109
2039
|
return ret;
|
|
2110
2040
|
}
|
|
2041
|
+
__name(getDefaultRequireResolvePaths, "getDefaultRequireResolvePaths");
|
|
2111
2042
|
const shortGithubUrlRegex = /^(?<user>[^/]+)\/(?<repo>[^#]+)(?:#(?<commit>.+))?$/;
|
|
2112
2043
|
function isShortGithubUrl(url2) {
|
|
2113
2044
|
return shortGithubUrlRegex.test(url2);
|
|
2114
2045
|
}
|
|
2046
|
+
__name(isShortGithubUrl, "isShortGithubUrl");
|
|
2115
2047
|
function parseShortGithubUrl(url2) {
|
|
2116
2048
|
const match = shortGithubUrlRegex.exec(url2);
|
|
2117
2049
|
if (!match || !match.groups) {
|
|
@@ -2123,10 +2055,12 @@ function parseShortGithubUrl(url2) {
|
|
|
2123
2055
|
commit: match.groups.commit
|
|
2124
2056
|
};
|
|
2125
2057
|
}
|
|
2058
|
+
__name(parseShortGithubUrl, "parseShortGithubUrl");
|
|
2126
2059
|
const githubPathnameRegex = /^\/(?<user>[^/]+)\/(?<repo>[^/]*?)(?:\.git)?(?:\/(?:tree|tarball|archive)\/(?<commit>.*?)(?:\.(?:zip|gz|tar\.gz))?)?$/;
|
|
2127
2060
|
function isGithubPathname(pathname) {
|
|
2128
2061
|
return githubPathnameRegex.test(pathname);
|
|
2129
2062
|
}
|
|
2063
|
+
__name(isGithubPathname, "isGithubPathname");
|
|
2130
2064
|
function parseGithubPathname(pathname) {
|
|
2131
2065
|
const match = githubPathnameRegex.exec(pathname);
|
|
2132
2066
|
if (!match || !match.groups) {
|
|
@@ -2138,6 +2072,7 @@ function parseGithubPathname(pathname) {
|
|
|
2138
2072
|
commit: match.groups.commit
|
|
2139
2073
|
};
|
|
2140
2074
|
}
|
|
2075
|
+
__name(parseGithubPathname, "parseGithubPathname");
|
|
2141
2076
|
function removePreservedProperties(preserve, oldObj, newObj) {
|
|
2142
2077
|
for (const prop of Object.keys(preserve)) {
|
|
2143
2078
|
if (isObject(preserve[prop]) && isObject(newObj[prop])) {
|
|
@@ -2155,6 +2090,7 @@ function removePreservedProperties(preserve, oldObj, newObj) {
|
|
|
2155
2090
|
}
|
|
2156
2091
|
}
|
|
2157
2092
|
}
|
|
2093
|
+
__name(removePreservedProperties, "removePreservedProperties");
|
|
2158
2094
|
function getInstanceIndicatorObjects(namespace, adapterCommon) {
|
|
2159
2095
|
const id = `system.adapter.${namespace}`;
|
|
2160
2096
|
return [
|
|
@@ -2357,27 +2293,29 @@ function getInstanceIndicatorObjects(namespace, adapterCommon) {
|
|
|
2357
2293
|
}
|
|
2358
2294
|
];
|
|
2359
2295
|
}
|
|
2296
|
+
__name(getInstanceIndicatorObjects, "getInstanceIndicatorObjects");
|
|
2360
2297
|
function getLogger(log) {
|
|
2361
2298
|
if (!log) {
|
|
2362
2299
|
log = {
|
|
2363
|
-
silly: function(_msg) {
|
|
2364
|
-
},
|
|
2365
|
-
debug: function(_msg) {
|
|
2366
|
-
},
|
|
2367
|
-
info: function(_msg) {
|
|
2368
|
-
},
|
|
2369
|
-
warn: function(msg) {
|
|
2300
|
+
silly: /* @__PURE__ */ __name(function(_msg) {
|
|
2301
|
+
}, "silly"),
|
|
2302
|
+
debug: /* @__PURE__ */ __name(function(_msg) {
|
|
2303
|
+
}, "debug"),
|
|
2304
|
+
info: /* @__PURE__ */ __name(function(_msg) {
|
|
2305
|
+
}, "info"),
|
|
2306
|
+
warn: /* @__PURE__ */ __name(function(msg) {
|
|
2370
2307
|
console.log(msg);
|
|
2371
|
-
},
|
|
2372
|
-
error: function(msg) {
|
|
2308
|
+
}, "warn"),
|
|
2309
|
+
error: /* @__PURE__ */ __name(function(msg) {
|
|
2373
2310
|
console.log(msg);
|
|
2374
|
-
}
|
|
2311
|
+
}, "error")
|
|
2375
2312
|
};
|
|
2376
2313
|
} else if (!log.silly) {
|
|
2377
2314
|
log.silly = log.debug;
|
|
2378
2315
|
}
|
|
2379
2316
|
return log;
|
|
2380
2317
|
}
|
|
2318
|
+
__name(getLogger, "getLogger");
|
|
2381
2319
|
async function setExecutableCapabilities(execPath, capabilities, modeEffective, modePermitted, modeInherited) {
|
|
2382
2320
|
if (import_node_os.default.platform() !== "linux") {
|
|
2383
2321
|
return;
|
|
@@ -2417,6 +2355,7 @@ async function setExecutableCapabilities(execPath, capabilities, modeEffective,
|
|
|
2417
2355
|
await execAsync(`sudo setcap ${capabilitiesStr}${modes} ${execPath}`);
|
|
2418
2356
|
}
|
|
2419
2357
|
}
|
|
2358
|
+
__name(setExecutableCapabilities, "setExecutableCapabilities");
|
|
2420
2359
|
async function _readLicenses(login, password2) {
|
|
2421
2360
|
const config = {
|
|
2422
2361
|
headers: { Authorization: `Basic ${Buffer.from(`${login}:${password2}`).toString("base64")}` },
|
|
@@ -2439,12 +2378,13 @@ async function _readLicenses(login, password2) {
|
|
|
2439
2378
|
}
|
|
2440
2379
|
}
|
|
2441
2380
|
}
|
|
2381
|
+
__name(_readLicenses, "_readLicenses");
|
|
2442
2382
|
async function updateLicenses(objects, login, password2) {
|
|
2443
2383
|
if (login && password2) {
|
|
2444
|
-
return _readLicenses(login, password2);
|
|
2384
|
+
return await _readLicenses(login, password2);
|
|
2445
2385
|
}
|
|
2446
2386
|
const systemLicenses = await objects.getObjectAsync("system.licenses");
|
|
2447
|
-
if (systemLicenses
|
|
2387
|
+
if (systemLicenses?.native?.password && systemLicenses.native.login) {
|
|
2448
2388
|
try {
|
|
2449
2389
|
const systemConfig = await objects.getObjectAsync("system.config");
|
|
2450
2390
|
let password3;
|
|
@@ -2469,7 +2409,7 @@ async function updateLicenses(objects, login, password2) {
|
|
|
2469
2409
|
return licenses;
|
|
2470
2410
|
} catch (err) {
|
|
2471
2411
|
if (err.message.includes("Authentication required") || err.message.includes("Cannot decode password:")) {
|
|
2472
|
-
if (systemLicenses
|
|
2412
|
+
if (systemLicenses?.native?.licenses?.length) {
|
|
2473
2413
|
systemLicenses.native.licenses = [];
|
|
2474
2414
|
systemLicenses.native.readTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
2475
2415
|
await objects.setObjectAsync("system.licenses", systemLicenses);
|
|
@@ -2478,7 +2418,7 @@ async function updateLicenses(objects, login, password2) {
|
|
|
2478
2418
|
throw err;
|
|
2479
2419
|
}
|
|
2480
2420
|
} else {
|
|
2481
|
-
if (systemLicenses
|
|
2421
|
+
if (systemLicenses?.native?.licenses?.length) {
|
|
2482
2422
|
systemLicenses.native.licenses = [];
|
|
2483
2423
|
systemLicenses.native.readTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
2484
2424
|
await objects.setObjectAsync("system.licenses", systemLicenses);
|
|
@@ -2486,6 +2426,7 @@ async function updateLicenses(objects, login, password2) {
|
|
|
2486
2426
|
throw new Error("No password or login");
|
|
2487
2427
|
}
|
|
2488
2428
|
}
|
|
2429
|
+
__name(updateLicenses, "updateLicenses");
|
|
2489
2430
|
function compressFileGZip(inputFilename, outputFilename, options = {}) {
|
|
2490
2431
|
const { deleteInput = false } = options;
|
|
2491
2432
|
return new Promise((resolve, reject) => {
|
|
@@ -2513,6 +2454,7 @@ function compressFileGZip(inputFilename, outputFilename, options = {}) {
|
|
|
2513
2454
|
input.pipe(compress).pipe(output);
|
|
2514
2455
|
});
|
|
2515
2456
|
}
|
|
2457
|
+
__name(compressFileGZip, "compressFileGZip");
|
|
2516
2458
|
function validateDataDir(dataDir) {
|
|
2517
2459
|
if (!import_node_path.default.isAbsolute(dataDir)) {
|
|
2518
2460
|
dataDir = import_node_path.default.normalize(import_node_path.default.join(getControllerDir(), dataDir));
|
|
@@ -2525,12 +2467,14 @@ function validateDataDir(dataDir) {
|
|
|
2525
2467
|
reason: isValid ? "Valid data directory" : "Data directory is not allowed to point into node_modules folder"
|
|
2526
2468
|
};
|
|
2527
2469
|
}
|
|
2470
|
+
__name(validateDataDir, "validateDataDir");
|
|
2528
2471
|
function maybeArrayToString(maybeArr) {
|
|
2529
2472
|
if (Array.isArray(maybeArr)) {
|
|
2530
2473
|
return JSON.stringify(maybeArr);
|
|
2531
2474
|
}
|
|
2532
2475
|
return maybeArr;
|
|
2533
2476
|
}
|
|
2477
|
+
__name(maybeArrayToString, "maybeArrayToString");
|
|
2534
2478
|
function getDNSResolutionOrder() {
|
|
2535
2479
|
let dnsOrder = "ipv4first";
|
|
2536
2480
|
try {
|
|
@@ -2544,25 +2488,31 @@ function getDNSResolutionOrder() {
|
|
|
2544
2488
|
}
|
|
2545
2489
|
return dnsOrder;
|
|
2546
2490
|
}
|
|
2491
|
+
__name(getDNSResolutionOrder, "getDNSResolutionOrder");
|
|
2547
2492
|
function isLocalAddress(ip) {
|
|
2548
2493
|
const localAddresses = ["::1", "127.0.0.1", "localhost"];
|
|
2549
2494
|
return localAddresses.includes(ip);
|
|
2550
2495
|
}
|
|
2496
|
+
__name(isLocalAddress, "isLocalAddress");
|
|
2551
2497
|
function isListenAllAddress(ip) {
|
|
2552
2498
|
return ip === "0.0.0.0" || ip === "::";
|
|
2553
2499
|
}
|
|
2500
|
+
__name(isListenAllAddress, "isListenAllAddress");
|
|
2554
2501
|
function getLocalAddress() {
|
|
2555
2502
|
const dnsOrder = getDNSResolutionOrder();
|
|
2556
2503
|
return dnsOrder === "ipv4first" ? "127.0.0.1" : "::1";
|
|
2557
2504
|
}
|
|
2505
|
+
__name(getLocalAddress, "getLocalAddress");
|
|
2558
2506
|
function getListenAllAddress() {
|
|
2559
2507
|
const dnsOrder = getDNSResolutionOrder();
|
|
2560
2508
|
return dnsOrder === "ipv4first" ? "0.0.0.0" : "::";
|
|
2561
2509
|
}
|
|
2510
|
+
__name(getListenAllAddress, "getListenAllAddress");
|
|
2562
2511
|
function ensureDNSOrder() {
|
|
2563
2512
|
const dnsOrder = getDNSResolutionOrder();
|
|
2564
2513
|
(0, import_node_dns.setDefaultResultOrder)(dnsOrder);
|
|
2565
2514
|
}
|
|
2515
|
+
__name(ensureDNSOrder, "ensureDNSOrder");
|
|
2566
2516
|
async function isIoBrokerInstalledAsSystemd() {
|
|
2567
2517
|
try {
|
|
2568
2518
|
const res = await execAsync("systemctl status iobroker");
|
|
@@ -2571,6 +2521,7 @@ async function isIoBrokerInstalledAsSystemd() {
|
|
|
2571
2521
|
return false;
|
|
2572
2522
|
}
|
|
2573
2523
|
}
|
|
2524
|
+
__name(isIoBrokerInstalledAsSystemd, "isIoBrokerInstalledAsSystemd");
|
|
2574
2525
|
function getHostObject(oldObj) {
|
|
2575
2526
|
const hostname = getHostName();
|
|
2576
2527
|
const ioPackage = import_fs_extra.default.readJSONSync(import_node_path.default.join(getControllerDir(), "io-package.json"));
|
|
@@ -2627,9 +2578,11 @@ function getHostObject(oldObj) {
|
|
|
2627
2578
|
}
|
|
2628
2579
|
return newObj;
|
|
2629
2580
|
}
|
|
2581
|
+
__name(getHostObject, "getHostObject");
|
|
2630
2582
|
function getPidsFileName() {
|
|
2631
2583
|
return import_node_path.default.join(getControllerDir(), "pids.txt");
|
|
2632
2584
|
}
|
|
2585
|
+
__name(getPidsFileName, "getPidsFileName");
|
|
2633
2586
|
async function getPids() {
|
|
2634
2587
|
let pids = [];
|
|
2635
2588
|
try {
|
|
@@ -2642,13 +2595,78 @@ async function getPids() {
|
|
|
2642
2595
|
}
|
|
2643
2596
|
return pids;
|
|
2644
2597
|
}
|
|
2598
|
+
__name(getPids, "getPids");
|
|
2645
2599
|
function isLogLevel(level) {
|
|
2646
2600
|
return ["silly", "debug", "info", "warn", "error"].includes(level);
|
|
2647
2601
|
}
|
|
2602
|
+
__name(isLogLevel, "isLogLevel");
|
|
2648
2603
|
async function getControllerPid() {
|
|
2649
2604
|
const pids = await getPids();
|
|
2650
2605
|
return pids.pop();
|
|
2651
2606
|
}
|
|
2607
|
+
__name(getControllerPid, "getControllerPid");
|
|
2608
|
+
function isProcessRunning(pid) {
|
|
2609
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
2610
|
+
return false;
|
|
2611
|
+
}
|
|
2612
|
+
try {
|
|
2613
|
+
process.kill(pid, 0);
|
|
2614
|
+
return true;
|
|
2615
|
+
} catch (e) {
|
|
2616
|
+
return e.code === "EPERM";
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
__name(isProcessRunning, "isProcessRunning");
|
|
2620
|
+
function isControllerCommandLine(commandLine) {
|
|
2621
|
+
const command = commandLine.toLowerCase();
|
|
2622
|
+
return (
|
|
2623
|
+
// On POSIX the title the running controller gives itself replaces the command line
|
|
2624
|
+
command.startsWith(`${appNameLowerCase}.js-controller`) || // "node <path>/controller.js", as started by the CLI, the service or the installer
|
|
2625
|
+
/(^|[\s"'/\\])controller\.js(["'\s]|$)/.test(command) || // The entry point started directly
|
|
2626
|
+
/[/\\](iobroker\.js-controller|controller)[/\\]build[/\\](esm|cjs)[/\\]main\.js/.test(command)
|
|
2627
|
+
);
|
|
2628
|
+
}
|
|
2629
|
+
__name(isControllerCommandLine, "isControllerCommandLine");
|
|
2630
|
+
async function isForeignProcess(pid) {
|
|
2631
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
2632
|
+
return false;
|
|
2633
|
+
}
|
|
2634
|
+
if (pid === process.pid) {
|
|
2635
|
+
return true;
|
|
2636
|
+
}
|
|
2637
|
+
try {
|
|
2638
|
+
if (import_node_os.default.platform() === "win32") {
|
|
2639
|
+
const { stdout: stdout2 } = await execFileAsync("powershell.exe", [
|
|
2640
|
+
"-NoProfile",
|
|
2641
|
+
"-NonInteractive",
|
|
2642
|
+
"-Command",
|
|
2643
|
+
`[Console]::OutputEncoding = [Text.Encoding]::UTF8; Get-CimInstance Win32_Process -Filter 'ProcessId=${pid}' | Select-Object Name, CommandLine | ConvertTo-Json -Compress`
|
|
2644
|
+
], { timeout: 1e4 });
|
|
2645
|
+
const output = (stdout2 || "").trim();
|
|
2646
|
+
if (!output) {
|
|
2647
|
+
return false;
|
|
2648
|
+
}
|
|
2649
|
+
const { Name, CommandLine } = JSON.parse(output);
|
|
2650
|
+
if (!Name) {
|
|
2651
|
+
return false;
|
|
2652
|
+
}
|
|
2653
|
+
if (!Name.toLowerCase().startsWith("node")) {
|
|
2654
|
+
return true;
|
|
2655
|
+
}
|
|
2656
|
+
return CommandLine ? !isControllerCommandLine(CommandLine) : false;
|
|
2657
|
+
}
|
|
2658
|
+
const { stdout } = await execFileAsync("ps", ["-p", String(pid), "-o", "args="], { timeout: 2e3 });
|
|
2659
|
+
const commandLine = (stdout || "").trim();
|
|
2660
|
+
if (!commandLine) {
|
|
2661
|
+
return false;
|
|
2662
|
+
}
|
|
2663
|
+
return !isControllerCommandLine(commandLine);
|
|
2664
|
+
} catch (e) {
|
|
2665
|
+
console.warn(`Cannot inspect process ${pid}, assuming it belongs to the controller: ${e.message}`);
|
|
2666
|
+
return false;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
__name(isForeignProcess, "isForeignProcess");
|
|
2652
2670
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2653
2671
|
0 && (module.exports = {
|
|
2654
2672
|
ERRORS,
|
|
@@ -2667,6 +2685,7 @@ async function getControllerPid() {
|
|
|
2667
2685
|
encrypt,
|
|
2668
2686
|
ensureDNSOrder,
|
|
2669
2687
|
execAsync,
|
|
2688
|
+
execFileAsync,
|
|
2670
2689
|
findIPs,
|
|
2671
2690
|
formatAliasValue,
|
|
2672
2691
|
generateDefaultCertificates,
|
|
@@ -2707,6 +2726,7 @@ async function getControllerPid() {
|
|
|
2707
2726
|
isDevInstallation,
|
|
2708
2727
|
isDevServerInstallation,
|
|
2709
2728
|
isDocker,
|
|
2729
|
+
isForeignProcess,
|
|
2710
2730
|
isGithubPathname,
|
|
2711
2731
|
isHostRunning,
|
|
2712
2732
|
isIoBrokerInstalledAsSystemd,
|
|
@@ -2714,6 +2734,7 @@ async function getControllerPid() {
|
|
|
2714
2734
|
isLocalAddress,
|
|
2715
2735
|
isLogLevel,
|
|
2716
2736
|
isObject,
|
|
2737
|
+
isProcessRunning,
|
|
2717
2738
|
isShortGithubUrl,
|
|
2718
2739
|
isSingleHost,
|
|
2719
2740
|
isValidPattern,
|