carcara-security 0.3.0 → 0.3.1

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 (2) hide show
  1. package/cli/carcara.mjs +43 -21
  2. package/package.json +1 -1
package/cli/carcara.mjs CHANGED
@@ -206,6 +206,34 @@ function resumoProjeto(raiz) {
206
206
  return [...ecos, ...extras].join(', ') || 'nenhum manifesto reconhecido';
207
207
  }
208
208
 
209
+ /**
210
+ * Espera uma tela do navegador (configurações, agendar) até ela fechar sozinha ou a pessoa apertar
211
+ * q, Esc ou Ctrl+C no terminal. `fechar` fecha a(s) tela(s). Vindo do menu, volta para ele.
212
+ */
213
+ async function esperarTelaOuTecla(aguardar, fechar, { doMenu = false } = {}) {
214
+ process.stdout.write(cor.cinza(` [q] ${doMenu ? 'voltar ao menu' : 'fechar'} · a tela fecha sozinha depois de 15 min parada\n\n`));
215
+ const stdin = process.stdin;
216
+ let ouvir = null;
217
+ if (stdin.isTTY) {
218
+ ouvir = (b) => {
219
+ const k = b.toString().toLowerCase();
220
+ if (k === 'q' || k === '\u001b' || k === '\u0003') fechar();
221
+ };
222
+ stdin.setRawMode(true);
223
+ stdin.resume();
224
+ stdin.on('data', ouvir);
225
+ }
226
+ try {
227
+ await aguardar();
228
+ } finally {
229
+ if (ouvir) {
230
+ stdin.off('data', ouvir);
231
+ stdin.setRawMode(false);
232
+ stdin.pause();
233
+ }
234
+ }
235
+ }
236
+
209
237
  function lerTecla() {
210
238
  return new Promise((resolve) => {
211
239
  const stdin = process.stdin;
@@ -243,6 +271,8 @@ async function telaInicial(op) {
243
271
  ['4', 'Agendar', 'verificações automáticas: projetos, o que verificar, frequência e horário'],
244
272
  ['5', 'Configurações', 'tela, aviso de versão e ferramentas'],
245
273
  ];
274
+ for (let volta = 0; ; volta++) {
275
+ if (volta) process.stdout.write(`\n ${cor.laranja(cor.negrito('Carcará'))} ${cor.cinza('· menu')}\n\n`);
246
276
  for (const [k, t, d] of opcoes) process.stdout.write(` ${cor.laranja('[' + k + ']')} ${t.padEnd(15)} ${cor.cinza(d)}\n`);
247
277
  process.stdout.write(cor.cinza('\n [q] sair · cada opção abre uma tela no navegador\n\n'));
248
278
 
@@ -254,19 +284,14 @@ async function telaInicial(op) {
254
284
  tecla = await lerTecla();
255
285
  }
256
286
  if (ENTER.includes(tecla)) tecla = '1';
257
- switch (tecla) {
258
- case '1':
259
- return comandoAuditoria({ ...op, _: ['auditoria', raiz] });
260
- case '2':
261
- return comandoCves({ ...op, _: ['cves', raiz] });
262
- case '3':
263
- return comandoPentest({ ...op, _: ['pentest'] });
264
- case '4':
265
- return comandoVarredura({ ...op, _: ['varredura', raiz] });
266
- case '5':
267
- return comandoConfiguracoes(op);
268
- default:
269
- process.stdout.write('\n');
287
+ if (!['1', '2', '3', '4', '5'].includes(tecla)) return void process.stdout.write('\n');
288
+ const doMenu = { ...op, doMenu: true };
289
+ if (tecla === '1') await comandoAuditoria({ ...doMenu, _: ['auditoria', raiz] });
290
+ else if (tecla === '2') await comandoCves({ ...doMenu, _: ['cves', raiz] });
291
+ else if (tecla === '3') await comandoPentest({ ...doMenu, _: ['pentest'] });
292
+ else if (tecla === '4') await comandoVarredura({ ...doMenu, _: ['varredura', raiz] });
293
+ else await comandoConfiguracoes(doMenu);
294
+ process.exitCode = undefined; // um aviso de uma opção (ex.: recusa do pentest) não encerra o menu
270
295
  }
271
296
  }
272
297
 
@@ -369,7 +394,7 @@ async function comandoAuditoria(op) {
369
394
  }
370
395
 
371
396
  /** Configurações numa tela do navegador. */
372
- async function comandoConfiguracoes() {
397
+ async function comandoConfiguracoes(op = {}) {
373
398
  let varreduras = null;
374
399
  const tela = await abrirTelaConfig({
375
400
  versao: VERSAO,
@@ -378,9 +403,8 @@ async function comandoConfiguracoes() {
378
403
  return varreduras.url;
379
404
  },
380
405
  });
381
- process.stdout.write(`\n ${cor.laranja(cor.negrito('Carcará · configurações'))}\n Tela aberta no navegador: ${tela.url}\n ${cor.cinza('Só no seu computador. Feche com Ctrl+C (ou ela fecha sozinha depois de 15 min parada).')}\n\n`);
382
- process.on('SIGINT', () => Promise.all([tela.fechar(), varreduras?.fechar()]).then(() => process.exit(0)));
383
- await tela.aguardar();
406
+ process.stdout.write(`\n ${cor.laranja(cor.negrito('Carcará · configurações'))}\n Tela aberta no navegador: ${tela.url}\n ${cor.cinza('Só no seu computador.')}\n`);
407
+ await esperarTelaOuTecla(() => tela.aguardar(), () => tela.fechar(), { doMenu: op.doMenu });
384
408
  await varreduras?.fechar();
385
409
  }
386
410
 
@@ -416,11 +440,9 @@ async function comandoVarredura(op) {
416
440
  process.stdout.write(`
417
441
  ${cor.laranja(cor.negrito('Carcará · agendar verificações'))}
418
442
  Tela aberta no navegador: ${tela.url}
419
- ${cor.cinza('Só no seu computador. Feche com Ctrl+C (ou ela fecha sozinha depois de 15 min parada).')}
420
-
443
+ ${cor.cinza('Só no seu computador.')}
421
444
  `);
422
- process.on('SIGINT', () => tela.fechar().then(() => process.exit(0)));
423
- await tela.aguardar();
445
+ await esperarTelaOuTecla(() => tela.aguardar(), () => tela.fechar(), { doMenu: op.doMenu });
424
446
  }
425
447
 
426
448
  /** Lê uma linha digitada (para o endereço e o "AUTORIZO host"). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carcara-security",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Ferramenta agêntica de segurança: CVEs das libs, análise de código e pentest, com a IA que você já tem.",
5
5
  "type": "module",
6
6
  "bin": {