@iobroker/js-controller-cli 4.0.0-alpha.8-20210909-001a711c → 4.0.3
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/LICENSE +1 -1
- package/README.md +1 -1
- package/index.js +12 -11
- package/lib/cli/cliCert.js +13 -7
- package/lib/cli/cliCompact.js +22 -8
- package/lib/cli/cliDebug.js +35 -9
- package/lib/cli/cliHost.js +17 -25
- package/lib/cli/cliLogs.js +9 -18
- package/lib/cli/cliMessage.js +3 -12
- package/lib/cli/cliObjects.js +162 -28
- package/lib/cli/cliPlugin.js +120 -175
- package/lib/cli/cliProcess.js +23 -15
- package/lib/cli/cliStates.js +179 -45
- package/lib/cli/cliTools.js +3 -4
- package/lib/cli/messages.js +55 -64
- package/lib/setup/setupList.js +843 -0
- package/package.json +8 -7
package/lib/cli/cliObjects.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
const CLI = require('./messages.js');
|
|
3
3
|
const CLICommand = require('./cliCommand.js');
|
|
4
4
|
const { formatValue } = require('./cliTools');
|
|
5
|
-
const { tools } = require('@iobroker/js-controller-common');
|
|
5
|
+
const { tools, EXIT_CODES } = require('@iobroker/js-controller-common');
|
|
6
6
|
|
|
7
7
|
/** Command iobroker object ... */
|
|
8
8
|
module.exports = class CLIObjects extends CLICommand {
|
|
9
|
-
|
|
10
|
-
/** @param {import('./cliCommand').CLICommandOptions} options */
|
|
9
|
+
/** @param {CLICommandOptions} options */
|
|
11
10
|
constructor(options) {
|
|
12
11
|
super(options);
|
|
13
12
|
}
|
|
@@ -37,6 +36,14 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
37
36
|
case 'delete':
|
|
38
37
|
case 'del':
|
|
39
38
|
return this.delete(args);
|
|
39
|
+
case 'getDBVersion':
|
|
40
|
+
return this.getDBVersion(args);
|
|
41
|
+
case 'setDBVersion':
|
|
42
|
+
return this.setDBVersion();
|
|
43
|
+
case 'activateSets':
|
|
44
|
+
return this.activateSets();
|
|
45
|
+
case 'deactivateSets':
|
|
46
|
+
return this.deactivateSets();
|
|
40
47
|
default:
|
|
41
48
|
CLI.error.unknownCommand('object', command);
|
|
42
49
|
showHelp();
|
|
@@ -44,6 +51,94 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Activates the usage of Redis Sets
|
|
56
|
+
*/
|
|
57
|
+
activateSets() {
|
|
58
|
+
const { callback, dbConnect } = this.options;
|
|
59
|
+
dbConnect(async (objects, states) => {
|
|
60
|
+
if (!parseInt(await objects.getMeta('objects.features.useSets'))) {
|
|
61
|
+
// all hosts need to be stopped for this
|
|
62
|
+
if (await tools.isHostRunning(objects, states)) {
|
|
63
|
+
console.log('Cannot activate the usage of Redis Sets while one or more hosts are running');
|
|
64
|
+
return void callback(EXIT_CODES.CONTROLLER_RUNNING);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await objects.activateSets();
|
|
68
|
+
const noMigrated = await objects.migrateToSets();
|
|
69
|
+
|
|
70
|
+
if (noMigrated) {
|
|
71
|
+
console.log(`Successfully migrated ${noMigrated} objects to Redis Sets`);
|
|
72
|
+
}
|
|
73
|
+
console.log(
|
|
74
|
+
`Successfully activated the usage of Redis Sets. Please make sure to only use js-controller 4.0 or higher on all hosts!`
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
console.log('Redis Sets are already activated.');
|
|
78
|
+
}
|
|
79
|
+
return void callback();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Deactivates the usage of Redis Sets
|
|
85
|
+
*/
|
|
86
|
+
deactivateSets() {
|
|
87
|
+
const { callback, dbConnect } = this.options;
|
|
88
|
+
dbConnect(async objects => {
|
|
89
|
+
if (parseInt(await objects.getMeta('objects.features.useSets'))) {
|
|
90
|
+
await objects.deactivateSets();
|
|
91
|
+
console.log(`Successfully deactivated the usage of Redis Sets.`);
|
|
92
|
+
} else {
|
|
93
|
+
console.log('Redis Sets are already deactivated.');
|
|
94
|
+
}
|
|
95
|
+
return void callback();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the protocol version
|
|
101
|
+
*/
|
|
102
|
+
getDBVersion() {
|
|
103
|
+
const { callback, dbConnect } = this.options;
|
|
104
|
+
dbConnect(async objects => {
|
|
105
|
+
const version = await objects.getProtocolVersion();
|
|
106
|
+
console.log(`Current Objects DB protocol version: ${version}`);
|
|
107
|
+
return void callback();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set protocol version
|
|
113
|
+
*/
|
|
114
|
+
setDBVersion() {
|
|
115
|
+
const { callback, dbConnect } = this.options;
|
|
116
|
+
dbConnect(async objects => {
|
|
117
|
+
const rl = require('readline-sync');
|
|
118
|
+
|
|
119
|
+
let answer = rl.question('Changing the protocol version will restart all hosts! Continue? [N/y]', {
|
|
120
|
+
limit: /^(yes|y|n|no)$/i,
|
|
121
|
+
defaultInput: 'no'
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
answer = answer.toLowerCase();
|
|
125
|
+
|
|
126
|
+
if (answer !== 'y' && answer !== 'yes') {
|
|
127
|
+
console.log('Protocol version has not been changed!');
|
|
128
|
+
return void callback();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await objects.setProtocolVersion(this.options.version);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error(`Cannot update protocol version: ${e.message}`);
|
|
135
|
+
return void callback(1);
|
|
136
|
+
}
|
|
137
|
+
console.log(`Objects DB protocol updated to version ${this.options.version}`);
|
|
138
|
+
return void callback();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
47
142
|
/**
|
|
48
143
|
* Changes access rights for all objects matching the pattern
|
|
49
144
|
* @param {any[]} args
|
|
@@ -74,10 +169,14 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
74
169
|
}
|
|
75
170
|
|
|
76
171
|
dbConnect((objects, states) => {
|
|
77
|
-
objects.chmodObject(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
172
|
+
objects.chmodObject(
|
|
173
|
+
pattern,
|
|
174
|
+
{ user: 'system.user.admin', object: modeObject, state: modeState },
|
|
175
|
+
(err, processed) => {
|
|
176
|
+
// Print the new object rights
|
|
177
|
+
this.printObjectList(objects, states, err, processed);
|
|
178
|
+
}
|
|
179
|
+
);
|
|
81
180
|
});
|
|
82
181
|
}
|
|
83
182
|
|
|
@@ -88,7 +187,7 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
88
187
|
chown(args) {
|
|
89
188
|
const { callback, dbConnect } = this.options;
|
|
90
189
|
/** @type {[string, string, any]} */
|
|
91
|
-
let [user, group, pattern] =
|
|
190
|
+
let [user, group, pattern] = args.slice(1);
|
|
92
191
|
|
|
93
192
|
if (!pattern) {
|
|
94
193
|
pattern = group;
|
|
@@ -110,10 +209,14 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
110
209
|
return void callback(1);
|
|
111
210
|
}
|
|
112
211
|
dbConnect((objects, states) => {
|
|
113
|
-
objects.chownObject(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
212
|
+
objects.chownObject(
|
|
213
|
+
pattern,
|
|
214
|
+
{ user: 'system.user.admin', owner: user, ownerGroup: group },
|
|
215
|
+
(err, processed) => {
|
|
216
|
+
// Print the new object rights
|
|
217
|
+
this.printObjectList(objects, states, err, processed);
|
|
218
|
+
}
|
|
219
|
+
);
|
|
117
220
|
});
|
|
118
221
|
}
|
|
119
222
|
|
|
@@ -131,7 +234,8 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
131
234
|
dbConnect((objects, states) => {
|
|
132
235
|
objects.getObjectList(pattern, { user: 'system.user.admin', sorted: true }, (err, processed) => {
|
|
133
236
|
this.printObjectList(
|
|
134
|
-
objects,
|
|
237
|
+
objects,
|
|
238
|
+
states,
|
|
135
239
|
err,
|
|
136
240
|
processed && processed.rows && processed.rows.map(r => r.value)
|
|
137
241
|
);
|
|
@@ -147,7 +251,7 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
147
251
|
get(args) {
|
|
148
252
|
const { callback, pretty, dbConnect } = this.options;
|
|
149
253
|
/** @type {[string, string]} */
|
|
150
|
-
const [id, propPath] =
|
|
254
|
+
const [id, propPath] = args.slice(1);
|
|
151
255
|
if (!id) {
|
|
152
256
|
CLI.error.requiredArgumentMissing('id', 'object get id [propertypath]');
|
|
153
257
|
return void callback(1);
|
|
@@ -270,7 +374,7 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
270
374
|
for (const prop in value) {
|
|
271
375
|
if (typeof res.native[prop] === 'string' && res.encryptedNative.includes(prop)) {
|
|
272
376
|
try {
|
|
273
|
-
config = config || await objects.getObjectAsync('system.config');
|
|
377
|
+
config = config || (await objects.getObjectAsync('system.config'));
|
|
274
378
|
res.native[prop] = tools.encrypt(config.native.secret, res.native[prop]);
|
|
275
379
|
} catch (e) {
|
|
276
380
|
console.error(`Could not auto-encrypt property "${prop}": ${e.message}`);
|
|
@@ -323,7 +427,20 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
323
427
|
* @return {Promise<object[]>}
|
|
324
428
|
*/
|
|
325
429
|
async _collectObjects(objects, params, callback) {
|
|
326
|
-
const types = [
|
|
430
|
+
const types = [
|
|
431
|
+
'state',
|
|
432
|
+
'channel',
|
|
433
|
+
'device',
|
|
434
|
+
'enum',
|
|
435
|
+
'instance',
|
|
436
|
+
'host',
|
|
437
|
+
'adapter',
|
|
438
|
+
'meta',
|
|
439
|
+
'config',
|
|
440
|
+
'group',
|
|
441
|
+
'user',
|
|
442
|
+
'script'
|
|
443
|
+
];
|
|
327
444
|
const result = [];
|
|
328
445
|
|
|
329
446
|
for (const type of types) {
|
|
@@ -348,10 +465,19 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
348
465
|
if (!ids || !ids.length) {
|
|
349
466
|
return tools.maybeCallback(callback);
|
|
350
467
|
} else {
|
|
468
|
+
let allEnums;
|
|
469
|
+
|
|
470
|
+
try {
|
|
471
|
+
// cache all enums, else it will be slow to delete many objects
|
|
472
|
+
allEnums = await tools.getAllEnums(objects);
|
|
473
|
+
} catch (e) {
|
|
474
|
+
console.error(`Could not retrieve all enums: ${e.message}`);
|
|
475
|
+
}
|
|
476
|
+
|
|
351
477
|
for (const id of ids) {
|
|
352
478
|
try {
|
|
353
479
|
await objects.delObjectAsync(id);
|
|
354
|
-
await tools.removeIdFromAllEnums(objects, id);
|
|
480
|
+
await tools.removeIdFromAllEnums(objects, id, allEnums);
|
|
355
481
|
} catch (e) {
|
|
356
482
|
console.warn(`Could not delete object or remove "${id}" from enums: ${e.message}`);
|
|
357
483
|
}
|
|
@@ -377,7 +503,7 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
377
503
|
if (id.endsWith('*')) {
|
|
378
504
|
const params = {
|
|
379
505
|
startkey: id.replace(/\*/g, ''),
|
|
380
|
-
endkey:
|
|
506
|
+
endkey: id.replace(/\*/g, '\u9999')
|
|
381
507
|
};
|
|
382
508
|
this._collectObjects(objects, params, result => {
|
|
383
509
|
if (!result || !result.length) {
|
|
@@ -389,12 +515,19 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
389
515
|
// if no auto confirmation, ask user
|
|
390
516
|
if (!this.options.f && this.options.y && !this.options.yes) {
|
|
391
517
|
const rl = require('readline').createInterface({
|
|
392
|
-
input:
|
|
518
|
+
input: process.stdin,
|
|
393
519
|
output: process.stdout
|
|
394
520
|
});
|
|
395
|
-
rl.question(result.length
|
|
521
|
+
rl.question(`${result.length} object(s) will be deleted. Are you sure? [y/N]: `, answer => {
|
|
396
522
|
rl.close();
|
|
397
|
-
if (
|
|
523
|
+
if (
|
|
524
|
+
answer === 'y' ||
|
|
525
|
+
answer === 'yes' ||
|
|
526
|
+
answer === 'j' ||
|
|
527
|
+
answer === 'ja' ||
|
|
528
|
+
answer === 'да' ||
|
|
529
|
+
answer === 'д'
|
|
530
|
+
) {
|
|
398
531
|
this._deleteObjects(objects, ids, callback);
|
|
399
532
|
} else {
|
|
400
533
|
console.log('Aborted.');
|
|
@@ -407,18 +540,19 @@ module.exports = class CLIObjects extends CLICommand {
|
|
|
407
540
|
});
|
|
408
541
|
} else {
|
|
409
542
|
// only one object
|
|
410
|
-
objects.delObject(id, err => {
|
|
543
|
+
objects.delObject(id, async err => {
|
|
411
544
|
if (err) {
|
|
412
545
|
CLI.error.objectNotFound(id, err);
|
|
413
|
-
|
|
546
|
+
callback(3);
|
|
414
547
|
} else {
|
|
415
|
-
|
|
548
|
+
try {
|
|
549
|
+
await tools.removeIdFromAllEnums(objects, id);
|
|
416
550
|
CLI.success.objectDeleted(id);
|
|
417
|
-
|
|
418
|
-
}
|
|
551
|
+
callback();
|
|
552
|
+
} catch (e) {
|
|
419
553
|
CLI.error.cannotDeleteObjectFromEnums(id, e.message);
|
|
420
|
-
|
|
421
|
-
}
|
|
554
|
+
callback(3);
|
|
555
|
+
}
|
|
422
556
|
}
|
|
423
557
|
});
|
|
424
558
|
}
|
package/lib/cli/cliPlugin.js
CHANGED
|
@@ -49,10 +49,7 @@ module.exports = class CLIPlugin extends CLICommand {
|
|
|
49
49
|
/** @type {string} */
|
|
50
50
|
const pluginName = args[1];
|
|
51
51
|
if (!pluginName) {
|
|
52
|
-
CLI.error.requiredArgumentMissing(
|
|
53
|
-
'pluginName',
|
|
54
|
-
'plugin enable <pluginname>'
|
|
55
|
-
);
|
|
52
|
+
CLI.error.requiredArgumentMissing('pluginName', 'plugin enable <pluginname>');
|
|
56
53
|
return void callback(34);
|
|
57
54
|
}
|
|
58
55
|
|
|
@@ -75,99 +72,82 @@ module.exports = class CLIPlugin extends CLICommand {
|
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
dbConnect(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
88
|
-
if (!hostObject) {
|
|
89
|
-
CLI.error.hostDoesNotExist(hostname);
|
|
90
|
-
return void callback(30);
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
objectNamespace = `system.adapter.${instance}`;
|
|
94
|
-
const instanceObject = await objects.getObject(
|
|
95
|
-
objectNamespace
|
|
96
|
-
);
|
|
97
|
-
if (!instanceObject) {
|
|
98
|
-
CLI.error.invalidInstance(instance);
|
|
99
|
-
return void callback(30);
|
|
100
|
-
}
|
|
75
|
+
dbConnect(async (objects, states, _isOffline, _dbType, iobrokerJson) => {
|
|
76
|
+
try {
|
|
77
|
+
// Check if the host or instance exists
|
|
78
|
+
/** @type {string} */ let objectNamespace;
|
|
79
|
+
if (hostname) {
|
|
80
|
+
objectNamespace = `system.host.${hostname}`;
|
|
81
|
+
const hostObject = await objects.getObject(objectNamespace);
|
|
82
|
+
if (!hostObject) {
|
|
83
|
+
CLI.error.hostDoesNotExist(hostname);
|
|
84
|
+
return void callback(30);
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
hostname,
|
|
108
|
-
instance
|
|
109
|
-
);
|
|
86
|
+
} else {
|
|
87
|
+
objectNamespace = `system.adapter.${instance}`;
|
|
88
|
+
const instanceObject = await objects.getObject(objectNamespace);
|
|
89
|
+
if (!instanceObject) {
|
|
90
|
+
CLI.error.invalidInstance(instance);
|
|
110
91
|
return void callback(30);
|
|
111
92
|
}
|
|
93
|
+
}
|
|
112
94
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
common: {
|
|
119
|
-
name: `${
|
|
120
|
-
hostname ? 'host' : 'instance'
|
|
121
|
-
}: plugin states`
|
|
122
|
-
},
|
|
123
|
-
native: {}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
const pluginFolderId = `${objectNamespace}.plugins.${pluginName}`;
|
|
127
|
-
if (!(await objects.getObjectAsync(pluginFolderId))) {
|
|
128
|
-
await objects.setObject(pluginFolderId, {
|
|
129
|
-
type: 'folder',
|
|
130
|
-
common: {
|
|
131
|
-
name: `${pluginName}: plugin states`
|
|
132
|
-
},
|
|
133
|
-
native: {}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
const pluginEnabledId = `${pluginFolderId}.enabled`;
|
|
137
|
-
if (!(await objects.getObjectAsync(pluginEnabledId))) {
|
|
138
|
-
await objects.setObject(pluginEnabledId, {
|
|
139
|
-
type: 'state',
|
|
140
|
-
common: {
|
|
141
|
-
name: 'Plugin enabled',
|
|
142
|
-
type: 'boolean',
|
|
143
|
-
read: true,
|
|
144
|
-
write: true,
|
|
145
|
-
role: 'value'
|
|
146
|
-
},
|
|
147
|
-
native: {}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
95
|
+
// Check if the plugin is defined
|
|
96
|
+
if (!pluginExists(pluginName, iobrokerJson, instance)) {
|
|
97
|
+
CLI.error.pluginNotDefined(pluginName, hostname, instance);
|
|
98
|
+
return void callback(30);
|
|
99
|
+
}
|
|
150
100
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
101
|
+
// Create the plugin state if it does not exist
|
|
102
|
+
const pluginsFolderId = `${objectNamespace}.plugins`;
|
|
103
|
+
if (!(await objects.getObjectAsync(pluginsFolderId))) {
|
|
104
|
+
await objects.setObject(pluginsFolderId, {
|
|
105
|
+
type: 'folder',
|
|
106
|
+
common: {
|
|
107
|
+
name: `${hostname ? 'host' : 'instance'}: plugin states`
|
|
108
|
+
},
|
|
109
|
+
native: {}
|
|
155
110
|
});
|
|
156
|
-
|
|
157
|
-
// Notify the user that we are done
|
|
158
|
-
CLI.success.pluginEnabledOrDisabled(
|
|
159
|
-
pluginName,
|
|
160
|
-
hostname,
|
|
161
|
-
instance,
|
|
162
|
-
enabled
|
|
163
|
-
);
|
|
164
|
-
return void callback();
|
|
165
|
-
} catch (err) {
|
|
166
|
-
CLI.error.unknown(err.message);
|
|
167
|
-
return void callback(1);
|
|
168
111
|
}
|
|
112
|
+
const pluginFolderId = `${objectNamespace}.plugins.${pluginName}`;
|
|
113
|
+
if (!(await objects.getObjectAsync(pluginFolderId))) {
|
|
114
|
+
await objects.setObject(pluginFolderId, {
|
|
115
|
+
type: 'folder',
|
|
116
|
+
common: {
|
|
117
|
+
name: `${pluginName}: plugin states`
|
|
118
|
+
},
|
|
119
|
+
native: {}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const pluginEnabledId = `${pluginFolderId}.enabled`;
|
|
123
|
+
if (!(await objects.getObjectAsync(pluginEnabledId))) {
|
|
124
|
+
await objects.setObject(pluginEnabledId, {
|
|
125
|
+
type: 'state',
|
|
126
|
+
common: {
|
|
127
|
+
name: 'Plugin enabled',
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
read: true,
|
|
130
|
+
write: true,
|
|
131
|
+
role: 'value'
|
|
132
|
+
},
|
|
133
|
+
native: {}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Update the state
|
|
138
|
+
await states.setStateAsync(pluginEnabledId, {
|
|
139
|
+
val: enabled,
|
|
140
|
+
from: getObjectFrom()
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Notify the user that we are done
|
|
144
|
+
CLI.success.pluginEnabledOrDisabled(pluginName, hostname, instance, enabled);
|
|
145
|
+
return void callback();
|
|
146
|
+
} catch (err) {
|
|
147
|
+
CLI.error.unknown(err.message);
|
|
148
|
+
return void callback(1);
|
|
169
149
|
}
|
|
170
|
-
);
|
|
150
|
+
});
|
|
171
151
|
}
|
|
172
152
|
|
|
173
153
|
/**
|
|
@@ -179,10 +159,7 @@ module.exports = class CLIPlugin extends CLICommand {
|
|
|
179
159
|
/** @type {string} */
|
|
180
160
|
const pluginName = args[1];
|
|
181
161
|
if (!pluginName) {
|
|
182
|
-
CLI.error.requiredArgumentMissing(
|
|
183
|
-
'pluginName',
|
|
184
|
-
'plugin status <pluginname>'
|
|
185
|
-
);
|
|
162
|
+
CLI.error.requiredArgumentMissing('pluginName', 'plugin status <pluginname>');
|
|
186
163
|
return void callback(34);
|
|
187
164
|
}
|
|
188
165
|
|
|
@@ -205,75 +182,60 @@ module.exports = class CLIPlugin extends CLICommand {
|
|
|
205
182
|
}
|
|
206
183
|
}
|
|
207
184
|
|
|
208
|
-
dbConnect(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
);
|
|
218
|
-
if (!hostObject) {
|
|
219
|
-
CLI.error.hostDoesNotExist(hostname);
|
|
220
|
-
return void callback(30);
|
|
221
|
-
}
|
|
222
|
-
} else {
|
|
223
|
-
objectNamespace = `system.adapter.${instance}`;
|
|
224
|
-
const instanceObject = await objects.getObject(
|
|
225
|
-
objectNamespace
|
|
226
|
-
);
|
|
227
|
-
if (!instanceObject) {
|
|
228
|
-
CLI.error.invalidInstance(instance);
|
|
229
|
-
return void callback(30);
|
|
230
|
-
}
|
|
185
|
+
dbConnect(async (objects, states, _isOffline, _dbType, iobrokerJson) => {
|
|
186
|
+
try {
|
|
187
|
+
// Check if the host or instance exists
|
|
188
|
+
/** @type {string} */ let objectNamespace;
|
|
189
|
+
if (hostname) {
|
|
190
|
+
objectNamespace = `system.host.${hostname}`;
|
|
191
|
+
const hostObject = await objects.getObject(objectNamespace);
|
|
192
|
+
if (!hostObject) {
|
|
193
|
+
CLI.error.hostDoesNotExist(hostname);
|
|
194
|
+
return void callback(30);
|
|
231
195
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
hostname,
|
|
238
|
-
instance
|
|
239
|
-
);
|
|
196
|
+
} else {
|
|
197
|
+
objectNamespace = `system.adapter.${instance}`;
|
|
198
|
+
const instanceObject = await objects.getObject(objectNamespace);
|
|
199
|
+
if (!instanceObject) {
|
|
200
|
+
CLI.error.invalidInstance(instance);
|
|
240
201
|
return void callback(30);
|
|
241
202
|
}
|
|
203
|
+
}
|
|
242
204
|
|
|
243
|
-
|
|
205
|
+
// Check if the plugin is defined
|
|
206
|
+
if (!pluginExists(pluginName, iobrokerJson, instance)) {
|
|
207
|
+
CLI.error.pluginNotDefined(pluginName, hostname, instance);
|
|
208
|
+
return void callback(30);
|
|
209
|
+
}
|
|
244
210
|
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
const { val } = await states.getStateAsync(pluginEnabledId);
|
|
211
|
+
const pluginEnabledId = `${objectNamespace}.plugins.${pluginName}.enabled`;
|
|
248
212
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
} catch {
|
|
254
|
-
/* ignore */
|
|
255
|
-
}
|
|
213
|
+
// Read the state
|
|
214
|
+
try {
|
|
215
|
+
const { val } = await states.getStateAsync(pluginEnabledId);
|
|
256
216
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
);
|
|
264
|
-
CLI.success.pluginStatus(
|
|
265
|
-
pluginName,
|
|
266
|
-
hostname,
|
|
267
|
-
instance,
|
|
268
|
-
enabled
|
|
269
|
-
);
|
|
270
|
-
return void callback();
|
|
271
|
-
} catch (err) {
|
|
272
|
-
CLI.error.unknown(err.message);
|
|
273
|
-
return void callback(1);
|
|
217
|
+
if (typeof val === 'boolean') {
|
|
218
|
+
CLI.success.pluginStatus(pluginName, hostname, instance, val);
|
|
219
|
+
return void callback();
|
|
220
|
+
}
|
|
221
|
+
} catch {
|
|
222
|
+
/* ignore */
|
|
274
223
|
}
|
|
224
|
+
|
|
225
|
+
// If the state could not be read or had no value, fall back to the configuration
|
|
226
|
+
const enabled = pluginEnabled(
|
|
227
|
+
pluginName,
|
|
228
|
+
instance,
|
|
229
|
+
await objects.getObjectAsync('system.config'),
|
|
230
|
+
iobrokerJson
|
|
231
|
+
);
|
|
232
|
+
CLI.success.pluginStatus(pluginName, hostname, instance, enabled);
|
|
233
|
+
return void callback();
|
|
234
|
+
} catch (err) {
|
|
235
|
+
CLI.error.unknown(err.message);
|
|
236
|
+
return void callback(1);
|
|
275
237
|
}
|
|
276
|
-
);
|
|
238
|
+
});
|
|
277
239
|
}
|
|
278
240
|
};
|
|
279
241
|
|
|
@@ -287,16 +249,9 @@ function pluginExists(pluginName, iobrokerJson, adapter) {
|
|
|
287
249
|
// 1. check if the plugin is defined in io-package.json
|
|
288
250
|
// TODO: replace this with fs-extra methods #799
|
|
289
251
|
try {
|
|
290
|
-
const ioPackPath = adapter
|
|
291
|
-
? path.join(tools.getAdapterDir(adapter), 'io-package.json')
|
|
292
|
-
: controllerIoPackPath;
|
|
252
|
+
const ioPackPath = adapter ? path.join(tools.getAdapterDir(adapter), 'io-package.json') : controllerIoPackPath;
|
|
293
253
|
const ioPack = JSON.parse(fs.readFileSync(ioPackPath, 'utf8'));
|
|
294
|
-
if (
|
|
295
|
-
ioPack &&
|
|
296
|
-
ioPack.common &&
|
|
297
|
-
ioPack.common.plugins &&
|
|
298
|
-
pluginName in ioPack.common.plugins
|
|
299
|
-
) {
|
|
254
|
+
if (ioPack && ioPack.common && ioPack.common.plugins && pluginName in ioPack.common.plugins) {
|
|
300
255
|
return true;
|
|
301
256
|
}
|
|
302
257
|
} catch {
|
|
@@ -304,11 +259,7 @@ function pluginExists(pluginName, iobrokerJson, adapter) {
|
|
|
304
259
|
}
|
|
305
260
|
|
|
306
261
|
// 2. check if the plugin is defined in iobroker.json
|
|
307
|
-
return
|
|
308
|
-
iobrokerJson &&
|
|
309
|
-
iobrokerJson.plugins &&
|
|
310
|
-
pluginName in iobrokerJson.plugins
|
|
311
|
-
);
|
|
262
|
+
return iobrokerJson && iobrokerJson.plugins && pluginName in iobrokerJson.plugins;
|
|
312
263
|
}
|
|
313
264
|
|
|
314
265
|
/**
|
|
@@ -320,20 +271,14 @@ function pluginExists(pluginName, iobrokerJson, adapter) {
|
|
|
320
271
|
*/
|
|
321
272
|
function pluginEnabled(pluginName, adapter, systemConfig, iobrokerJson) {
|
|
322
273
|
// 1. check if diagnostics are disabled in ioBroker
|
|
323
|
-
if (
|
|
324
|
-
systemConfig &&
|
|
325
|
-
systemConfig.common &&
|
|
326
|
-
systemConfig.common.diag === 'none'
|
|
327
|
-
) {
|
|
274
|
+
if (systemConfig && systemConfig.common && systemConfig.common.diag === 'none') {
|
|
328
275
|
return false;
|
|
329
276
|
}
|
|
330
277
|
|
|
331
278
|
// 2. check if the plugin is disabled in io-package.json
|
|
332
279
|
// TODO: replace this with fs-extra methods #799
|
|
333
280
|
try {
|
|
334
|
-
const ioPackPath = adapter
|
|
335
|
-
? path.join(tools.getAdapterDir(adapter), 'io-package.json')
|
|
336
|
-
: controllerIoPackPath;
|
|
281
|
+
const ioPackPath = adapter ? path.join(tools.getAdapterDir(adapter), 'io-package.json') : controllerIoPackPath;
|
|
337
282
|
const ioPack = JSON.parse(fs.readFileSync(ioPackPath, 'utf8'));
|
|
338
283
|
if (
|
|
339
284
|
ioPack &&
|