EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
test-mesh-quick.js
Go to the documentation of this file.
1/**
2 * Quick HTTP-only test for MeshCentral login
3 */
4
5require('dotenv').config();
6const https = require('https');
7
8const MESHCENTRAL_URL = process.env.MESHCENTRAL_URL || 'https://209.38.80.86:4430';
9const MESHCENTRAL_USERNAME = process.env.MESHCENTRAL_USERNAME;
10const MESHCENTRAL_PASSWORD = process.env.MESHCENTRAL_PASSWORD;
11
12console.log('🔐 Testing MeshCentral Login (HTTP only)');
13console.log('URL:', MESHCENTRAL_URL);
14console.log('Username:', MESHCENTRAL_USERNAME);
15console.log('');
16
17const postData = JSON.stringify({
18 username: MESHCENTRAL_USERNAME,
19 password: MESHCENTRAL_PASSWORD
20});
21
22const url = new URL(MESHCENTRAL_URL);
23const options = {
24 hostname: url.hostname,
25 port: url.port,
26 path: '/login',
27 method: 'POST',
28 headers: {
29 'Content-Type': 'application/json',
30 'Content-Length': Buffer.byteLength(postData)
31 },
32 rejectUnauthorized: false,
33 timeout: 5000
34};
35
36const req = https.request(options, (res) => {
37 console.log('Status:', res.statusCode);
38
39 let body = '';
40 res.on('data', (chunk) => body += chunk);
41
42 res.on('end', () => {
43 if (res.headers['set-cookie']) {
44 console.log('✅ Login successful! Cookie received.');
45 const cookie = res.headers['set-cookie'][0];
46 console.log('🍪 Cookie preview:', cookie.substring(0, 50) + '...');
47 console.log('');
48
49 // Now try to get server info with the cookie
50 console.log('📊 Testing authenticated request...');
51
52 const getOptions = {
53 hostname: url.hostname,
54 port: url.port,
55 path: '/serverinfo',
56 method: 'GET',
57 headers: {
58 'Cookie': cookie.split(';')[0]
59 },
60 rejectUnauthorized: false,
61 timeout: 5000
62 };
63
64 const getReq = https.request(getOptions, (getRes) => {
65 let getData = '';
66 getRes.on('data', (chunk) => getData += chunk);
67 getRes.on('end', () => {
68 console.log('Server info status:', getRes.statusCode);
69 if (getRes.statusCode === 200) {
70 console.log('✅ Authenticated request successful!');
71 const info = JSON.parse(getData);
72 console.log('Server version:', info.serverinfo?.version || 'unknown');
73 }
74 process.exit(0);
75 });
76 });
77
78 getReq.on('error', (e) => console.error('Get error:', e.message));
79 getReq.end();
80
81 } else {
82 console.log('❌ Login failed - no cookie received');
83 console.log('Response:', body.substring(0, 200));
84 process.exit(1);
85 }
86 });
87});
88
89req.on('error', (e) => {
90 console.error('❌ Request error:', e.message);
91 process.exit(1);
92});
93
94req.on('timeout', () => {
95 console.error('❌ Request timeout');
96 req.destroy();
97 process.exit(1);
98});
99
100req.write(postData);
101req.end();