@meru2802/aux-server 1.0.13 → 1.0.14

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 +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;AAKjE,qBAAa,aAAc,SAAQ,cAAc;gBACnC,gBAAgB,CAAC,EAAE,iBAAiB;IAIzC,YAAY,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CA2EtE;IAEK,cAAc,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CAiEd;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,CA2EtE;IAEK,cAAc,GACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,KACZ,OAAO,CAAC,IAAI,CAAC,CA+Pd;CACH"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ApiController = void 0;
7
7
  const BaseController_1 = require("./BaseController");
8
8
  const utils_1 = require("../lib/utils");
9
+ const utils_2 = require("@meru2802/rmm-lib/utils");
9
10
  const axios_1 = __importDefault(require("axios"));
10
11
  class ApiController extends BaseController_1.BaseController {
11
12
  constructor(serviceContainer) {
@@ -71,10 +72,11 @@ class ApiController extends BaseController_1.BaseController {
71
72
  }
72
73
  };
73
74
  this.getConnectUrls = async (req, res) => {
74
- var _a;
75
+ var _a, _b, _c, _d, _e, _f, _g;
75
76
  try {
76
77
  const meshNodeId = req.body.meshNodeId;
77
78
  const userId = req.body.userId;
79
+ const isApplet = req.body.isApplet;
78
80
  if (!meshNodeId || !userId) {
79
81
  const errorResponse = {
80
82
  error: "'meshNodeId' or 'userId' are missing in body params",
@@ -83,7 +85,7 @@ class ApiController extends BaseController_1.BaseController {
83
85
  res.status(400).json(errorResponse);
84
86
  return;
85
87
  }
86
- const nexus_epm_user_id_query = "SELECT id FROM accounts_user WHERE username= $1";
88
+ const nexus_epm_user_id_query = "SELECT id, role_id FROM accounts_user WHERE username= $1";
87
89
  const nexus_epm_user_id = await this.dbPool.query(nexus_epm_user_id_query, [userId]);
88
90
  if (nexus_epm_user_id.rows.length === 0) {
89
91
  const errorResponse = {
@@ -93,7 +95,160 @@ class ApiController extends BaseController_1.BaseController {
93
95
  res.status(400).json(errorResponse);
94
96
  return;
95
97
  }
96
- const meshUser = `user//${userId}___${(_a = nexus_epm_user_id.rows[0]) === null || _a === void 0 ? void 0 : _a.id}`.toLowerCase();
98
+ if (!isApplet) {
99
+ const nexus_epm_agent_id_query = "SELECT agent_id, site_id FROM agents_agent where mesh_node_id= $1";
100
+ const nexus_epm_agent_id = await this.dbPool.query(nexus_epm_agent_id_query, [meshNodeId]);
101
+ if (!((_a = nexus_epm_user_id.rows[0]) === null || _a === void 0 ? void 0 : _a.role_id)) {
102
+ const errorResponse = {
103
+ error: `'Role id corresponding to user ${userId}' Not Found`,
104
+ timestamp: new Date().toISOString(),
105
+ };
106
+ res.status(400).json(errorResponse);
107
+ return;
108
+ }
109
+ if (nexus_epm_agent_id.rows.length === 0) {
110
+ const errorResponse = {
111
+ error: `'Agent Id corresponding to mesh node id ${meshNodeId}' Not Found`,
112
+ timestamp: new Date().toISOString(),
113
+ };
114
+ res.status(400).json(errorResponse);
115
+ return;
116
+ }
117
+ const nexus_epm_agent_client_id_query = "SELECT client_id FROM clients_site WHERE id= $1";
118
+ const nexus_epm_agent_client_id = await this.dbPool.query(nexus_epm_agent_client_id_query, [
119
+ (_b = nexus_epm_agent_id.rows[0]) === null || _b === void 0 ? void 0 : _b.site_id,
120
+ ]);
121
+ if (nexus_epm_agent_client_id.rows.length === 0) {
122
+ const errorResponse = {
123
+ error: `'Client ID corresponding to site id ${(_c = nexus_epm_agent_id.rows[0]) === null || _c === void 0 ? void 0 : _c.site_id}' Not Found`,
124
+ timestamp: new Date().toISOString(),
125
+ };
126
+ res.status(400).json(errorResponse);
127
+ return;
128
+ }
129
+ const nexus_epm_role_client_ids_query = "SELECT client_id FROM accounts_role_can_view_clients WHERE role_id= $1";
130
+ const nexus_epm_role_site_ids_query = "SELECT site_id FROM accounts_role_can_view_sites WHERE role_id= $1";
131
+ const [nexus_epm_role_client_ids, nexus_epm_role_site_ids] = await Promise.all([
132
+ this.dbPool.query(nexus_epm_role_client_ids_query, [
133
+ (_d = nexus_epm_user_id.rows[0]) === null || _d === void 0 ? void 0 : _d.role_id,
134
+ ]),
135
+ this.dbPool.query(nexus_epm_role_site_ids_query, [
136
+ (_e = nexus_epm_user_id.rows[0]) === null || _e === void 0 ? void 0 : _e.role_id,
137
+ ]),
138
+ ]);
139
+ const roleHasPermissionForAgentClient = () => {
140
+ var _a, _b;
141
+ for (let i = 0; i < nexus_epm_role_client_ids.rows.length; i++) {
142
+ if (((_a = nexus_epm_role_client_ids.rows[i]) === null || _a === void 0 ? void 0 : _a.client_id) ==
143
+ ((_b = nexus_epm_agent_client_id.rows[0]) === null || _b === void 0 ? void 0 : _b.client_id)) {
144
+ return true;
145
+ }
146
+ }
147
+ return false;
148
+ };
149
+ const roleHasPermissionForAgentSite = () => {
150
+ var _a, _b;
151
+ for (let i = 0; i < nexus_epm_role_site_ids.rows.length; i++) {
152
+ if (((_a = nexus_epm_role_site_ids.rows[i]) === null || _a === void 0 ? void 0 : _a.site_id) ==
153
+ ((_b = nexus_epm_agent_id.rows[0]) === null || _b === void 0 ? void 0 : _b.site_id)) {
154
+ return true;
155
+ }
156
+ }
157
+ return false;
158
+ };
159
+ if (!roleHasPermissionForAgentSite &&
160
+ !roleHasPermissionForAgentClient) {
161
+ const errorResponse = {
162
+ error: `'User ${userId}' does not have permission to take control of machine with mesh node id ${meshNodeId}`,
163
+ timestamp: new Date().toISOString(),
164
+ };
165
+ res.status(401).json(errorResponse);
166
+ return;
167
+ }
168
+ }
169
+ const meshUser = `user//${userId}___${(_f = nexus_epm_user_id.rows[0]) === null || _f === void 0 ? void 0 : _f.id}`.toLowerCase();
170
+ const meshUserWithoutDomain = `${userId}___${(_g = nexus_epm_user_id.rows[0]) === null || _g === void 0 ? void 0 : _g.id}`.toLowerCase();
171
+ const addUserToDevice = async () => {
172
+ const rights = 4088024;
173
+ const responseId = `id-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
174
+ const base64NodeId = (0, utils_2.hexToBase64)(meshNodeId);
175
+ const addDeviceUserMessage = {
176
+ action: "adddeviceuser",
177
+ responseid: responseId,
178
+ usernames: [meshUserWithoutDomain],
179
+ nodeid: base64NodeId,
180
+ rights: rights,
181
+ };
182
+ console.log(JSON.stringify(addDeviceUserMessage));
183
+ const messageSent = this.WebSocketService.sendMessage(addDeviceUserMessage);
184
+ if (!messageSent) {
185
+ console.error("Could not send adddeviceuser message over socket");
186
+ return false;
187
+ }
188
+ if (!this.webSocket) {
189
+ console.error("Socket not found");
190
+ return false;
191
+ }
192
+ return new Promise((resolve, reject) => {
193
+ let responseReceived = false;
194
+ const timeout = setTimeout(() => {
195
+ if (!responseReceived) {
196
+ responseReceived = true;
197
+ console.error("Timeout waiting for adddeviceuser response");
198
+ resolve(false);
199
+ }
200
+ }, 10000);
201
+ const messageHandler = (data) => {
202
+ var _a, _b;
203
+ if (responseReceived)
204
+ return;
205
+ try {
206
+ const message = JSON.parse(data.toString());
207
+ if (message.responseid === responseId) {
208
+ responseReceived = true;
209
+ clearTimeout(timeout);
210
+ (_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.removeListener("message", messageHandler);
211
+ if (message.result === "ok" || message.success === true) {
212
+ console.log(`Successfully added user ${meshUser} to device ${base64NodeId}`);
213
+ resolve(true);
214
+ }
215
+ else {
216
+ console.error(`Failed to add user to device: ${message.result || message.error}`);
217
+ resolve(false);
218
+ }
219
+ }
220
+ else if (message.action === "adddeviceuser" &&
221
+ !message.responseid) {
222
+ responseReceived = true;
223
+ clearTimeout(timeout);
224
+ (_b = this.webSocket) === null || _b === void 0 ? void 0 : _b.removeListener("message", messageHandler);
225
+ if (message.result === "ok" || message.success === true) {
226
+ console.log(`Successfully added user ${meshUser} to device ${base64NodeId}`);
227
+ resolve(true);
228
+ }
229
+ else {
230
+ console.error(`Failed to add user to device: ${message.result || message.error}`);
231
+ resolve(false);
232
+ }
233
+ }
234
+ }
235
+ catch (parseError) {
236
+ console.error("Error parsing WebSocket message:", parseError);
237
+ }
238
+ };
239
+ this.webSocket.on("message", messageHandler);
240
+ });
241
+ };
242
+ const userAdded = await addUserToDevice();
243
+ if (!userAdded) {
244
+ console.warn(`Could not add user ${meshUser} to device ${meshNodeId}, proceeding anyway`);
245
+ const errorResponse = {
246
+ error: `Failed to grant user ${userId} access to device`,
247
+ timestamp: new Date().toISOString(),
248
+ };
249
+ res.status(500).json(errorResponse);
250
+ return;
251
+ }
97
252
  const loginEncryptionKey = (0, utils_1.getBinaryKey)(this.config.meshcentralConfig.loginEncryptionKey);
98
253
  const authRelayCookie = (0, utils_1.encodeCookie)({ a: 3, u: meshUser }, loginEncryptionKey);
99
254
  const token_param = `login=${authRelayCookie}`;
@@ -17,7 +17,7 @@ class HealthController extends BaseController_1.BaseController {
17
17
  this.status = (req, res) => {
18
18
  const response = {
19
19
  service: "aux-server",
20
- version: "1.0.13",
20
+ version: "1.0.14",
21
21
  meshCentral: {
22
22
  connected: this.isWebSocketConnected,
23
23
  server: this.meshServer,
@@ -16,6 +16,7 @@ export declare const addUserToGroupSchema: z.ZodObject<{
16
16
  export declare const generateConnectUrlsSchema: z.ZodObject<{
17
17
  meshNodeId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
18
18
  userId: z.ZodString;
19
+ isApplet: z.ZodPipe<z.ZodOptional<z.ZodBoolean>, z.ZodTransform<boolean | undefined, boolean | undefined>>;
19
20
  }, z.core.$strip>;
20
21
  export declare const getEndpointInstallScriptSchema: z.ZodObject<{
21
22
  clientId: z.ZodNumber;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EACL,UAAU,EACV,gBAAgB,EAGjB,MAAM,IAAI,CAAC;AAEZ,eAAO,MAAM,0BAA0B;;;iBAkEpC,CAAC;AAEJ,eAAO,MAAM,uBAAuB;;;iBA+BlC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;iBAkH9B,CAAC;AAEJ,eAAO,MAAM,yBAAyB;;;iBA0DpC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;kBA6BvC,CAAC;AAEL,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAC/C,OAAO,0BAA0B,CAClC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC/E,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACzE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,yBAAyB,CACjC,CAAC;AACF,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CACnD,OAAO,8BAA8B,CACtC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EACL,UAAU,EACV,gBAAgB,EAGjB,MAAM,IAAI,CAAC;AAEZ,eAAO,MAAM,0BAA0B;;;iBAkEpC,CAAC;AAEJ,eAAO,MAAM,uBAAuB;;;iBA+BlC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;iBAkH9B,CAAC;AAEJ,eAAO,MAAM,yBAAyB;;;;iBAmEpC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;kBA6BvC,CAAC;AAEL,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAC/C,OAAO,0BAA0B,CAClC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC/E,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACzE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,yBAAyB,CACjC,CAAC;AACF,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CACnD,OAAO,8BAA8B,CACtC,CAAC"}
@@ -195,6 +195,14 @@ exports.generateConnectUrlsSchema = zod_1.default.object({
195
195
  }, {
196
196
  message: "User ID cannot contain consecutive dots",
197
197
  }),
198
+ isApplet: zod_1.default
199
+ .boolean()
200
+ .optional()
201
+ .describe("Indicates whether the connection URL is for an applet or standard application")
202
+ .refine((value) => value === undefined || typeof value === "boolean", {
203
+ message: "isApplet must be a boolean value",
204
+ })
205
+ .transform((value) => (value === undefined ? undefined : Boolean(value))),
198
206
  });
199
207
  exports.getEndpointInstallScriptSchema = zod_1.default
200
208
  .object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meru2802/aux-server",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Nexus EPM auxillary server to facilitate additional functionality required by Scogo Iceberg",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -30,7 +30,7 @@
30
30
  "author": "meru2802",
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
- "@meru2802/rmm-lib": "^1.0.0",
33
+ "@meru2802/rmm-lib": "^1.0.6",
34
34
  "axios": "^1.9.0",
35
35
  "base-64": "^1.0.0",
36
36
  "cookie-parser": "^1.4.7",