iosignal-cli 1.0.0

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 ADDED
@@ -0,0 +1,198 @@
1
+ # IOSignal CLI
2
+
3
+ iosignal-cli program that makes it simple to run a iosignal server and client. It uses the [iosignal](https://www.npmjs.com/package/iosignal) library and uses Redis for authentication database functionality.
4
+
5
+ ## supports
6
+ Windows, Mac, and Linux.
7
+
8
+ ## install
9
+ Linux, Mac and shell
10
+ ```sh
11
+ # global install.
12
+ $ npm install -g iosignal-cli
13
+
14
+ # If NO Permissioin error, use sudo prefix.
15
+ $ sudo npm install -g iosignal-cli
16
+ ```
17
+ windows as admin permission
18
+ ```sh
19
+ # global install.
20
+ $ npm install -g iosignal-cli
21
+ ```
22
+
23
+
24
+ ## IOSignal server
25
+
26
+ ```sh
27
+ $ io-server
28
+ # start server with default option.
29
+ # default. open port 7777 with WebSocket.
30
+
31
+
32
+ $ io-server -l 5555
33
+ # you can specify listen port number
34
+
35
+ $ io-server -l 0 -L 5555
36
+ # use number 0 to disable WebSocket service.
37
+
38
+ ```
39
+
40
+ ## iosignal client
41
+
42
+
43
+ ```sh
44
+ $ io # or io alias
45
+ # connect to localhost:7777 with websocket.
46
+
47
+ # use -c to define websocket url and port number.
48
+ $ io -c wss://websocket_server_url:port
49
+ $ io -c ws://localhost:7777
50
+
51
+ # support ws or wss(TLS).
52
+
53
+ ```
54
+
55
+ ## iosignal commands
56
+
57
+ - subscribe('tag')
58
+ - publish('tag', message )
59
+ - signal('tag', message ) // same with publish
60
+ - not ready whole document.
61
+
62
+ ## tutorial
63
+
64
+ ### signaling
65
+
66
+ - multi-cast: publish/subscribe channel_name
67
+ - uni-cast: use cid(communication id)
68
+
69
+ 1. start server
70
+ ```sh
71
+ $ io-server # alias ios
72
+
73
+ ```
74
+
75
+ 2. start client A.
76
+
77
+ ```sh
78
+ $ io
79
+ Connecting to ws://localhost:7777
80
+ ready: cid: ?c3Nr
81
+ # connected and receive client cid.
82
+ # CID(Communicaion Id of the io client.)
83
+
84
+ > .subscribe channel_name
85
+ # subscribe some channel
86
+ ```
87
+
88
+ 3. start client B.
89
+ ```sh
90
+ $ io
91
+ Connecting to ws://localhost:7777
92
+ ready: cid: ?rr75
93
+ >
94
+ # connected and received cid.
95
+
96
+ # multicast.
97
+ > .signal channel_name some_message
98
+
99
+ # unicast to A.
100
+ > .signal ?c3Nr@ direct_message
101
+ # IMPORTANT.
102
+ # unicast signal tag must include '@' charactor. tag = 'cid' + @
103
+ ```
104
+
105
+ ### authentication
106
+
107
+ #### type1. auth data from file.
108
+
109
+ - for personal use only
110
+ - raw plain password string. (Not Hashed)
111
+ - each device have 4 values: `deviceId`, `deviceKey`, `deviceCId`, `level`
112
+ - you can find sample auth_file.mjs and auth_file.json in root folder.
113
+ ```sh
114
+ $ io-server -d auth_file.json
115
+ or
116
+ $ io-server -d auth_file.mjs
117
+ ```
118
+
119
+ auth_file.json structure
120
+ - deviceId string size limit: 8 charactors.
121
+ - No passphrase string limit. (It will be digested 32bytes with sha256.)
122
+ - CID string size limit: current 20 chars. can be changed.
123
+ - JSON file does not support comment.
124
+ ```js
125
+ [
126
+ ["id","key","cid",0],
127
+ ["did2","did2key","did2-cid",0],
128
+ ["uno3","uno3-key","uno3-cid",1]
129
+ ]
130
+ ```
131
+
132
+ ### auth_file.mjs
133
+ - support comments.
134
+
135
+ ```js
136
+ // *.mjs file support comments.
137
+ export const authInfo = [
138
+ // device id, key, communication id, level:Number(0~255)
139
+ ["did","passowrd","cid",0],
140
+ ["device1","device1_key","device1_cid",0],
141
+ ["root","root-key","root-cid",255], // default admin_root level is 255
142
+ ["uno","uno-key","uno",1]
143
+ ]
144
+ ```
145
+
146
+
147
+
148
+ #### type2. auth data from Redis(or other DataBase)
149
+ - Recommended
150
+ - you can find source and examples here.
151
+ - `iosiganl` "/src/auth/"
152
+ - `iosignal-cli` "/test_auth_redis/"
153
+
154
+ Before running the server, you need to make sure that your Redis server is up and running and that you have registered your device credentials. A simple credentials enrollment example is included in the source above.
155
+
156
+ start server with local redis-auth-system
157
+ ```sh
158
+ $ io-server -r // redis://localhost:6379
159
+ ```
160
+
161
+
162
+ #### auth client
163
+ 1. start auth server.
164
+ 2. connect and login
165
+
166
+ ```sh
167
+ $ io
168
+ ready: cid: ?YXDr
169
+ > .login uno3 uno3-key
170
+ try manual login: uno3
171
+ > >> QUOTA_LEVEL : 1
172
+ current quota: {"signalSize":255,"publishCounter":10,"trafficRate":100000}
173
+ ready: cid: uno3-cid
174
+
175
+ # now device have (pre-registered) CID.
176
+
177
+ ```
178
+
179
+ ## Support for both web browsers and Arduino
180
+ ### Specifying two types of ports
181
+ IOSignal uses websockets for web browser peer connections. If you want to use an Arduino connection, you must specify the use of the CongSocket port using the -L option.
182
+
183
+ The -l option specifies the Websocket port, and the -L option specifies the CongSocket port for the Arduino.
184
+
185
+ ```sh
186
+
187
+ $ io-server -l 7777 -L 8888
188
+ # -l option for WebSocket port
189
+ # -L option for CongSocket port ( Arduino connection)
190
+ ```
191
+
192
+ ### IOSignal Arduino Library
193
+
194
+ Search for `IOSignal` in the Arduino library manager and install it, or see the [`iosignal-arduino`](https://github.com/remocons/iosignal-arduino) github repository
195
+
196
+
197
+ ## iosignal stack
198
+ ![IOSignal](./img/iosignal_stack.png)
@@ -0,0 +1,9 @@
1
+ import { readFile } from 'fs/promises';
2
+
3
+ const json = JSON.parse(
4
+ await readFile(
5
+ new URL('../package.json', import.meta.url)
6
+ )
7
+ );
8
+
9
+ export let version = json.version
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { IO, IOCongSocket, ENC_MODE, serverOption } from 'iosignal'
4
+ import { EventEmitter } from 'events'
5
+ import readline from 'readline'
6
+ import tty from 'tty'
7
+ import { program } from 'commander'
8
+ import { version } from './getVersion.js'
9
+
10
+ class Console extends EventEmitter {
11
+ constructor() {
12
+ super()
13
+
14
+ this.showIncommingMessage = true
15
+ this.stdin = process.stdin
16
+ this.stdout = process.stdout
17
+ this.stderr = process.stderr
18
+
19
+ this.readlineInterface = readline.createInterface(this.stdin, this.stdout)
20
+
21
+ this.readlineInterface
22
+ .on('line', (data) => {
23
+ this.emit('line', data)
24
+ })
25
+ .on('close', () => {
26
+ this.emit('close')
27
+ })
28
+
29
+ this._resetInput = () => {
30
+ this.clear()
31
+ }
32
+ }
33
+
34
+ static get Colors() {
35
+ return {
36
+ Red: '\u001b[31m',
37
+ Green: '\u001b[32m',
38
+ Yellow: '\u001b[33m',
39
+ Blue: '\u001b[34m',
40
+ Default: '\u001b[39m'
41
+ }
42
+ }
43
+
44
+ static get Types() {
45
+ return {
46
+ Incoming: '< ',
47
+ Control: '',
48
+ Error: 'error: ',
49
+ Put: '.'
50
+ }
51
+ }
52
+
53
+ prompt() {
54
+ this.readlineInterface.prompt(true)
55
+ }
56
+
57
+ print(type, msg, color) {
58
+ if (tty.isatty(1)) {
59
+ this.clear()
60
+
61
+ // if (options.execute) color = type = '';
62
+ // else if (!options.color) color = '';
63
+
64
+ this.stdout.write(color + type + msg + Console.Colors.Default + '\n')
65
+ this.prompt()
66
+ } else if (type === Console.Types.Incoming) {
67
+ this.stdout.write(msg + '\n')
68
+ } else if (type === Console.Types.Error) {
69
+ this.stderr.write(type + msg + '\n')
70
+ } else if (type === Console.Types.Put) {
71
+ // this.stdout.write( '.' )
72
+ } else {
73
+ // is a control message and we're not in a tty... drop it.
74
+ }
75
+ }
76
+
77
+ clear() {
78
+ if (tty.isatty(1)) {
79
+ this.stdout.write('\r\u001b[2K\u001b[3D')
80
+ }
81
+ }
82
+
83
+ pause() {
84
+ this.stdin.on('keypress', this._resetInput)
85
+ }
86
+
87
+ resume() {
88
+ this.stdin.removeListener('keypress', this._resetInput)
89
+ }
90
+ }
91
+
92
+ function noop() { }
93
+
94
+ program
95
+ .version(version)
96
+ .usage('[options] (--connect <url> )')
97
+ .option('-t, --timeout <milliseconds>', 'ping period & timeout')
98
+ .option('-s, --show-message <none|message|frame>', 'show receive message. ')
99
+ .option('-c, --connect <url>', 'connect to a server')
100
+ .option('-i, --id <id>', 'userId')
101
+ .option('-k, --key <key>', 'userKey')
102
+ .option('-a, --auth-idKey <idkey>', 'auth id.key')
103
+ .option('-j, --join-channel <channelName>', 'join to channel')
104
+ .parse(process.argv)
105
+
106
+ const options = program.opts()
107
+
108
+ console.log(options)
109
+
110
+
111
+ if (!options.connect) {
112
+ options.connect = 'localhost:' + serverOption.port;
113
+ }
114
+
115
+
116
+ const wsConsole = new Console()
117
+
118
+ let connectUrl = options.connect
119
+ // console.log('connectUrl raw', connectUrl )
120
+
121
+ let io;
122
+
123
+
124
+ if (connectUrl.indexOf('cong') === 0) {
125
+ //use TCP connection
126
+ io = new IOCongSocket(connectUrl)
127
+ } else { // ws connection
128
+ if (!connectUrl.match(/\w+:\/\/.*$/i)) {
129
+ connectUrl = `ws://${connectUrl}`
130
+ }
131
+ io = new IO(connectUrl)
132
+ }
133
+
134
+ if (options.id && options.key) {
135
+ io.auth(options.id, options.key)
136
+ } else if (options.authIdKey) {
137
+ io.auth(options.authIdKey)
138
+ }
139
+
140
+
141
+ io.listen('@', (...args) => {
142
+ console.log('rcv @', args)
143
+ })
144
+
145
+ if (options.joinChannel) {
146
+ console.log('options joinchannel', options.joinChannel)
147
+ io.channels.add(options.joinChannel)
148
+
149
+ }
150
+
151
+
152
+ wsConsole.print(Console.Types.Control, `Connecting to ${connectUrl}`, Console.Colors.Yellow)
153
+
154
+ io.on('@pong', (...data) => {
155
+ wsConsole.print(
156
+ Console.Types.Control,
157
+ `>> receive pong from ${data[0]}`,
158
+ Console.Colors.Yellow)
159
+ })
160
+
161
+ io.on('ready', () => {
162
+ wsConsole.print(
163
+ Console.Types.Control,
164
+ `ready: cid: ${io.cid}`,
165
+ Console.Colors.Green)
166
+ })
167
+
168
+ io.on('close', () => {
169
+ wsConsole.print(Console.Types.Control, `closed`, Console.Colors.Yellow)
170
+ })
171
+
172
+
173
+ io.on('authorized', () => {
174
+ wsConsole.print(
175
+ Console.Types.Control,
176
+ `Boho authorized. TLS: ${io.TLS}`,
177
+ Console.Colors.Yellow)
178
+ })
179
+
180
+ io.on('auth_fail', () => {
181
+ wsConsole.print(
182
+ Console.Types.Control,
183
+ `Boho auth_fail.`,
184
+ Console.Colors.Yellow)
185
+ })
186
+ io.on('over_size', () => {
187
+ wsConsole.print(
188
+ Console.Types.Control,
189
+ `OVER_SIZE: your signalSize limit is: ${io.quota.signalSize}`,
190
+ Console.Colors.Yellow)
191
+ })
192
+
193
+
194
+ io.on('message', (data, isBinary) => {
195
+
196
+ let moreBytesIndicator = ""
197
+ if (isBinary) {
198
+ let buffer
199
+ const displayBufferLimit = 20
200
+ if (data.byteLength > displayBufferLimit) {
201
+ buffer = Buffer.from(data, 0, displayBufferLimit);
202
+ moreBytesIndicator = "..."
203
+ } else {
204
+ buffer = Buffer.from(data);
205
+ }
206
+
207
+ let prn = `${buffer.toString('hex')}${moreBytesIndicator} [${data.byteLength} bytes total]`;
208
+ if (wsConsole.showIncommingMessage) wsConsole.print(Console.Types.Incoming, `rx: bin [hex] ${prn}`, Console.Colors.Green)
209
+
210
+ } else {
211
+ if (wsConsole.showIncommingMessage) wsConsole.print(Console.Types.Incoming, `rx: text: ${data}`, Console.Colors.Green)
212
+ }
213
+ })
214
+
215
+ // to send frame message.
216
+ wsConsole.on('line', (data) => {
217
+ if (data[0] === '.') {
218
+ const toks = data.split(/\s+/)
219
+ const cmd = toks[0].substring(1)
220
+ let ch = ""
221
+ switch (cmd) {
222
+ case 'login':
223
+ toks.shift()
224
+ io.login(...toks)
225
+ break;
226
+ case 'auth':
227
+ toks.shift()
228
+ io.auth(...toks)
229
+ break;
230
+
231
+ case 'encNo':
232
+ io.encMode = ENC_MODE.NO
233
+ wsConsole.print(Console.Types.Incoming, `encMode: ${ENC_MODE[io.encMode]}`, Console.Colors.Green)
234
+ break;
235
+ case 'encYes':
236
+ io.encMode = ENC_MODE.YES
237
+ wsConsole.print(Console.Types.Incoming, `encMode: ${ENC_MODE[io.encMode]}`, Console.Colors.Green)
238
+ break;
239
+ case 'encAuto':
240
+ io.encMode = ENC_MODE.AUTO
241
+ wsConsole.print(Console.Types.Incoming, `encMode: ${ENC_MODE[io.encMode]}`, Console.Colors.Green)
242
+ break;
243
+ case 'encMode':
244
+ wsConsole.print(Console.Types.Incoming, `encMode: ${ENC_MODE[io.encMode]}`, Console.Colors.Green)
245
+ break;
246
+
247
+ case 'echo':
248
+ io.echo(toks[1])
249
+ break;
250
+
251
+ case 'iam':
252
+ io.iam(toks[1])
253
+ break;
254
+
255
+ case 'id':
256
+ console.log(`cid: ${io.cid} level: ${io.level}`)
257
+ break;
258
+
259
+ case 'sudo':
260
+ toks.shift()
261
+ console.log('sudo toks', toks)
262
+ io.req('sudo', ...toks).then(res => {
263
+ if (res.ok) {
264
+ console.log('>> sudo response:', res.body)
265
+ } else {
266
+ console.log('>> sudo response:', res.body)
267
+ }
268
+ }).catch(err => {
269
+ console.log('sudo call err', err)
270
+ })
271
+
272
+ break;
273
+
274
+
275
+ case 'quota':
276
+ console.log(`quota: ${JSON.stringify(io.quota)}`)
277
+ break;
278
+
279
+ case 'ch':
280
+ let chList = []
281
+ io.channels.forEach(v => {
282
+ chList.push(v)
283
+ })
284
+ console.log(`channels: ${chList.toString()}`)
285
+ break;
286
+
287
+ case 'sig':
288
+ case 'signal':
289
+ toks.shift()
290
+ io.signal(...toks)
291
+ break;
292
+
293
+ case 'sig_bin':
294
+ toks.shift()
295
+ let to = toks[0]
296
+ let size = parseInt(toks[1])
297
+ console.log(`signal tag: ${to} size: ${size}`)
298
+ io.signal(to, new Uint8Array(size))
299
+ break;
300
+
301
+ case 'pub':
302
+ case 'publish':
303
+ toks.shift()
304
+ io.publish(...toks)
305
+ break;
306
+
307
+ case 'set':
308
+ io.set(toks[1])
309
+ break;
310
+
311
+ case 'api':
312
+ case 'req':
313
+ toks.shift()
314
+ if (toks.length < 2) {
315
+ wsConsole.print(
316
+ Console.Types.Error,
317
+ '[.req need at least two params] req target command [, ..args]',
318
+ Console.Colors.Yellow
319
+ )
320
+ return
321
+ }
322
+ io.req(...toks).then(result => {
323
+ console.log('>> response:', result)
324
+ }).catch(e => {
325
+ console.log(e)
326
+ })
327
+ break;
328
+
329
+ case 'join':
330
+ case 'sub':
331
+ case 'subscribe':
332
+ case 'listen':
333
+ toks.shift()
334
+ let tag = toks[0]
335
+ console.log('listen tag', tag)
336
+ io.listen(tag, (...args) => {
337
+ console.log(`subscribe & listen tag: ${tag} args:`, args)
338
+
339
+ })
340
+ io.subscribe_memory_channels()
341
+ break;
342
+
343
+
344
+ case 'unsub':
345
+ io.unsubscribe(toks[1]);
346
+ break;
347
+
348
+ case 'pping':
349
+ io.signal(toks[1] + "@ping", io.cid)
350
+ break;
351
+ case 'ping':
352
+ io.ping()
353
+ break;
354
+
355
+ case 'pong':
356
+ io.pong()
357
+ break
358
+
359
+ case 'close':
360
+ io.close()
361
+ break
362
+
363
+ case 'open':
364
+ case 'connect':
365
+ if (toks[1]) {
366
+ let url = toks[1]
367
+ if (!url.match(/\w+:\/\/.*$/i)) {
368
+ url = `ws://${url}`
369
+ }
370
+ io.open(url) // new url
371
+ } else {
372
+ io.open() // last url
373
+ }
374
+ break
375
+ case 'show':
376
+ wsConsole.showIncommingMessage = true
377
+ break;
378
+ case 'hide':
379
+ wsConsole.showIncommingMessage = false
380
+ break;
381
+ case 'quit':
382
+ case 'exit':
383
+ process.exit();
384
+ default:
385
+ wsConsole.print(
386
+ Console.Types.Error,
387
+ 'command list: .signal .sig .listen .publish .pub .subscribe .sub .unsub .ping .pong .id .iam .open .connect .close .login .auth .quit .exit',
388
+ Console.Colors.Yellow
389
+ )
390
+ }
391
+ } else {
392
+ }
393
+ wsConsole.prompt()
394
+ })
395
+
396
+
397
+
398
+
399
+
400
+
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { RAND } from 'iosignal'
4
+
5
+ // base64 from random n-byte
6
+ function rand_b64(srcByteSize) {
7
+ return RAND(srcByteSize).toString('base64')
8
+ }
9
+
10
+ // accept 1 ~ 12
11
+ function rand_number_string(len) {
12
+ if (len > 12) throw new RangeError("Member: rand_number range is over.")
13
+
14
+ let bigNumberBuffer, n, nString;
15
+ const cropFrom = 1;
16
+ do {
17
+ bigNumberBuffer = RAND(8);
18
+ n = bigNumberBuffer.readBigUInt64LE(0);
19
+ nString = n.toString()
20
+ // console.log('>', n )
21
+ } while ((n < 2 ** 44) || nString[cropFrom] == '0') // 44-> 14digit.
22
+
23
+ nString = nString.substring(cropFrom, len + cropFrom)
24
+ return nString
25
+ }
26
+
27
+
28
+ let key20 = rand_b64(15)
29
+ let did4 = rand_b64(3)
30
+ let did8 = rand_b64(6)
31
+ let randNumber4 = rand_number_string(4)
32
+ let randNumber8 = rand_number_string(8)
33
+ // console.log('rand number 8chars', rand_number_string(8) )
34
+ // console.log('random 15bytes as base64 20chars: ', key )
35
+ // console.log('random 3bytes as base64 4chars: ', did )
36
+
37
+ console.log('\n random values')
38
+ console.log('+------------------------------------+')
39
+ console.log('| ID:', did4, ' KEY:', key20)
40
+ console.log('+------------------------------------+')
41
+ console.log('| ID_KEY: ', did4 + '.' + key20)
42
+ console.log('+------------------------------------+')
43
+ console.log('| numbers: ', randNumber4, randNumber8)
44
+ console.log('+------------------------------------+')
45
+ console.log('')
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ Server, serverOption, Auth_File, Auth_Env, Auth_Redis,
5
+ api_reply, api_sudo, RedisAPI
6
+ } from 'iosignal'
7
+ import { createClient } from 'redis';
8
+ import { program } from 'commander'
9
+ import { version } from './getVersion.js'
10
+
11
+ program
12
+ .version(version)
13
+ .usage('[options] (--listen <port> )')
14
+ .option('-l, --listen <port>', 'listen on port (start WebSocket Server)')
15
+ .option('-L, --listen-congport <port>', 'listen on cong port (start CongSocket Server)')
16
+ .option('-d, --auth-file <path>', 'auth data file path')
17
+ .option('-e, --auth-param <id.key.level>', 'auth data from argument: id.key.level,id2.key2.level2')
18
+ .option('-E, --auth-env', 'auth data from shell env BOHO_AUTH')
19
+ .option('-r, --auth-redis', 'connect to redis. if exist use env REDIS_HOST, REDIS_PORT or localhost:6379')
20
+ .option('-t, --timeout <milliseconds>', 'ping period & timeout')
21
+ .option('-m, --metric <type>', 'show metric <number> 1:traffic, 2:echo')
22
+ .option('-s, --show-message <none|message|frame>', 'show receive message. ')
23
+ .option('-f, --file-logger', 'write log files.')
24
+ .option('-a, --api-list [list...]', 'one or multiple api names: -a api_1 api_2 ')
25
+ .option('-o, --show-options', 'show server init options.')
26
+ .parse(process.argv)
27
+
28
+ const options = program.opts()
29
+
30
+
31
+ if (options.fileLogger) {
32
+ serverOption.fileLogger.connection.use = true;
33
+ serverOption.fileLogger.auth.use = true;
34
+ serverOption.fileLogger.attack.use = true;
35
+ }
36
+
37
+ if (options.listen) {
38
+ serverOption.port = options.listen
39
+ }
40
+
41
+ if (options.listenCongport) {
42
+ serverOption.congPort = parseInt(options.listenCongport)
43
+ }
44
+
45
+ if (options.showMessage) {
46
+ serverOption.showMessage = options.showMessage
47
+ }
48
+
49
+ if (options.metric) {
50
+ serverOption.showMetric = options.metric
51
+ }
52
+
53
+ if (options.timeout) {
54
+ serverOption.timeout = options.timeout
55
+ }
56
+
57
+
58
+ let authManager;
59
+ let redisClient;
60
+
61
+ if (options.authFile) {
62
+ console.log("auth data origin: auth_file")
63
+ let authFilePath = options.authFile;
64
+ authManager = new Auth_File(authFilePath)
65
+ } else if (options.authParam) {
66
+ authManager = new Auth_Env(options.authParam)
67
+ } else if (options.authEnv) {
68
+ authManager = new Auth_Env()
69
+ } else if (options.authRedis) {
70
+ console.log("auth data origin: redis")
71
+ // console.log('####### default redis server url: redis://localhost:6379 ' )
72
+ redisClient = createClient();
73
+ redisClient.on('error', (err) => console.log('Redis Client Error', err));
74
+ redisClient.connect();
75
+ authManager = new Auth_Redis(redisClient)
76
+ } else {
77
+ console.log("No authentication support.")
78
+
79
+ }
80
+
81
+
82
+ const server = new Server(serverOption, authManager)
83
+
84
+ if (options.apiList && options.apiList.length > 0) {
85
+ let apiList = options.apiList
86
+ console.log('api list', apiList)
87
+ if (apiList.includes('reply')) server.api('reply', api_reply)
88
+ if (apiList.includes('sudo')) server.api('sudo', api_sudo)
89
+ if (apiList.includes('redis')) server.api('redis', new RedisAPI(redisClient))
90
+
91
+ }
92
+
93
+ if (options.showOptions) {
94
+ console.log('ServerOptions:', serverOption)
95
+ console.log('server api list', server.apiNames)
96
+ }
97
+
98
+
99
+
Binary file
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "iosignal-cli",
3
+ "version": "1.0.0",
4
+ "description": "IOSignal server and client CLI program.",
5
+ "type": "module",
6
+ "bin": {
7
+ "io-server": "./bin/io-server.js",
8
+ "io-client": "./bin/io-client.js",
9
+ "ios": "./bin/io-server.js",
10
+ "io": "./bin/io-client.js",
11
+ "io-keygen": "./bin/io-keygen.js"
12
+ },
13
+ "author": {
14
+ "name": "Lee Dongeun",
15
+ "email": "sixgen@gmail.com"
16
+ },
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "commander": "^11.1.0",
20
+ "iosignal": "^1.0.0",
21
+ "meta-buffer-pack": "^1.3.1",
22
+ "redis": "^4.6.12"
23
+ }
24
+ ,
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/remocons/iosignal-cli.git"
28
+ },
29
+ "homepage": "https://iosignal.net",
30
+ "keywords": [
31
+ "io","pubsub","arduino","iot","auth","signal","CLI","remocon"
32
+ ]
33
+ }
@@ -0,0 +1,32 @@
1
+ import { Auth_Redis } from 'iosignal'
2
+ import { createClient } from 'redis';
3
+
4
+ let redisClient = createClient();
5
+ redisClient.on('error', (err) => console.log('Redis Client Error', err));
6
+ redisClient.connect();
7
+
8
+ let auth = new Auth_Redis( redisClient)
9
+
10
+ //addUSer(did,dkey,cid,level)
11
+ if( process.argv.length != 5 ){
12
+ console.log('=> $ node addAdmin.js id key cid')
13
+ process.exit()
14
+ }
15
+
16
+ let did = process.argv[2]
17
+ let dkey = process.argv[3]
18
+ let cid = process.argv[4]
19
+
20
+ let addResult = await auth.addAuth( did, dkey, cid ,255)
21
+ let getResult = await auth.getAuth( did )
22
+ let saveResult = await auth.save();
23
+
24
+ console.log('add',addResult )
25
+ console.log('get',getResult)
26
+ console.log('data.key',getResult.key)
27
+ console.log('save result', saveResult)
28
+
29
+ process.exit()
30
+
31
+
32
+
@@ -0,0 +1,29 @@
1
+ import { Auth_Redis } from 'iosignal'
2
+ import { createClient } from 'redis';
3
+
4
+ let redisClient = createClient();
5
+ redisClient.on('error', (err) => console.log('Redis Client Error', err));
6
+ redisClient.connect();
7
+
8
+ let auth = new Auth_Redis( redisClient)
9
+
10
+ // node filename base_id level number
11
+ // node uno 1 10
12
+ //addUSer(did,dey,cid,level)
13
+ let baseId = process.argv[2] ? process.argv[2] : 'uno'
14
+ let level = process.argv[3] ? process.argv[3] : 1;
15
+ let n = process.argv[4] ? process.argv[4] : 10;
16
+
17
+ console.log( baseId, n )
18
+ for(let i=0; i< n ;i++){
19
+ let id = baseId + i;
20
+ let addResult = await auth.addAuth( id, id, id ,level)
21
+ console.log('add',addResult )
22
+ }
23
+
24
+ await auth.save();
25
+
26
+ process.exit()
27
+
28
+
29
+
@@ -0,0 +1,24 @@
1
+ import { Auth_Redis } from 'iosignal'
2
+ import { createClient } from 'redis';
3
+
4
+ let redisClient = createClient();
5
+ redisClient.on('error', (err) => console.log('Redis Client Error', err));
6
+ redisClient.connect();
7
+
8
+ let auth = new Auth_Redis( redisClient)
9
+
10
+ //addUSer(did,dey,cid,level)
11
+ let addResult = await auth.addAuth('uno','uno','uno',1)
12
+ let getResult = await auth.getAuth('uno')
13
+ let wrongResult = await auth.getAuth('noid')
14
+
15
+ console.log('add',addResult )
16
+ console.log('get',getResult)
17
+ console.log('data.key',getResult.key)
18
+ console.log('wrongResult',wrongResult)
19
+ console.log('wrongResult.key',wrongResult?.key)
20
+
21
+ process.exit()
22
+
23
+
24
+
@@ -0,0 +1,12 @@
1
+ import { Auth_Redis , serverOption , Server } from 'iosignal'
2
+ import { createClient } from 'redis';
3
+
4
+ let redisClient = createClient();
5
+ redisClient.on('error', (err) => console.log('Redis Client Error', err));
6
+ redisClient.connect();
7
+
8
+ let authManager = new Auth_Redis( redisClient)
9
+
10
+ serverOption.showMessage = 'message';
11
+ const server = new Server( serverOption ,authManager )
12
+ console.log( 'serverOption:', serverOption )