typescript-virtual-container 1.1.4 → 1.1.5

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.
@@ -1,4 +1,5 @@
1
1
  import { randomBytes, randomUUID, scryptSync } from "node:crypto";
2
+ import { EventEmitter } from "node:events";
2
3
  import * as path from "node:path";
3
4
  import type VirtualFileSystem from "../VirtualFileSystem";
4
5
 
@@ -31,7 +32,7 @@ export interface VirtualActiveSession {
31
32
  *
32
33
  * Passwords are hashed with scrypt and stored in the backing virtual filesystem.
33
34
  */
34
- export class VirtualUserManager {
35
+ export class VirtualUserManager extends EventEmitter {
35
36
  private readonly usersPath = "/virtual-env-js/.auth/htpasswd";
36
37
  private readonly sudoersPath = "/virtual-env-js/.auth/sudoers";
37
38
  private readonly quotasPath = "/virtual-env-js/.auth/quotas";
@@ -53,7 +54,9 @@ export class VirtualUserManager {
53
54
  private readonly vfs: VirtualFileSystem,
54
55
  private readonly defaultRootPassword: string = "root",
55
56
  private readonly autoSudoForNewUsers: boolean = true,
56
- ) {}
57
+ ) {
58
+ super();
59
+ }
57
60
 
58
61
  /**
59
62
  * Loads users/sudoers from disk and ensures root account exists.
@@ -88,6 +91,7 @@ export class VirtualUserManager {
88
91
  }
89
92
 
90
93
  await this.persist();
94
+ this.emit("initialized");
91
95
  }
92
96
 
93
97
  /**
@@ -240,6 +244,7 @@ export class VirtualUserManager {
240
244
  );
241
245
  }
242
246
  await this.persist();
247
+ this.emit("user:add", { username });
243
248
  }
244
249
 
245
250
  /**
@@ -278,6 +283,7 @@ export class VirtualUserManager {
278
283
 
279
284
  this.sudoers.delete(username);
280
285
 
286
+ this.emit("user:delete", { username });
281
287
  await this.persist();
282
288
  }
283
289
 
@@ -339,8 +345,12 @@ export class VirtualUserManager {
339
345
  remoteAddress,
340
346
  startedAt: new Date().toISOString(),
341
347
  };
342
-
343
348
  this.activeSessions.set(session.id, session);
349
+ this.emit("session:register", {
350
+ sessionId: session.id,
351
+ username,
352
+ remoteAddress,
353
+ });
344
354
  return session;
345
355
  }
346
356
 
@@ -354,6 +364,14 @@ export class VirtualUserManager {
354
364
  return;
355
365
  }
356
366
 
367
+ const session = this.activeSessions.get(sessionId);
368
+ this.activeSessions.delete(sessionId);
369
+ if (session) {
370
+ this.emit("session:unregister", {
371
+ sessionId,
372
+ username: session.username,
373
+ });
374
+ }
357
375
  this.activeSessions.delete(sessionId);
358
376
  }
359
377
 
package/src/index.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import { HoneyPot } from "./Honeypot";
1
2
  import { SshClient } from "./SSHClient";
2
3
  import { SftpMimic, SshMimic } from "./SSHMimic/index";
3
4
  import VirtualFileSystem from "./VirtualFileSystem";
4
5
  import { VirtualShell } from "./VirtualShell";
5
6
  import { VirtualUserManager } from "./VirtualUserManager";
6
7
 
8
+ export type {
9
+ AuditLogEntry,
10
+ HoneyPotStats,
11
+ } from "./Honeypot";
7
12
  export type {
8
13
  CommandContext,
9
14
  CommandMode,
@@ -30,6 +35,7 @@ export type {
30
35
  } from "./types/vfs";
31
36
 
32
37
  export {
38
+ HoneyPot,
33
39
  SshClient,
34
40
  VirtualFileSystem,
35
41
  SftpMimic as VirtualSftpServer,