@iobroker/js-controller-cli 4.0.21 → 4.1.0-alpha.0-20220819-74ceeddc
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/index.d.ts +89 -0
- package/{index.js → build/index.js} +7 -1
- package/build/lib/cli/cliCert.d.ts +16 -0
- package/build/lib/cli/cliCert.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliCert.js +5 -9
- package/build/lib/cli/cliCert.js.map +1 -0
- package/build/lib/cli/cliCommand.d.ts +24 -0
- package/build/lib/cli/cliCommand.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliCommand.js +2 -5
- package/build/lib/cli/cliCommand.js.map +1 -0
- package/build/lib/cli/cliCompact.d.ts +26 -0
- package/build/lib/cli/cliCompact.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliCompact.js +23 -43
- package/build/lib/cli/cliCompact.js.map +1 -0
- package/build/lib/cli/cliDebug.d.ts +19 -0
- package/build/lib/cli/cliDebug.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliDebug.js +6 -13
- package/build/lib/cli/cliDebug.js.map +1 -0
- package/build/lib/cli/cliHost.d.ts +36 -0
- package/build/lib/cli/cliHost.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliHost.js +22 -47
- package/build/lib/cli/cliHost.js.map +1 -0
- package/build/lib/cli/cliLogs.d.ts +58 -0
- package/build/lib/cli/cliLogs.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliLogs.js +16 -19
- package/build/lib/cli/cliLogs.js.map +1 -0
- package/build/lib/cli/cliMessage.d.ts +10 -0
- package/build/lib/cli/cliMessage.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliMessage.js +5 -7
- package/build/lib/cli/cliMessage.js.map +1 -0
- package/build/lib/cli/cliObjects.d.ts +105 -0
- package/build/lib/cli/cliObjects.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliObjects.js +69 -110
- package/build/lib/cli/cliObjects.js.map +1 -0
- package/build/lib/cli/cliPlugin.d.ts +23 -0
- package/build/lib/cli/cliPlugin.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliPlugin.js +24 -50
- package/build/lib/cli/cliPlugin.js.map +1 -0
- package/build/lib/cli/cliProcess.d.ts +50 -0
- package/build/lib/cli/cliProcess.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliProcess.js +50 -62
- package/build/lib/cli/cliProcess.js.map +1 -0
- package/build/lib/cli/cliStates.d.ts +51 -0
- package/build/lib/cli/cliStates.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliStates.js +64 -86
- package/build/lib/cli/cliStates.js.map +1 -0
- package/build/lib/cli/cliTools.d.ts +64 -0
- package/build/lib/cli/cliTools.d.ts.map +1 -0
- package/{lib → build/lib}/cli/cliTools.js +1 -12
- package/build/lib/cli/cliTools.js.map +1 -0
- package/build/lib/cli/messages.d.ts +53 -0
- package/build/lib/cli/messages.d.ts.map +1 -0
- package/{lib → build/lib}/cli/messages.js +27 -66
- package/build/lib/cli/messages.js.map +1 -0
- package/build/lib/setup/setupBackup.d.ts +126 -0
- package/build/lib/setup/setupBackup.d.ts.map +1 -0
- package/build/lib/setup/setupBackup.js +1031 -0
- package/build/lib/setup/setupBackup.js.map +1 -0
- package/build/lib/setup/setupInstall.d.ts +23 -0
- package/build/lib/setup/setupInstall.d.ts.map +1 -0
- package/build/lib/setup/setupInstall.js +1620 -0
- package/build/lib/setup/setupInstall.js.map +1 -0
- package/build/lib/setup/setupList.d.ts +49 -0
- package/build/lib/setup/setupList.d.ts.map +1 -0
- package/build/lib/setup/setupList.js +722 -0
- package/build/lib/setup/setupList.js.map +1 -0
- package/build/lib/setup/setupPacketManager.d.ts +65 -0
- package/build/lib/setup/setupPacketManager.d.ts.map +1 -0
- package/build/lib/setup/setupPacketManager.js +216 -0
- package/build/lib/setup/setupPacketManager.js.map +1 -0
- package/build/lib/setup/setupUpload.d.ts +72 -0
- package/build/lib/setup/setupUpload.d.ts.map +1 -0
- package/build/lib/setup/setupUpload.js +784 -0
- package/build/lib/setup/setupUpload.js.map +1 -0
- package/package.json +18 -11
- package/lib/setup/setupList.js +0 -840
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* List different objects for CLI
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2013-2022 bluefox <dogafox@gmail.com>
|
|
6
|
+
*
|
|
7
|
+
* MIT License
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
27
|
+
if (mod && mod.__esModule) return mod;
|
|
28
|
+
var result = {};
|
|
29
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
30
|
+
__setModuleDefault(result, mod);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.List = void 0;
|
|
35
|
+
const js_controller_common_1 = require("@iobroker/js-controller-common");
|
|
36
|
+
const fs = __importStar(require("fs-extra"));
|
|
37
|
+
const js_controller_common_2 = require("@iobroker/js-controller-common");
|
|
38
|
+
class List {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
options = options || {};
|
|
41
|
+
if (!options.states) {
|
|
42
|
+
throw new Error('Invalid Modified arguments: states is missing');
|
|
43
|
+
}
|
|
44
|
+
if (!options.objects) {
|
|
45
|
+
throw new Error('Invalid arguments: objects is missing');
|
|
46
|
+
}
|
|
47
|
+
if (!options.processExit) {
|
|
48
|
+
throw new Error('Invalid arguments: processExit is missing');
|
|
49
|
+
}
|
|
50
|
+
this.config = fs.readJSONSync(js_controller_common_2.tools.getConfigFileName());
|
|
51
|
+
this.objects = options.objects;
|
|
52
|
+
this.states = options.states;
|
|
53
|
+
this.processExit = options.processExit;
|
|
54
|
+
}
|
|
55
|
+
static _perm2str(perm) {
|
|
56
|
+
let result = '';
|
|
57
|
+
// user
|
|
58
|
+
result += perm & 0x400 ? 'r' : '-';
|
|
59
|
+
result += perm & 0x200 ? 'w' : '-';
|
|
60
|
+
result += perm & 0x100 ? 'x' : '-';
|
|
61
|
+
// group
|
|
62
|
+
result += perm & 0x040 ? 'r' : '-';
|
|
63
|
+
result += perm & 0x020 ? 'w' : '-';
|
|
64
|
+
result += perm & 0x010 ? 'x' : '-';
|
|
65
|
+
// any
|
|
66
|
+
result += perm & 0x004 ? 'r' : '-';
|
|
67
|
+
result += perm & 0x002 ? 'w' : '-';
|
|
68
|
+
result += perm & 0x001 ? 'x' : '-';
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
showFileHeader(adapter) {
|
|
72
|
+
adapter && console.log(`\n-- ${adapter} --`);
|
|
73
|
+
console.log(' Modified at |Permission| User | Group | Size | Name');
|
|
74
|
+
console.log('----------------+----------+--------------+--------------+------+---------');
|
|
75
|
+
}
|
|
76
|
+
showFile(adapter, path, file) {
|
|
77
|
+
//drwxr-xr-x 1 odroid odroid 43 Oct 3 2013 .xsessionrc
|
|
78
|
+
let text = '';
|
|
79
|
+
let time = '';
|
|
80
|
+
if (file.modifiedAt) {
|
|
81
|
+
const ts = new Date(file.modifiedAt);
|
|
82
|
+
time = ts.toISOString();
|
|
83
|
+
time = time.replace('T', ' ');
|
|
84
|
+
time = time.substring(0, 16) + ' ';
|
|
85
|
+
}
|
|
86
|
+
text += time.padEnd(17);
|
|
87
|
+
if (file.acl) {
|
|
88
|
+
text += (file.isDir ? 'd' : '-') + List._perm2str(file.acl.permissions || 0);
|
|
89
|
+
let owner = file.acl.owner;
|
|
90
|
+
// cut system.user.
|
|
91
|
+
owner = owner.substring(12);
|
|
92
|
+
text += ` ${owner.padStart(14)}`;
|
|
93
|
+
let group = file.acl.ownerGroup;
|
|
94
|
+
// cut system.group.
|
|
95
|
+
group = group.substring(13);
|
|
96
|
+
text += ` ${group.padStart(14)}`;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
text += (file.isDir ? 'd' : '-') + '?????????' + new Array(31).join(' ');
|
|
100
|
+
}
|
|
101
|
+
const size = file.stats && file.stats.size ? file.stats.size.toString() : '';
|
|
102
|
+
text += ` ${size.padStart(6)} ${adapter}${!path || path[0] === '/' ? '' : '/'}${path}/${file.file}`;
|
|
103
|
+
if (file.isDir) {
|
|
104
|
+
text += '/';
|
|
105
|
+
console.log(text);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(text);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
showObjectHeader() {
|
|
112
|
+
console.log('ObjectAC | StateAC | User | Group | ID');
|
|
113
|
+
console.log('---------+---------+--------------+--------------+--------------');
|
|
114
|
+
}
|
|
115
|
+
showObject(obj) {
|
|
116
|
+
//drwxr-xr-x 1 odroid odroid 43 Oct 3 2013 .xsessionrc
|
|
117
|
+
let text = '';
|
|
118
|
+
if (obj.acl) {
|
|
119
|
+
text += `${List._perm2str(obj.acl.object || 0)} ${obj.type === 'state' ? List._perm2str(obj.acl.state || 0) : ' '}`;
|
|
120
|
+
let owner = obj.acl.owner;
|
|
121
|
+
// cut system.user.
|
|
122
|
+
owner = owner.substring(12);
|
|
123
|
+
text += ` ${owner.padStart(14)}`;
|
|
124
|
+
let group = obj.acl.ownerGroup;
|
|
125
|
+
// cut system.group.
|
|
126
|
+
group = group.substring(13);
|
|
127
|
+
text += ` ${group.padStart(14)}`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
text += `?????????${obj.type === 'state' ? ' ?????????' : ' '}${new Array(31).join(' ')}`;
|
|
131
|
+
}
|
|
132
|
+
text += ` ${obj._id}`;
|
|
133
|
+
console.log(text);
|
|
134
|
+
}
|
|
135
|
+
listDirectory(adapter, path, allFiles, callback) {
|
|
136
|
+
if (typeof path === 'function') {
|
|
137
|
+
callback = path;
|
|
138
|
+
path = '';
|
|
139
|
+
allFiles = [];
|
|
140
|
+
}
|
|
141
|
+
if (typeof allFiles === 'function') {
|
|
142
|
+
callback = allFiles;
|
|
143
|
+
allFiles = [];
|
|
144
|
+
}
|
|
145
|
+
const _allFiles = allFiles || [];
|
|
146
|
+
const _path = path || '';
|
|
147
|
+
this.objects.readDir(adapter, _path, null, (err, files) => {
|
|
148
|
+
if (err && err.code === 'ENOTDIR') {
|
|
149
|
+
const pos = _path.lastIndexOf('/');
|
|
150
|
+
if (pos !== -1) {
|
|
151
|
+
const dir = _path.substring(0, pos);
|
|
152
|
+
const fname = _path.substring(pos + 1);
|
|
153
|
+
this.objects.readDir(adapter, dir, null, (err, files) => {
|
|
154
|
+
if (err) {
|
|
155
|
+
console.log(`Cannot read "${path}": ${err.message}`);
|
|
156
|
+
typeof callback === 'function' && callback(_allFiles);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// @ts-expect-error if no error, files are guranteed to be an Array https://github.com/ioBroker/adapter-core/issues/455
|
|
160
|
+
for (const file of files) {
|
|
161
|
+
if (file.file === '.' || file.file === '..') {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (file.file === fname) {
|
|
165
|
+
_allFiles.push({ adapter, path: _path, file });
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
typeof callback === 'function' && callback(_allFiles);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else if (typeof callback === 'function') {
|
|
174
|
+
callback(_allFiles);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
let count = 0;
|
|
179
|
+
// @ts-expect-error if no error, files are guranteed to be an Array https://github.com/ioBroker/adapter-core/issues/455
|
|
180
|
+
for (const file of files) {
|
|
181
|
+
if (file.file === '.' || file.file === '..') {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
_allFiles.push({ adapter: adapter, path: _path, file });
|
|
185
|
+
if (file.isDir) {
|
|
186
|
+
count++;
|
|
187
|
+
this.listDirectory(adapter, `${path}/${file.file}`, allFiles, () => {
|
|
188
|
+
if (!--count && callback) {
|
|
189
|
+
typeof callback === 'function' && callback(_allFiles);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!count && typeof callback === 'function') {
|
|
195
|
+
callback(_allFiles);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
sortFiles(a, b) {
|
|
201
|
+
let a1 = a.path + a.file.file;
|
|
202
|
+
if (a1[0] !== '/') {
|
|
203
|
+
a1 = '/' + a1;
|
|
204
|
+
}
|
|
205
|
+
let b1 = b.path + b.file.file;
|
|
206
|
+
if (b1[0] !== '/') {
|
|
207
|
+
b1 = '/' + b1;
|
|
208
|
+
}
|
|
209
|
+
return a1.localeCompare(b1);
|
|
210
|
+
}
|
|
211
|
+
listAdaptersFiles(adapters, filter, callback) {
|
|
212
|
+
if (typeof filter === 'function') {
|
|
213
|
+
callback = filter;
|
|
214
|
+
filter = null;
|
|
215
|
+
}
|
|
216
|
+
if (filter) {
|
|
217
|
+
filter = filter.replace(/\*/g, '');
|
|
218
|
+
if (filter[filter.length - 1] === '/') {
|
|
219
|
+
filter = filter.substring(0, filter.length - 1);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (adapters && adapters.length) {
|
|
223
|
+
const adapter = adapters.shift();
|
|
224
|
+
this.listDirectory(adapter, filter, files => {
|
|
225
|
+
files.sort(this.sortFiles);
|
|
226
|
+
this.showFileHeader(adapter);
|
|
227
|
+
files
|
|
228
|
+
.filter(f => !filter || `${f.path}/${f.file.file}`.startsWith(filter))
|
|
229
|
+
.forEach(f => this.showFile(f.adapter, f.path, f.file));
|
|
230
|
+
this.listAdaptersFiles(adapters, filter, callback);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
return js_controller_common_2.tools.maybeCallback(callback);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
_readOnlineState(lines, flags, cb, _result) {
|
|
238
|
+
const result = _result || [];
|
|
239
|
+
if (!lines || !lines.length) {
|
|
240
|
+
cb(result);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
const task = lines.shift();
|
|
244
|
+
const id = `${task.id}.alive`;
|
|
245
|
+
this.states.getState(id, (err, state) => {
|
|
246
|
+
if (state && state.val) {
|
|
247
|
+
result.push(`+ ${task.value}`);
|
|
248
|
+
}
|
|
249
|
+
else if (!flags.alive) {
|
|
250
|
+
result.push(` ${task.value}`);
|
|
251
|
+
}
|
|
252
|
+
setImmediate(() => this._readOnlineState(lines, flags, cb, result));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
list(type, filter, flags) {
|
|
257
|
+
this.objects.getObject('system.config', (err, systemConf) => {
|
|
258
|
+
const lang = (systemConf && systemConf.common && systemConf.common.language) || 'en';
|
|
259
|
+
switch (type) {
|
|
260
|
+
case 'objects':
|
|
261
|
+
case 'o':
|
|
262
|
+
this.objects.getObjectList({}, (err, objs) => {
|
|
263
|
+
var _a, _b;
|
|
264
|
+
if (!objs) {
|
|
265
|
+
this.processExit();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const reg = filter ? new RegExp(js_controller_common_2.tools.pattern2RegEx(filter)) : null;
|
|
269
|
+
for (const obj of objs.rows) {
|
|
270
|
+
let name = (_b = (_a = obj.value) === null || _a === void 0 ? void 0 : _a.common) === null || _b === void 0 ? void 0 : _b.name;
|
|
271
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
272
|
+
name = name[lang] || name.en;
|
|
273
|
+
}
|
|
274
|
+
if (!reg || reg.test(obj.value._id) || (name && reg.test(name))) {
|
|
275
|
+
if (obj.value.type) {
|
|
276
|
+
const id = obj.value._id;
|
|
277
|
+
const type = obj.value.type;
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
279
|
+
console.log(`${id.padStart(39)}: ${type.padStart(39)} - ${name || ''}`);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
// @ts-expect-error if we would have an design object it would have no type
|
|
283
|
+
console.log(obj.value._id);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
this.processExit();
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
case 'states':
|
|
291
|
+
case 's':
|
|
292
|
+
this.states.getKeys(filter || '*', (err, keys) => {
|
|
293
|
+
if (err) {
|
|
294
|
+
console.error(err);
|
|
295
|
+
return void this.processExit(js_controller_common_1.EXIT_CODES.CANNOT_GET_STATES);
|
|
296
|
+
}
|
|
297
|
+
if (!keys) {
|
|
298
|
+
return void this.processExit();
|
|
299
|
+
}
|
|
300
|
+
this.states.getStates(keys, (err, states) => {
|
|
301
|
+
if (err || !states) {
|
|
302
|
+
console.error(err);
|
|
303
|
+
return void this.processExit(js_controller_common_1.EXIT_CODES.CANNOT_GET_STATES);
|
|
304
|
+
}
|
|
305
|
+
for (let i = 0; i < states.length; i++) {
|
|
306
|
+
const state = states[i];
|
|
307
|
+
if (!state) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const id = keys[i];
|
|
311
|
+
const from = state.from || '';
|
|
312
|
+
const type = typeof state.val;
|
|
313
|
+
console.log(`${id.padEnd(39)}: from [${from.padEnd(29)}] (${type.padEnd(9)}) ${state.ack ? ' ack' : 'not ack'} ${JSON.stringify(state.val)}`);
|
|
314
|
+
}
|
|
315
|
+
this.processExit();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
break;
|
|
319
|
+
case 'adapters':
|
|
320
|
+
case 'a':
|
|
321
|
+
this.objects.getObjectList({ startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' }, (err, objs) => {
|
|
322
|
+
if (!objs) {
|
|
323
|
+
this.processExit();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const reg = filter ? new RegExp(js_controller_common_2.tools.pattern2RegEx('system.adapter.' + filter)) : null;
|
|
327
|
+
for (const obj of objs.rows) {
|
|
328
|
+
if (obj.value.type !== 'adapter') {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (!reg ||
|
|
332
|
+
reg.test(obj.value._id) ||
|
|
333
|
+
(obj.value.common && reg.test(obj.value.common.name))) {
|
|
334
|
+
const id = obj.value._id;
|
|
335
|
+
let name = obj.value.common.name;
|
|
336
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
337
|
+
name = name[lang] || name.en;
|
|
338
|
+
}
|
|
339
|
+
const text = `${id.padEnd(39)}: ${name.padEnd(14)} - v${obj.value.common.version}`;
|
|
340
|
+
console.log(text);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
this.processExit();
|
|
344
|
+
});
|
|
345
|
+
break;
|
|
346
|
+
case 'instances':
|
|
347
|
+
case 'i':
|
|
348
|
+
this.objects.getObjectList({ startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' }, (err, objs) => {
|
|
349
|
+
var _a;
|
|
350
|
+
if (!objs) {
|
|
351
|
+
this.processExit();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const reg = filter ? new RegExp(js_controller_common_2.tools.pattern2RegEx(`system.adapter.${filter}`)) : null;
|
|
355
|
+
objs.rows.sort((a, b) => {
|
|
356
|
+
if (a.id > b.id) {
|
|
357
|
+
return 1;
|
|
358
|
+
}
|
|
359
|
+
else if (a.id < b.id) {
|
|
360
|
+
return -1;
|
|
361
|
+
}
|
|
362
|
+
return 0;
|
|
363
|
+
});
|
|
364
|
+
const lines = [];
|
|
365
|
+
for (const row of objs.rows) {
|
|
366
|
+
if (row.value.type !== 'instance') {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
let name = (_a = row.value.common) === null || _a === void 0 ? void 0 : _a.name;
|
|
370
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
371
|
+
name = name[lang] || name.en;
|
|
372
|
+
}
|
|
373
|
+
if (!reg || reg.test(row.value._id) || (name && reg.test(name))) {
|
|
374
|
+
if (flags.enabled && !row.value.common.enabled) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (flags.disabled && row.value.common.enabled) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (flags.port && row.value.native.port === undefined) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (flags.ssl && row.value.native.secure === undefined) {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (flags.ip && row.value.native.bind === undefined) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
let id = row.value._id;
|
|
390
|
+
let host = row.value.common.host;
|
|
391
|
+
if (id.length < 40) {
|
|
392
|
+
id = id.padEnd(40);
|
|
393
|
+
}
|
|
394
|
+
if (name && name.length < 22) {
|
|
395
|
+
name = name.padEnd(22);
|
|
396
|
+
}
|
|
397
|
+
if (host && host.length < 40) {
|
|
398
|
+
host = host.padEnd(40);
|
|
399
|
+
}
|
|
400
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
401
|
+
let text = `${id}: ${name || ''}: ${host} - ${row.value.common.enabled ? ' enabled' : 'disabled'}`;
|
|
402
|
+
if (this.config.system && this.config.system.compact && row.value.common.compact) {
|
|
403
|
+
text +=
|
|
404
|
+
', compact ' +
|
|
405
|
+
(row.value.common.compact && row.value.common.runAsCompactMode
|
|
406
|
+
? `enabled (group ${row.value.common.compactGroup !== undefined
|
|
407
|
+
? row.value.common.compactGroup
|
|
408
|
+
: 1})`
|
|
409
|
+
: 'disabled');
|
|
410
|
+
}
|
|
411
|
+
if (row.value.native && row.value.native.port) {
|
|
412
|
+
text += `, port: ${row.value.native.port}`;
|
|
413
|
+
}
|
|
414
|
+
if (row.value.native && row.value.native.bind) {
|
|
415
|
+
text += `, bind: ${row.value.native.bind}`;
|
|
416
|
+
}
|
|
417
|
+
if (row.value.native && row.value.native.secure) {
|
|
418
|
+
text += ' (SSL)';
|
|
419
|
+
}
|
|
420
|
+
if (row.value.native && row.value.native.defaultUser) {
|
|
421
|
+
text += `, run as: ${row.value.native.defaultUser}`;
|
|
422
|
+
}
|
|
423
|
+
lines.push({ id: row.value._id, value: text });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
this._readOnlineState(lines, flags, result => {
|
|
427
|
+
console.log(result.join('\n'));
|
|
428
|
+
console.log('\n+ instance is alive');
|
|
429
|
+
this.processExit();
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
break;
|
|
433
|
+
case 'users':
|
|
434
|
+
case 'u':
|
|
435
|
+
this.objects.getObjectList({ startkey: 'system.user.', endkey: 'system.user.\u9999' }, (err, objs) => {
|
|
436
|
+
this.objects.getObjectList({ startkey: 'system.group.', endkey: 'system.group.\u9999' }, (err, groups) => {
|
|
437
|
+
if (!objs) {
|
|
438
|
+
this.processExit();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const reg = filter
|
|
442
|
+
? new RegExp(js_controller_common_2.tools.pattern2RegEx('system.user.' + filter))
|
|
443
|
+
: null;
|
|
444
|
+
console.log(' ID | Name | Active | Groups');
|
|
445
|
+
console.log('---------------------------------------+-------------+----------+--------------');
|
|
446
|
+
for (const obj of objs.rows) {
|
|
447
|
+
if (obj.value.type !== 'user') {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!reg ||
|
|
451
|
+
reg.test(obj.value._id) ||
|
|
452
|
+
(obj.value.common && reg.test(obj.value.common.name))) {
|
|
453
|
+
const id = obj.value._id;
|
|
454
|
+
let name = obj.value.common.name;
|
|
455
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
456
|
+
name = name[lang] || name.en;
|
|
457
|
+
}
|
|
458
|
+
const text = `${id.padEnd(39)}| ${name.padEnd(11)} | ${obj.value.common.enabled ? ' enabled' : 'disabled'} |`;
|
|
459
|
+
if (groups) {
|
|
460
|
+
const gs = [];
|
|
461
|
+
// find all groups
|
|
462
|
+
for (const group of groups.rows) {
|
|
463
|
+
if (group.value.common.members &&
|
|
464
|
+
group.value.common.members.indexOf(obj.value._id) !== -1) {
|
|
465
|
+
gs.push(group.value._id.substring(13));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
console.log(`${text} ${gs.join(', ')}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
this.processExit();
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
break;
|
|
476
|
+
case 'groups':
|
|
477
|
+
case 'g':
|
|
478
|
+
this.objects.getObjectList({ startkey: 'system.group.', endkey: 'system.group.\u9999' }, (err, objs) => {
|
|
479
|
+
if (!objs) {
|
|
480
|
+
this.processExit();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const reg = filter ? new RegExp(js_controller_common_2.tools.pattern2RegEx('system.group.' + filter)) : null;
|
|
484
|
+
console.log('');
|
|
485
|
+
console.log(' system.group | object | state | file | user | others | users');
|
|
486
|
+
console.log(' | l r w d | l r w d | l r w c d | w c d | |');
|
|
487
|
+
console.log('--------------------+---------+---------+-----------+-------+------------------------+---------');
|
|
488
|
+
for (const obj of objs.rows) {
|
|
489
|
+
if (obj.value.type !== 'group') {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (!reg ||
|
|
493
|
+
reg.test(obj.value._id) ||
|
|
494
|
+
(obj.value.common && reg.test(obj.value.common.name))) {
|
|
495
|
+
const id = obj.value._id.substring(13);
|
|
496
|
+
//let name = objs.rows[i].value.common.name;
|
|
497
|
+
if (id === 'administrator') {
|
|
498
|
+
obj.value.common.acl = {
|
|
499
|
+
file: {
|
|
500
|
+
read: true,
|
|
501
|
+
write: true,
|
|
502
|
+
delete: true,
|
|
503
|
+
create: true,
|
|
504
|
+
list: true
|
|
505
|
+
},
|
|
506
|
+
// @ts-expect-error todo discuss, is create missing or intended?
|
|
507
|
+
object: {
|
|
508
|
+
read: true,
|
|
509
|
+
write: true,
|
|
510
|
+
delete: true,
|
|
511
|
+
list: true
|
|
512
|
+
},
|
|
513
|
+
state: {
|
|
514
|
+
read: true,
|
|
515
|
+
write: true,
|
|
516
|
+
delete: true,
|
|
517
|
+
create: true,
|
|
518
|
+
list: true
|
|
519
|
+
},
|
|
520
|
+
user: {
|
|
521
|
+
write: true,
|
|
522
|
+
create: true,
|
|
523
|
+
delete: true
|
|
524
|
+
},
|
|
525
|
+
other: {
|
|
526
|
+
execute: true,
|
|
527
|
+
http: true,
|
|
528
|
+
sendto: true
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
let text = id.padEnd(19);
|
|
533
|
+
text += ' | ';
|
|
534
|
+
if (obj.value.common.acl && obj.value.common.acl.object) {
|
|
535
|
+
text += (obj.value.common.acl.object.list ? '+' : '-') + ' ';
|
|
536
|
+
text += (obj.value.common.acl.object.read ? '+' : '-') + ' ';
|
|
537
|
+
text += (obj.value.common.acl.object.write ? '+' : '-') + ' ';
|
|
538
|
+
text += (obj.value.common.acl.object.delete ? '+' : '-') + ' ';
|
|
539
|
+
text += '|';
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
text += ' |';
|
|
543
|
+
}
|
|
544
|
+
if (obj.value.common.acl && obj.value.common.acl.state) {
|
|
545
|
+
text += ' ';
|
|
546
|
+
text += (obj.value.common.acl.state.list ? '+' : '-') + ' ';
|
|
547
|
+
text += (obj.value.common.acl.state.read ? '+' : '-') + ' ';
|
|
548
|
+
text += (obj.value.common.acl.state.write ? '+' : '-') + ' ';
|
|
549
|
+
text += (obj.value.common.acl.state.delete ? '+' : '-') + ' ';
|
|
550
|
+
text += '|';
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
text += ' |';
|
|
554
|
+
}
|
|
555
|
+
if (obj.value.common.acl && obj.value.common.acl.file) {
|
|
556
|
+
text += ' ';
|
|
557
|
+
text += (obj.value.common.acl.file.list ? '+' : '-') + ' ';
|
|
558
|
+
text += (obj.value.common.acl.file.read ? '+' : '-') + ' ';
|
|
559
|
+
text += (obj.value.common.acl.file.write ? '+' : '-') + ' ';
|
|
560
|
+
text += (obj.value.common.acl.file.create ? '+' : '-') + ' ';
|
|
561
|
+
text += (obj.value.common.acl.file.delete ? '+' : '-') + ' ';
|
|
562
|
+
text += '|';
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
text += ' |';
|
|
566
|
+
}
|
|
567
|
+
if (obj.value.common.acl && obj.value.common.acl.users) {
|
|
568
|
+
text += ' ';
|
|
569
|
+
text += (obj.value.common.acl.users.write ? '+' : '-') + ' ';
|
|
570
|
+
text += (obj.value.common.acl.users.create ? '+' : '-') + ' ';
|
|
571
|
+
text += (obj.value.common.acl.users.delete ? '+' : '-') + ' ';
|
|
572
|
+
text += '|';
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
text += ' |';
|
|
576
|
+
}
|
|
577
|
+
if (obj.value.common.acl && obj.value.common.acl.other) {
|
|
578
|
+
text += ' ';
|
|
579
|
+
let others = '';
|
|
580
|
+
for (const [r, otherPerm] of Object.entries(obj.value.common.acl.other)) {
|
|
581
|
+
others += r + (otherPerm ? '+' : '-') + ' ';
|
|
582
|
+
}
|
|
583
|
+
text += `${others.padEnd(22)}|`;
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
text += new Array(25).join(' ') + '|';
|
|
587
|
+
}
|
|
588
|
+
if (obj.value.common.members) {
|
|
589
|
+
for (let m = 0; m < obj.value.common.members.length; m++) {
|
|
590
|
+
obj.value.common.members[m] = obj.value.common.members[m].substring(12);
|
|
591
|
+
}
|
|
592
|
+
text += ` ${obj.value.common.members.join(', ')}`;
|
|
593
|
+
}
|
|
594
|
+
console.log(text);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
console.log('--------------------+---------+---------+-----------+-------+------------------------+---------');
|
|
598
|
+
console.log('Legend: (l)ist, (r)ead, (w)rite, (c)reate, (d)elete');
|
|
599
|
+
this.processExit();
|
|
600
|
+
});
|
|
601
|
+
break;
|
|
602
|
+
case 'h':
|
|
603
|
+
case 'hosts':
|
|
604
|
+
this.objects.getObjectList({ startkey: 'system.host.', endkey: 'system.host.\u9999' }, (err, objs) => {
|
|
605
|
+
if (!objs) {
|
|
606
|
+
this.processExit();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
this.states.getKeys('system.host.*', (err, keys) => {
|
|
610
|
+
if (!keys) {
|
|
611
|
+
this.processExit();
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
this.states.getStates(keys, (err, states) => {
|
|
615
|
+
var _a;
|
|
616
|
+
if (!states) {
|
|
617
|
+
this.processExit();
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const reg = filter
|
|
621
|
+
? new RegExp(js_controller_common_2.tools.pattern2RegEx('system.host.' + filter))
|
|
622
|
+
: null;
|
|
623
|
+
for (const obj of objs.rows) {
|
|
624
|
+
if (obj.value.type !== 'host') {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (!reg ||
|
|
628
|
+
reg.test(obj.value._id) ||
|
|
629
|
+
(obj.value.common && reg.test(obj.value.common.name))) {
|
|
630
|
+
const id = obj.value._id.substring(12);
|
|
631
|
+
let name = obj.value.common.name;
|
|
632
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
633
|
+
name = name[lang] || name.en;
|
|
634
|
+
}
|
|
635
|
+
const hostname = obj.value.common.hostname;
|
|
636
|
+
const version = obj.value.common.installedVersion;
|
|
637
|
+
let alive = '';
|
|
638
|
+
let uptime = '';
|
|
639
|
+
for (let k = 0; k < keys.length; k++) {
|
|
640
|
+
if (keys[k] === `${obj.value._id}.alive`) {
|
|
641
|
+
alive = 'alive';
|
|
642
|
+
}
|
|
643
|
+
if (keys[k] === `${obj.value._id}.uptime`) {
|
|
644
|
+
uptime = ((_a = states[k].val) === null || _a === void 0 ? void 0 : _a.toString()) || '-';
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
alive = alive || 'dead';
|
|
648
|
+
if (!uptime) {
|
|
649
|
+
uptime = '-';
|
|
650
|
+
}
|
|
651
|
+
const text = `${id.padEnd(19)} ${name} (version: ${version}, hostname: ${hostname.padEnd(14)}, ${alive}, uptime: ${uptime})`;
|
|
652
|
+
// todo
|
|
653
|
+
console.log(text);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
this.processExit();
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
break;
|
|
661
|
+
case 'enums':
|
|
662
|
+
case 'e':
|
|
663
|
+
this.objects.getObjectList({ startkey: 'enum.', endkey: 'enum.\u9999' }, (err, objs) => {
|
|
664
|
+
var _a;
|
|
665
|
+
if (!objs) {
|
|
666
|
+
this.processExit();
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const reg = filter ? new RegExp(js_controller_common_2.tools.pattern2RegEx(`enum.${filter}`)) : null;
|
|
670
|
+
for (const obj of objs.rows) {
|
|
671
|
+
if (obj.value.type !== 'enum') {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
let name = (_a = obj.value.common) === null || _a === void 0 ? void 0 : _a.name;
|
|
675
|
+
if (js_controller_common_2.tools.isObject(name)) {
|
|
676
|
+
name = name[lang] || name.en;
|
|
677
|
+
}
|
|
678
|
+
if (!reg || reg.test(obj.value._id) || (name && reg.test(name))) {
|
|
679
|
+
console.log('\n=====================================================================================');
|
|
680
|
+
const id = obj.value._id.substring(5);
|
|
681
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
682
|
+
console.log(`${id.padEnd(19)}(${name})`);
|
|
683
|
+
console.log('-------------------------------------------------------------------------------------');
|
|
684
|
+
if (obj.value.common.members) {
|
|
685
|
+
console.log(obj.value.common.members.join(', '));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
this.processExit();
|
|
690
|
+
});
|
|
691
|
+
break;
|
|
692
|
+
case 'files':
|
|
693
|
+
case 'f':
|
|
694
|
+
this.objects.getObjectList({ startkey: '', endkey: '\u9999' }, (err, objs) => {
|
|
695
|
+
if (!objs) {
|
|
696
|
+
this.processExit();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
const adapter = filter || null;
|
|
700
|
+
const names = filter ? filter.split('/') : null;
|
|
701
|
+
if (names && !names[0]) {
|
|
702
|
+
names.splice(0, 1);
|
|
703
|
+
}
|
|
704
|
+
const adapters = objs.rows
|
|
705
|
+
.filter(row => row.value.type === 'meta' &&
|
|
706
|
+
!(names &&
|
|
707
|
+
adapter &&
|
|
708
|
+
row.value._id !== names[0] &&
|
|
709
|
+
!row.value._id.startsWith(`${names[0]}.`)))
|
|
710
|
+
.map(row => row.value._id);
|
|
711
|
+
if (names) {
|
|
712
|
+
names.shift();
|
|
713
|
+
}
|
|
714
|
+
this.listAdaptersFiles(adapters, names ? names.join('/') : null, () => this.processExit());
|
|
715
|
+
});
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
exports.List = List;
|
|
722
|
+
//# sourceMappingURL=setupList.js.map
|