@iobroker/socket-classes 1.4.1 → 1.4.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/README.md +7 -1
- package/lib/socketCommands.js +328 -225
- package/lib/socketCommandsAdmin.js +379 -241
- package/lib/socketCommon.js +76 -52
- package/package.json +6 -5
|
@@ -13,7 +13,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
13
13
|
'getLocationOnDisk',
|
|
14
14
|
'getDevList',
|
|
15
15
|
'getLogs',
|
|
16
|
-
'getHostInfo'
|
|
16
|
+
'getHostInfo'
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
constructor(adapter, updateSession, objects, states) {
|
|
@@ -26,16 +26,15 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
26
26
|
this.cmdSessions = {};
|
|
27
27
|
|
|
28
28
|
this.eventsThreshold = {
|
|
29
|
-
count:
|
|
30
|
-
timeActivated:
|
|
31
|
-
active:
|
|
32
|
-
accidents:
|
|
33
|
-
repeatSeconds:
|
|
34
|
-
value:
|
|
35
|
-
checkInterval:
|
|
29
|
+
count: 0,
|
|
30
|
+
timeActivated: 0,
|
|
31
|
+
active: false,
|
|
32
|
+
accidents: 0,
|
|
33
|
+
repeatSeconds: 3, // how many seconds continuously must be number of events > value
|
|
34
|
+
value: parseInt(adapter.config.thresholdValue, 10) || 200, // how many events allowed in one check interval
|
|
35
|
+
checkInterval: 1000 // duration of one check interval
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
this.cache = {};
|
|
40
39
|
this.cacheGB = null; // cache garbage collector
|
|
41
40
|
// do not send too many state updates
|
|
@@ -70,9 +69,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
try {
|
|
73
|
-
const response = await axios.get(`https://rating.iobroker.net/rating?uuid=${uuid}`, {
|
|
72
|
+
const response = await axios.get(`https://rating.iobroker.net/rating?uuid=${uuid}`, {
|
|
73
|
+
timeout: 15000,
|
|
74
|
+
validateStatus: status => status < 400
|
|
75
|
+
});
|
|
74
76
|
this.adapter._ratings = response.data;
|
|
75
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
!this.adapter._ratings ||
|
|
79
|
+
typeof this.adapter._ratings !== 'object' ||
|
|
80
|
+
Array.isArray(this.adapter._ratings)
|
|
81
|
+
) {
|
|
76
82
|
this.adapter._ratings = {};
|
|
77
83
|
}
|
|
78
84
|
this.adapter._ratings.uuid = uuid;
|
|
@@ -82,32 +88,35 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
82
88
|
this.adapter.ratingTimeout && clearTimeout(this.adapter.ratingTimeout);
|
|
83
89
|
this.adapter.ratingTimeout = setTimeout(() => {
|
|
84
90
|
this.adapter.ratingTimeout = null;
|
|
85
|
-
this.updateRatings(uuid, true)
|
|
86
|
-
.then(() => this.adapter.log.info('Adapter rating updated'));
|
|
91
|
+
this.updateRatings(uuid, true).then(() => this.adapter.log.info('Adapter rating updated'));
|
|
87
92
|
}, 24 * 3600000);
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
return this.adapter._ratings;
|
|
91
96
|
} catch (error) {
|
|
92
|
-
this.adapter.log.warn(
|
|
97
|
+
this.adapter.log.warn(
|
|
98
|
+
'Cannot update rating: ' + (error.response ? error.response.data : error.message || error.code)
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
_readInstanceConfig(id, user, isTab, configs) {
|
|
97
104
|
return new Promise(resolve =>
|
|
98
|
-
this.adapter.getForeignObject(`system.adapter.${id}`, {user}, (error, obj) => {
|
|
105
|
+
this.adapter.getForeignObject(`system.adapter.${id}`, { user }, (error, obj) => {
|
|
99
106
|
if (obj && obj.common) {
|
|
100
107
|
const instance = id.split('.').pop();
|
|
101
108
|
const config = {
|
|
102
109
|
id,
|
|
103
|
-
title:
|
|
104
|
-
desc:
|
|
105
|
-
color:
|
|
106
|
-
url:
|
|
107
|
-
|
|
110
|
+
title: obj.common.titleLang || obj.common.title,
|
|
111
|
+
desc: obj.common.desc,
|
|
112
|
+
color: obj.common.color,
|
|
113
|
+
url: `/adapter/${obj.common.name}/${isTab ? 'tab' : 'index'}${
|
|
114
|
+
!isTab && obj.common.materialize ? '_m' : ''
|
|
115
|
+
}.html${instance ? `?${instance}` : ''}`,
|
|
116
|
+
icon: obj.common.icon,
|
|
108
117
|
materialize: obj.common.materialize,
|
|
109
|
-
jsonConfig:
|
|
110
|
-
version:
|
|
118
|
+
jsonConfig: obj.common.jsonConfig,
|
|
119
|
+
version: obj.common.version
|
|
111
120
|
};
|
|
112
121
|
if (isTab) {
|
|
113
122
|
config.tab = true;
|
|
@@ -123,14 +132,18 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
123
132
|
configs.push(config);
|
|
124
133
|
}
|
|
125
134
|
resolve();
|
|
126
|
-
})
|
|
135
|
+
})
|
|
136
|
+
);
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
_sendToHost(host, command, message, callback) {
|
|
130
140
|
const hash = `${host}_${command}`;
|
|
131
141
|
if (!message && SocketCommandsAdmin.ALLOW_CACHE.includes(command) && this.cache[hash]) {
|
|
132
142
|
if (Date.now() - this.cache[hash].ts < 500) {
|
|
133
|
-
return
|
|
143
|
+
return (
|
|
144
|
+
typeof callback === 'function' &&
|
|
145
|
+
setImmediate(data => callback(data), JSON.parse(this.cache[hash].res))
|
|
146
|
+
);
|
|
134
147
|
} else {
|
|
135
148
|
delete this.cache[hash];
|
|
136
149
|
}
|
|
@@ -139,20 +152,22 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
139
152
|
try {
|
|
140
153
|
this.adapter.sendToHost(host, command, message, res => {
|
|
141
154
|
if (!message && SocketCommandsAdmin.ALLOW_CACHE.includes(command)) {
|
|
142
|
-
this.cache[hash] = {ts: Date.now(), res: JSON.stringify(res)};
|
|
143
|
-
|
|
144
|
-
this.cacheGB =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
this.cache[hash] = { ts: Date.now(), res: JSON.stringify(res) };
|
|
156
|
+
|
|
157
|
+
this.cacheGB =
|
|
158
|
+
this.cacheGB ||
|
|
159
|
+
setInterval(() => {
|
|
160
|
+
const commands = Object.keys(this.cache);
|
|
161
|
+
commands.forEach(cmd => {
|
|
162
|
+
if (Date.now() - this.cache[cmd].ts > 500) {
|
|
163
|
+
delete this.cache[cmd];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
if (!commands.length) {
|
|
167
|
+
clearInterval(this.cacheGB);
|
|
168
|
+
this.cacheGB = null;
|
|
149
169
|
}
|
|
150
|
-
});
|
|
151
|
-
if (!commands.length) {
|
|
152
|
-
clearInterval(this.cacheGB);
|
|
153
|
-
this.cacheGB = null;
|
|
154
|
-
}
|
|
155
|
-
}, 2000);
|
|
170
|
+
}, 2000);
|
|
156
171
|
}
|
|
157
172
|
typeof callback === 'function' && setImmediate(() => callback(res));
|
|
158
173
|
});
|
|
@@ -170,17 +185,27 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
170
185
|
validateStatus: status => status < 400
|
|
171
186
|
};
|
|
172
187
|
|
|
173
|
-
return axios
|
|
188
|
+
return axios
|
|
189
|
+
.get(`https://iobroker.net:3001/api/v1/licenses`, config)
|
|
174
190
|
.then(response => {
|
|
175
191
|
if (response.data && response.data.length) {
|
|
176
192
|
const now = Date.now();
|
|
177
|
-
response.data = response.data.filter(
|
|
193
|
+
response.data = response.data.filter(
|
|
194
|
+
license =>
|
|
195
|
+
!license.validTill ||
|
|
196
|
+
license.validTill === '0000-00-00 00:00:00' ||
|
|
197
|
+
new Date(license.validTill).getTime() > now
|
|
198
|
+
);
|
|
178
199
|
}
|
|
179
200
|
return response.data;
|
|
180
201
|
})
|
|
181
202
|
.catch(error => {
|
|
182
203
|
if (error.response) {
|
|
183
|
-
throw new Error(
|
|
204
|
+
throw new Error(
|
|
205
|
+
(error.response.data && error.response.data.error) ||
|
|
206
|
+
error.response.data ||
|
|
207
|
+
error.response.status
|
|
208
|
+
);
|
|
184
209
|
} else if (error.request) {
|
|
185
210
|
throw new Error('no response');
|
|
186
211
|
} else {
|
|
@@ -196,76 +221,100 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
196
221
|
return this._readLicenses(login, password);
|
|
197
222
|
} else {
|
|
198
223
|
// get actual object
|
|
199
|
-
return this.adapter.getForeignObjectAsync('system.licenses', options)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
return this.adapter.getForeignObjectAsync('system.licenses', options).then(systemLicenses => {
|
|
225
|
+
// If password and login exist
|
|
226
|
+
if (
|
|
227
|
+
systemLicenses &&
|
|
228
|
+
systemLicenses.native &&
|
|
229
|
+
systemLicenses.native.password &&
|
|
230
|
+
systemLicenses.native.login
|
|
231
|
+
) {
|
|
232
|
+
// get the secret to decode the password
|
|
233
|
+
return this.adapter
|
|
234
|
+
.getForeignObjectAsync('system.config', options)
|
|
235
|
+
.then(systemConfig => {
|
|
236
|
+
// decode the password
|
|
237
|
+
let password;
|
|
238
|
+
try {
|
|
239
|
+
password = this.adapter.decrypt(
|
|
240
|
+
systemConfig.native.secret,
|
|
241
|
+
systemLicenses.native.password
|
|
242
|
+
);
|
|
243
|
+
} catch {
|
|
244
|
+
throw new Error('Cannot decode password');
|
|
245
|
+
}
|
|
213
246
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
247
|
+
// read licenses from iobroker.net
|
|
248
|
+
return this._readLicenses(systemLicenses.native.login, password);
|
|
249
|
+
})
|
|
250
|
+
.then(licenses => {
|
|
251
|
+
// save licenses to system.licenses and remember the time
|
|
252
|
+
// merge the information together
|
|
253
|
+
const oldLicenses = systemLicenses.native.licenses || [];
|
|
254
|
+
systemLicenses.native.licenses = licenses;
|
|
255
|
+
oldLicenses.forEach(oldLicense => {
|
|
256
|
+
if (oldLicense.usedBy) {
|
|
257
|
+
const newLicense = licenses.find(item => item.json === oldLicense.json);
|
|
258
|
+
if (newLicense) {
|
|
259
|
+
newLicense.usedBy = oldLicense.usedBy;
|
|
228
260
|
}
|
|
229
|
-
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
230
263
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
264
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
265
|
+
|
|
266
|
+
// save only if an object changed
|
|
267
|
+
return this.adapter
|
|
268
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
269
|
+
.then(() => licenses);
|
|
270
|
+
})
|
|
271
|
+
.catch(error => {
|
|
272
|
+
// if password is invalid
|
|
273
|
+
if (
|
|
274
|
+
error.message.includes('Authentication required') ||
|
|
275
|
+
error.message.includes('Cannot decode password')
|
|
276
|
+
) {
|
|
277
|
+
// clear existing licenses if exist
|
|
278
|
+
if (
|
|
279
|
+
systemLicenses &&
|
|
280
|
+
systemLicenses.native &&
|
|
281
|
+
systemLicenses.native.licenses &&
|
|
282
|
+
systemLicenses.native.licenses.length
|
|
283
|
+
) {
|
|
284
|
+
systemLicenses.native.licenses = [];
|
|
285
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
286
|
+
return this.adapter
|
|
287
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
288
|
+
.then(() => {
|
|
289
|
+
throw error;
|
|
290
|
+
});
|
|
251
291
|
} else {
|
|
252
292
|
throw error;
|
|
253
293
|
}
|
|
294
|
+
} else {
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
// if password or login are empty => clear existing licenses if exist
|
|
300
|
+
if (
|
|
301
|
+
systemLicenses &&
|
|
302
|
+
systemLicenses.native &&
|
|
303
|
+
systemLicenses.native.licenses &&
|
|
304
|
+
systemLicenses.native.licenses.length
|
|
305
|
+
) {
|
|
306
|
+
systemLicenses.native.licenses = [];
|
|
307
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
308
|
+
return this.adapter
|
|
309
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
310
|
+
.then(() => {
|
|
311
|
+
throw new Error('No password or login');
|
|
254
312
|
});
|
|
255
313
|
} else {
|
|
256
|
-
|
|
257
|
-
if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
|
|
258
|
-
systemLicenses.native.licenses = [];
|
|
259
|
-
systemLicenses.native.readTime = new Date().toISOString();
|
|
260
|
-
return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
261
|
-
.then(() => {
|
|
262
|
-
throw new Error('No password or login');
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
throw new Error('No password or login');
|
|
266
|
-
}
|
|
314
|
+
throw new Error('No password or login');
|
|
267
315
|
}
|
|
268
|
-
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
269
318
|
}
|
|
270
319
|
}
|
|
271
320
|
|
|
@@ -277,15 +326,15 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
277
326
|
this.eventsThreshold.timeActivated = 0;
|
|
278
327
|
this.adapter.log.info('Subscribe to all states again');
|
|
279
328
|
|
|
280
|
-
setTimeout(
|
|
329
|
+
setTimeout(() => {
|
|
281
330
|
this.onThresholdChanged && this.onThresholdChanged(false);
|
|
282
331
|
this.adapter.unsubscribeForeignStates('system.adapter.*');
|
|
283
332
|
|
|
284
333
|
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
285
334
|
try {
|
|
286
|
-
|
|
335
|
+
this.adapter.subscribeForeignStatesAsync(pattern);
|
|
287
336
|
} catch (e) {
|
|
288
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
337
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
289
338
|
}
|
|
290
339
|
}
|
|
291
340
|
}, 50);
|
|
@@ -296,17 +345,19 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
296
345
|
if (!this.eventsThreshold.active) {
|
|
297
346
|
this.eventsThreshold.active = true;
|
|
298
347
|
|
|
299
|
-
setTimeout(
|
|
300
|
-
this.adapter.log.info(
|
|
348
|
+
setTimeout(() => {
|
|
349
|
+
this.adapter.log.info(
|
|
350
|
+
`Unsubscribe from all states, except system's, because over ${this.eventsThreshold.repeatSeconds} seconds the number of events is over ${this.eventsThreshold.value} (in last second ${this.eventsThreshold.count})`
|
|
351
|
+
);
|
|
301
352
|
this.eventsThreshold.timeActivated = Date.now();
|
|
302
353
|
|
|
303
354
|
this.onThresholdChanged && this.onThresholdChanged(true);
|
|
304
355
|
|
|
305
356
|
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
306
357
|
try {
|
|
307
|
-
|
|
358
|
+
this.adapter.unsubscribeForeignStatesAsync(pattern);
|
|
308
359
|
} catch (e) {
|
|
309
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
360
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
310
361
|
}
|
|
311
362
|
}
|
|
312
363
|
|
|
@@ -322,7 +373,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
322
373
|
}
|
|
323
374
|
|
|
324
375
|
if (!user.match(/^[-.A-Za-züäößÖÄÜа-яА-Я@+$§0-9=?!&# ]+$/)) {
|
|
325
|
-
return SocketCommands._fixCallback(
|
|
376
|
+
return SocketCommands._fixCallback(
|
|
377
|
+
callback,
|
|
378
|
+
'Invalid characters in the name. Only following special characters are allowed: -@+$§=?!&# and letters'
|
|
379
|
+
);
|
|
326
380
|
}
|
|
327
381
|
|
|
328
382
|
try {
|
|
@@ -331,21 +385,26 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
331
385
|
SocketCommands._fixCallback(callback, 'User yet exists');
|
|
332
386
|
} else {
|
|
333
387
|
try {
|
|
334
|
-
this.adapter.setForeignObject(
|
|
388
|
+
this.adapter.setForeignObject(
|
|
389
|
+
`system.user.${user}`,
|
|
390
|
+
{
|
|
335
391
|
type: 'user',
|
|
336
392
|
common: {
|
|
337
393
|
name: user,
|
|
338
394
|
enabled: true,
|
|
339
395
|
groups: []
|
|
340
396
|
}
|
|
341
|
-
},
|
|
397
|
+
},
|
|
398
|
+
options,
|
|
399
|
+
() => {
|
|
342
400
|
try {
|
|
343
401
|
this.adapter.setPassword(user, pw, options, callback);
|
|
344
402
|
} catch (error) {
|
|
345
403
|
this.adapter.log.error(`[_addUser] cannot set password: ${error.toString()}`);
|
|
346
404
|
SocketCommands._fixCallback(callback, error);
|
|
347
405
|
}
|
|
348
|
-
}
|
|
406
|
+
}
|
|
407
|
+
);
|
|
349
408
|
} catch (error) {
|
|
350
409
|
this.adapter.log.error(`[_addUser] cannot save user: ${error.toString()}`);
|
|
351
410
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -370,7 +429,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
370
429
|
try {
|
|
371
430
|
this.adapter.delForeignObject(`system.user.${user}`, options, error =>
|
|
372
431
|
// Remove this user from all groups in web client
|
|
373
|
-
SocketCommands._fixCallback(callback, error)
|
|
432
|
+
SocketCommands._fixCallback(callback, error)
|
|
433
|
+
);
|
|
374
434
|
} catch (error) {
|
|
375
435
|
this.adapter.log.error(`[_delUser] cannot delete user: ${error.toString()}`);
|
|
376
436
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -404,7 +464,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
404
464
|
group = group.substring(0, 1).toLowerCase() + group.substring(1);
|
|
405
465
|
|
|
406
466
|
if (!group.match(/^[-.A-Za-züäößÖÄÜа-яА-Я@+$§0-9=?!&#_ ]+$/)) {
|
|
407
|
-
return SocketCommands._fixCallback(
|
|
467
|
+
return SocketCommands._fixCallback(
|
|
468
|
+
callback,
|
|
469
|
+
'Invalid characters in the group name. Only following special characters are allowed: -@+$§=?!&# and letters'
|
|
470
|
+
);
|
|
408
471
|
}
|
|
409
472
|
|
|
410
473
|
try {
|
|
@@ -413,7 +476,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
413
476
|
SocketCommands._fixCallback(callback, 'Group yet exists');
|
|
414
477
|
} else {
|
|
415
478
|
obj = {
|
|
416
|
-
_id:
|
|
479
|
+
_id: 'system.group.' + group,
|
|
417
480
|
type: 'group',
|
|
418
481
|
common: {
|
|
419
482
|
name,
|
|
@@ -424,7 +487,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
424
487
|
};
|
|
425
488
|
try {
|
|
426
489
|
this.adapter.setForeignObject(`system.group.${group}`, obj, options, error =>
|
|
427
|
-
SocketCommands._fixCallback(callback, error, obj)
|
|
490
|
+
SocketCommands._fixCallback(callback, error, obj)
|
|
491
|
+
);
|
|
428
492
|
} catch (error) {
|
|
429
493
|
this.adapter.log.error(`[_addGroup] cannot write group: ${error.toString()}`);
|
|
430
494
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -449,7 +513,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
449
513
|
try {
|
|
450
514
|
this.adapter.delForeignObject(`system.group.${group}`, options, error =>
|
|
451
515
|
// Remove this group from all users in the web client
|
|
452
|
-
SocketCommands._fixCallback(callback, error)
|
|
516
|
+
SocketCommands._fixCallback(callback, error)
|
|
517
|
+
);
|
|
453
518
|
} catch (error) {
|
|
454
519
|
this.adapter.log.error(`[_delGroup] cannot delete group: ${error.toString()}`);
|
|
455
520
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -500,12 +565,17 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
500
565
|
|
|
501
566
|
if (this._checkPermissions(socket, 'getObjects', callback)) {
|
|
502
567
|
if (this.objects) {
|
|
503
|
-
if (
|
|
568
|
+
if (
|
|
569
|
+
socket._acl &&
|
|
504
570
|
socket._acl.user !== 'system.user.admin' &&
|
|
505
|
-
!socket._acl.groups.includes('system.group.administrator')
|
|
571
|
+
!socket._acl.groups.includes('system.group.administrator')
|
|
572
|
+
) {
|
|
506
573
|
const result = {};
|
|
507
574
|
for (const id in this.objects) {
|
|
508
|
-
if (
|
|
575
|
+
if (
|
|
576
|
+
this.objects.hasOwnProperty(id) &&
|
|
577
|
+
SocketCommandsAdmin._checkObject(this.objects[id], socket._acl, 4 /* 'read' */)
|
|
578
|
+
) {
|
|
509
579
|
result[id] = this.objects[id];
|
|
510
580
|
}
|
|
511
581
|
}
|
|
@@ -515,14 +585,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
515
585
|
}
|
|
516
586
|
} else {
|
|
517
587
|
try {
|
|
518
|
-
this.adapter.getObjectList({include_docs: true}, {user: socket._acl.user}, (error, res) => {
|
|
588
|
+
this.adapter.getObjectList({ include_docs: true }, { user: socket._acl.user }, (error, res) => {
|
|
519
589
|
this.adapter.log.info('received all objects');
|
|
520
590
|
res = res.rows;
|
|
521
591
|
const objects = {};
|
|
522
592
|
|
|
523
|
-
if (
|
|
593
|
+
if (
|
|
594
|
+
socket._acl &&
|
|
524
595
|
socket._acl.user !== 'system.user.admin' &&
|
|
525
|
-
!socket._acl.groups.includes('system.group.administrator')
|
|
596
|
+
!socket._acl.groups.includes('system.group.administrator')
|
|
597
|
+
) {
|
|
526
598
|
for (let i = 0; i < res.length; i++) {
|
|
527
599
|
if (SocketCommandsAdmin._checkObject(res[i].doc, socket._acl, 4 /* 'read' */)) {
|
|
528
600
|
objects[res[i].doc._id] = res[i].doc;
|
|
@@ -551,8 +623,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
551
623
|
// @param {string} pass - user password
|
|
552
624
|
// @param {function} callback - `function (error)`
|
|
553
625
|
if (this._checkPermissions(socket, 'addUser', callback, user)) {
|
|
554
|
-
this._addUser(user, pass, {user: socket._acl.user}, (error, ...args) =>
|
|
555
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
626
|
+
this._addUser(user, pass, { user: socket._acl.user }, (error, ...args) =>
|
|
627
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
628
|
+
);
|
|
556
629
|
}
|
|
557
630
|
};
|
|
558
631
|
|
|
@@ -561,8 +634,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
561
634
|
// @param {string} user - user name, like 'benjamin
|
|
562
635
|
// @param {function} callback - `function (error)`
|
|
563
636
|
if (this._checkPermissions(socket, 'delUser', callback, user)) {
|
|
564
|
-
this._delUser(user, {user: socket._acl.user}, (error, ...args) =>
|
|
565
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
637
|
+
this._delUser(user, { user: socket._acl.user }, (error, ...args) =>
|
|
638
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
639
|
+
);
|
|
566
640
|
}
|
|
567
641
|
};
|
|
568
642
|
|
|
@@ -573,8 +647,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
573
647
|
// @param {object} acl - optional access control list object, like `{"object":{"list":true,"read":true,"write":false,"delete":false},"state":{"list":true,"read":true,"write":true,"create":true,"delete":false},"users":{"list":true,"read":true,"write":false,"create":false,"delete":false},"other":{"execute":false,"http":true,"sendto":false},"file":{"list":true,"read":true,"write":false,"create":false,"delete":false}}`
|
|
574
648
|
// @param {function} callback - `function (error)`
|
|
575
649
|
if (this._checkPermissions(socket, 'addGroup', callback, group)) {
|
|
576
|
-
this._addGroup(group, desc, acl, {user: socket._acl.user}, (error, ...args) =>
|
|
577
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
650
|
+
this._addGroup(group, desc, acl, { user: socket._acl.user }, (error, ...args) =>
|
|
651
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
652
|
+
);
|
|
578
653
|
}
|
|
579
654
|
};
|
|
580
655
|
|
|
@@ -583,8 +658,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
583
658
|
// @param {string} group - group name, like 'users`
|
|
584
659
|
// @param {function} callback - `function (error)`
|
|
585
660
|
if (this._checkPermissions(socket, 'delGroup', callback, group)) {
|
|
586
|
-
this._delGroup(group, {user: socket._acl.user}, (error, ...args) =>
|
|
587
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
661
|
+
this._delGroup(group, { user: socket._acl.user }, (error, ...args) =>
|
|
662
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
663
|
+
);
|
|
588
664
|
}
|
|
589
665
|
};
|
|
590
666
|
|
|
@@ -595,8 +671,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
595
671
|
// @param {function} callback - `function (error)`
|
|
596
672
|
if (user === socket._acl.user || this._checkPermissions(socket, 'changePassword', callback, user)) {
|
|
597
673
|
try {
|
|
598
|
-
this.adapter.setPassword(user, pass, {user: socket._acl.user}, (error, ...args) =>
|
|
599
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
674
|
+
this.adapter.setPassword(user, pass, { user: socket._acl.user }, (error, ...args) =>
|
|
675
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
676
|
+
);
|
|
600
677
|
} catch (error) {
|
|
601
678
|
this.adapter.log.error(`[_changePassword] ERROR: ${error.toString()}`);
|
|
602
679
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -615,16 +692,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
615
692
|
}
|
|
616
693
|
if (this._checkPermissions(socket, 'getHostByIp', ip)) {
|
|
617
694
|
try {
|
|
618
|
-
this.adapter.getObjectView('system', 'host', {}, {user: socket._acl.user}, (error, data) => {
|
|
695
|
+
this.adapter.getObjectView('system', 'host', {}, { user: socket._acl.user }, (error, data) => {
|
|
619
696
|
if (data && data.rows && data.rows.length) {
|
|
620
697
|
for (let i = 0; i < data.rows.length; i++) {
|
|
621
698
|
const obj = data.rows[i].value;
|
|
622
699
|
// if we requested specific name
|
|
623
700
|
if (obj.common.hostname === ip) {
|
|
624
701
|
return callback(ip, obj);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (obj.native.hardware && obj.native.hardware.networkInterfaces) {
|
|
702
|
+
}
|
|
703
|
+
// try to find this IP in the list
|
|
704
|
+
else if (obj.native.hardware && obj.native.hardware.networkInterfaces) {
|
|
628
705
|
const net = obj.native.hardware.networkInterfaces;
|
|
629
706
|
for (const eth in net) {
|
|
630
707
|
if (!Object.prototype.hasOwnProperty.call(net, eth)) {
|
|
@@ -673,7 +750,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
673
750
|
if (this._checkPermissions(socket, 'readLogs', callback)) {
|
|
674
751
|
let timeout = setTimeout(() => {
|
|
675
752
|
if (timeout) {
|
|
676
|
-
let result = {list: []};
|
|
753
|
+
let result = { list: [] };
|
|
677
754
|
|
|
678
755
|
// deliver the file list
|
|
679
756
|
try {
|
|
@@ -681,7 +758,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
681
758
|
// detect file log
|
|
682
759
|
if (config && config.log && config.log.transport) {
|
|
683
760
|
for (const transport in config.log.transport) {
|
|
684
|
-
if (
|
|
761
|
+
if (
|
|
762
|
+
Object.prototype.hasOwnProperty.call(config.log.transport, transport) &&
|
|
763
|
+
config.log.transport[transport].type === 'file'
|
|
764
|
+
) {
|
|
685
765
|
let fileName = config.log.transport[transport].filename || 'log/';
|
|
686
766
|
const parts = fileName.replace(/\\/g, '/').split('/');
|
|
687
767
|
parts.pop();
|
|
@@ -711,18 +791,20 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
711
791
|
} catch (_error) {
|
|
712
792
|
// push unchecked
|
|
713
793
|
// result.list.push('log/' + transport + '/' + files[f]);
|
|
714
|
-
this.adapter.log.error(
|
|
794
|
+
this.adapter.log.error(
|
|
795
|
+
`Cannot check file: ${fileName}/${files[f]}`
|
|
796
|
+
);
|
|
715
797
|
}
|
|
716
798
|
}
|
|
717
799
|
}
|
|
718
800
|
}
|
|
719
801
|
}
|
|
720
802
|
} else {
|
|
721
|
-
result = {error: 'no file loggers'};
|
|
803
|
+
result = { error: 'no file loggers' };
|
|
722
804
|
}
|
|
723
805
|
} catch (error) {
|
|
724
806
|
this.adapter.log.error(`Cannot read logs: ${error}`);
|
|
725
|
-
result = {error};
|
|
807
|
+
result = { error };
|
|
726
808
|
}
|
|
727
809
|
SocketCommands._fixCallback(callback, result.error, result.list);
|
|
728
810
|
}
|
|
@@ -746,8 +828,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
746
828
|
delete this.states[id];
|
|
747
829
|
}
|
|
748
830
|
try {
|
|
749
|
-
this.adapter.delForeignState(id, {user: socket._acl.user}, (error, ...args) =>
|
|
750
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
831
|
+
this.adapter.delForeignState(id, { user: socket._acl.user }, (error, ...args) =>
|
|
832
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
833
|
+
);
|
|
751
834
|
} catch (error) {
|
|
752
835
|
this.adapter.log.error(`[delState] ERROR: ${error.toString()}`);
|
|
753
836
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -766,9 +849,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
766
849
|
if (this._checkPermissions(socket, 'cmdExec', callback, cmd)) {
|
|
767
850
|
this.adapter.log.debug(`cmdExec on ${host}(${id}): ${cmd}`);
|
|
768
851
|
// remember socket for this ID.
|
|
769
|
-
this.cmdSessions[id] = {socket};
|
|
852
|
+
this.cmdSessions[id] = { socket };
|
|
770
853
|
try {
|
|
771
|
-
this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id});
|
|
854
|
+
this.adapter.sendToHost(host, 'cmdExec', { data: cmd, id });
|
|
772
855
|
SocketCommands._fixCallback(callback, null);
|
|
773
856
|
} catch (error) {
|
|
774
857
|
this.adapter.log.error(`[cmdExec] ERROR: ${error.toString()}`);
|
|
@@ -792,8 +875,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
792
875
|
// @param {boolean} update - if true, the ratings will be read from central server, if false from local cache
|
|
793
876
|
// @param {function} callback - `function (error, ratings)`, where `ratings` is object like `{accuweather: {rating: {r: 3.33, c: 3}, 1.2.1: {r: 3, c: 1}},…}`
|
|
794
877
|
if (update || !this.adapter._ratings) {
|
|
795
|
-
this.updateRatings()
|
|
796
|
-
.then(() => SocketCommands._fixCallback(callback, null, this.adapter._ratings));
|
|
878
|
+
this.updateRatings().then(() => SocketCommands._fixCallback(callback, null, this.adapter._ratings));
|
|
797
879
|
} else {
|
|
798
880
|
SocketCommands._fixCallback(callback, null, this.adapter._ratings);
|
|
799
881
|
}
|
|
@@ -813,10 +895,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
813
895
|
SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
|
|
814
896
|
} else {
|
|
815
897
|
try {
|
|
816
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
898
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
817
899
|
if (obj && obj.native && obj.native.secret) {
|
|
818
900
|
this.secret = obj.native.secret;
|
|
819
|
-
SocketCommands._fixCallback(
|
|
901
|
+
SocketCommands._fixCallback(
|
|
902
|
+
callback,
|
|
903
|
+
null,
|
|
904
|
+
this.adapter.decrypt(this.secret, encryptedText)
|
|
905
|
+
);
|
|
820
906
|
} else {
|
|
821
907
|
this.adapter.log.error(`No system.config found: ${error}`);
|
|
822
908
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -836,7 +922,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
836
922
|
if (this.secret) {
|
|
837
923
|
SocketCommands._fixCallback(callback, null, this.adapter.encrypt(this.secret, plainText));
|
|
838
924
|
} else {
|
|
839
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
925
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
840
926
|
if (obj && obj.native && obj.native.secret) {
|
|
841
927
|
this.secret = obj.native.secret;
|
|
842
928
|
try {
|
|
@@ -876,44 +962,59 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
876
962
|
}
|
|
877
963
|
|
|
878
964
|
if (this.adapter.config.accessLimit) {
|
|
879
|
-
const configs
|
|
965
|
+
const configs = [];
|
|
880
966
|
const promises = [];
|
|
881
|
-
this.adapter.config.accessAllowedConfigs.forEach(id =>
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
967
|
+
this.adapter.config.accessAllowedConfigs.forEach(id =>
|
|
968
|
+
promises.push(this._readInstanceConfig(id, user, false, configs))
|
|
969
|
+
);
|
|
970
|
+
this.adapter.config.accessAllowedTabs.forEach(id =>
|
|
971
|
+
promises.push(this._readInstanceConfig(id, user, true, configs))
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
Promise.all(promises).then(() => {
|
|
975
|
+
callback(null, {
|
|
976
|
+
strict: true,
|
|
977
|
+
configs
|
|
890
978
|
});
|
|
979
|
+
});
|
|
891
980
|
} else {
|
|
892
|
-
this.adapter.getObjectView(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
981
|
+
this.adapter.getObjectView(
|
|
982
|
+
'system',
|
|
983
|
+
'instance',
|
|
984
|
+
{ startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' },
|
|
985
|
+
{ user },
|
|
986
|
+
(error, doc) => {
|
|
987
|
+
const promises = [];
|
|
988
|
+
const configs = [];
|
|
989
|
+
if (!error && doc.rows.length) {
|
|
990
|
+
for (let i = 0; i < doc.rows.length; i++) {
|
|
991
|
+
const obj = doc.rows[i].value;
|
|
992
|
+
if (obj.common.noConfig && !obj.common.adminTab) {
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (!obj.common.enabled) {
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
if (!obj.common.noConfig) {
|
|
999
|
+
promises.push(
|
|
1000
|
+
this._readInstanceConfig(
|
|
1001
|
+
obj._id.substring('system.adapter.'.length),
|
|
1002
|
+
user,
|
|
1003
|
+
false,
|
|
1004
|
+
configs
|
|
1005
|
+
)
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
906
1008
|
}
|
|
907
1009
|
}
|
|
908
|
-
|
|
909
|
-
Promise.all(promises)
|
|
910
|
-
.then(() =>
|
|
1010
|
+
Promise.all(promises).then(() =>
|
|
911
1011
|
callback(null, {
|
|
912
1012
|
strict: false,
|
|
913
|
-
configs
|
|
1013
|
+
configs
|
|
914
1014
|
})
|
|
915
1015
|
);
|
|
916
|
-
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
917
1018
|
}
|
|
918
1019
|
}
|
|
919
1020
|
};
|
|
@@ -923,27 +1024,39 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
923
1024
|
// @param {string} adapterName - optional adapter name
|
|
924
1025
|
// @param {function} callback - `function (error, results)`, where `results` is array of objects like `{_id: 'system.adapter.javascript', common: {...}}`
|
|
925
1026
|
if (typeof callback === 'function' && this._checkPermissions(socket, 'getObject', callback)) {
|
|
926
|
-
this.adapter.getObjectView(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
(error, doc) =>
|
|
1027
|
+
this.adapter.getObjectView(
|
|
1028
|
+
'system',
|
|
1029
|
+
'adapter',
|
|
930
1030
|
{
|
|
1031
|
+
startkey: `system.adapter.${adapterName || ''}`,
|
|
1032
|
+
endkey: `system.adapter.${adapterName || '\u9999'}`
|
|
1033
|
+
},
|
|
1034
|
+
{ user: socket._acl.user },
|
|
1035
|
+
(error, doc) => {
|
|
931
1036
|
if (error) {
|
|
932
1037
|
callback(error);
|
|
933
1038
|
} else {
|
|
934
|
-
callback(
|
|
935
|
-
|
|
936
|
-
.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1039
|
+
callback(
|
|
1040
|
+
null,
|
|
1041
|
+
doc.rows
|
|
1042
|
+
.filter(
|
|
1043
|
+
obj =>
|
|
1044
|
+
obj &&
|
|
1045
|
+
(!adapterName || (obj.common && obj.common.name === this.adapterName))
|
|
1046
|
+
)
|
|
1047
|
+
.map(item => {
|
|
1048
|
+
const obj = item.value;
|
|
1049
|
+
if (obj.common) {
|
|
1050
|
+
delete obj.common.news;
|
|
1051
|
+
delete obj.native;
|
|
1052
|
+
}
|
|
1053
|
+
this._fixAdminUI(obj);
|
|
1054
|
+
return obj;
|
|
1055
|
+
})
|
|
1056
|
+
);
|
|
945
1057
|
}
|
|
946
|
-
}
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
947
1060
|
}
|
|
948
1061
|
};
|
|
949
1062
|
|
|
@@ -961,7 +1074,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
961
1074
|
}
|
|
962
1075
|
}, 7000);
|
|
963
1076
|
|
|
964
|
-
this._sendToHost(this.adapter.common.host, 'updateLicenses', {login, password}, result => {
|
|
1077
|
+
this._sendToHost(this.adapter.common.host, 'updateLicenses', { login, password }, result => {
|
|
965
1078
|
if (timeout) {
|
|
966
1079
|
clearTimeout(timeout);
|
|
967
1080
|
timeout = null;
|
|
@@ -970,7 +1083,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
970
1083
|
});
|
|
971
1084
|
} else {
|
|
972
1085
|
// remove this branch when js-controller 4.x will be mainstream
|
|
973
|
-
this._updateLicenses(login, password, {user: socket._acl.user})
|
|
1086
|
+
this._updateLicenses(login, password, { user: socket._acl.user })
|
|
974
1087
|
.then(licenses => SocketCommands._fixCallback(callback, null, licenses))
|
|
975
1088
|
.catch(error => SocketCommands._fixCallback(callback, error));
|
|
976
1089
|
}
|
|
@@ -982,9 +1095,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
982
1095
|
// @param {function} callback - `function (error, results)`, where `results` is an object like `{'system.adapter.javascript.0': {adminTab, name, icon, enabled}}`
|
|
983
1096
|
if (typeof callback === 'function') {
|
|
984
1097
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
985
|
-
this.adapter.getObjectView(
|
|
986
|
-
|
|
987
|
-
|
|
1098
|
+
this.adapter.getObjectView(
|
|
1099
|
+
'system',
|
|
1100
|
+
'instance',
|
|
1101
|
+
{ startkey: `system.adapter.`, endkey: `system.adapter.\u9999` },
|
|
1102
|
+
{ user: socket._acl.user },
|
|
988
1103
|
(error, doc) => {
|
|
989
1104
|
if (error) {
|
|
990
1105
|
callback(error);
|
|
@@ -998,13 +1113,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
998
1113
|
adminTab: obj.common.adminTab,
|
|
999
1114
|
name: obj.common.name,
|
|
1000
1115
|
icon: obj.common.icon,
|
|
1001
|
-
enabled: obj.common.enabled
|
|
1116
|
+
enabled: obj.common.enabled
|
|
1002
1117
|
};
|
|
1003
1118
|
});
|
|
1004
1119
|
|
|
1005
1120
|
callback(null, result);
|
|
1006
1121
|
}
|
|
1007
|
-
}
|
|
1122
|
+
}
|
|
1123
|
+
);
|
|
1008
1124
|
}
|
|
1009
1125
|
}
|
|
1010
1126
|
};
|
|
@@ -1014,9 +1130,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1014
1130
|
// @param {function} callback - `function (error, results)`, where `results` is an object like `{'javascript': {icon, v: '1.0.1', iv: 'ignoredVersion}}`
|
|
1015
1131
|
if (typeof callback === 'function') {
|
|
1016
1132
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1017
|
-
this.adapter.getObjectView(
|
|
1018
|
-
|
|
1019
|
-
|
|
1133
|
+
this.adapter.getObjectView(
|
|
1134
|
+
'system',
|
|
1135
|
+
'adapter',
|
|
1136
|
+
{ startkey: `system.adapter.`, endkey: `system.adapter.\u9999` },
|
|
1137
|
+
{ user: socket._acl.user },
|
|
1020
1138
|
(error, doc) => {
|
|
1021
1139
|
if (error) {
|
|
1022
1140
|
callback(error);
|
|
@@ -1027,7 +1145,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1027
1145
|
doc.rows.forEach(item => {
|
|
1028
1146
|
const obj = item.value;
|
|
1029
1147
|
if (obj && obj.common && obj.common.name) {
|
|
1030
|
-
result[obj.common.name] = {icon: obj.common.icon, v: obj.common.version};
|
|
1148
|
+
result[obj.common.name] = { icon: obj.common.icon, v: obj.common.version };
|
|
1031
1149
|
if (obj.common.ignoreVersion) {
|
|
1032
1150
|
result[obj.common.name].iv = obj.common.ignoreVersion;
|
|
1033
1151
|
}
|
|
@@ -1036,7 +1154,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1036
1154
|
|
|
1037
1155
|
callback(null, result);
|
|
1038
1156
|
}
|
|
1039
|
-
}
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1040
1159
|
}
|
|
1041
1160
|
}
|
|
1042
1161
|
};
|
|
@@ -1048,7 +1167,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1048
1167
|
if (this._checkPermissions(socket, 'sendToHost', callback)) {
|
|
1049
1168
|
this._sendToHost(host, 'getInstalled', null, data => {
|
|
1050
1169
|
const result = {};
|
|
1051
|
-
Object.keys(data).forEach(name => result[name] = {version: data[name].version});
|
|
1170
|
+
Object.keys(data).forEach(name => (result[name] = { version: data[name].version }));
|
|
1052
1171
|
callback(result);
|
|
1053
1172
|
});
|
|
1054
1173
|
}
|
|
@@ -1059,12 +1178,12 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1059
1178
|
// Read system config in short form to save bandwidth
|
|
1060
1179
|
// @param {function} callback - `function (error, systemConfig)`, where `systemConfig` is an object like `{common: {...}, native: {secret: 'aaa'}}`
|
|
1061
1180
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1062
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
1181
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
1063
1182
|
obj = obj || {};
|
|
1064
1183
|
const secret = obj && obj.native && obj.native.secret;
|
|
1065
1184
|
delete obj.native;
|
|
1066
1185
|
if (secret) {
|
|
1067
|
-
obj.native = {secret};
|
|
1186
|
+
obj.native = { secret };
|
|
1068
1187
|
}
|
|
1069
1188
|
callback(error, obj);
|
|
1070
1189
|
});
|
|
@@ -1075,15 +1194,18 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1075
1194
|
// Read repositories from cache in short form to save bandwidth
|
|
1076
1195
|
// @param {function} callback - `function (error, repositories)`, where `repositories` is an object like `{_id: 'system.repositories', common: {...}, native: {repositories: {default: {json: {_repoInfo: {...}}}}}}`
|
|
1077
1196
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1078
|
-
this.adapter.getForeignObject('system.repositories', {user: socket._acl.user}, (error, obj) => {
|
|
1079
|
-
obj &&
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1197
|
+
this.adapter.getForeignObject('system.repositories', { user: socket._acl.user }, (error, obj) => {
|
|
1198
|
+
obj &&
|
|
1199
|
+
obj.native &&
|
|
1200
|
+
obj.native.repositories &&
|
|
1201
|
+
Object.keys(obj.native.repositories).forEach(name => {
|
|
1202
|
+
if (obj.native.repositories[name].json) {
|
|
1203
|
+
// limit information to _repoInfo
|
|
1204
|
+
obj.native.repositories[name].json = {
|
|
1205
|
+
_repoInfo: obj.native.repositories[name].json._repoInfo
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1087
1209
|
callback(error, obj);
|
|
1088
1210
|
});
|
|
1089
1211
|
}
|
|
@@ -1096,10 +1218,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1096
1218
|
this._sendToHost(host, 'getRepository', null, data => {
|
|
1097
1219
|
// Extract only the version and icon
|
|
1098
1220
|
const result = {};
|
|
1099
|
-
data &&
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1221
|
+
data &&
|
|
1222
|
+
Object.keys(data).forEach(
|
|
1223
|
+
name =>
|
|
1224
|
+
(result[name] = {
|
|
1225
|
+
version: data[name].version,
|
|
1226
|
+
icon: data[name].extIcon
|
|
1227
|
+
})
|
|
1228
|
+
);
|
|
1103
1229
|
callback(result);
|
|
1104
1230
|
});
|
|
1105
1231
|
}
|
|
@@ -1109,9 +1235,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1109
1235
|
// Read all hosts in short form to save bandwidth
|
|
1110
1236
|
// @param {function} callback - `function (error, hosts)`, where `hosts` is an array of objects like `[{_id:'system.host.raspi',common:{name:'raspi',icon:'icon',color:'blue',installedVersion:'2.1.0'},native:{hardware:{networkInterfaces:[...]}}}]`
|
|
1111
1237
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1112
|
-
this.adapter.getObjectView(
|
|
1113
|
-
|
|
1114
|
-
|
|
1238
|
+
this.adapter.getObjectView(
|
|
1239
|
+
'system',
|
|
1240
|
+
'host',
|
|
1241
|
+
{ startkey: 'system.host.', endkey: 'system.host.\u9999' },
|
|
1242
|
+
{ user: socket._acl.user },
|
|
1115
1243
|
(error, doc) => {
|
|
1116
1244
|
if (error) {
|
|
1117
1245
|
callback(error);
|
|
@@ -1131,15 +1259,20 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1131
1259
|
},
|
|
1132
1260
|
native: {
|
|
1133
1261
|
hardware: {
|
|
1134
|
-
networkInterfaces:
|
|
1262
|
+
networkInterfaces:
|
|
1263
|
+
(host.native &&
|
|
1264
|
+
host.native.hardware &&
|
|
1265
|
+
host.native.hardware.networkInterfaces) ||
|
|
1266
|
+
undefined
|
|
1135
1267
|
}
|
|
1136
1268
|
}
|
|
1137
1269
|
});
|
|
1138
1270
|
}
|
|
1139
|
-
})
|
|
1271
|
+
});
|
|
1140
1272
|
callback(null, result);
|
|
1141
1273
|
}
|
|
1142
|
-
}
|
|
1274
|
+
}
|
|
1275
|
+
);
|
|
1143
1276
|
}
|
|
1144
1277
|
};
|
|
1145
1278
|
}
|
|
@@ -1164,15 +1297,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1164
1297
|
if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
|
|
1165
1298
|
if (typeof options === 'function') {
|
|
1166
1299
|
callback = options;
|
|
1167
|
-
options = {user: socket._acl.user};
|
|
1300
|
+
options = { user: socket._acl.user };
|
|
1168
1301
|
}
|
|
1169
1302
|
options = options || {};
|
|
1170
1303
|
options.user = socket._acl.user;
|
|
1171
1304
|
|
|
1172
1305
|
try {
|
|
1173
1306
|
const buffer = Buffer.from(data64, 'base64');
|
|
1174
|
-
this.adapter.writeFile(_adapter, fileName, buffer, {user: socket._acl.user}, (error, ...args) =>
|
|
1175
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1307
|
+
this.adapter.writeFile(_adapter, fileName, buffer, { user: socket._acl.user }, (error, ...args) =>
|
|
1308
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1309
|
+
);
|
|
1176
1310
|
} catch (error) {
|
|
1177
1311
|
this.adapter.log.error(`[writeFile] Cannot convert data: ${error.toString()}`);
|
|
1178
1312
|
callback && callback(`Cannot convert data: ${error.toString()}`);
|
|
@@ -1188,14 +1322,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1188
1322
|
// Read absolutely all objects
|
|
1189
1323
|
// @param {function} callback - `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
1190
1324
|
return this._getAllObjects(socket, callback);
|
|
1191
|
-
}
|
|
1325
|
+
};
|
|
1192
1326
|
|
|
1193
1327
|
// Identical to getAllObjects
|
|
1194
1328
|
this.commands['getObjects'] = (socket, callback) => {
|
|
1195
1329
|
// Read absolutely all objects. Same as `getAllObjects`.
|
|
1196
1330
|
// @param {function} callback - `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
1197
1331
|
return this._getAllObjects(socket, callback);
|
|
1198
|
-
}
|
|
1332
|
+
};
|
|
1199
1333
|
|
|
1200
1334
|
this.commands['extendObject'] = (socket, id, obj, callback) => {
|
|
1201
1335
|
// Extend the existing object
|
|
@@ -1204,8 +1338,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1204
1338
|
// @param {function} callback - `function (error)`
|
|
1205
1339
|
if (this._checkPermissions(socket, 'extendObject', callback, id)) {
|
|
1206
1340
|
try {
|
|
1207
|
-
this.adapter.extendForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>
|
|
1208
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1341
|
+
this.adapter.extendForeignObject(id, obj, { user: socket._acl.user }, (error, ...args) =>
|
|
1342
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1343
|
+
);
|
|
1209
1344
|
} catch (error) {
|
|
1210
1345
|
this.adapter.log.error(`[extendObject] ERROR: ${error}`);
|
|
1211
1346
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1226,8 +1361,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1226
1361
|
|
|
1227
1362
|
if (typeof callback === 'function') {
|
|
1228
1363
|
try {
|
|
1229
|
-
this.adapter.getForeignObjects(pattern, type, {user: socket._acl.user}, (error, ...args) =>
|
|
1230
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1364
|
+
this.adapter.getForeignObjects(pattern, type, { user: socket._acl.user }, (error, ...args) =>
|
|
1365
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1366
|
+
);
|
|
1231
1367
|
} catch (error) {
|
|
1232
1368
|
this.adapter.log.error(`[extendObject] ERROR: ${error}`);
|
|
1233
1369
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1255,7 +1391,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1255
1391
|
try {
|
|
1256
1392
|
// options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1257
1393
|
this.adapter.delForeignObject(id, options, (error, ...args) =>
|
|
1258
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1394
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1395
|
+
);
|
|
1259
1396
|
} catch (error) {
|
|
1260
1397
|
this.adapter.log.error(`[delObject] ERROR: ${error}`);
|
|
1261
1398
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1276,7 +1413,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1276
1413
|
options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1277
1414
|
try {
|
|
1278
1415
|
this.adapter.delForeignObject(id, options, (error, ...args) =>
|
|
1279
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1416
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1417
|
+
);
|
|
1280
1418
|
} catch (error) {
|
|
1281
1419
|
this.adapter.log.error(`[delObjects] ERROR: ${error}`);
|
|
1282
1420
|
SocketCommands._fixCallback(callback, error);
|