@webos-tools/cli 3.1.1 → 3.1.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/CHANGELOG.md +173 -157
- package/LICENSES/342/200/216/LicenseRef-3rd_party_licenses.txt +1355 -0
- package/README.md +21 -19
- package/bin/ares-config.js +6 -3
- package/bin/ares-device.js +2 -2
- package/bin/ares-log.js +6 -2
- package/bin/ares-pull.js +1 -1
- package/bin/ares-push.js +1 -1
- package/bin/ares-setup-device.js +573 -528
- package/bin/ares-shell.js +1 -1
- package/bin/ares.js +1 -1
- package/files/conf/ares.json +5 -5
- package/files/conf/novacom-devices.json +18 -1
- package/files/conf-base/env/sdk-apollo.json +8 -0
- package/files/conf-base/profile/config-apollo.json +29 -0
- package/files/conf-base/profile/config-ose.json +1 -1
- package/files/conf-base/template-conf/apollo-sdk-templates.json +56 -0
- package/files/help/ares-config.help +6 -1
- package/files/help/ares-device.help +15 -0
- package/files/help/ares-generate.help +27 -1
- package/files/help/ares-inspect.help +6 -0
- package/files/help/ares-install.help +5 -0
- package/files/help/ares-launch.help +5 -0
- package/files/help/ares-server.help +5 -0
- package/files/help/ares-setup-device.help +40 -0
- package/files/help/ares.help +5 -0
- package/files/schema/NovacomDevices.schema +2 -1
- package/files/templates/apollo-sdk-templates/appinfo/appinfo.json +10 -0
- package/files/templates/apollo-sdk-templates/bootplate-web/index.html +88 -0
- package/files/templates/apollo-sdk-templates/hosted-webapp/index.html +14 -0
- package/files/templates/apollo-sdk-templates/icon/icon.png +0 -0
- package/files/templates/apollo-sdk-templates/js-service/helloclient.js +31 -0
- package/files/templates/apollo-sdk-templates/js-service/helloworld_webos_service.js +188 -0
- package/files/templates/apollo-sdk-templates/native-service/CMakeLists.txt +72 -0
- package/files/templates/apollo-sdk-templates/native-service/services.json +11 -0
- package/files/templates/apollo-sdk-templates/native-service/src/main.c +144 -0
- package/files/templates/apollo-sdk-templates/serviceinfo/package.json +11 -0
- package/files/templates/apollo-sdk-templates/serviceinfo/services.json +8 -0
- package/lib/base/novacom.js +1 -1
- package/lib/base/setup-device.js +338 -335
- package/lib/device.js +1 -1
- package/lib/generator.js +408 -377
- package/lib/package.js +3 -1
- package/lib/shell.js +1 -1
- package/npm-shrinkwrap.json +9242 -9242
- package/package.json +100 -100
- package/sbom-info.yaml +1758 -0
- package/spec/jsSpecs/ares-config.spec.js +10 -0
- package/spec/jsSpecs/ares-generate.spec.js +4 -4
- package/spec/jsSpecs/ares-log.spec.js +1 -1
- package/spec/test_data/ares-generate.json +18 -1
- package/spec/test_data/ares.json +17 -0
- package/webos-tools-cli-3.1.3.tgz +0 -0
package/lib/base/setup-device.js
CHANGED
|
@@ -1,335 +1,338 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const async = require('async'),
|
|
8
|
-
chalk = require('chalk'),
|
|
9
|
-
Table = require('easy-table'),
|
|
10
|
-
npmlog = require('npmlog'),
|
|
11
|
-
Appdata = require('./cli-appdata'),
|
|
12
|
-
errHndl = require('./error-handler'),
|
|
13
|
-
novacom = require('./novacom');
|
|
14
|
-
|
|
15
|
-
(function() {
|
|
16
|
-
const log = npmlog;
|
|
17
|
-
log.heading = 'setup-device';
|
|
18
|
-
log.level = 'warn';
|
|
19
|
-
|
|
20
|
-
const appdata = new Appdata(),
|
|
21
|
-
devicetools = {},
|
|
22
|
-
defaultDeviceInfo = appdata.getConfig(true).defaultDeviceInfo;
|
|
23
|
-
defaultDeviceInfo.profile = appdata.getConfig(true).profile;
|
|
24
|
-
|
|
25
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
26
|
-
module.exports = devicetools;
|
|
27
|
-
module.exports.isValidDeviceName = isValidDeviceName;
|
|
28
|
-
module.exports.isValidIpv4 = isValidIpv4;
|
|
29
|
-
module.exports.isValidPort =isValidPort;
|
|
30
|
-
module.exports.replaceDefaultDeviceInfo = replaceDefaultDeviceInfo;
|
|
31
|
-
module.exports.displayGetKeyGuide = displayGetKeyGuide;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isValidDeviceName(name) {
|
|
35
|
-
return ['$', '%'].indexOf(name[0]) === -1;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function isValidIpv4(host) {
|
|
39
|
-
return host === "localhost" || host.match(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isValidPort(port) {
|
|
43
|
-
const intPort = Number(port);
|
|
44
|
-
return Number.isInteger(intPort) && intPort > 0 && intPort <= 65535;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
devicetools.showDeviceList = function(next) {
|
|
48
|
-
async.waterfall([
|
|
49
|
-
_getDeviceInfo.bind(this, 'list'),
|
|
50
|
-
function(data, next) {
|
|
51
|
-
const table = new Table();
|
|
52
|
-
data.forEach(function(item) {
|
|
53
|
-
if (!isValidDeviceName(item.name)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
table.cell('name', (item.default === true) ? item.name + chalk.green(' (default)') : item.name);
|
|
57
|
-
table.cell('deviceinfo', item.info);
|
|
58
|
-
table.cell('connection', item.connection);
|
|
59
|
-
table.cell('profile', item.profile);
|
|
60
|
-
table.newRow();
|
|
61
|
-
});
|
|
62
|
-
next(null, table.toString());
|
|
63
|
-
}
|
|
64
|
-
], function(err, results) {
|
|
65
|
-
next(err, {msg: results});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
devicetools.showDeviceListFull = function(next) {
|
|
70
|
-
async.waterfall([
|
|
71
|
-
_getDeviceInfo.bind(this, 'full'),
|
|
72
|
-
function(data, next) {
|
|
73
|
-
next(null, JSON.stringify(data, null, 4));
|
|
74
|
-
}
|
|
75
|
-
], function(err, results) {
|
|
76
|
-
next(err, {msg: results});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
devicetools.resetDeviceList = function(next) {
|
|
81
|
-
async.series([
|
|
82
|
-
function(next) {
|
|
83
|
-
appdata.resetDeviceList(next);
|
|
84
|
-
},
|
|
85
|
-
this.showDeviceList.bind(this, next)
|
|
86
|
-
], function(err) {
|
|
87
|
-
next(err);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
devicetools.setDefaultDevice = function(name, next) {
|
|
92
|
-
try {
|
|
93
|
-
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
94
|
-
inDevice = {name: name, default: true};
|
|
95
|
-
async.series([
|
|
96
|
-
resolver.load.bind(resolver),
|
|
97
|
-
resolver.modifyDeviceFile.bind(resolver, 'default', inDevice),
|
|
98
|
-
this.showDeviceList.bind(this, next)
|
|
99
|
-
], function(err) {
|
|
100
|
-
if (err) {
|
|
101
|
-
return next(err);
|
|
102
|
-
}
|
|
103
|
-
next();
|
|
104
|
-
});
|
|
105
|
-
} catch (err) {
|
|
106
|
-
next(err);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
devicetools.removeDeviceInfo = function(options, next) {
|
|
111
|
-
try {
|
|
112
|
-
// For CLI
|
|
113
|
-
if (options.remove === 'true') {
|
|
114
|
-
next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
115
|
-
}
|
|
116
|
-
// For API
|
|
117
|
-
if (!options.remove) {
|
|
118
|
-
next(errHndl.getErrMsg("INVALID_REMOVE_MODE"));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
122
|
-
inDevice = {name: options.remove, profile: defaultDeviceInfo.profile};
|
|
123
|
-
async.series([
|
|
124
|
-
resolver.load.bind(resolver),
|
|
125
|
-
resolver.modifyDeviceFile.bind(resolver, 'remove', inDevice),
|
|
126
|
-
this.showDeviceList.bind(this, next)
|
|
127
|
-
], function(err) {
|
|
128
|
-
if (err) {
|
|
129
|
-
return next(err);
|
|
130
|
-
}
|
|
131
|
-
next();
|
|
132
|
-
});
|
|
133
|
-
} catch (err) {
|
|
134
|
-
next(err);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
devicetools.modifyDeviceInfo = function(options, next) {
|
|
139
|
-
try {
|
|
140
|
-
const mode = (options.add) ? "add" : (options.modify) ? "modify" : null;
|
|
141
|
-
if (!mode) {
|
|
142
|
-
return next(errHndl.getErrMsg("INVALID_MODE"));
|
|
143
|
-
}
|
|
144
|
-
if (options[mode].match(/^-/)) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
inDevice.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
inDevice.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
inDevice.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
return next(errHndl.getErrMsg("
|
|
189
|
-
}
|
|
190
|
-
if (inDevice.
|
|
191
|
-
return next(errHndl.getErrMsg("INVALID_VALUE", "
|
|
192
|
-
}
|
|
193
|
-
if (inDevice.port) {
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
if (
|
|
197
|
-
inDevice.
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if(
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
if(
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
resolver.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
item.deviceinfo =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
item.details.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
inDevice.
|
|
318
|
-
inDevice.
|
|
319
|
-
inDevice.
|
|
320
|
-
inDevice.
|
|
321
|
-
inDevice.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
+ "\n
|
|
331
|
-
+ "\n
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const async = require('async'),
|
|
8
|
+
chalk = require('chalk'),
|
|
9
|
+
Table = require('easy-table'),
|
|
10
|
+
npmlog = require('npmlog'),
|
|
11
|
+
Appdata = require('./cli-appdata'),
|
|
12
|
+
errHndl = require('./error-handler'),
|
|
13
|
+
novacom = require('./novacom');
|
|
14
|
+
|
|
15
|
+
(function() {
|
|
16
|
+
const log = npmlog;
|
|
17
|
+
log.heading = 'setup-device';
|
|
18
|
+
log.level = 'warn';
|
|
19
|
+
|
|
20
|
+
const appdata = new Appdata(),
|
|
21
|
+
devicetools = {},
|
|
22
|
+
defaultDeviceInfo = appdata.getConfig(true).defaultDeviceInfo;
|
|
23
|
+
defaultDeviceInfo.profile = appdata.getConfig(true).profile;
|
|
24
|
+
|
|
25
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
26
|
+
module.exports = devicetools;
|
|
27
|
+
module.exports.isValidDeviceName = isValidDeviceName;
|
|
28
|
+
module.exports.isValidIpv4 = isValidIpv4;
|
|
29
|
+
module.exports.isValidPort =isValidPort;
|
|
30
|
+
module.exports.replaceDefaultDeviceInfo = replaceDefaultDeviceInfo;
|
|
31
|
+
module.exports.displayGetKeyGuide = displayGetKeyGuide;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isValidDeviceName(name) {
|
|
35
|
+
return ['$', '%'].indexOf(name[0]) === -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isValidIpv4(host) {
|
|
39
|
+
return host === "localhost" || host.match(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isValidPort(port) {
|
|
43
|
+
const intPort = Number(port);
|
|
44
|
+
return Number.isInteger(intPort) && intPort > 0 && intPort <= 65535;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
devicetools.showDeviceList = function(next) {
|
|
48
|
+
async.waterfall([
|
|
49
|
+
_getDeviceInfo.bind(this, 'list'),
|
|
50
|
+
function(data, next) {
|
|
51
|
+
const table = new Table();
|
|
52
|
+
data.forEach(function(item) {
|
|
53
|
+
if (!isValidDeviceName(item.name)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
table.cell('name', (item.default === true) ? item.name + chalk.green(' (default)') : item.name);
|
|
57
|
+
table.cell('deviceinfo', item.info);
|
|
58
|
+
table.cell('connection', item.connection);
|
|
59
|
+
table.cell('profile', item.profile);
|
|
60
|
+
table.newRow();
|
|
61
|
+
});
|
|
62
|
+
next(null, table.toString());
|
|
63
|
+
}
|
|
64
|
+
], function(err, results) {
|
|
65
|
+
next(err, {msg: results});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
devicetools.showDeviceListFull = function(next) {
|
|
70
|
+
async.waterfall([
|
|
71
|
+
_getDeviceInfo.bind(this, 'full'),
|
|
72
|
+
function(data, next) {
|
|
73
|
+
next(null, JSON.stringify(data, null, 4));
|
|
74
|
+
}
|
|
75
|
+
], function(err, results) {
|
|
76
|
+
next(err, {msg: results});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
devicetools.resetDeviceList = function(next) {
|
|
81
|
+
async.series([
|
|
82
|
+
function(next) {
|
|
83
|
+
appdata.resetDeviceList(next);
|
|
84
|
+
},
|
|
85
|
+
this.showDeviceList.bind(this, next)
|
|
86
|
+
], function(err) {
|
|
87
|
+
next(err);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
devicetools.setDefaultDevice = function(name, next) {
|
|
92
|
+
try {
|
|
93
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
94
|
+
inDevice = {name: name, default: true};
|
|
95
|
+
async.series([
|
|
96
|
+
resolver.load.bind(resolver),
|
|
97
|
+
resolver.modifyDeviceFile.bind(resolver, 'default', inDevice),
|
|
98
|
+
this.showDeviceList.bind(this, next)
|
|
99
|
+
], function(err) {
|
|
100
|
+
if (err) {
|
|
101
|
+
return next(err);
|
|
102
|
+
}
|
|
103
|
+
next();
|
|
104
|
+
});
|
|
105
|
+
} catch (err) {
|
|
106
|
+
next(err);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
devicetools.removeDeviceInfo = function(options, next) {
|
|
111
|
+
try {
|
|
112
|
+
// For CLI
|
|
113
|
+
if (options.remove === 'true') {
|
|
114
|
+
next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
115
|
+
}
|
|
116
|
+
// For API
|
|
117
|
+
if (!options.remove) {
|
|
118
|
+
next(errHndl.getErrMsg("INVALID_REMOVE_MODE"));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
122
|
+
inDevice = {name: options.remove, profile: defaultDeviceInfo.profile};
|
|
123
|
+
async.series([
|
|
124
|
+
resolver.load.bind(resolver),
|
|
125
|
+
resolver.modifyDeviceFile.bind(resolver, 'remove', inDevice),
|
|
126
|
+
this.showDeviceList.bind(this, next)
|
|
127
|
+
], function(err) {
|
|
128
|
+
if (err) {
|
|
129
|
+
return next(err);
|
|
130
|
+
}
|
|
131
|
+
next();
|
|
132
|
+
});
|
|
133
|
+
} catch (err) {
|
|
134
|
+
next(err);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
devicetools.modifyDeviceInfo = function(options, next) {
|
|
139
|
+
try {
|
|
140
|
+
const mode = (options.add) ? "add" : (options.modify) ? "modify" : null;
|
|
141
|
+
if (!mode) {
|
|
142
|
+
return next(errHndl.getErrMsg("INVALID_MODE"));
|
|
143
|
+
}
|
|
144
|
+
if (options[mode].match(/^-/)) {
|
|
145
|
+
let indexMode = options.argv.cooked.indexOf("--" + mode);
|
|
146
|
+
if (indexMode != -1 && options.argv.cooked.length > indexMode + 2 && !options.argv.cooked[indexMode + 2].match(/^--[a-z]+$/)) {
|
|
147
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const argName = (options.info) ? "info" : mode;
|
|
151
|
+
const inDevice = _getParams(options, argName);
|
|
152
|
+
if (!inDevice.name) {
|
|
153
|
+
if (options[mode] === "true") {
|
|
154
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
155
|
+
}
|
|
156
|
+
inDevice.name = options[mode];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
log.info("modifyDeviceInfo()", "devicename:", inDevice.name, ", mode:", mode);
|
|
160
|
+
|
|
161
|
+
if (inDevice.default !== undefined && mode === "modify") {
|
|
162
|
+
log.verbose("modifyDeviceInfo()", "Ignoring invalid arguments:default");
|
|
163
|
+
inDevice.default = undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (inDevice.privateKey) {
|
|
167
|
+
inDevice.privatekey = inDevice.privateKey;
|
|
168
|
+
}
|
|
169
|
+
if (typeof inDevice.privatekey === "string") {
|
|
170
|
+
inDevice.privateKey = inDevice.privatekey;
|
|
171
|
+
inDevice.privateKey = { "openSsh": inDevice.privateKey };
|
|
172
|
+
delete inDevice.privatekey;
|
|
173
|
+
inDevice.password = "@DELETE@";
|
|
174
|
+
}
|
|
175
|
+
if (typeof inDevice.password !== "undefined" && inDevice.password !== "@DELETE@") {
|
|
176
|
+
inDevice.privateKey = "@DELETE@";
|
|
177
|
+
inDevice.passphrase = "@DELETE@";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (mode === "add") {
|
|
181
|
+
replaceDefaultDeviceInfo(inDevice);
|
|
182
|
+
if (!inDevice.privateKey && !inDevice.password) {
|
|
183
|
+
inDevice.password = "";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// check validation
|
|
187
|
+
if (!isValidDeviceName(inDevice.name)) {
|
|
188
|
+
return next(errHndl.getErrMsg("INVALID_DEVICENAME"));
|
|
189
|
+
}
|
|
190
|
+
if (inDevice.host && !isValidIpv4(inDevice.host)) {
|
|
191
|
+
return next(errHndl.getErrMsg("INVALID_VALUE", "host", inDevice.host));
|
|
192
|
+
}
|
|
193
|
+
if (inDevice.port && !isValidPort(inDevice.port)) {
|
|
194
|
+
return next(errHndl.getErrMsg("INVALID_VALUE", "port", inDevice.port));
|
|
195
|
+
}
|
|
196
|
+
if (inDevice.port) {
|
|
197
|
+
inDevice.port = Number(inDevice.port);
|
|
198
|
+
}
|
|
199
|
+
if (!inDevice.profile) {
|
|
200
|
+
inDevice.profile = defaultDeviceInfo.profile;
|
|
201
|
+
}
|
|
202
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver());
|
|
203
|
+
async.series([
|
|
204
|
+
resolver.load.bind(resolver),
|
|
205
|
+
resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
|
|
206
|
+
this.showDeviceList.bind(this)
|
|
207
|
+
], function(err, results) {
|
|
208
|
+
if (err) {
|
|
209
|
+
return next(err);
|
|
210
|
+
}
|
|
211
|
+
if(results[2] && results[2].msg){
|
|
212
|
+
console.log(results[2].msg);
|
|
213
|
+
}
|
|
214
|
+
if(inDevice.username === 'prisoner' && mode === 'add'){
|
|
215
|
+
displayGetKeyGuide(inDevice.name);
|
|
216
|
+
}
|
|
217
|
+
next();
|
|
218
|
+
});
|
|
219
|
+
} catch (err) {
|
|
220
|
+
next(err);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
function _getDeviceInfo(mode, next) {
|
|
225
|
+
const datas= [],
|
|
226
|
+
resolver = new novacom.Resolver();
|
|
227
|
+
async.waterfall([
|
|
228
|
+
resolver.load.bind(resolver),
|
|
229
|
+
resolver.list.bind(resolver),
|
|
230
|
+
function(devices, next) {
|
|
231
|
+
if (Array.isArray(devices)) {
|
|
232
|
+
devices.forEach(function(device) {
|
|
233
|
+
const conn = device.conn.concat([]),
|
|
234
|
+
info = (device.username && device.host && device.port) ? device.username + '@' + device.host + ':' + device.port : device.id,
|
|
235
|
+
item = {
|
|
236
|
+
profile: device.profile,
|
|
237
|
+
name: device.name,
|
|
238
|
+
default: device.default,
|
|
239
|
+
deviceinfo: {},
|
|
240
|
+
connection: device.conn || ['ssh'],
|
|
241
|
+
details: {
|
|
242
|
+
platform: device.type
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
if (conn.length === 1 && conn.indexOf('novacom') !== -1) {
|
|
247
|
+
item.deviceinfo.uid = device.id;
|
|
248
|
+
item.details.type = device.name.slice(0, 3);
|
|
249
|
+
} else {
|
|
250
|
+
item.deviceinfo = {
|
|
251
|
+
ip: device.host,
|
|
252
|
+
port: String(device.port),
|
|
253
|
+
user: device.username
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
item.details.password = device.password;
|
|
257
|
+
item.details.privatekey = device.privateKeyName;
|
|
258
|
+
item.details.passphrase = device.passphrase;
|
|
259
|
+
item.details.description = device.description;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (device.id) {
|
|
263
|
+
item.deviceinfo.uid = device.id;
|
|
264
|
+
item.details.type = device.name.slice(0, 3);
|
|
265
|
+
}
|
|
266
|
+
const data = (mode === 'full') ? item : {name: device.name, default: device.default, info:info, connection: (device.conn || 'ssh'), profile: device.profile };
|
|
267
|
+
datas.push(data);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
next(null, datas);
|
|
271
|
+
}
|
|
272
|
+
], function(err, results) {
|
|
273
|
+
next(err, results);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function _getParams(argv, option) {
|
|
278
|
+
let inputParams = [];
|
|
279
|
+
const params = {};
|
|
280
|
+
if (argv[option]) {
|
|
281
|
+
inputParams = [].concat(argv[option]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (inputParams.length === 1 && inputParams[0].indexOf('{') !== -1 && inputParams[0].indexOf('}') !== -1 &&
|
|
285
|
+
((inputParams[0].split("'").length - 1) % 2) === 0) {
|
|
286
|
+
// eslint-disable-next-line no-useless-escape
|
|
287
|
+
inputParams[0] = inputParams[0].replace(/\'/g, '"');
|
|
288
|
+
}
|
|
289
|
+
inputParams.forEach(function(strParam) {
|
|
290
|
+
try {
|
|
291
|
+
const data = JSON.parse(strParam);
|
|
292
|
+
for (const k in data) {
|
|
293
|
+
params[k] = data[k];
|
|
294
|
+
}
|
|
295
|
+
} catch (err) {
|
|
296
|
+
const tokens = strParam.split('=');
|
|
297
|
+
if (tokens.length === 2) {
|
|
298
|
+
params[tokens[0]] = tokens[1];
|
|
299
|
+
log.verbose("_getParams()", "Inserting params ", tokens[0] + " = " + tokens[1]);
|
|
300
|
+
} else {
|
|
301
|
+
log.verbose("_getParams()", "Ignoring invalid arguments:", strParam);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// FIXME : -i default=true is set as "true" string
|
|
307
|
+
if (params.default !== undefined && typeof params.default === "string") {
|
|
308
|
+
params.default = (params.default === "true");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
log.silly("_getParams()", "params:", JSON.stringify(params));
|
|
312
|
+
return params;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function replaceDefaultDeviceInfo(inDevice) {
|
|
316
|
+
if (inDevice) {
|
|
317
|
+
inDevice.profile = inDevice.profile || defaultDeviceInfo.profile;
|
|
318
|
+
inDevice.type = inDevice.type || defaultDeviceInfo.type;
|
|
319
|
+
inDevice.host = inDevice.host || defaultDeviceInfo.ipAddress;
|
|
320
|
+
inDevice.port = inDevice.port || defaultDeviceInfo.port;
|
|
321
|
+
inDevice.username = inDevice.username || defaultDeviceInfo.user;
|
|
322
|
+
inDevice.files = inDevice.files || defaultDeviceInfo.files;
|
|
323
|
+
inDevice.description = inDevice.description || defaultDeviceInfo.description;
|
|
324
|
+
inDevice.default = inDevice.default || defaultDeviceInfo.default;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function displayGetKeyGuide(deviceName) {
|
|
329
|
+
const guideSteps = "** To connect to TV you need to do following steps:"
|
|
330
|
+
+ "\n 1. Turning on Developer Mode following this guide: https://webostv.developer.lge.com/develop/getting-started/developer-mode-app"
|
|
331
|
+
+ "\n 2. Launch the Developer Mode app and click the Key Server button in the Developer Mode app"
|
|
332
|
+
+ "\n 3. Get the ssh key file from your webOS TV with the following command on your PC"
|
|
333
|
+
+ "\n > ares-novacom --device " + deviceName + " --getkey"
|
|
334
|
+
+ "\n > Enter the passphrase displayed on the Developer Mode app";
|
|
335
|
+
|
|
336
|
+
console.log(guideSteps);
|
|
337
|
+
}
|
|
338
|
+
}());
|