@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +173 -157
  2. package/LICENSES/342/200/216/LicenseRef-3rd_party_licenses.txt +1355 -0
  3. package/README.md +21 -19
  4. package/bin/ares-config.js +6 -3
  5. package/bin/ares-device.js +2 -2
  6. package/bin/ares-log.js +6 -2
  7. package/bin/ares-pull.js +1 -1
  8. package/bin/ares-push.js +1 -1
  9. package/bin/ares-setup-device.js +573 -528
  10. package/bin/ares-shell.js +1 -1
  11. package/bin/ares.js +1 -1
  12. package/files/conf/ares.json +5 -5
  13. package/files/conf/novacom-devices.json +18 -1
  14. package/files/conf-base/env/sdk-apollo.json +8 -0
  15. package/files/conf-base/profile/config-apollo.json +29 -0
  16. package/files/conf-base/profile/config-ose.json +1 -1
  17. package/files/conf-base/template-conf/apollo-sdk-templates.json +56 -0
  18. package/files/help/ares-config.help +6 -1
  19. package/files/help/ares-device.help +15 -0
  20. package/files/help/ares-generate.help +27 -1
  21. package/files/help/ares-inspect.help +6 -0
  22. package/files/help/ares-install.help +5 -0
  23. package/files/help/ares-launch.help +5 -0
  24. package/files/help/ares-server.help +5 -0
  25. package/files/help/ares-setup-device.help +40 -0
  26. package/files/help/ares.help +5 -0
  27. package/files/schema/NovacomDevices.schema +2 -1
  28. package/files/templates/apollo-sdk-templates/appinfo/appinfo.json +10 -0
  29. package/files/templates/apollo-sdk-templates/bootplate-web/index.html +88 -0
  30. package/files/templates/apollo-sdk-templates/hosted-webapp/index.html +14 -0
  31. package/files/templates/apollo-sdk-templates/icon/icon.png +0 -0
  32. package/files/templates/apollo-sdk-templates/js-service/helloclient.js +31 -0
  33. package/files/templates/apollo-sdk-templates/js-service/helloworld_webos_service.js +188 -0
  34. package/files/templates/apollo-sdk-templates/native-service/CMakeLists.txt +72 -0
  35. package/files/templates/apollo-sdk-templates/native-service/services.json +11 -0
  36. package/files/templates/apollo-sdk-templates/native-service/src/main.c +144 -0
  37. package/files/templates/apollo-sdk-templates/serviceinfo/package.json +11 -0
  38. package/files/templates/apollo-sdk-templates/serviceinfo/services.json +8 -0
  39. package/lib/base/novacom.js +1 -1
  40. package/lib/base/setup-device.js +338 -335
  41. package/lib/device.js +1 -1
  42. package/lib/generator.js +408 -377
  43. package/lib/package.js +3 -1
  44. package/lib/shell.js +1 -1
  45. package/npm-shrinkwrap.json +9242 -9242
  46. package/package.json +100 -100
  47. package/sbom-info.yaml +1758 -0
  48. package/spec/jsSpecs/ares-config.spec.js +10 -0
  49. package/spec/jsSpecs/ares-generate.spec.js +4 -4
  50. package/spec/jsSpecs/ares-log.spec.js +1 -1
  51. package/spec/test_data/ares-generate.json +18 -1
  52. package/spec/test_data/ares.json +17 -0
  53. package/webos-tools-cli-3.1.3.tgz +0 -0
