2 * Quick HTTP-only test for MeshCentral login
5require('dotenv').config();
6const https = require('https');
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;
12console.log('🔐 Testing MeshCentral Login (HTTP only)');
13console.log('URL:', MESHCENTRAL_URL);
14console.log('Username:', MESHCENTRAL_USERNAME);
17const postData = JSON.stringify({
18 username: MESHCENTRAL_USERNAME,
19 password: MESHCENTRAL_PASSWORD
22const url = new URL(MESHCENTRAL_URL);
24 hostname: url.hostname,
29 'Content-Type': 'application/json',
30 'Content-Length': Buffer.byteLength(postData)
32 rejectUnauthorized: false,
36const req = https.request(options, (res) => {
37 console.log('Status:', res.statusCode);
40 res.on('data', (chunk) => body += chunk);
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) + '...');
49 // Now try to get server info with the cookie
50 console.log('📊 Testing authenticated request...');
53 hostname: url.hostname,
58 'Cookie': cookie.split(';')[0]
60 rejectUnauthorized: false,
64 const getReq = https.request(getOptions, (getRes) => {
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');
78 getReq.on('error', (e) => console.error('Get error:', e.message));
82 console.log('❌ Login failed - no cookie received');
83 console.log('Response:', body.substring(0, 200));
89req.on('error', (e) => {
90 console.error('❌ Request error:', e.message);
94req.on('timeout', () => {
95 console.error('❌ Request timeout');