EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
get-meshid.js
Go to the documentation of this file.
1require('dotenv').config({ path: '../.env' });
2require('dotenv').config();
3
4const https = require('https');
5
6const MESHCENTRAL_URL = 'https://rmm-psa-meshcentral-aq48h.ondigitalocean.app';
7const username = process.env.MESHCENTRAL_USERNAME;
8const password = process.env.MESHCENTRAL_PASSWORD;
9
10// Login and get mesh list
11/**
12 *
13 */
14async function getMeshes() {
15 return new Promise((resolve, reject) => {
16 // Step 1: Login
17 const loginData = `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`;
18
19 const options = {
20 hostname: 'rmm-psa-meshcentral-aq48h.ondigitalocean.app',
21 port: 443,
22 path: '/',
23 method: 'POST',
24 headers: {
25 'Content-Type': 'application/x-www-form-urlencoded',
26 'Content-Length': loginData.length
27 },
28 rejectUnauthorized: false
29 };
30
31 const req = https.request(options, (res) => {
32 let cookie = '';
33 if (res.headers['set-cookie']) {
34 cookie = res.headers['set-cookie'][0].split(';')[0];
35 }
36
37 let body = '';
38 res.on('data', chunk => body += chunk);
39 res.on('end', () => {
40 console.log('Login response:', res.statusCode);
41 console.log('Cookie:', cookie);
42
43 // Step 2: Get mesh list
44 const meshOptions = {
45 hostname: 'rmm-psa-meshcentral-aq48h.ondigitalocean.app',
46 port: 443,
47 path: '/meshes',
48 method: 'GET',
49 headers: {
50 'Cookie': cookie
51 },
52 rejectUnauthorized: false
53 };
54
55 const meshReq = https.request(meshOptions, (meshRes) => {
56 let meshBody = '';
57 meshRes.on('data', chunk => meshBody += chunk);
58 meshRes.on('end', () => {
59 console.log('\nMesh list response:', meshRes.statusCode);
60 console.log('Body:', meshBody.substring(0, 500));
61 resolve(meshBody);
62 });
63 });
64
65 meshReq.on('error', reject);
66 meshReq.end();
67 });
68 });
69
70 req.on('error', reject);
71 req.write(loginData);
72 req.end();
73 });
74}
75
76getMeshes().catch(console.error);