safely-serve 0.0.2 → 0.0.9

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/safely-serve CHANGED
@@ -2,106 +2,369 @@
2
2
 
3
3
  // SPDX-License-Identifier: AGPL-3.0-or-later
4
4
 
5
- // ----------------------------------------------------------------------
6
- // Copyright © 2024, 2025 Pellegrino Prevete
7
- //
8
- // All rights reserved
9
- // ----------------------------------------------------------------------
10
- //
11
- // This program is free software: you can redistribute it and/or modify
12
- // it under the terms of the GNU Affero General Public License as published by
13
- // the Free Software Foundation, either version 3 of the License, or
14
- // (at your option) any later version.
15
- //
16
- // This program is distributed in the hope that it will be useful,
17
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- // GNU Affero General Public License for more details.
20
- //
21
- // You should have received a copy of the GNU Affero General Public License
22
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
5
+ /** ----------------------------------------------------------------------
6
+ * safely-serve
7
+ * ----------------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2024, 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation, either version 3 of the License, or
18
+ * (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+
29
+ /* eslint
30
+ no-undef:
31
+ "error" */
32
+ /* eslint
33
+ no-unused-vars: [
34
+ "error",
35
+ { "vars":
36
+ "local",
37
+ "varsIgnorePattern":
38
+ "_input_args_check" } ] */
23
39
 
24
40
  const
25
41
  _os =
26
42
  require(
27
43
  "os");
28
- _homedir =
29
- _os.homedir;
44
+ const
45
+ _homedir =
46
+ _os.homedir;
30
47
  const
31
48
  _libcrash =
32
49
  require(
33
50
  'crash-js');
34
- _cmdline_check =
35
- _libcrash._cmdline_check;
36
- _msg_info =
37
- _libcrash._msg_info;
38
- _msg_error =
39
- _libcrash._msg_error;
51
+ /* global
52
+ _cmdline_check */
53
+ const
54
+ _cmdline_check =
55
+ _libcrash._cmdline_check;
56
+ /* global
57
+ _msg_info */
58
+ const
59
+ _msg_info =
60
+ _libcrash._msg_info;
61
+ /* global
62
+ _msg_error */
63
+ const
64
+ _msg_error =
65
+ _libcrash._msg_error;
66
+ /* global
67
+ _path_join */
68
+ const
69
+ _path_join =
70
+ _libcrash._path_join;
71
+ /* global
72
+ _process_exit */
73
+ const
74
+ _process_exit =
75
+ _libcrash._process_exit;
76
+ /* global
77
+ _pwd */
78
+ const
79
+ _pwd =
80
+ _libcrash._pwd;
81
+ /* global
82
+ _argv_url_get */
83
+ const
84
+ _argv_url_get =
85
+ _libcrash._argv_url_get;
86
+ /* global
87
+ _yargv_get */
88
+ const
89
+ _yargv_get =
90
+ _libcrash._yargv_get;
40
91
  const
41
92
  _libsafely_serve_module =
42
93
  require(
43
- "./safely-serve");
44
- _safely_serve =
45
- _libsafely_serve_module._safely_serve;
94
+ "./libsafely-serve");
95
+ /* global
96
+ _path_encode */
97
+ const
98
+ _path_encode =
99
+ _libsafely_serve_module._path_encode;
100
+ /* global
101
+ _safely_serve */
102
+ const
103
+ _safely_serve =
104
+ _libsafely_serve_module._safely_serve;
46
105
 
47
106
  function
