underpost 2.7.83 → 2.7.92

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 (85) hide show
  1. package/.github/workflows/ghpkg.yml +41 -1
  2. package/.github/workflows/pwa-microservices-template.page.yml +54 -0
  3. package/.vscode/settings.json +7 -0
  4. package/CHANGELOG.md +64 -16
  5. package/bin/cron.js +47 -0
  6. package/bin/db.js +60 -7
  7. package/bin/deploy.js +358 -26
  8. package/bin/file.js +18 -1
  9. package/bin/hwt.js +59 -0
  10. package/bin/index.js +1 -1
  11. package/bin/util.js +31 -1
  12. package/conf.js +46 -8
  13. package/docker-compose.yml +1 -1
  14. package/package.json +133 -133
  15. package/src/api/core/core.router.js +9 -9
  16. package/src/api/core/core.service.js +12 -4
  17. package/src/api/default/default.service.js +4 -4
  18. package/src/api/file/file.service.js +3 -3
  19. package/src/api/user/user.service.js +10 -8
  20. package/src/client/components/core/404.js +20 -0
  21. package/src/client/components/core/500.js +20 -0
  22. package/src/client/{ssr/common → components/core}/Alert.js +13 -11
  23. package/src/client/components/core/CommonJs.js +3 -0
  24. package/src/client/components/core/CssCore.js +30 -3
  25. package/src/client/components/core/Docs.js +110 -10
  26. package/src/client/components/core/LoadingAnimation.js +4 -2
  27. package/src/client/components/core/Modal.js +223 -22
  28. package/src/client/components/core/Panel.js +1 -1
  29. package/src/client/components/core/PanelForm.js +2 -1
  30. package/src/client/components/core/Responsive.js +34 -5
  31. package/src/client/components/core/RichText.js +4 -2
  32. package/src/client/components/core/Translate.js +21 -5
  33. package/src/client/components/core/VanillaJs.js +2 -1
  34. package/src/client/components/core/WebComponent.js +44 -0
  35. package/src/client/components/core/Worker.js +15 -18
  36. package/src/client/components/default/MenuDefault.js +68 -0
  37. package/src/client/components/default/RoutesDefault.js +2 -0
  38. package/src/client/public/default/plantuml/client-conf.svg +1 -1
  39. package/src/client/public/default/plantuml/client-schema.svg +1 -1
  40. package/src/client/public/default/plantuml/cron-conf.svg +1 -1
  41. package/src/client/public/default/plantuml/cron-schema.svg +1 -1
  42. package/src/client/public/default/plantuml/server-conf.svg +1 -1
  43. package/src/client/public/default/plantuml/server-schema.svg +1 -1
  44. package/src/client/public/default/plantuml/ssr-conf.svg +1 -1
  45. package/src/client/public/default/plantuml/ssr-schema.svg +1 -1
  46. package/src/client/public/default/site.webmanifest +69 -0
  47. package/src/client/ssr/Render.js +1 -6
  48. package/src/client/ssr/{components/body → body}/CacheControl.js +1 -1
  49. package/src/client/ssr/head/Production.js +1 -0
  50. package/src/client/ssr/head/Pwa.js +146 -0
  51. package/src/client/ssr/head/Seo.js +14 -0
  52. package/src/client/ssr/mailer/DefaultRecoverEmail.js +21 -0
  53. package/src/client/ssr/mailer/DefaultVerifyEmail.js +17 -0
  54. package/src/client/ssr/offline/NoNetworkConnection.js +65 -0
  55. package/src/client/ssr/pages/Test.js +196 -0
  56. package/src/client/ssr/pages/maintenance.js +14 -0
  57. package/src/client/ssr/pages/offline.js +21 -0
  58. package/src/client/sw/default.sw.js +44 -165
  59. package/src/db/DataBaseProvider.js +12 -1
  60. package/src/db/mongo/MongooseDB.js +0 -1
  61. package/src/mailer/EmailRender.js +2 -4
  62. package/src/mailer/MailerProvider.js +4 -1
  63. package/src/runtime/lampp/Lampp.js +9 -9
  64. package/src/server/backup.js +82 -70
  65. package/src/server/client-build.js +133 -155
  66. package/src/server/client-formatted.js +2 -4
  67. package/src/server/conf.js +114 -23
  68. package/src/server/crypto.js +91 -0
  69. package/src/server/dns.js +48 -16
  70. package/src/server/network.js +94 -7
  71. package/src/server/proxy.js +26 -28
  72. package/src/server/runtime.js +42 -12
  73. package/src/server/ssl.js +2 -2
  74. package/src/client/ssr/common/SsrCore.js +0 -91
  75. package/src/client/ssr/common/Translate.js +0 -26
  76. package/src/client/ssr/common/Worker.js +0 -28
  77. package/src/client/ssr/components/head/PwaDefault.js +0 -60
  78. package/src/client/ssr/offline/default.index.js +0 -31
  79. package/src/cron.js +0 -30
  80. package/src/server/cron.js +0 -35
  81. /package/src/client/ssr/{components/body → body}/DefaultSplashScreen.js +0 -0
  82. /package/src/client/ssr/{components/email → email}/DefaultRecoverEmail.js +0 -0
  83. /package/src/client/ssr/{components/email → email}/DefaultVerifyEmail.js +0 -0
  84. /package/src/client/ssr/{components/head → head}/Css.js +0 -0
  85. /package/src/client/ssr/{components/head → head}/DefaultScripts.js +0 -0
