UNPKG

coolify-deploy-logs-cli

Version:
206 lines (171 loc) • 7.6 kB
#!/usr/bin/env node /** * Coolify Tools Debug Version */ const https = require('https'); const { URL } = require('url'); class CoolifyDeployDebug { constructor() { this.baseURL = 'https://coolify.247420.xyz'; this.cookies = ''; this.csrfToken = null; } async request(url, options = {}) { return new Promise((resolve, reject) => { const urlObj = new URL(url); const requestOptions = { hostname: urlObj.hostname, port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80), path: urlObj.pathname + urlObj.search, method: options.method || 'GET', headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', ...options.headers } }; if (this.cookies) { requestOptions.headers['Cookie'] = this.cookies; } if (options.data) { const data = typeof options.data === 'string' ? options.data : JSON.stringify(options.data); requestOptions.headers['Content-Type'] = requestOptions.headers['Content-Type'] || 'application/json'; requestOptions.headers['Content-Length'] = Buffer.byteLength(data); } const req = https.request(requestOptions, (res) => { let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', () => { // Handle cookies if (res.headers['set-cookie']) { this.cookies = res.headers['set-cookie'].map(cookie => cookie.split(';')[0]).join('; '); } // Extract CSRF token if present if (rawData.includes('name="_token"')) { const csrfMatch = rawData.match(/name="_token"[^>]+value="([^"]+)"/); if (csrfMatch) { this.csrfToken = csrfMatch[1]; } } resolve({ status: res.statusCode, headers: res.headers, raw: rawData }); }); }); req.on('error', (err) => { reject(err); }); if (options.data) { const data = typeof options.data === 'string' ? options.data : JSON.stringify(options.data); req.write(data); } req.end(); }); } async login() { console.log('šŸ” Logging in...'); try { const loginPage = await this.request(this.baseURL + '/login'); if (!this.csrfToken) { throw new Error('Could not find CSRF token on login page'); } const loginResponse = await this.request(this.baseURL + '/login', { method: 'POST', data: 'email=admin%40247420.xyz&password=123%2Cslam123%2Cslam&_token=' + this.csrfToken, headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': this.baseURL + '/login' } }); if (loginResponse.status === 302 || loginResponse.status === 200) { console.log('āœ… Login successful'); return true; } else { throw new Error('Login failed with status: ' + loginResponse.status); } } catch (error) { console.error('āŒ Login error:', error.message); throw error; } } async debugDashboard() { console.log('\nšŸ” Debugging dashboard content...'); try { const dashboardResponse = await this.request(this.baseURL + '/dashboard'); console.log('Dashboard status:', dashboardResponse.status); console.log('Content length:', dashboardResponse.raw.length); // Look for any UUID-like patterns const uuidPattern = /[a-z0-9]{24}/g; const uuids = [...dashboardResponse.raw.matchAll(uuidPattern)]; console.log('\nFound UUIDs:', uuids.length); if (uuids.length > 0) { uuids.slice(0, 10).forEach((match, index) => { console.log(' ' + (index + 1) + ': ' + match[0]); }); } // Look for project-related patterns const projectPatterns = [ /project\/([^"\s]+)/g, /data-project-id="([^"]+)"/g, /data-uuid="([^"]+)"/g, /href="\/project\/([^"]+)"/g, /"uuid":"([^"]+)"/g ]; console.log('\nProject-related patterns:'); projectPatterns.forEach((pattern, index) => { const matches = [...dashboardResponse.raw.matchAll(pattern)]; if (matches.length > 0) { console.log(' Pattern ' + (index + 1) + ':', matches.length, 'matches'); matches.slice(0, 3).forEach(match => { console.log(' - ' + match[1]); }); } }); // Look for environment-related patterns const envPatterns = [ /environment\/([^"\s]+)/g, /data-environment-id="([^"]+)"/g, /data-environment-uuid="([^"]+)"/g, /"environment_uuid":"([^"]+)"/g ]; console.log('\nEnvironment-related patterns:'); envPatterns.forEach((pattern, index) => { const matches = [...dashboardResponse.raw.matchAll(pattern)]; if (matches.length > 0) { console.log(' Pattern ' + (index + 1) + ':', matches.length, 'matches'); matches.slice(0, 3).forEach(match => { console.log(' - ' + match[1]); }); } }); // Save a portion of the dashboard for manual inspection const fs = require('fs'); fs.writeFileSync('/tmp/dashboard_debug.html', dashboardResponse.raw); console.log('\nšŸ“„ Dashboard content saved to /tmp/dashboard_debug.html'); return dashboardResponse; } catch (error) { console.error('āŒ Dashboard debug error:', error.message); throw error; } } } // Main execution async function main() { const debug = new CoolifyDeployDebug(); try { await debug.login(); await debug.debugDashboard(); console.log('\nāœ… Debug completed'); } catch (error) { console.error('āŒ Debug failed:', error.message); } } main();