48
107
  _global_variables() {
108
+ /* global
109
+ app_name:
110
+ writable */
49
111
  app_name =
50
112
  "safely-serve";
51
- target_certificate =
113
+ /* global
114
+ app_opts:
115
+ writable */
116
+ app_opts =
117
+ [];
118
+ /* global
119
+ runtime_environment:
120
+ writable */
121
+ target_directory =
52
122
  "";
123
+ /* global
124
+ target_directory:
125
+ writable */
53
126
  target_directory =
54
127
  "";
55
- key_private =
128
+ /* global
129
+ listen_uris:
130
+ writable */
131
+ listen_uris =
132
+ [];
133
+ /* global
134
+ target_port:
135
+ writable */
136
+ target_port =
137
+ "";
138
+ /* global
139
+ index_redirect:
140
+ writable */
141
+ index_redirect =
142
+ "";
143
+ /* global
144
+ debug_enabled:
145
+ writable */
146
+ debug_enabled =
147
+ "";
148
+ /* global
149
+ config_file:
150
+ writable */
151
+ config_file =
152
+ "";
153
+ /* global
154
+ logging_disabled:
155
+ writable */
156
+ logging_disabled =
157
+ "";
158
+ /* global
159
+ cors_enabled:
160
+ writable */
161
+ cors_enabled =
162
+ "";
163
+ /* global
164
+ clipboard_disabled:
165
+ writable */
166
+ clipboard_disabled =
167
+ "";
168
+ /* global
169
+ compression_disabled:
170
+ writable */
171
+ compression_disabled =
172
+ "";
173
+ /* global
174
+ etag_disabled:
175
+ writable*/
176
+ etag_disabled =
177
+ "";
178
+ /* global
179
+ symlinks_enabled:
180
+ writable */
181
+ symlinks_enabled =
182
+ "";
183
+ /* global
184
+ ssl_cert:
185
+ writable */
186
+ ssl_cert =
187
+ "";
188
+ /* global
189
+ ssl_key:
190
+ writable */
191
+ ssl_key =
192
+ "";
193
+ /* global
194
+ ssl_pass:
195
+ writable */
196
+ ssl_pass =
197
+ "";
198
+ /* global
199
+ cert_gen:
200
+ writable */
201
+ cert_gen =
202
+ "";
203
+ /* global
204
+ port_switching_disabled:
205
+ writable */
206
+ port_switching_disabled =
56
207
  "";
208
+ /* global
209
+ keys_length:
210
+ writable */
57
211
  keys_length =
58
212
  "";
213
+ /* global
214
+ serial_number:
215
+ writable */
59
216
  serial_number =
60
217
  "";
218
+ /* global
219
+ validity_min:
220
+ writable*/
61
221
  validity_min =
62
222
  "";
223
+ /* global
224
+ validity_max:
225
+ writable */
63
226
  validity_max =
64
227
  "";
228
+ /* global
229
+ domain_name:
230
+ writable */
65
231
  domain_name =
66
232
  "";
233
+ /* global
234
+ country_name:
235
+ writable */
67
236
  country_name =
68
237
  "";
238
+ /* global
239
+ state_name:
240
+ writable */
69
241
  state_name =
70
242
  "";
243
+ /* global
244
+ locality_name:
245
+ writable */
71
246
  locality_name =
72
247
  "";
248
+ /* global
249
+ organization_name:
250
+ writable */
73
251
  organization_name =
74
252
  "";
253
+ /* global
254
+ organization_unit:
255
+ writable */
75
256
  organization_unit =
76
257
  "";
77
- output_file =
258
+ /* global
259
+ cache_dir:
260
+ writable */
261
+ cache_dir =
78
262
  "";
263
+ /* global
264
+ quiet:
265
+ writable */
79
266
  quiet =
80
267
  "";
81
268
  }
82
269
 
83
270
  function