package/bin/deploy.js CHANGED
@@ -25,13 +25,16 @@ import {
25
25
  Cmd,
26
26
  restoreMacroDb,
27
27
  fixDependencies,
28
+ setUpProxyMaintenanceServer,
28
29
  } from '../src/server/conf.js';
29
30
  import { buildClient } from '../src/server/client-build.js';
30
31
  import { range, setPad, timer, uniqueArray } from '../src/client/components/core/CommonJs.js';
31
- import toJsonSchema from 'to-json-schema';
32
32
  import simpleGit from 'simple-git';
33
33
  import { MongooseDB } from '../src/db/mongo/MongooseDB.js';
34
34
  import { Lampp } from '../src/runtime/lampp/Lampp.js';
35
+ import { DefaultConf } from '../conf.js';
36
+ import { JSONweb } from '../src/server/client-formatted.js';
37
+ import ejs from 'easy-json-schema';
35
38
 
36
39
  const logger = loggerFactory(import.meta);
37
40
 
@@ -152,10 +155,15 @@ try {
152
155
  await deployRun(dataDeploy);
153
156
  } else {
154
157
  loadConf(process.argv[3]);
155
- shellExec(`npm start ${process.argv[3]}`);
158
+ shellExec(`npm start ${process.argv.includes('maintenance') ? 'maintenance' : ''}`);
156
159
  }
157
160
  }
158
161
  break;
162
+
163
+ case 'remove-await-deploy': {
164
+ if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
165
+ break;
166
+ }
159
167
  case 'new-nodejs-app':