@@ -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
- return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
146
- }
147
- const argName = (options.info) ? "info" : mode;
148
- const inDevice = _getParams(options, argName);
149
- if (!inDevice.name) {
150
- if (options[mode] === "true") {
151
- return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
152
- }
153
- inDevice.name = options[mode];
154
- }
155
-
156
- log.info("modifyDeviceInfo()", "devicename:", inDevice.name, ", mode:", mode);
157
-
158
- if (inDevice.default !== undefined && mode === "modify") {
159
- log.verbose("modifyDeviceInfo()", "Ignoring invalid arguments:default");
160
- inDevice.default = undefined;
161
- }
162
-
163
- if (inDevice.privateKey) {
164
- inDevice.privatekey = inDevice.privateKey;
165
- }
166
- if (typeof inDevice.privatekey === "string") {
167
- inDevice.privateKey = inDevice.privatekey;
168
- inDevice.privateKey = { "openSsh": inDevice.privateKey };
169
- delete inDevice.privatekey;
170
- inDevice.password = "@DELETE@";
171
- }
172
- if (typeof inDevice.password !== "undefined" && inDevice.password !== "@DELETE@") {
173
- inDevice.privateKey = "@DELETE@";
174
- inDevice.passphrase = "@DELETE@";
175
- }
176
-
177
- if (mode === "add") {
178
- replaceDefaultDeviceInfo(inDevice);
179
- if (!inDevice.privateKey && !inDevice.password) {
180
- inDevice.password = "";
181
- }
182
- }
183
- // check validation
184
- if (!isValidDeviceName(inDevice.name)) {
185
- return next(errHndl.getErrMsg("INVALID_DEVICENAME"));
186
- }
187
- if (inDevice.host && !isValidIpv4(inDevice.host)) {
188
- return next(errHndl.getErrMsg("INVALID_VALUE", "host", inDevice.host));
189
- }
190
- if (inDevice.port && !isValidPort(inDevice.port)) {
191
- return next(errHndl.getErrMsg("INVALID_VALUE", "port", inDevice.port));
192
- }
193
- if (inDevice.port) {
194
- inDevice.port = Number(inDevice.port);
195
- }
196
- if (!inDevice.profile) {
197
- inDevice.profile = defaultDeviceInfo.profile;
198
- }
199
- const resolver = this.resolver || (this.resolver = new novacom.Resolver());
200
- async.series([
201
- resolver.load.bind(resolver),
202
- resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
203
- this.showDeviceList.bind(this),
204
- ], function(err, results) {
205
- if (err) {
206
- return next(err);
207
- }
208
- if(results[2] && results[2].msg){
209
- console.log(results[2].msg);
210
- }
211
- if(inDevice.username === 'prisoner' && mode === 'add'){
212
- displayGetKeyGuide(inDevice.name);
213
- }
214
- next();
215
- });
216
- } catch (err) {
217
- next(err);
218
- }
219
- };
220
-
221
- function _getDeviceInfo(mode, next) {
222
- const datas= [],
223
- resolver = new novacom.Resolver();
224
- async.waterfall([
225
- resolver.load.bind(resolver),
226
- resolver.list.bind(resolver),
227
- function(devices, next) {
228
- if (Array.isArray(devices)) {
229
- devices.forEach(function(device) {
230
- const conn = device.conn.concat([]),
231
- info = (device.username && device.host && device.port) ? device.username + '@' + device.host + ':' + device.port : device.id,
232
- item = {
233
- profile: device.profile,
234
- name: device.name,
235
- default: device.default,
236
- deviceinfo: {},
237
- connection: device.conn || ['ssh'],
238
- details: {
239
- platform: device.type
240
- }
241
- };
242
-
243
- if (conn.length === 1 && conn.indexOf('novacom') !== -1) {
244
- item.deviceinfo.uid = device.id;
245
- item.details.type = device.name.slice(0, 3);
246
- } else {
247
- item.deviceinfo = {
248
- ip: device.host,
249
- port: String(device.port),
250
- user: device.username
251
- };
252
-
253
- item.details.password = device.password;
254
- item.details.privatekey = device.privateKeyName;
255
- item.details.passphrase = device.passphrase;
256
- item.details.description = device.description;
257
- }
258
-
259
- if (device.id) {
260
- item.deviceinfo.uid = device.id;
261
- item.details.type = device.name.slice(0, 3);
262
- }
263
- const data = (mode === 'full') ? item : {name: device.name, default: device.default, info:info, connection: (device.conn || 'ssh'), profile: device.profile };
264
- datas.push(data);
265
- });
266
- }
267
- next(null, datas);
268
- }
269
- ], function(err, results) {
270
- next(err, results);
271
- });
272
- }
273
-
274
- function _getParams(argv, option) {
275
- let inputParams = [];
276
- const params = {};
277
- if (argv[option]) {
278
- inputParams = [].concat(argv[option]);
279
- }
280
-
281
- if (inputParams.length === 1 && inputParams[0].indexOf('{') !== -1 && inputParams[0].indexOf('}') !== -1 &&
282
- ((inputParams[0].split("'").length - 1) % 2) === 0) {
283
- // eslint-disable-next-line no-useless-escape
284
- inputParams[0] = inputParams[0].replace(/\'/g, '"');
285
- }
286
- inputParams.forEach(function(strParam) {
287
- try {
288
- const data = JSON.parse(strParam);
289
- for (const k in data) {
290
- params[k] = data[k];
291
- }
292
- } catch (err) {
293
- const tokens = strParam.split('=');
294
- if (tokens.length === 2) {
295
- params[tokens[0]] = tokens[1];
296
- log.verbose("_getParams()", "Inserting params ", tokens[0] + " = " + tokens[1]);
297
- } else {
298
- log.verbose("_getParams()", "Ignoring invalid arguments:", strParam);
299
- }
300
- }
301
- });
302
-
303
- // FIXME : -i default=true is set as "true" string
304
- if (params.default !== undefined && typeof params.default === "string") {
305
- params.default = (params.default === "true");
306
- }
307
-
308
- log.silly("_getParams()", "params:", JSON.stringify(params));
309
- return params;
310
- }
311
-
312
- function replaceDefaultDeviceInfo(inDevice) {
313
- if (inDevice) {
314
- inDevice.profile = inDevice.profile || defaultDeviceInfo.profile;
315
- inDevice.type = inDevice.type || defaultDeviceInfo.type;
316
- inDevice.host = inDevice.host || defaultDeviceInfo.ipAddress;
317
- inDevice.port = inDevice.port || defaultDeviceInfo.port;
318
- inDevice.username = inDevice.username || defaultDeviceInfo.user;
319
- inDevice.files = inDevice.files || defaultDeviceInfo.files;
320
- inDevice.description = inDevice.description || defaultDeviceInfo.description;
321
- inDevice.default = inDevice.default || defaultDeviceInfo.default;
322
- }
323
- }
324
-
325
- function displayGetKeyGuide(deviceName) {
326
- const guideSteps = "** To connect to TV you need to do following steps:"
327
- + "\n 1. Turning on Developer Mode following this guide: https://webostv.developer.lge.com/develop/getting-started/developer-mode-app"
328
- + "\n 2. Launch the Developer Mode app and click the Key Server button in the Developer Mode app"
329
- + "\n 3. Get the ssh key file from your webOS TV with the following command on your PC"
330
- + "\n > ares-novacom --device " + deviceName + " --getkey"
331
- + "\n > Enter the passphrase displayed on the Developer Mode app";
332
-
333
- console.log(guideSteps);
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
+ }());