@meru2802/aux-server 1.0.16 → 1.0.19

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.
@@ -10,6 +10,7 @@ export declare class ConfigManager {
10
10
  user: string;
11
11
  password: string;
12
12
  server: string;
13
+ host: string;
13
14
  loginEncryptionKey: string;
14
15
  inviteEncryptionKey: string;
15
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO;WAIO,WAAW,IAAI,aAAa;IAO1C,OAAO,CAAC,UAAU;IAwDX,SAAS,IAAI,MAAM;IAInB,aAAa;;;;;;;IAIb,WAAW;;;;;;;IAIX,gBAAgB;;;;;;;;;IAIhB,gBAAgB;;;;;;;;CAGxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO;WAIO,WAAW,IAAI,aAAa;IAO1C,OAAO,CAAC,UAAU;IAwDX,SAAS,IAAI,MAAM;IAInB,aAAa;;;;;;;;IAIb,WAAW;;;;;;;IAIX,gBAAgB;;;;;;;;;IAIhB,gBAAgB;;;;;;;;CAGxB"}
@@ -1,7 +1,7 @@
1
1
  import { Pool } from "pg";
2
2
  import WebSocket from "ws";
3
3
  import { IServiceContainer } from "../services/ServiceContainer";
4
- import { Config } from "../types";
4
+ import { Config, MeshUser } from "../types";
5
5
  import { IWebSocketService } from "../services/WebSocketService";
6
6
  import { HttpsProxyAgent } from "https-proxy-agent";
7
7
  import { Agent } from "https";
@@ -15,5 +15,14 @@ export declare abstract class BaseController {
15
15
  protected get isWebSocketConnected(): boolean;
16
16
  protected get meshServer(): string;
17
17
  protected get httpsAgent(): HttpsProxyAgent<string> | Agent;
18
+ protected get genResponseId(): string;
19
+ protected createMeshUsers(meshUsers: MeshUser[]): Promise<{
20
+ createdUsers: MeshUser[];
21
+ existingUsers: MeshUser[];
22
+ failedToCreate: string[];
23
+ }>;
24
+ private createSingleMeshUser;
25
+ private makeMeshPassword;
26
+ private getSecureRandomInt;
18
27
  }
19
28
  //# sourceMappingURL=BaseController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseController.d.ts","sourceRoot":"","sources":["../../src/controllers/BaseController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAEL,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAG9B,8BAAsB,cAAc;IAClC,SAAS,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;gBAElC,gBAAgB,CAAC,EAAE,iBAAiB;IAIhD,SAAS,KAAK,MAAM,IAAI,IAAI,CAE3B;IAED,SAAS,KAAK,SAAS,IAAI,SAAS,GAAG,IAAI,CAE1C;IAED,SAAS,KAAK,gBAAgB,IAAI,iBAAiB,CAElD;IAED,SAAS,KAAK,MAAM,IAAI,MAAM,CAE7B;IAED,SAAS,KAAK,oBAAoB,IAAI,OAAO,CAE5C;IAED,SAAS,KAAK,UAAU,IAAI,MAAM,CAEjC;IAED,SAAS,KAAK,UAAU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B,OAAO,CAAC,kBAAkB;CAS3B"}
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.BaseController = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
4
8
  const ServiceContainer_1 = require("../services/ServiceContainer");
9
+ const types_1 = require("../types");
5
10
  const utils_1 = require("../lib/utils");
6
11
  class BaseController {
7
12
  constructor(serviceContainer) {
@@ -31,5 +36,144 @@ class BaseController {
31
36
  }
32
37
  return (0, utils_1.getNoProxyHttpAgent)();
33
38
  }
39
+ get genResponseId() {
40
+ const bytes = new Uint8Array(16);
41
+ crypto_1.default.getRandomValues(bytes);
42
+ const byte6 = bytes[6];
43
+ const byte8 = bytes[8];
44
+ if (byte6 === undefined || byte8 === undefined) {
45
+ throw new Error("Failed to generate UUID bytes");
46
+ }
47
+ bytes[6] = (byte6 & 0x0f) | 0x40;
48
+ bytes[8] = (byte8 & 0x3f) | 0x80;
49
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
50
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
51
+ }
52
+ async createMeshUsers(meshUsers) {
53
+ const createdUsers = [];
54
+ const existingUsers = [];
55
+ const failedToCreate = [];
56
+ const createPromises = meshUsers.map((user) => this.createSingleMeshUser(user));
57
+ const results = await Promise.allSettled(createPromises);
58
+ results.forEach((result, index) => {
59
+ const user = meshUsers[index];
60
+ if (!user) {
61
+ console.log("User is undefined: createMeshUsers");
62
+ return;
63
+ }
64
+ if (result.status === "fulfilled") {
65
+ const { status } = result.value;
66
+ if (status === "created") {
67
+ createdUsers.push(user);
68
+ console.log(`User '${user.meshUserName}' created in MeshCentral`);
69
+ }
70
+ else if (status === "exists") {
71
+ existingUsers.push(user);
72
+ console.log(`User '${user.meshUserName}' already exists in MeshCentral`);
73
+ }
74
+ else {
75
+ failedToCreate.push(user.meshUserName);
76
+ console.error(`Failed to create user '${user.meshUserName}': ${result.value.error}`);
77
+ }
78
+ }
79
+ else {
80
+ failedToCreate.push(user.meshUserName);
81
+ console.error(`Failed to create user '${user.meshUserName}':`, result.reason);
82
+ }
83
+ });
84
+ return { createdUsers, existingUsers, failedToCreate };
85
+ }
86
+ createSingleMeshUser(user) {
87
+ return new Promise((resolve) => {
88
+ const responseId = this.genResponseId;
89
+ const createUserMessage = {
90
+ action: types_1.MeshActions.ADD_USER,
91
+ username: user.meshUserName,
92
+ realname: user.fullName,
93
+ email: user.email,
94
+ pass: this.makeMeshPassword(),
95
+ emailVerified: true,
96
+ resetNextLogin: false,
97
+ responseid: responseId,
98
+ };
99
+ console.log(`Creating MeshCentral user: ${user.meshUserName}`);
100
+ const messageSent = this.WebSocketService.sendMessage(createUserMessage);
101
+ if (!messageSent) {
102
+ resolve({
103
+ status: "failed",
104
+ error: "Could not send message over socket",
105
+ });
106
+ return;
107
+ }
108
+ const timeout = setTimeout(() => {
109
+ var _a;
110
+ (_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.removeListener("message", messageHandler);
111
+ resolve({
112
+ status: "failed",
113
+ error: "Timeout waiting for create user response",
114
+ });
115
+ }, 30000);
116
+ const messageHandler = (data) => {
117
+ var _a;
118
+ try {
119
+ const message = JSON.parse(data.toString());
120
+ if (message.action === "adduser" &&
121
+ message.responseid === responseId) {
122
+ clearTimeout(timeout);
123
+ (_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.removeListener("message", messageHandler);
124
+ if (message.result === "ok") {
125
+ resolve({ status: "created" });
126
+ }
127
+ else if (message.result === "User already exists" ||
128
+ message.msgid === 7) {
129
+ resolve({ status: "exists" });
130
+ }
131
+ else {
132
+ resolve({
133
+ status: "failed",
134
+ error: message.result || "Unknown error",
135
+ });
136
+ }
137
+ }
138
+ }
139
+ catch (_b) {
140
+ // Ignore parse errors for messages that aren't relevant to us
141
+ }
142
+ };
143
+ this.webSocket.on("message", messageHandler);
144
+ });
145
+ }
146
+ makeMeshPassword() {
147
+ const alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
148
+ const nonalpha = "!@#$";
149
+ const passwd = [];
150
+ for (let i = 0; i < 29; i++) {
151
+ const char = alpha[this.getSecureRandomInt(alpha.length)];
152
+ if (char)
153
+ passwd.push(char);
154
+ }
155
+ const specialChar = nonalpha[this.getSecureRandomInt(nonalpha.length)];
156
+ if (specialChar)
157
+ passwd.push(specialChar);
158
+ for (let i = passwd.length - 1; i > 0; i--) {
159
+ const j = this.getSecureRandomInt(i + 1);
160
+ const temp = passwd[i];
161
+ const swapChar = passwd[j];
162
+ if (temp !== undefined && swapChar !== undefined) {
163
+ passwd[i] = swapChar;
164
+ passwd[j] = temp;
165
+ }
166
+ }
167
+ return passwd.join("");
168
+ }
169
+ getSecureRandomInt(max) {
170
+ const randomBuffer = new Uint32Array(1);
171
+ crypto_1.default.getRandomValues(randomBuffer);
172
+ const value = randomBuffer[0];
173
+ if (value === undefined) {
174
+ throw new Error("Failed to generate random number");
175
+ }
176
+ return value % max;
177
+ }
34
178
  }
35
179
  exports.BaseController = BaseController;
@@ -1 +1 @@
1
- {"version":3,"file":"apiController.d.ts","sourceRoot":"","sources":["../../src/controllers/apiController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAOjE,qBAAa,aAAc,SAAQ,cAAc;gBACnC,gBAAgB,CAAC,EAAE,iBAAiB;IAIzC,YAAY,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAwGtE;IAEK,cAAc,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CA+Pd;CACH"}
1
+ {"version":3,"file":"apiController.d.ts","sourceRoot":"","sources":["../../src/controllers/apiController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAOjE,qBAAa,aAAc,SAAQ,cAAc;gBACnC,gBAAgB,CAAC,EAAE,iBAAiB;IAIzC,YAAY,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAwGtE;IAEK,cAAc,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CA2Rd;CACH"}
@@ -100,7 +100,7 @@ class ApiController extends BaseController_1.BaseController {
100
100
  }
101
101
  };
102
102
  this.getConnectUrls = async (req, res) => {
103
- var _a, _b, _c, _d, _e, _f, _g;
103
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
104
104
  try {
105
105
  const meshNodeId = req.body.meshNodeId;
106
106
  const userId = req.body.userId;
@@ -113,7 +113,7 @@ class ApiController extends BaseController_1.BaseController {
113
113
  res.status(400).json(errorResponse);
114
114
  return;
115
115
  }
116
- const nexus_epm_user_id_query = "SELECT id, role_id FROM accounts_user WHERE username= $1";
116
+ const nexus_epm_user_id_query = "SELECT id, username, email, first_name, last_name, role_id FROM accounts_user WHERE username= $1";
117
117
  const nexus_epm_user_id = await this.dbPool.query(nexus_epm_user_id_query, [userId]);
118
118
  if (nexus_epm_user_id.rows.length === 0) {
119
119
  const errorResponse = {
@@ -196,6 +196,23 @@ class ApiController extends BaseController_1.BaseController {
196
196
  }
197
197
  const meshUser = `user//${userId}___${(_f = nexus_epm_user_id.rows[0]) === null || _f === void 0 ? void 0 : _f.id}`.toLowerCase();
198
198
  const meshUserWithoutDomain = `${userId}___${(_g = nexus_epm_user_id.rows[0]) === null || _g === void 0 ? void 0 : _g.id}`.toLowerCase();
199
+ const meshUsers = [
200
+ {
201
+ meshId: meshUser,
202
+ meshUserName: meshUserWithoutDomain,
203
+ fullName: `${(_h = nexus_epm_user_id.rows[0]) === null || _h === void 0 ? void 0 : _h.first_name} ${(_j = nexus_epm_user_id.rows[0]) === null || _j === void 0 ? void 0 : _j.last_name}`,
204
+ email: ((_k = nexus_epm_user_id.rows[0]) === null || _k === void 0 ? void 0 : _k.email) || "",
205
+ },
206
+ ];
207
+ const { createdUsers, existingUsers, failedToCreate } = await this.createMeshUsers(meshUsers);
208
+ if (failedToCreate.length == 1) {
209
+ const errorResponse = {
210
+ error: `User with id ${(_l = nexus_epm_user_id.rows[0]) === null || _l === void 0 ? void 0 : _l.id} Could not be created in Nexus Mesh!`,
211
+ timestamp: new Date().toISOString(),
212
+ };
213
+ res.status(500).json(errorResponse);
214
+ return;
215
+ }
199
216
  const addUserToDevice = async () => {
200
217
  const rights = 4088024;
201
218
  const responseId = `id-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
@@ -280,9 +297,9 @@ class ApiController extends BaseController_1.BaseController {
280
297
  const loginEncryptionKey = (0, utils_1.getBinaryKey)(this.config.meshcentralConfig.loginEncryptionKey);
281
298
  const authRelayCookie = (0, utils_1.encodeCookie)({ a: 3, u: meshUser }, loginEncryptionKey);
282
299
  const token_param = `login=${authRelayCookie}`;
283
- const control = `https://${this.config.meshcentralConfig.server}/?${token_param}&gotonode=${meshNodeId}&viewmode=11&hide=31`;
284
- const terminal = `https://${this.config.meshcentralConfig.server}/?${token_param}&gotonode=${meshNodeId}&viewmode=12&hide=31`;
285
- const fileSystem = `https://${this.config.meshcentralConfig.server}/?${token_param}&gotonode=${meshNodeId}&viewmode=13&hide=31`;
300
+ const control = `https://${this.config.meshcentralConfig.host}/?${token_param}&gotonode=${meshNodeId}&viewmode=11&hide=31`;
301
+ const terminal = `https://${this.config.meshcentralConfig.host}/?${token_param}&gotonode=${meshNodeId}&viewmode=12&hide=31`;
302
+ const fileSystem = `https://${this.config.meshcentralConfig.host}/?${token_param}&gotonode=${meshNodeId}&viewmode=13&hide=31`;
286
303
  const response = {
287
304
  control,
288
305
  terminal,
@@ -7,5 +7,17 @@ export declare class CoreController extends BaseController {
7
7
  createDeviceGroup: (req: Request, res: Response) => Promise<void>;
8
8
  addUserToGroup: (req: Request, res: Response) => Promise<void>;
9
9
  getEndpointInstallScript: (req: Request, res: Response) => Promise<void>;
10
+ private sendErrorResponse;
11
+ private ensureWebSocket;
12
+ private ensureMessageSent;
13
+ private sendScript;
14
+ private buildDownloadLink;
15
+ private buildDownloadLinkResponse;
16
+ private waitForWebSocketResponse;
17
+ private waitForAddUserToGroupResponse;
18
+ private fetchMeshUsers;
19
+ private fetchIcebergDetails;
20
+ private generateWindowsScript;
21
+ private generateLinuxScript;
10
22
  }
11
23
  //# sourceMappingURL=coreController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"coreController.d.ts","sourceRoot":"","sources":["../../src/controllers/coreController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAgBlD,qBAAa,cAAe,SAAQ,cAAc;gBACpC,gBAAgB,CAAC,EAAE,iBAAiB;IAIzC,eAAe,GACpB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CAkJd;IAEK,iBAAiB,GACtB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CAoHd;IAEK,cAAc,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CA8Ld;IAEK,w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