84
- _target_certificate_auto_detect() {
85
- let
86
- _encoded_target,
87
- _target_certificate;
88
- _target_certificate =
89
- target_certificate;
90
- if ( _target_certificate == "" ) {
91
- _encoded_target =
92
- _sha256sum(
271
+ _cache_dir_auto_detect() {
272
+ return _homedir() +
273
+ `/.cache/${app_name}`;
274
+ }
275
+
276
+ function
277
+ _work_dir_get(
278
+ _target_directory) {
279
+ const
280
+ _target_directory_encoded =
281
+ _path_encode(
282
+ _target_directory);
283
+ const
284
+ _work_dir =
285
+ _path_join( [
286
+ cache_dir,
287
+ _target_directory_encoded ]);
288
+ return _work_dir;
289
+ }
290
+
291
+ function
292
+ _ssl_config_auto_detect() {
293
+ const
294
+ _work_dir =
295
+ _work_dir_get(
93
296
  target_directory);
94
- _target_certificate =
95
- _homedir() +
96
- `/.cache/${app_name}/${_encoded_target}`;
297
+ if ( ssl_cert == "" ) {
298
+ ssl_cert =
299
+ `${_work_dir}/cert.pem`;
300
+ if ( cert_gen == "" ) {
301
+ cert_gen =
302
+ "y";
303
+ }
304
+ }
305
+ else {
306
+ cert_gen =
307
+ "n";
308
+ }
309
+ if ( ssl_cert == "" ) {
310
+ ssl_cert =
311
+ `${_work_dir}/cert.pem`;
312
+ }
313
+ if ( ssl_key == "" ) {
314
+ ssl_key =
315
+ `${_work_dir}/key.pem`;
97
316
  }
98
- return _target_certificate;
99
317
  }
100
318
 
101
319
  function
102
320
  _overrides_set() {
103
- target_certificate =
104
- _target_certificate_auto_detect();
321
+ cache_dir =
322
+ _cache_dir_auto_detect();
323
+ if ( target_directory == "" ) {
324
+ target_directory =
325
+ _pwd();
326
+ }
327
+ if ( target_port == "" ) {
328
+ target_port =
329
+ "3000";
330
+ }
331
+ if ( index_redirect == "" ) {
332
+ index_redirect =
333
+ "y";
334
+ }
335
+ if ( logging_disabled == "" ) {
336
+ logging_disabled =
337
+ "n";
338
+ }
339
+ if ( cors_enabled == "" ) {
340
+ cors_enabled =
341
+ "n";
342
+ }
343
+ if ( clipboard_disabled == "" ) {
344
+ clipboard_disabled =
345
+ "n";
346
+ }
347
+ if ( compression_disabled == "" ) {
348
+ compression_disabled =
349
+ "n";
350
+ }
351
+ if ( etag_disabled == "" ) {
352
+ etag_disabled =
353
+ "n";
354
+ }
355
+ if ( symlinks_enabled == "" ) {
356
+ symlinks_enabled =
357
+ "n";
358
+ }
359
+ _ssl_config_auto_detect();
360
+ if ( port_switching_disabled == "" ) {
361
+ port_switching_disabled =
362
+ "n";
363
+ }
364
+ if ( keys_length == "" ) {
365
+ keys_length =
366
+ "4096";
367
+ }
105
368
  if ( validity_min == "" ) {
106
369
  validity_min =
107
370
  new Date();
@@ -141,39 +404,46 @@ function
141
404
  organization_unit =
142
405
  "Index Development Team";
143
406
  }
144
- if ( key_private == "" ) {
145
- key_private =
146
- process.cwd() +
147
- "/key.pem";
148
- }
149
- if ( output_file == "" ) {
150
- output_file =
151
- process.cwd() +
152
- "/cert.pem";
153
- }
154
407
  }
155
408
 
156
409
  function
157
410
  _config_show() {
158
411
  let
159
- _line,
160
- _text;
161
- _text = [
162
- `${app_name} configuration:`,
163
- ` Runtime environment: ${runtime_environment}`,
164
- ` Target directory: ${target_directory}`,
165
- ` Key length: ${keys_length}`,
166
- ` Serial number: ${serial_number}`,
167
- ` Valid after: ${validity_min}`,
168
- ` Expires on: ${validity_max}`,
169
- ` Domain name: ${domain_name}`,
170
- ` Country: ${country_name}`,
171
- ` State: ${state_name}`,
172
- ` Locality: ${locality_name}`,
173
- ` Organization: ${organization_name}`,
174
- ` Organization unit: ${organization_unit}`,
175
- ` Output file: ${output_file}`,
176
- ];
412
+ _line;
413
+ const
414
+ _text = [
415
+ `${app_name} configuration:`,
416
+ ` Runtime environment: ${runtime_environment}`,
417
+ ` Target directory: ${target_directory}`,
418
+ ` Serve options:`,
419
+ ` Listen URIs: ${listen_uris}`,
420
+ ` Target port: ${target_port}`,
421
+ ` Index redirect: ${index_redirect}`,
422
+ ` Configuration file: ${config_file}`,
423
+ ` Quiet stdout log: ${logging_disabled}`,
424
+ ` Cors: ${cors_enabled}`,
425
+ ` No clipboard: ${clipboard_disabled}`,
426
+ ` No compression: ${compression_disabled}`,
427
+ ` Disable ETag: ${etag_disabled}`,
428
+ ` Symlinks: ${symlinks_enabled}`,
429
+ ` No port switching: ${port_switching_disabled}`,
430
+ ` SSL options:`,
431
+ ` Generate certificate: ${cert_gen}`,
432
+ ` SSL Certificate: ${ssl_cert}`,
433
+ ` SSL private key: ${ssl_key}`,
434
+ ` Key password: ${ssl_pass}`,
435
+ ` Certificate options:`,
436
+ ` Key length: ${keys_length}`,
437
+ ` Serial number: ${serial_number}`,
438
+ ` Valid after: ${validity_min}`,
439
+ ` Expires on: ${validity_max}`,
440
+ ` Domain name: ${domain_name}`,
441
+ ` Country: ${country_name}`,
442
+ ` State: ${state_name}`,
443
+ ` Locality: ${locality_name}`,
444
+ ` Organization: ${organization_name}`,
445
+ ` Organization unit: ${organization_unit}`,
446
+ ];
177
447
  for ( _line of _text ) {
178
448
  _msg_info(
179
449
  _line);
@@ -184,71 +454,119 @@ function
184
454
  _usage(
185
455
  _exit_code) {
186
456
  let
187
- _line,
188
- _text;
189
- _text = [
190
- "",
191
- "Serve extension which self-generate a SSL certificate at runtime.",
192
- "",
193
- "Usage:",
194
- "",
195
- " safely-serve",
196
- " [options]",
197
- " [serve-options]",
198
- "",
199
- " options:",
200
- " -i, --key-private=FILE Use existing private key.",
201
- ` Default: '${key_private}'`,
202
- " -l, --keys-length=N Keys pair length.",
203
- ` Default: '${keys_length}'`,
204
- " -o, --output-file=FILE Set output file.",
205
- ` Default: '${output_file}'`,
206
- "",
207
- " validity options:",
208
- " -B, --validity-start=DATE Set activation date.",
209
- ` Default: '${validity_min}'`,
210
- " -E, --validity-end=DATE Set expiration date.",
211
- ` Default: '${validity_max}'`,
212
- "",
213
- " identity options:",
214
- " -D, --domain-name=DOMAIN Set domain name.",
215
- ` Default: '${domain_name}'`,
216
- " -C, --country-name=COUNTRY Set country name.",
217
- ` Default: '${country_name}'`,
218
- " -S, --state-name=STATE Set state name.",
219
- ` Default: '${state_name}'`,
220
-
221
- " -L, --locality-name=LOCALITY Set locality name.",
222
- ` Default: '${locality_name}'`,
223
- " -O, --organization-name=ORG Set organization name.",
224
- ` Default: '${organization_name}'`,
225
- " -U, --organization-unit=UNIT Set organization unit.",
226
- ` Default: '${organization_unit}'`,
227
- " -s, --serial-number=SERIAL Set serial number.",
228
- ` Default: '${serial_number}'`,
229
- "",
230
- " -h --help This message.",
231
- " -v --verbose Enable verbose output.",
232
- "",
233
- ];
457
+ _line;
458
+ const
459
+ _text = [
460
+ "",
461
+ "Serve extension which generates a self-signed SSL certificate at runtime.",
462
+ "",
463
+ "Usage:",
464
+ "",
465
+ " safely-serve",
466
+ " [options]",
467
+ " <target-directory>",
468
+ "",
469
+ " serve options:",
470
+ " -l, --listen=URI Specify a URI endpoint on",
471
+ " which to listen (see below);",
472
+ " more than one may be specified to",
473
+ " listen in multiple places.",
474
+ ` Default: '${listen_uris}'`,
475
+ " -p, --port=PORT Specify custom port",
476
+ ` Default: '${target_port}'`,
477
+ " -s, --single Rewrite all not-found requests",
478
+ " to 'index.html'.",
479
+ ` Default: '${index_redirect}'`,
480
+ " -d, --debug Show debugging information.",
481
+ ` Default: '${debug_enabled}'`,
482
+ " -c, --config=PATH Specify custom path to 'serve.json'.",
483
+ ` Default: '${config_file}'`,
484
+ " -L, --no-request-logging Do not log any request information",
485
+ " to the console.",
486
+ ` Default: '${logging_disabled}'`,
487
+ " -C, --cors Enable CORS, sets",
488
+ " 'Access-Control-Allow-Origin'",
489
+ " to '*'.",
490
+ ` Default: '${cors_enabled}'`,
491
+ " -n, --no-clipboard Do not copy the local address",
492
+ " to the clipboard.",
493
+ ` Default: '${clipboard_disabled}'`,
494
+ " -u, --no-compression Do not compress files.",
495
+ ` Default: '${compression_disabled}'`,
496
+ " -e, --no-etag Send 'Last-Modified' header",
497
+ " instead of `ETag`.",
498
+ ` Default: '${etag_disabled}'`,
499
+ " -S, --symlinks Resolve symlinks instead of",
500
+ " showing 404 errors.",
501
+ ` Default: '${symlinks_enabled}'`,
502
+ " --no-port-switching Do not open a port other than",
503
+ " the one specified when it's taken.",
504
+ ` Default: '${port_switching_disabled}'`,
505
+ " ssl options:",
506
+ " -g, --gen-cert If enabled, generate self-signed certificate",
507
+ " at the specified path.",
508
+ ` Default: '${cert_gen}'`,
509
+ " -I, --ssl-cert=PATH Optional path to an SSL/TLS",
510
+ " certificate to serve with HTTPS.",
511
+ " Supported formats: PEM (default)",
512
+ " and PKCS12 (PFX)",
513
+ ` Default: '${ssl_cert}'`,
514
+ " -i, --ssl-key=PATH Optional path to the SSL/TLS",
515
+ " certificate's private key.",
516
+ " Applicable only for PEM certificates.",
517
+ ` Default: '${ssl_key}'`,
518
+ " -k --ssl-pass=PATH Optional path to the SSL/TLS",
519
+ " certificate's passphrase.",
520
+ ` Default: '${ssl_pass}'`,
521
+ "",
522
+ " certificate options:",
523
+ " -N, --keys-length=N Generated keys pair length.",
524
+ ` Default: '${keys_length}'`,
525
+ " -B, --validity-min=DATE Set activation date.",
526
+ ` Default: '${validity_min}'`,
527
+ " -E, --validity-max=DATE Set expiration date.",
528
+ ` Default: '${validity_max}'`,
529
+ " -D, --domain-name=DOMAIN Set domain name.",
530
+ ` Default: '${domain_name}'`,
531
+ " -C, --country-name=COUNTRY Set country name.",
532
+ ` Default: '${country_name}'`,
533
+ " -S, --state-name=STATE Set state name.",
534
+ ` Default: '${state_name}'`,
535
+ " --locality-name=LOCALITY Set locality name.",
536
+ ` Default: '${locality_name}'`,
537
+ " -O, --organization-name=ORG Set organization name.",
538
+ ` Default: '${organization_name}'`,
539
+ " -U, --organization-unit=UNIT Set organization unit.",
540
+ ` Default: '${organization_unit}'`,
541
+ " -X, --serial-number=SERIAL Set serial number.",
542
+ ` Default: '${serial_number}'`,
543
+ "",
544
+ " application options:",
545
+ " -N, --keys-length=N Generated keys pair length.",
546
+ " -W, --cache-dir Work directory.",
547
+ ` Default: '${cache_dir}'`,
548
+ " -v, --version Displays the current version of",
549
+ " Safely Serve.",
550
+ " -h, --help Shows this help message.",
551
+ "",
552
+ ];
234
553
  for ( _line of _text ) {
235
554
  console.log(
236
555
  _line);
237
556
  }
238
- process.exit(
557
+ _process_exit(
239
558
  _exit_code);
240
559
  }
241
560
 
242
561
  function
243
562
  _cmdline_parse_help(
244
563
  _argv) {
245
- let
246
- _help_display;
247
- _help_display =
248
- _argv[
249
- "help"] ||
250
- _argv[
251
- "h"];
564
+ const
565
+ _help_display =
566
+ _argv[
567
+ "help"] ||
568
+ _argv[
569
+ "h"];
252
570
  if ( _help_display ) {
253
571
  quiet =
254
572
  "n";
@@ -258,13 +576,28 @@ function
258
576
  }
259
577
  }
260
578
 
579
+ function
580
+ _cmdline_parse_debug(
581
+ _argv) {
582
+ debug_enabled =
583
+ _opt_read(
584
+ _argv,
585
+ "d",
586
+ "debug");
587
+ if ( debug_enabled ) {
588
+ quiet =
589
+ "n";
590
+ }
591
+ }
592
+
261
593
  function
262
594
  _input_args_check(
263
595
  _argv) {
264
596
  if ( _argv[
265
597
  "_"].length < 1 ) {
266
- _msg =
267
- "Target directory required.";
598
+ const
599
+ _msg =
600
+ "Target directory required.";
268
601
  _msg_error(
269
602
  _msg,
270
603
  0);
@@ -273,201 +606,319 @@ function
273
606
  }
274
607
  }
275
608
 
276
- function
277
- _cmdline_parse() {
609
+ function
610
+ _target_directory_auto_detect(
611
+ _argv) {
278
612
  let
279
- _argv,
280
- _msg;
281
- _argv =
282
- _yargv_get();
283
- quiet =
284
- "y";
285
- runtime_environment =
286
- "node";
287
- _cmdline_parse_help(
288
- _argv);
289
- // _input_args_check(
290
- // _argv);
291
- // input_file =
292
- // _argv[
293
- // "_"][
294
- // 0];
295
- if ( "i" in _argv ) {
296
- key_private =
297
- _argv[
298
- "i"];
299
- }
300
- if ( "key-private" in _argv ) {
301
- key_private =
302
- _argv[
303
- "key-private"];
304
- }
305
- if ( "l" in _argv ) {
306
- keys_length =
307
- _argv[
308
- "l"];
309
- }
310
- if ( "keys-length" in _argv ) {
311
- keys_length =
312
- _argv[
313
- "keys-length"];
314
- }
315
- if ( "B" in _argv ) {
316
- validity_min =
317
- _argv[
318
- "B"];
319
- }
320
- if ( "validity-max" in _argv ) {
321
- validity_max =
322
- _argv[
323
- "validity-max"];
324
- }
325
- if ( "D" in _argv ) {
326
- domain_name =
327
- _argv[
328
- "D"];
329
- }
330
- if ( "domain-name" in _argv ) {
331
- domain_name =
332
- _argv[
333
- "domain-name"];
334
- }
335
- if ( "C" in _argv ) {
336
- country_name =
337
- _argv[
338
- "C"];
339
- }
340
- if ( "country-name" in _argv ) {
341
- country_name =
342
- _argv[
343
- "country-name"];
344
- }
345
- if ( "S" in _argv ) {
346
- state_name =
347
- _argv[
348
- "S"];
349
- }
350
- if ( "state-name" in _argv ) {
351
- country_name =
352
- _argv[
353
- "state-name"];
354
- }
355
- if ( "L" in _argv ) {
356
- locality_name =
357
- _argv[
358
- "L"];
359
- }
360
- if ( "locality-name" in _argv ) {
361
- locality_name =
362
- _argv[
363
- "locality-name"];
364
- }
365
- if ( "O" in _argv ) {
366
- organization_name =
367
- _argv[
368
- "O"];
369
- }
370
- if ( "organization-name" in _argv ) {
371
- organization_name =
372
- _argv[
373
- "organization-name"];
374
- }
375
- if ( "U" in _argv ) {
376
- organization_unit =
377
- _argv[
378
- "U"];
379
- }
380
- if ( "organization-unit" in _argv ) {
381
- organization_unit =
382
- _argv[
383
- "organization-unit"];
384
- }
385
- if ( "o" in _argv ) {
386
- output_file =
387
- _argv[
388
- "o"];
613
+ _target_directory;
614
+ _target_directory =
615
+ _argv[
616
+ "_"][
617
+ 0];
618
+ if ( typeof _target_directory === 'undefined' ) {
619
+ _target_directory =
620
+ _pwd();
621
+ return _target_directory;
622
+ }
623
+ else {
624
+ const
625
+ _msg =
626
+ `Target directory value ` +
627
+ `'${_target_directory}'.`;
628
+ _msg_info(
629
+ _msg);
389
630
  }
390
- if ( "output-file" in _argv ) {
391
- output_file =
392
- _argv[
393
- "output-file"];
631
+ return _target_directory;
632
+ }
633
+
634
+ function
635
+ _opt_read(
636
+ _argv,
637
+ _letter_opt,
638
+ _word_opt,
639
+ _type) {
640
+ let
641
+ _value;
642
+ if ( _letter_opt in _argv &&
643
+ _word_opt in _argv ) {
644
+ const
645
+ _msg =
646
+ `You can only use ` +
647
+ `'${_letter_opt}' or '--${_word_opt}'`;
648
+ _msg_error(
649
+ _msg,
650
+ 1);
394
651
  }
395
- if ( "s" in _argv ) {
396
- serial_number =
652
+ if ( _letter_opt in _argv ) {
653
+ _value =
397
654
  _argv[
398
- "s"];
655
+ _letter_opt];
399
656
  }
400
- if ( "serial-number" in _argv ) {
401
- serial_number =
657
+ if ( _word_opt in _argv ) {
658
+ _value =
402
659
  _argv[
403
- "serial-number"];
660
+ _word_opt];
404
661
  }
405
- verbose =
406
- _argv[
407
- "verbose"] ||
408
- _argv[
409
- "v"];
410
- if ( verbose ) {
411
- quiet =
412
- "n";
662
+ if ( typeof _value === 'undefined' ) {
663
+ _value =
664
+ "";
665
+ if ( _type === "list" ) {
666
+ _value =
667
+ [];
668
+ }
413
669
  }
670
+ return _value;
671
+ }
672
+
673
+ function
674
+ _cmdline_parse() {
675
+ const
676
+ _argv =
677
+ _yargv_get();
678
+ quiet =
679
+ "y";
680
+ runtime_environment =
681
+ "node";
682
+ _cmdline_parse_debug(
683
+ _argv);
684
+ _cmdline_parse_help(
685
+ _argv);
686
+ target_directory =
687
+ _target_directory_auto_detect(
688
+ _argv);
689
+ listen_uris =
690
+ _opt_read(
691
+ _argv,
692
+ "l",
693
+ "listen",
694
+ "list");
695
+ target_port =
696
+ _opt_read(
697
+ _argv,
698
+ "p",
699
+ "port");
700
+ target_port =
701
+ _opt_read(
702
+ _argv,
703
+ "p",
704
+ "port");
705
+ index_redirect =
706
+ _opt_read(
707
+ _argv,
708
+ "s",
709
+ "single");
710
+ config_file =
711
+ _opt_read(
712
+ _argv,
713
+ "c",
714
+ "config");
715
+ logging_disabled =
716
+ _opt_read(
717
+ _argv,
718
+ "L",
719
+ "no-request-logging");
720
+ cors_enabled =
721
+ _opt_read(
722
+ _argv,
723
+ "C",
724
+ "cors");
725
+ clipboard_disabled =
726
+ _opt_read(
727
+ _argv,
728
+ "n",
729
+ "no-clipboard");
730
+ compression_disabled =
731
+ _opt_read(
732
+ _argv,
733
+ "u",
734
+ "no-compression");
735
+ etag_disabled =
736
+ _opt_read(
737
+ _argv,
738
+ "e",
739
+ "no-etag");
740
+ symlinks_enabled =
741
+ _opt_read(
742
+ _argv,
743
+ "S",
744
+ "symlinks");
745
+ ssl_cert =
746
+ _opt_read(
747
+ _argv,
748
+ "I",
749
+ "ssl-cert");
750
+ ssl_key =
751
+ _opt_read(
752
+ _argv,
753
+ "i",
754
+ "ssl-key");
755
+ ssl_pass =
756
+ _opt_read(
757
+ _argv,
758
+ "k",
759
+ "ssl-pass");
760
+ keys_length =
761
+ _opt_read(
762
+ _argv,
763
+ "l",
764
+ "keys-length");
765
+ validity_min =
766
+ _opt_read(
767
+ _argv,
768
+ "B",
769
+ "validity-min");
770
+ validity_max =
771
+ _opt_read(
772
+ _argv,
773
+ "E",
774
+ "validity-max");
775
+ domain_name =
776
+ _opt_read(
777
+ _argv,
778
+ "D",
779
+ "domain-name");
780
+ country_name =
781
+ _opt_read(
782
+ _argv,
783
+ "C",
784
+ "country-name");
785
+ state_name =
786
+ _opt_read(
787
+ _argv,
788
+ "S",
789
+ "state-name");
790
+ locality_name =
791
+ _opt_read(
792
+ _argv,
793
+ "L",
794
+ "locality-name");
795
+ organization_name =
796
+ _opt_read(
797
+ _argv,
798
+ "O",
799
+ "organization-name");
800
+ organization_unit =
801
+ _opt_read(
802
+ _argv,
803
+ "U",
804
+ "organization-unit");
805
+ serial_number =
806
+ _opt_read(
807
+ _argv,
808
+ "X",
809
+ "serial-number");
810
+ cache_dir =
811
+ _opt_read(
812
+ _argv,
813
+ "W",
814
+ "cache-dir");
414
815
  }
415
816
 
416
817
  function
417
818
  _url_parse() {
418
- let
419
- _argv;
420
819
  runtime_environment =
421
820
  "browser";
422
- _argv =
423
- _argv_url_get();
424
- key_private =
425
- _argv_url_get(
426
- "key_private")[
821
+ const
822
+ _argv =
823
+ _argv_url_get();
824
+ target_directory =
825
+ _argv[
826
+ "target_directory"][
427
827
  0];
428
- keys_length =
429
- _argv_url_get(
430
- "keys_length")[
828
+ listen_uris =
829
+ _argv[
830
+ "listen"];
831
+ target_port =
832
+ _argv[
833
+ "port"][
834
+ 0];
835
+ index_redirect =
836
+ _argv[
837
+ "single"][
838
+ 0];
839
+ config_file =
840
+ _argv[
841
+ "config_file"][
842
+ 0];
843
+ compression_disabled =
844
+ _argv[
845
+ "no_compression"][
846
+ 0];
847
+ etag_disabled =
848
+ _argv[
849
+ "no_etag"][
850
+ 0];
851
+ logging_disabled =
852
+ _argv[
853
+ "no_request_logging"][
854
+ 0];
855
+ cors_enabled =
856
+ _argv[
857
+ "cors"][
858
+ 0];
859
+ clipboard_disabled =
860
+ _argv[
861
+ "no_clipboard"][
862
+ 0];
863
+ ssl_cert =
864
+ _argv[
865
+ "ssl_cert"][
866
+ 0];
867
+ port_switching_disabled =
868
+ _argv[
869
+ "no_compression"][
870
+ 0];
871
+ symlinks_enabled =
872
+ _argv[
873
+ "symlinks"][
874
+ 0];
875
+ ssl_key =
876
+ _argv[
877
+ "ssl_key"][
431
878
  0];
432
- output_file =
433
- _argv_url_get(
434
- "output_file")[
879
+ keys_length =
880
+ _argv[
881
+ "keys_length"][
435
882
  0];
436
883
  validity_min =
437
- _argv_url_get(
438
- "validity_min")[
884
+ _argv[
885
+ "validity_min"][
439
886
  0];
440
887
  validity_max =
441
- _argv_url_get(
442
- "validity_max")[
888
+ _argv[
889
+ "validity_max"][
443
890
  0];
444
891
  country_name =
445
- _argv_url_get(
446
- "country_name")[
892
+ _argv[
893
+ "country_name"][
447
894
  0];
448
895
  state_name =
449
- _argv_url_get(
450
- "state_name")[
896
+ _argv[
897
+ "state_name"][
451
898
  0];
452
899
  locality_name =
453
- _argv_url_get(
454
- "locality_name")[
900
+ _argv[
901
+ "locality_name"][
455
902
  0];
456
903
  organization_name =
457
- _argv_url_get(
458
- "organization_name")[
904
+ _argv[
905
+ "organization_name"][
459
906
  0];
460
907
  organization_unit =
461
- _argv_url_get(
462
- "organization_unit")[
908
+ _argv[
909
+ "organization_unit"][
463
910
  0];
464
911
  serial_number =
465
- _argv_url_get(
466
- "serial_number")[
912
+ _argv[
913
+ "serial_number"][
914
+ 0];
915
+ cache_dir =
916
+ _argv[
917
+ "cache_dir"][
467
918
  0];
468
919
  quiet =
469
- _argv_url_get(
470
- "quiet");
920
+ _argv[
921
+ "quiet"];
471
922
  if ( quiet.length === 0 ) {
472
923
  quiet =
473
924
  "n";
@@ -485,7 +936,23 @@ else {
485
936
  _overrides_set();
486
937
  _config_show();
487
938
  app_opts = [
488
- key_private,
939
+ target_directory,
940
+ listen_uris,
941
+ target_port,
942
+ index_redirect,
943
+ debug_enabled,
944
+ config_file,
945
+ logging_disabled,
946
+ cors_enabled,
947
+ clipboard_disabled,
948
+ compression_disabled,
949
+ etag_disabled,
950
+ symlinks_enabled,
951
+ cert_gen,
952
+ ssl_cert,
953
+ ssl_key,
954
+ ssl_pass,
955
+ port_switching_disabled,
489
956
  keys_length,
490
957
  serial_number,
491
958
  validity_min,
@@ -495,8 +962,7 @@ app_opts = [
495
962
  state_name,
496
963
  locality_name,
497
964
  organization_name,
498
- organization_unit,
499
- output_file,
965
+ organization_unit
500
966
  ];
501
967
  _safely_serve.apply(
502
968
  null,