try to implement websockets
This commit is contained in:
@@ -8,8 +8,8 @@ class DNSReconApp {
|
||||
constructor() {
|
||||
console.log('DNSReconApp constructor called');
|
||||
this.graphManager = null;
|
||||
this.socket = null;
|
||||
this.scanStatus = 'idle';
|
||||
this.pollInterval = null;
|
||||
this.currentSessionId = null;
|
||||
|
||||
this.elements = {};
|
||||
@@ -31,13 +31,11 @@ class DNSReconApp {
|
||||
this.initializeElements();
|
||||
this.setupEventHandlers();
|
||||
this.initializeGraph();
|
||||
this.updateStatus();
|
||||
this.initializeSocket();
|
||||
this.loadProviders();
|
||||
this.initializeEnhancedModals();
|
||||
this.addCheckboxStyling();
|
||||
|
||||
this.updateGraph();
|
||||
|
||||
console.log('DNSRecon application initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize DNSRecon application:', error);
|
||||
@@ -45,6 +43,25 @@ class DNSReconApp {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initializeSocket() {
|
||||
this.socket = io();
|
||||
|
||||
this.socket.on('connect', () => {
|
||||
console.log('Connected to WebSocket server');
|
||||
this.updateConnectionStatus('idle');
|
||||
this.socket.emit('get_status');
|
||||
});
|
||||
|
||||
this.socket.on('scan_update', (data) => {
|
||||
if (data.status !== this.scanStatus) {
|
||||
this.handleStatusChange(data.status, data.task_queue_size);
|
||||
}
|
||||
this.scanStatus = data.status;
|
||||
this.updateStatusDisplay(data);
|
||||
this.graphManager.updateGraph(data.graph);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DOM element references
|
||||
@@ -328,15 +345,8 @@ class DNSReconApp {
|
||||
|
||||
console.log(`Scan started for ${target} with depth ${maxDepth}`);
|
||||
|
||||
// Start polling immediately with faster interval for responsiveness
|
||||
this.startPolling(1000);
|
||||
|
||||
// Force an immediate status update
|
||||
console.log('Forcing immediate status update...');
|
||||
setTimeout(() => {
|
||||
this.updateStatus();
|
||||
this.updateGraph();
|
||||
}, 100);
|
||||
// Request initial status update via WebSocket
|
||||
this.socket.emit('get_status');
|
||||
|
||||
} else {
|
||||
throw new Error(response.error || 'Failed to start scan');
|
||||
@@ -368,22 +378,6 @@ class DNSReconApp {
|
||||
|
||||
if (response.success) {
|
||||
this.showSuccess('Scan stop requested');
|
||||
|
||||
// Force immediate status update
|
||||
setTimeout(() => {
|
||||
this.updateStatus();
|
||||
}, 100);
|
||||
|
||||
// Continue polling for a bit to catch the status change
|
||||
this.startPolling(500); // Fast polling to catch status change
|
||||
|
||||
// Stop fast polling after 10 seconds
|
||||
setTimeout(() => {
|
||||
if (this.scanStatus === 'stopped' || this.scanStatus === 'idle') {
|
||||
this.stopPolling();
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
} else {
|
||||
throw new Error(response.error || 'Failed to stop scan');
|
||||
}
|
||||
@@ -548,68 +542,6 @@ class DNSReconApp {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start polling for scan updates with configurable interval
|
||||
*/
|
||||
startPolling(interval = 2000) {
|
||||
console.log('=== STARTING POLLING ===');
|
||||
|
||||
if (this.pollInterval) {
|
||||
console.log('Clearing existing poll interval');
|
||||
clearInterval(this.pollInterval);
|
||||
}
|
||||
|
||||
this.pollInterval = setInterval(() => {
|
||||
this.updateStatus();
|
||||
this.updateGraph();
|
||||
this.loadProviders();
|
||||
}, interval);
|
||||
|
||||
console.log(`Polling started with ${interval}ms interval`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop polling for updates
|
||||
*/
|
||||
stopPolling() {
|
||||
console.log('=== STOPPING POLLING ===');
|
||||
if (this.pollInterval) {
|
||||
clearInterval(this.pollInterval);
|
||||
this.pollInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Status update with better error handling
|
||||
*/
|
||||
async updateStatus() {
|
||||
try {
|
||||
const response = await this.apiCall('/api/scan/status');
|
||||
|
||||
|
||||
if (response.success && response.status) {
|
||||
const status = response.status;
|
||||
|
||||
this.updateStatusDisplay(status);
|
||||
|
||||
// Handle status changes
|
||||
if (status.status !== this.scanStatus) {
|
||||
console.log(`*** STATUS CHANGED: ${this.scanStatus} -> ${status.status} ***`);
|
||||
this.handleStatusChange(status.status, status.task_queue_size);
|
||||
}
|
||||
|
||||
this.scanStatus = status.status;
|
||||
} else {
|
||||
console.error('Status update failed:', response);
|
||||
// Don't show error for status updates to avoid spam
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to update status:', error);
|
||||
this.showConnectionError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update graph from server
|
||||
*/
|
||||
@@ -737,25 +669,20 @@ class DNSReconApp {
|
||||
case 'running':
|
||||
this.setUIState('scanning', task_queue_size);
|
||||
this.showSuccess('Scan is running');
|
||||
// Increase polling frequency for active scans
|
||||
this.startPolling(1000); // Poll every 1 second for running scans
|
||||
this.updateConnectionStatus('active');
|
||||
break;
|
||||
|
||||
case 'completed':
|
||||
this.setUIState('completed', task_queue_size);
|
||||
this.stopPolling();
|
||||
this.showSuccess('Scan completed successfully');
|
||||
this.updateConnectionStatus('completed');
|
||||
this.loadProviders();
|
||||
// Force a final graph update
|
||||
console.log('Scan completed - forcing final graph update');
|
||||
setTimeout(() => this.updateGraph(), 100);
|
||||
break;
|
||||
|
||||
case 'failed':
|
||||
this.setUIState('failed', task_queue_size);
|
||||
this.stopPolling();
|
||||
this.showError('Scan failed');
|
||||
this.updateConnectionStatus('error');
|
||||
this.loadProviders();
|
||||
@@ -763,7 +690,6 @@ class DNSReconApp {
|
||||
|
||||
case 'stopped':
|
||||
this.setUIState('stopped', task_queue_size);
|
||||
this.stopPolling();
|
||||
this.showSuccess('Scan stopped');
|
||||
this.updateConnectionStatus('stopped');
|
||||
this.loadProviders();
|
||||
@@ -771,7 +697,6 @@ class DNSReconApp {
|
||||
|
||||
case 'idle':
|
||||
this.setUIState('idle', task_queue_size);
|
||||
this.stopPolling();
|
||||
this.updateConnectionStatus('idle');
|
||||
break;
|
||||
|
||||
@@ -2033,10 +1958,10 @@ class DNSReconApp {
|
||||
|
||||
// If the scanner was idle, it's now running. Start polling to see the new node appear.
|
||||
if (this.scanStatus === 'idle') {
|
||||
this.startPolling(1000);
|
||||
this.socket.emit('get_status');
|
||||
} else {
|
||||
// If already scanning, force a quick graph update to see the change sooner.
|
||||
setTimeout(() => this.updateGraph(), 500);
|
||||
setTimeout(() => this.socket.emit('get_status'), 500);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user