160
168
  {
161
169
  const deployId = process.argv[3];
@@ -222,21 +230,18 @@ try {
222
230
  break;
223
231
  case 'build-full-client':
224
232
  {
233
+ if (!process.argv[3]) process.argv[3] = 'default';
225
234
  const { deployId, folder } = loadConf(process.argv[3]);
226
235
 
227
- let argHost = process.argv[4] ? process.argv[4].split(',') : undefined;
228
- let argPath = process.argv[5] ? process.argv[5].split(',') : undefined;
236
+ let argHost = process.argv[4] ? process.argv[4].split(',') : [];
237
+ let argPath = process.argv[5] ? process.argv[5].split(',') : [];
229
238
  let deployIdSingleReplicas = [];
230
239
  const serverConf = deployId
231
240
  ? JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'))
232
241
  : Config.default.server;
233
- if (!deployId) {
234
- argHost = 'default.net';
235
- argPath = '/';
236
- }
237
242
  for (const host of Object.keys(serverConf)) {
238
243
  for (const path of Object.keys(serverConf[host])) {
239
- if (argHost && argPath && (!argHost.includes(host) || !argPath.includes(path))) {
244
+ if (argHost.length && argPath.length && (!argHost.includes(host) || !argPath.includes(path))) {
240
245
  delete serverConf[host][path];
241
246
  } else {
242
247
  serverConf[host][path].liteBuild = process.argv.includes('l') ? true : false;
@@ -278,6 +283,154 @@ try {
278
283
  }
279
284
  break;
280
285
 
286
+ case 'adminer': {
287
+ const directory = '/dd/engine/public/adminer';
288
+ // const host = '127.0.0.1';
289
+ const host = 'localhost';
290
+ const port = 80;
291
+ if (!process.argv.includes('server')) {
292
+ if (fs.existsSync(directory)) fs.removeSync(directory);
293
+ fs.mkdirSync(directory, { recursive: true });
294
+ shellExec(`cd ${directory} && wget https://www.adminer.org/latest.php -O adminer.php`);
295
+ }
296
+ Lampp.removeRouter();
297
+ Lampp.appendRouter(` Listen ${port}
298
+ <VirtualHost *:${port}>
299
+ DocumentRoot "${directory}"
300
+ ServerName ${host}:${port}
301
+
302
+ <Directory "${directory}">
303
+ Options Indexes FollowSymLinks MultiViews
304
+ AllowOverride All
305
+ Require all granted
306
+ </Directory>
307
+
308
+ </VirtualHost>
309
+ `);
310
+ if (Lampp.enabled() && Lampp.router) Lampp.initService({ daemon: true });
311
+ shellExec(`open /opt/lampp/apache2/conf/httpd.conf`);
312
+ break;
313
+ }
314
+
315
+ case 'pma':
316
+ {
317
+ const directory = '/dd/engine/public/phpmyadmin';
318
+ // const host = '127.0.0.1';
319
+ const host = 'localhost';
320
+ const port = 80;
321
+ // data config path: /etc/phpmyadmin
322
+
323
+ // The config.inc.php file is not required, and only needed for custom configurations
324
+
325
+ // phpmyadmin will first refer to ./libraries/config.default.php to retrieve the default values.
326
+
327
+ // If for some reason you need to modify the default values, and the ./config.inc.php
328
+ // file doesn't exist, you will need to create one as per the Installation documentation.
329
+
330
+ // You will also need to configure pmadb for some of phpmyadmin's special features such as bookmarks.
331
+
332
+ // CREATE USER 'pma'@'localhost' IDENTIFIED VIA mysql_native_password USING 'pmapass';
333
+ // GRANT SELECT, INSERT, UPDATE, DELETE ON `<pma_db>`.* TO 'pma'@'localhost';
334
+
335
+ if (!process.argv.includes('server')) {
336
+ // if (fs.existsSync(directory)) fs.removeSync(directory);
337
+ shellExec(`sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl`);
338
+ shellExec(`sudo phpenmod mbstring`);
339
+ shellExec(
340
+ `cd /usr/share/phpmyadmin && git init && git add . && git commit -m "Base phpMyAdmin implementation"`,
341
+ );
342
+ }
343
+
344
+ // if (!fs.existsSync(directory)) fs.mkdirSync(directory, { recursive: true });
345
+ // if (!fs.existsSync('./public/phpmyadmin/phpmyadmin'))
346
+ // fs.copySync('/usr/share/phpmyadmin', './public/phpmyadmin/phpmyadmin');
347
+
348
+ Lampp.removeRouter();
349
+ Lampp.appendRouter(` Listen ${port} `);
350
+ if (Lampp.enabled() && Lampp.router) Lampp.initService({ daemon: true });
351
+ // shellExec(`open /opt/lampp/apache2/conf/httpd.conf`);
352
+
353
+ // Create a link in /var/www like this:
354
+
355
+ // sudo ln -s /usr/share/phpmyadmin /var/www/
356
+
357
+ // Note: since 14.04 you may want to use /var/www/html/ instead of /var/www/
358
+
359
+ // If that's not working for you, you need to include PHPMyAdmin inside apache configuration.
360
+
361
+ // Open apache.conf using your favorite editor, mine is vim :)
362
+
363
+ // sudo vim /etc/apache2/apache2.conf
364
+
365
+ // Then add the following line:
366
+
367
+ // Include /etc/phpmyadmin/apache.conf
368
+
369
+ // For Ubuntu 15.04 and 16.04
370
+
371
+ // sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
372
+ // sudo a2enconf phpmyadmin.conf
373
+ // sudo service apache2 reload
374
+ break;
375
+ Lampp.appendRouter(` Listen ${port}
376
+
377
+ <VirtualHost *:${port}>
378
+ DocumentRoot "${directory}"
379
+ ServerName ${host}:${port}
380
+
381
+ <Directory "${directory}">
382
+ Options Indexes FollowSymLinks MultiViews
383
+ AllowOverride All
384
+ Require all granted
385
+ </Directory>
386
+
387
+ </VirtualHost>`);
388
+ // phpMyAdmin default Apache configuration:
389
+ Lampp.appendRouter(`
390
+
391
+ Listen ${port}
392
+
393
+ Alias /phpmyadmin /usr/share/phpmyadmin
394
+
395
+ <Directory /usr/share/phpmyadmin>
396
+ Options Indexes FollowSymLinks
397
+ DirectoryIndex index.php
398
+
399
+ <IfModule mod_php5.c>
400
+ AddType application/x-httpd-php .php
401
+
402
+ php_flag magic_quotes_gpc Off
403
+ php_flag track_vars On
404
+ php_flag register_globals Off
405
+ php_value include_path .
406
+ </IfModule>
407
+
408
+ </Directory>
409
+
410
+ # Authorize for setup
411
+ <Directory /usr/share/phpmyadmin/setup>
412
+ <IfModule mod_authn_file.c>
413
+ AuthType Basic
414
+ AuthName "phpMyAdmin Setup"
415
+ AuthUserFile /etc/phpmyadmin/htpasswd.setup
416
+ </IfModule>
417
+ Require valid-user
418
+ </Directory>
419
+
420
+ # Disallow web access to directories that don't need it
421
+ <Directory /usr/share/phpmyadmin/libraries>
422
+ Order Deny,Allow
423
+ Deny from All
424
+ </Directory>
425
+ <Directory /usr/share/phpmyadmin/setup/lib>
426
+ Order Deny,Allow
427
+ Deny from All
428
+ </Directory>
429
+
430
+ `);
431
+ }
432
+ break;
433
+
281
434
  case 'update-package':
282
435
  const files = await fs.readdir(`./engine-private/conf`, { recursive: true });
283
436
  const originPackage = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
@@ -294,21 +447,37 @@ try {
294
447
  {
295
448
  if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
296
449
  const dataDeploy = getDataDeploy({ deployGroupId: process.argv[3], buildSingleReplica: true });
297
- await deployRun(dataDeploy, true);
450
+ if (!process.argv[4]) await setUpProxyMaintenanceServer({ deployGroupId: process.argv[3] });
451
+ await deployRun(
452
+ process.argv[4] ? dataDeploy.filter((d) => d.deployId.match(process.argv[4])) : dataDeploy,
453
+ true,
454
+ );
298
455
  }
299
456
  break;
300
457
 
301
- case 'run-macro-build':
458
+ case 'build-macro':
302
459
  {
303
- if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
304
460
  const dataDeploy = getDataDeploy({ deployGroupId: process.argv[3], buildSingleReplica: true });
305
461
  for (const deploy of dataDeploy) {
306
- shellExec(Cmd.conf(deploy.deployId));
307
- shellExec(Cmd.build(deploy.deployId));
462
+ if (!process.argv[4] || (process.argv[4] && process.argv[4] === deploy.deployId)) {
463
+ shellExec(Cmd.conf(deploy.deployId));
464
+ shellExec(Cmd.build(deploy.deployId));
465
+ }
308
466
  }
309
- await deployRun(dataDeploy, true);
310
467
  }
311
468
  break;
469
+ case 'macro': {
470
+ shellExec(`git checkout .`);
471
+ shellExec(`node bin/deploy build-macro ${process.argv.slice(3).join(' ')}`);
472
+ shellExec(`git checkout .`);
473
+ shellExec(`node bin/deploy run-macro ${process.argv.slice(3).join(' ')}`);
474
+ break;
475
+ }
476
+
477
+ case 'keep-server': {
478
+ await setUpProxyMaintenanceServer({ deployGroupId: process.argv[3] });
479
+ break;
480
+ }
312
481
  case 'prometheus':
313
482
  case 'prom':
314
483
  {
@@ -404,29 +573,33 @@ try {
404
573
  }
405
574
  case 'build-uml':
406
575
  {
407
- const host = process.argv[3];
408
- const path = process.argv[4];
409
- const folder = `./public/${host}${path}/docs/plantuml`;
576
+ const folder = process.argv[3] ? process.argv[3] : `./src/client/public/default/plantuml`;
410
577
  const confData = Config.default;
411
578
 
412
579
  if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
413
580
 
414
581
  for (const typeConf of Object.keys(confData)) {
415
- {
582
+ logger.info(`generate ${typeConf} instance`);
583
+ try {
416
584
  const svg = await plantuml(`
417
585
  @startjson
418
586
  ${JSON.stringify(confData[typeConf])}
419
587
  @endjson
420
588
  `);
421
589
  fs.writeFileSync(`${folder}/${typeConf}-conf.svg`, svg);
590
+ } catch (error) {
591
+ logger.error(error, error.stack);
422
592
  }
423
- {
593
+ logger.info(`generate ${typeConf} schema`);
594
+ try {
424
595
  const svg = await plantuml(`
425
596
  @startjson
426
- ${JSON.stringify(toJsonSchema(confData[typeConf]))}
597
+ ${JSON.stringify(ejs(confData[typeConf]))}
427
598
  @endjson
428
599
  `);
429
600
  fs.writeFileSync(`${folder}/${typeConf}-schema.svg`, svg);
601
+ } catch (error) {
602
+ logger.error(error, error.stack);
430
603
  }
431
604
  }
432
605
  }
@@ -452,7 +625,7 @@ try {
452
625
  `./engine-private/replica/${replicaDeployId}/package.json`,
453
626
  fs
454
627
  .readFileSync(`./engine-private/replica/${replicaDeployId}/package.json`, 'utf8')
455
- .replaceAll(`--name ${deployId}`, `--name ${replicaDeployId}`),
628
+ .replaceAll(`${deployId}`, `${replicaDeployId}`),
456
629
  'utf8',
457
630
  );
458
631
  }
@@ -564,10 +737,8 @@ try {
564
737
  );
565
738
 
566
739
  fs.writeFileSync(
567
- `./src/client/ssr/components/body/CacheControl.js`,
568
- fs
569
- .readFileSync(`./src/client/ssr/components/body/CacheControl.js`, 'utf8')
570
- .replaceAll(`v${version}`, `v${newVersion}`),
740
+ `./src/client/ssr/body/CacheControl.js`,
741
+ fs.readFileSync(`./src/client/ssr/body/CacheControl.js`, 'utf8').replaceAll(`v${version}`, `v${newVersion}`),
571
742
  'utf8',
572
743
  );
573
744
 
@@ -666,6 +837,167 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
666
837
  break;
667
838
  }
668
839
 
840
+ case 'update-default-conf': {
841
+ const host = process.argv[3] ? process.argv[3] : 'underpostnet.github.io';
842
+ const path = process.argv[4] ? process.argv[4] : '/pwa-microservices-template-ghpkg';
843
+ DefaultConf.server = {
844
+ [host]: { [path]: DefaultConf.server['default.net']['/'] },
845
+ };
846
+ DefaultConf.server[host][path].apiBaseProxyPath = '/';
847
+ DefaultConf.server[host][path].apiBaseHost = 'www.nexodev.org';
848
+ fs.writeFileSync(
849
+ './conf.js',
850
+ `
851
+ const DefaultConf = ${JSONweb(DefaultConf)};
852
+
853
+ export { DefaultConf }
854
+
855
+ `,
856
+ 'utf8',
857
+ );
858
+
859
+ break;
860
+ }
861
+ case 'ssh-export-server-keys': {
862
+ fs.copyFile('/etc/ssh/ssh_host_rsa_key', './engine-private/deploy/ssh_host_rsa_key');
863
+ fs.copyFile('/etc/ssh/ssh_host_rsa_key.pub', './engine-private/deploy/ssh_host_rsa_key.pub');
864
+ break;
865
+ }
866
+ case 'ssh-import-server-keys': {
867
+ fs.copyFile('./engine-private/deploy/ssh_host_rsa_key', '/etc/ssh/ssh_host_rsa_key');
868
+ fs.copyFile('./engine-private/deploy/ssh_host_rsa_key.pub', '/etc/ssh/ssh_host_rsa_key.pub');
869
+ break;
870
+ }
871
+ case 'ssh-import-client-keys': {
872
+ const host = process.argv[3];
873
+ shellExec(`node bin/deploy set-ssh-keys ./engine-private/deploy/ssh_host_rsa_key${host ? ` ${host}` : ``} clean`);
874
+ break;
875
+ }
876
+ case 'ssh-keys': {
877
+ // create ssh keys
878
+ const sshAccount = process.argv[3]; // [sudo username]@[host/ip]
879
+ const destPath = process.argv[4];
880
+ // shellExec(`ssh-keygen -t ed25519 -C "${sshAccount}" -f ${destPath}`);
881
+ if (fs.existsSync(destPath)) {
882
+ fs.removeSync(destPath);
883
+ fs.removeSync(destPath + '.pub');
884
+ }
885
+ shellExec(`ssh-keygen -t rsa -b 4096 -C "${sshAccount}" -f ${destPath}`);
886
+ // add host to keyscan
887
+ // shellExec(`ssh-keyscan -t rsa ${sshAccount.split(`@`)[1]} >> ~/.ssh/known_hosts`);
888
+ break;
889
+ }
890
+
891
+ case 'set-ssh-keys': {
892
+ const files = ['authorized_keys', 'id_rsa', 'id_rsa.pub', 'known_hosts ', 'known_hosts.old'];
893
+
894
+ // > write
895
+ // >> append
896
+
897
+ // /root/.ssh/id_rsa
898
+ // /root/.ssh/id_rsa.pub
899
+ if (process.argv.includes('clean')) {
900
+ for (const file of files) {
901
+ if (fs.existsSync(`/root/.ssh/${file}`)) {
902
+ logger.info('remove', `/root/.ssh/${file}`);
903
+ fs.removeSync(`/root/.ssh/${file}`);
904
+ }
905
+ fs.writeFileSync(`/root/.ssh/${file}`, '', 'utf8');
906
+ }
907
+ shellExec('eval `ssh-agent -s`' + ` && ssh-add -D`);
908
+ }
909
+
910
+ const destPath = process.argv[3];
911
+ const sshAuthKeyTarget = '/root/.ssh/authorized_keys';
912
+ if (!fs.existsSync(sshAuthKeyTarget)) shellExec(`touch ${sshAuthKeyTarget}`);
913
+ shellExec(`cat ${destPath}.pub > ${sshAuthKeyTarget}`);
914
+ shellExec(`cat ${destPath} >> ${sshAuthKeyTarget}`);
915
+
916
+ if (!fs.existsSync('/root/.ssh/id_rsa')) shellExec(`touch ${'/root/.ssh/id_rsa'}`);
917
+ shellExec(`cat ${destPath} > ${'/root/.ssh/id_rsa'}`);
918
+
919
+ if (!fs.existsSync('/root/.ssh/id_rsa.pub')) shellExec(`touch ${'/root/.ssh/id_rsa.pub'}`);
920
+ shellExec(`cat ${destPath}.pub > ${'/root/.ssh/id_rsa.pub'}`);
921
+
922
+ shellExec(`chmod 700 /root/.ssh/`);
923
+ for (const file of files) {
924
+ shellExec(`chmod 600 /root/.ssh/${file}`);
925
+ }
926
+ const host = process.argv[4];
927
+ // add key
928
+ shellExec('eval `ssh-agent -s`' + ' && ssh-add /root/.ssh/id_rsa' + ' && ssh-add -l');
929
+ if (host) shellExec(`ssh-keyscan -H ${host} >> ~/.ssh/known_hosts`);
930
+ shellExec(`sudo systemctl enable ssh`);
931
+ shellExec(`sudo systemctl restart ssh`);
932
+ shellExec(`sudo systemctl status ssh`);
933
+
934
+ break;
935
+ }
936
+
937
+ case 'ssh': {
938
+ if (!process.argv.includes('server')) {
939
+ shellExec(`sudo apt update`);
940
+ shellExec(`sudo apt install openssh-server -y`);
941
+ shellExec(`sudo apt install ssh-askpass`);
942
+ }
943
+ shellExec(`sudo systemctl enable ssh`);
944
+ shellExec(`sudo systemctl restart ssh`);
945
+ shellExec(`sudo systemctl status ssh`);
946
+ // sudo service ssh restart
947
+ shellExec(`ip a`);
948
+
949
+ // adduser newuser
950
+ // usermod -aG sudo newuser
951
+
952
+ // ssh -i '/path/to/keyfile' username@server
953
+
954
+ // ssh-keygen -t ed25519 -C "your_email@example.com" -f $HOME/.ssh/id_rsa
955
+
956
+ // legacy: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f $HOME/.ssh/id_rsa
957
+
958
+ // vi .ssh/authorized_keys
959
+ // chmod 700 .ssh
960
+ // chmod 600 authorized_keys
961
+
962
+ // cat id_rsa.pub > .ssh/authorized_keys
963
+
964
+ // add public key to authorized keys
965
+ // cat .ssh/id_ed25519.pub | ssh [sudo username]@[host/ip] 'cat >> .ssh/authorized_keys'
966
+
967
+ // 2. Open /etc/ssh/sshd_config file
968
+ // nano /etc/ssh/sshd_config
969
+
970
+ // 3. add example code to last line of file
971
+ // Match User newuser
972
+ // PasswordAuthentication yes
973
+
974
+ // ssh [sudo username]@[host/ip]
975
+ // open port 22
976
+
977
+ // init ssh agent service
978
+ // eval `ssh-agent -s`
979
+
980
+ // list keys
981
+ // ssh-add -l
982
+
983
+ // add key
984
+ // ssh-add /root/.ssh/id_rsa
985
+
986
+ // remove
987
+ // ssh-add -d /path/to/private/key
988
+
989
+ // remove all
990
+ // ssh-add -D
991
+
992
+ // sshpass -p ${{ secrets.PSWD }} ssh -o StrictHostKeyChecking=no -p 22 ${{ secrets.USER}}@${{ secrets.VPS_IP }} 'cd /home/adam && ./deploy.sh'
993
+
994
+ // copies the public key of your default identity (use -i identity_file for other identities) to the remote host.
995
+ // ssh-copy-id user@hostname.example.com
996
+ // ssh-copy-id "user@hostname.example.com -p <port-number>"
997
+
998
+ break;
999
+ }
1000
+
669
1001
  default:
670
1002
  break;
671
1003
  }
package/bin/file.js CHANGED
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
2
2
 
3
3
  import { loggerFactory } from '../src/server/logger.js';
4
4
  import { cap, getCapVariableName, getDirname } from '../src/client/components/core/CommonJs.js';
5
- import { shellExec } from '../src/server/process.js';
5
+ import { shellCd, shellExec } from '../src/server/process.js';
6
6
  import walk from 'ignore-walk';
7
7
  import { validateTemplatePath } from '../src/server/conf.js';
8
8
 
@@ -76,6 +76,23 @@ try {
76
76
  fs.copySync(`./.vscode`, `../pwa-microservices-template/.vscode`);
77
77
  fs.copySync(`./.github`, `../pwa-microservices-template/.github`);
78
78
  fs.copySync(`./src/client/public/default`, `../pwa-microservices-template/src/client/public/default`);
79
+
80
+ shellCd('../pwa-microservices-template');
81
+ for (const deletePath of ['CHANGELOG.md', 'README.md', 'package-lock.json', 'package.json']) {
82
+ shellExec(`git checkout ${deletePath}`);
83
+ }
84
+ for (const deletePath of [
85
+ '.github/workflows/coverall.yml',
86
+ '.github/workflows/docker-image.yml',
87
+ '.github/workflows/deploy.ssh.yml',
88
+ '.github/workflows/deploy.api-rest.yml',
89
+ 'bin/web3.js',
90
+ 'bin/cyberia.js',
91
+ 'src/ipfs.js',
92
+ 'src/k8s.js',
93
+ ]) {
94
+ fs.removeSync('../pwa-microservices-template/' + deletePath);
95
+ }
79
96
  }
80
97
 
81
98
  break;
package/bin/hwt.js ADDED
@@ -0,0 +1,59 @@
1
+ import fs from 'fs-extra';
2
+ import axios from 'axios';
3
+ import https from 'https';
4
+
5
+ import dotenv from 'dotenv';
6
+ import { shellCd, shellExec } from '../src/server/process.js';
7
+ import { loggerFactory } from '../src/server/logger.js';
8
+
9
+ const logger = loggerFactory(import.meta);
10
+
11
+ const httpsAgent = new https.Agent({
12
+ rejectUnauthorized: false,
13
+ });
14
+
15
+ axios.defaults.httpsAgent = httpsAgent;
16
+
17
+ logger.info('argv', process.argv);
18
+
19
+ const [exe, dir, operator, templateId, publicPath] = process.argv;
20
+
21
+ // engine for 'html-website-templates'
22
+
23
+ try {
24
+ switch (operator) {
25
+ case 'set-base':
26
+ {
27
+ switch (parseInt(templateId)) {
28
+ // Horizontal Scroll One Page Template Website
29
+ case 0:
30
+ {
31
+ fs.writeFile(
32
+ `${publicPath}/index.html`,
33
+ fs
34
+ .readFileSync(`${publicPath}/index.html`, 'utf8')
35
+ .replace(`<ul class="menu">`, `<ul class="menu hidden">`)
36
+ .replaceAll(`<section class="slide fade-6 kenBurns">`, `<section class="fade-6 kenBurns hidden">`)
37
+ .replace(`<section class="fade-6 kenBurns hidden">`, `<section class="slide fade-6 kenBurns">`)
38
+ .replaceAll(
39
+ `<nav class="panel bottom forceMobileView">`,
40
+ `<nav class="panel bottom forceMobileView hidden">`,
41
+ ),
42
+
43
+ 'utf8',
44
+ );
45
+ }
46
+ break;
47
+
48
+ default:
49
+ break;
50
+ }
51
+ }
52
+ break;
53
+
54
+ default:
55
+ break;
56
+ }
57
+ } catch (error) {
58
+ logger.error(error, error.stack);
59
+ }
package/bin/index.js CHANGED
@@ -19,7 +19,7 @@ const globalBinFolder = `${shellExec(`npm root -g`, {
19
19
 
20
20
  const program = new Command();
21
21
 
22
- const version = '2.7.83';
22
+ const version = '2.7.92';
23
23
 
24
24
  program.name('underpost').description(`underpost.net ci/cd cli ${version}`).version(version);
25
25
 
package/bin/util.js CHANGED
@@ -3,6 +3,8 @@ import merge from 'deepmerge';
3
3
  import si from 'systeminformation';
4
4
  import * as dir from 'path';
5
5
  import { svg } from 'font-awesome-assets';
6
+ import axios from 'axios';
7
+ import https from 'https';
6
8
 
7
9
  import { loggerFactory } from '../src/server/logger.js';
8
10
  import { shellCd, shellExec } from '../src/server/process.js';
@@ -12,6 +14,11 @@ import { Config } from '../src/server/conf.js';
12
14
  import { FileFactory } from '../src/api/file/file.service.js';
13
15
  import { buildTextImg, faBase64Png, getBufferPngText } from '../src/server/client-icons.js';
14
16
 
17
+ const httpsAgent = new https.Agent({
18
+ rejectUnauthorized: false,
19
+ });
20
+ axios.defaults.httpsAgent = httpsAgent;
21
+
15
22
  const logger = loggerFactory(import.meta);
16
23
 
17
24
  logger.info('argv', process.argv);
@@ -118,6 +125,10 @@ try {
118
125
  break;
119
126
  case 'delete-empty-folder':
120
127
  function cleanEmptyFoldersRecursively(folder) {
128
+ if (!fs.existsSync(folder)) {
129
+ logger.warn('Does not exist', folder);
130
+ return;
131
+ }
121
132
  const isDir = fs.statSync(folder).isDirectory();
122
133
  if (!isDir) return;
123
134
 
@@ -135,7 +146,11 @@ try {
135
146
 
136
147
  if (files.length === 0) {
137
148
  console.log('removing: ', folder);
138
- fs.rmdirSync(folder);
149
+ try {
150
+ fs.rmdirSync(folder);
151
+ } catch (error) {
152
+ logger.error(error);
153
+ }
139
154
  return;
140
155
  }
141
156
  }
@@ -174,6 +189,21 @@ try {
174
189
  fs.writeFileSync('b64-image', `data:image/jpg;base64,${fs.readFileSync(process.argv[3]).toString('base64')}`);
175
190
  break;
176
191
 
192
+ case 'get-ip': {
193
+ const response = await axios.get(process.argv[3]);
194
+ logger.info(process.argv[3] + ' IP', response.request.socket.remoteAddress);
195
+ break;
196
+ }
197
+
198
+ case 'clean-env': {
199
+ shellExec(`git checkout package.json`);
200
+ shellExec(`git checkout .env.production`);
201
+ shellExec(`git checkout .env.development`);
202
+ shellExec(`git checkout .env.test`);
203
+ shellExec(`git checkout jsdoc.json`);
204
+ break;
205
+ }
206
+
177
207
  default:
178
208
  break;
179
209
  }