Skip to content

Commit 71d409d

Browse files
mrveissclaude
andcommitted
fix(infra): replace hardcoded IPs in utility scripts with env var overrides (#3051)
3 files updated to use AUTOBOT_FRONTEND_URL, AUTOBOT_BROWSER_HOST, AUTOBOT_BROWSER_PORT env vars with 127.0.0.1 safe defaults: - test_console_using_browser_vm.js: 3 IPs replaced - capture_console_logs.js: 1 IP replaced - playwright-server.js: 4 IPs replaced Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 021b586 commit 71d409d

3 files changed

Lines changed: 58 additions & 37 deletions

File tree

autobot-infrastructure/shared/scripts/infrastructure/playwright-server.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const express = require('express');
77
const winston = require('winston');
88
const app = express();
99

10+
// Configuration from environment variables with safe localhost defaults
11+
const FRONTEND_URL = process.env.AUTOBOT_FRONTEND_URL || 'http://127.0.0.1:5173';
12+
1013
// Configure Winston logger
1114
const logger = winston.createLogger({
1215
level: process.env.LOG_LEVEL || 'info',
@@ -315,7 +318,7 @@ app.post('/send-test-message', async (req, res) => {
315318
message: req.body.message
316319
});
317320
try {
318-
const { frontend_url = 'http://172.16.168.21:5173', message = 'what network scanning tools do we have available?' } = req.body;
321+
const { frontend_url = FRONTEND_URL, message = 'what network scanning tools do we have available?' } = req.body;
319322

320323
const browser = await initBrowser();
321324
const page = await browser.newPage();
@@ -534,7 +537,7 @@ app.post('/test-frontend', async (req, res) => {
534537
frontend_url: req.body.frontend_url
535538
});
536539
try {
537-
const { frontend_url = 'http://172.16.168.21:5173' } = req.body;
540+
const { frontend_url = FRONTEND_URL } = req.body;
538541

539542
const browser = await initBrowser();
540543
const page = await browser.newPage();
@@ -1016,7 +1019,7 @@ app.post('/reload', async (req, res) => {
10161019

10171020
// Health check endpoint with frontend connectivity test
10181021
app.get('/test-frontend-connectivity', async (req, res) => {
1019-
const frontendUrl = req.query.url || 'http://172.16.168.21:5173';
1022+
const frontendUrl = req.query.url || FRONTEND_URL;
10201023

10211024
logger.info('Testing frontend connectivity', {
10221025
endpoint: '/test-frontend-connectivity',
@@ -1060,7 +1063,7 @@ app.get('/test-frontend-connectivity', async (req, res) => {
10601063
frontend_url: frontendUrl,
10611064
error: error.message,
10621065
navigation_config: NAVIGATION_CONFIG,
1063-
recommendation: 'Check if frontend is running on VM1 (172.16.168.21:5173)',
1066+
recommendation: `Check if frontend is running at ${FRONTEND_URL}`,
10641067
timestamp: new Date().toISOString()
10651068
});
10661069
}

autobot-infrastructure/shared/scripts/utilities/capture_console_logs.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/**
22
* Console log capture script for Browser VM
33
* Captures browser console warnings and errors from chat view
4+
*
5+
* Environment variables:
6+
* AUTOBOT_FRONTEND_URL - Frontend base URL (default: http://127.0.0.1:5173)
47
*/
58

69
const puppeteer = require('puppeteer');
710

11+
// Configuration from environment variables with safe localhost defaults
12+
const FRONTEND_URL = process.env.AUTOBOT_FRONTEND_URL || 'http://127.0.0.1:5173';
13+
814
async function captureConsoleLogs() {
915
let browser;
1016
try {
@@ -59,8 +65,9 @@ async function captureConsoleLogs() {
5965
});
6066

6167
// Navigate to chat view
62-
console.log('Navigating to chat view...');
63-
await page.goto('http://172.16.168.21:5173/chat', {
68+
const chatUrl = `${FRONTEND_URL}/chat`;
69+
console.log(`Navigating to chat view at ${chatUrl}...`);
70+
await page.goto(chatUrl, {
6471
waitUntil: 'networkidle2',
6572
timeout: 30000
6673
});
@@ -93,9 +100,9 @@ async function captureConsoleLogs() {
93100
// Output results
94101
console.log('\n=== CONSOLE ANALYSIS RESULTS ===');
95102
if (consoleMessages.length === 0) {
96-
console.log('No console warnings or errors detected');
103+
console.log('No console warnings or errors detected');
97104
} else {
98-
console.log(`Found ${consoleMessages.length} console issues:`);
105+
console.log(`Found ${consoleMessages.length} console issues:`);
99106
consoleMessages.forEach((msg, index) => {
100107
console.log(`\n${index + 1}. [${msg.type.toUpperCase()}] ${msg.text}`);
101108
if (msg.location && msg.location.url) {
@@ -112,7 +119,7 @@ async function captureConsoleLogs() {
112119
const resultsPath = '/tmp/console_analysis_results.json';
113120
fs.writeFileSync(resultsPath, JSON.stringify({
114121
timestamp: new Date().toISOString(),
115-
url: 'http://172.16.168.21:5173/chat',
122+
url: chatUrl,
116123
totalIssues: consoleMessages.length,
117124
messages: consoleMessages
118125
}, null, 2));

autobot-infrastructure/shared/scripts/utilities/test_console_using_browser_vm.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
/**
22
* Test console warnings and errors using AutoBot's Browser VM
3-
* This script uses AutoBot's dedicated Browser VM (172.16.168.25:3000) for browser automation
3+
* This script uses AutoBot's dedicated Browser VM for browser automation
44
* instead of installing Playwright locally on Kali Linux (which is incompatible)
5+
*
6+
* Environment variables:
7+
* AUTOBOT_BROWSER_HOST - Browser VM hostname (default: 127.0.0.1)
8+
* AUTOBOT_BROWSER_PORT - Browser VM port (default: 3000)
9+
* AUTOBOT_FRONTEND_URL - Frontend base URL (default: http://127.0.0.1:5173)
510
*/
611

712
const http = require('http');
813
const https = require('https');
914
const querystring = require('querystring');
1015

16+
// Configuration from environment variables with safe localhost defaults
17+
const BROWSER_VM_HOST = process.env.AUTOBOT_BROWSER_HOST || '127.0.0.1';
18+
const BROWSER_VM_PORT = parseInt(process.env.AUTOBOT_BROWSER_PORT || '3000', 10);
19+
const FRONTEND_URL = process.env.AUTOBOT_FRONTEND_URL || 'http://127.0.0.1:5173';
20+
1121
class BrowserVMClient {
12-
constructor(browserVMHost = '172.16.168.25', browserVMPort = 3000) {
22+
constructor(browserVMHost = BROWSER_VM_HOST, browserVMPort = BROWSER_VM_PORT) {
1323
this.browserVMHost = browserVMHost;
1424
this.browserVMPort = browserVMPort;
1525
this.baseUrl = `http://${browserVMHost}:${browserVMPort}`;
@@ -69,16 +79,16 @@ class BrowserVMClient {
6979
*/
7080
async startBrowserSession() {
7181
try {
72-
console.log('🌐 Starting browser session on Browser VM...');
82+
console.log('Starting browser session on Browser VM...');
7383
const response = await this.sendRequest('/api/browser/start', 'POST', {
7484
headless: false,
7585
viewport: { width: 1920, height: 1080 }
7686
});
7787

78-
console.log('Browser session started:', response);
88+
console.log('Browser session started:', response);
7989
return response.sessionId;
8090
} catch (error) {
81-
console.error('Failed to start browser session:', error.message);
91+
console.error('Failed to start browser session:', error.message);
8292
throw error;
8393
}
8494
}
@@ -88,7 +98,7 @@ class BrowserVMClient {
8898
*/
8999
async navigateAndCaptureConsole(sessionId, url) {
90100
try {
91-
console.log(`🔍 Navigating to ${url} and capturing console messages...`);
101+
console.log(`Navigating to ${url} and capturing console messages...`);
92102

93103
// Navigate to the URL
94104
await this.sendRequest('/api/browser/navigate', 'POST', {
@@ -108,7 +118,7 @@ class BrowserVMClient {
108118

109119
return consoleMessages;
110120
} catch (error) {
111-
console.error('Failed to navigate and capture console:', error.message);
121+
console.error('Failed to navigate and capture console:', error.message);
112122
throw error;
113123
}
114124
}
@@ -119,9 +129,9 @@ class BrowserVMClient {
119129
async closeBrowserSession(sessionId) {
120130
try {
121131
await this.sendRequest('/api/browser/close', 'POST', { sessionId });
122-
console.log('Browser session closed');
132+
console.log('Browser session closed');
123133
} catch (error) {
124-
console.error('⚠️ Failed to close browser session:', error.message);
134+
console.error('Failed to close browser session:', error.message);
125135
}
126136
}
127137
}
@@ -135,18 +145,18 @@ async function testChatViewConsole() {
135145
sessionId = await browserClient.startBrowserSession();
136146

137147
// Test chat view console
138-
const chatUrl = 'http://172.16.168.21:5173/chat';
139-
console.log(`🔍 Testing chat view console at: ${chatUrl}`);
148+
const chatUrl = `${FRONTEND_URL}/chat`;
149+
console.log(`Testing chat view console at: ${chatUrl}`);
140150

141151
const consoleMessages = await browserClient.navigateAndCaptureConsole(sessionId, chatUrl);
142152

143153
// Analyze results
144154
console.log('\n=== CONSOLE ANALYSIS RESULTS ===');
145155
if (!consoleMessages || !consoleMessages.messages || consoleMessages.messages.length === 0) {
146-
console.log('No console warnings or errors detected in chat view!');
147-
console.log('🎉 Console warnings and errors have been successfully eliminated!');
156+
console.log('No console warnings or errors detected in chat view!');
157+
console.log('Console warnings and errors have been successfully eliminated!');
148158
} else {
149-
console.log(`Found ${consoleMessages.messages.length} console issues:`);
159+
console.log(`Found ${consoleMessages.messages.length} console issues:`);
150160
consoleMessages.messages.forEach((msg, index) => {
151161
console.log(`\n${index + 1}. [${msg.type.toUpperCase()}] ${msg.text}`);
152162
if (msg.location && msg.location.url) {
@@ -167,30 +177,30 @@ async function testChatViewConsole() {
167177
const fs = require('fs');
168178
const resultsPath = '/tmp/console_test_results.json';
169179
fs.writeFileSync(resultsPath, JSON.stringify(results, null, 2));
170-
console.log(`\n💾 Results saved to: ${resultsPath}`);
180+
console.log(`\nResults saved to: ${resultsPath}`);
171181

172182
return results;
173183

174184
} catch (error) {
175-
console.error('Browser VM automation failed:', error);
185+
console.error('Browser VM automation failed:', error);
176186

177187
// Fallback: Try simple HTTP check
178-
console.log('\n🔄 Falling back to simple HTTP check...');
188+
console.log('\nFalling back to simple HTTP check...');
179189
try {
180190
const http = require('http');
181-
const testReq = http.get('http://172.16.168.21:5173/', (res) => {
182-
console.log(`Frontend is accessible (HTTP ${res.statusCode})`);
183-
console.log('💡 Frontend and backend are now properly connected');
184-
console.log('🎯 Previous console warnings were likely due to backend module import failures');
185-
console.log('Backend is now running with correct Python path, eliminating import errors');
191+
const testReq = http.get(`${FRONTEND_URL}/`, (res) => {
192+
console.log(`Frontend is accessible (HTTP ${res.statusCode})`);
193+
console.log('Frontend and backend are now properly connected');
194+
console.log('Previous console warnings were likely due to backend module import failures');
195+
console.log('Backend is now running with correct Python path, eliminating import errors');
186196
});
187197

188198
testReq.on('error', (err) => {
189-
console.error('Frontend accessibility test failed:', err.message);
199+
console.error('Frontend accessibility test failed:', err.message);
190200
});
191201

192202
} catch (fallbackError) {
193-
console.error('Fallback test also failed:', fallbackError.message);
203+
console.error('Fallback test also failed:', fallbackError.message);
194204
}
195205

196206
} finally {
@@ -202,11 +212,12 @@ async function testChatViewConsole() {
202212
}
203213

204214
// Run the test
205-
console.log('🚀 Starting console test using AutoBot Browser VM...');
206-
console.log('📋 This uses the dedicated Browser VM (172.16.168.25:3000) instead of local Playwright');
207-
console.log('🔧 Following CLAUDE.md guidelines for Kali Linux compatibility\n');
215+
console.log('Starting console test using AutoBot Browser VM...');
216+
console.log(`Browser VM: ${BROWSER_VM_HOST}:${BROWSER_VM_PORT}`);
217+
console.log(`Frontend URL: ${FRONTEND_URL}`);
218+
console.log('Following CLAUDE.md guidelines for Kali Linux compatibility\n');
208219

209220
testChatViewConsole().catch(error => {
210-
console.error('💥 Test execution failed:', error);
221+
console.error('Test execution failed:', error);
211222
process.exit(1);
212223
});

0 commit comments

Comments
 (0)