UNPKG

coolify-deploy-logs-cli

Version:
188 lines (156 loc) • 7.17 kB
#!/usr/bin/env node /** * Improved Coolify Debug with redirect handling */ const https = require('https'); const { URL } = require('url'); class CoolifyDeployImproved { constructor() { this.baseURL = 'https://coolify.247420.xyz'; this.cookies = ''; this.csrfToken = null; } async request(url, options = {}, followRedirects = true) { return new Promise((resolve, reject) => { const makeRequest = (requestUrl) => { const urlObj = new URL(requestUrl); 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]; } } // Handle redirects if (followRedirects && (res.statusCode === 302 || res.statusCode === 301 || res.statusCode === 303)) { if (res.headers.location) { const redirectUrl = res.headers.location.startsWith('http') ? res.headers.location : this.baseURL + res.headers.location; console.log('šŸ”„ Following redirect to:', redirectUrl); return makeRequest(redirectUrl); } } 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(); }; makeRequest(url); }); } 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 exploreRoutes() { console.log('\nšŸ” Exploring possible routes...'); const routes = [ '/', '/dashboard', '/projects', '/project', '/admin', '/resources', '/applications' ]; for (const route of routes) { try { console.log('\nšŸ” Checking route:', route); const response = await this.request(this.baseURL + route); console.log(' Status:', response.status); console.log(' Content length:', response.raw.length); // Look for project patterns const projectMatches = response.raw.match(/project\/[a-z0-9]{24}/g); if (projectMatches && projectMatches.length > 0) { console.log(' Found project patterns:', projectMatches.slice(0, 3)); } // Look for environment patterns const envMatches = response.raw.match(/environment\/[a-z0-9]{24}/g); if (envMatches && envMatches.length > 0) { console.log(' Found environment patterns:', envMatches.slice(0, 3)); } } catch (error) { console.log(' Error:', error.message); } } } } // Main execution async function main() { const debug = new CoolifyDeployImproved(); try { await debug.login(); await debug.exploreRoutes(); console.log('\nāœ… Exploration completed'); } catch (error) { console.error('āŒ Exploration failed:', error.message); } } main();