2025-08-11 20:52:14 -04:00
|
|
|
const EnhancedMinimalHeader = ({
|
|
|
|
|
status,
|
|
|
|
|
fingerprint,
|
|
|
|
|
verificationCode,
|
|
|
|
|
onDisconnect,
|
|
|
|
|
isConnected,
|
|
|
|
|
securityLevel,
|
2025-08-17 02:22:55 -04:00
|
|
|
webrtcManager
|
2025-08-11 20:52:14 -04:00
|
|
|
}) => {
|
2025-08-17 02:22:55 -04:00
|
|
|
const [realSecurityLevel, setRealSecurityLevel] = React.useState(null);
|
2025-08-17 20:38:47 -04:00
|
|
|
const [lastSecurityUpdate, setLastSecurityUpdate] = React.useState(0);
|
2025-10-13 11:13:11 -04:00
|
|
|
// Added local session state to remove references errors after session timer removal
|
|
|
|
|
const [hasActiveSession, setHasActiveSession] = React.useState(false);
|
|
|
|
|
const [currentTimeLeft, setCurrentTimeLeft] = React.useState(0);
|
|
|
|
|
const [sessionType, setSessionType] = React.useState('unknown');
|
2025-08-14 23:34:54 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
// ============================================
|
|
|
|
|
// FIXED SECURITY UPDATE LOGIC
|
|
|
|
|
// ============================================
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
React.useEffect(() => {
|
2025-08-17 20:38:47 -04:00
|
|
|
let isUpdating = false;
|
|
|
|
|
let lastUpdateAttempt = 0;
|
|
|
|
|
|
|
|
|
|
const updateRealSecurityStatus = async () => {
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
if (now - lastUpdateAttempt < 10000) {
|
|
|
|
|
return;
|
2025-08-14 23:34:54 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
if (isUpdating) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isUpdating = true;
|
|
|
|
|
lastUpdateAttempt = now;
|
|
|
|
|
|
2025-08-17 02:22:55 -04:00
|
|
|
try {
|
2025-08-17 20:38:47 -04:00
|
|
|
if (!webrtcManager || !isConnected) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
const activeWebrtcManager = webrtcManager;
|
|
|
|
|
|
|
|
|
|
let realSecurityData = null;
|
|
|
|
|
|
|
|
|
|
if (typeof activeWebrtcManager.getRealSecurityLevel === 'function') {
|
|
|
|
|
realSecurityData = await activeWebrtcManager.getRealSecurityLevel();
|
|
|
|
|
} else if (typeof activeWebrtcManager.calculateAndReportSecurityLevel === 'function') {
|
|
|
|
|
realSecurityData = await activeWebrtcManager.calculateAndReportSecurityLevel();
|
|
|
|
|
} else {
|
|
|
|
|
realSecurityData = await window.EnhancedSecureCryptoUtils.calculateSecurityLevel(activeWebrtcManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (realSecurityData && realSecurityData.isRealData !== false) {
|
|
|
|
|
const currentScore = realSecurityLevel?.score || 0;
|
|
|
|
|
const newScore = realSecurityData.score || 0;
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
if (currentScore !== newScore || !realSecurityLevel) {
|
|
|
|
|
setRealSecurityLevel(realSecurityData);
|
|
|
|
|
setLastSecurityUpdate(now);
|
2025-10-02 01:43:32 -04:00
|
|
|
|
|
|
|
|
} else if (window.DEBUG_MODE) {
|
2025-08-17 02:22:55 -04:00
|
|
|
}
|
2025-08-17 20:38:47 -04:00
|
|
|
} else {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 02:22:55 -04:00
|
|
|
}
|
2025-08-17 20:38:47 -04:00
|
|
|
|
2025-08-17 02:22:55 -04:00
|
|
|
} catch (error) {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
} finally {
|
|
|
|
|
isUpdating = false;
|
2025-08-17 02:22:55 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
if (isConnected) {
|
|
|
|
|
updateRealSecurityStatus();
|
|
|
|
|
|
|
|
|
|
if (!realSecurityLevel || realSecurityLevel.score < 50) {
|
|
|
|
|
const retryInterval = setInterval(() => {
|
|
|
|
|
if (!realSecurityLevel || realSecurityLevel.score < 50) {
|
|
|
|
|
updateRealSecurityStatus();
|
|
|
|
|
} else {
|
|
|
|
|
clearInterval(retryInterval);
|
|
|
|
|
}
|
|
|
|
|
}, 5000);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => clearInterval(retryInterval), 30000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const interval = setInterval(updateRealSecurityStatus, 30000);
|
|
|
|
|
|
2025-08-17 02:22:55 -04:00
|
|
|
return () => clearInterval(interval);
|
2025-09-23 20:01:02 -04:00
|
|
|
}, [webrtcManager, isConnected]);
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
// ============================================
|
|
|
|
|
// FIXED EVENT HANDLERS
|
|
|
|
|
// ============================================
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
const handleSecurityUpdate = (event) => {
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
|
setLastSecurityUpdate(0);
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRealSecurityCalculated = (event) => {
|
|
|
|
|
|
|
|
|
|
if (event.detail && event.detail.securityData) {
|
|
|
|
|
setRealSecurityLevel(event.detail.securityData);
|
|
|
|
|
setLastSecurityUpdate(Date.now());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('security-level-updated', handleSecurityUpdate);
|
|
|
|
|
document.addEventListener('real-security-calculated', handleRealSecurityCalculated);
|
|
|
|
|
|
|
|
|
|
window.forceHeaderSecurityUpdate = (webrtcManager) => {
|
|
|
|
|
|
|
|
|
|
if (webrtcManager && window.EnhancedSecureCryptoUtils) {
|
|
|
|
|
window.EnhancedSecureCryptoUtils.calculateSecurityLevel(webrtcManager)
|
|
|
|
|
.then(securityData => {
|
|
|
|
|
if (securityData && securityData.isRealData !== false) {
|
|
|
|
|
setRealSecurityLevel(securityData);
|
|
|
|
|
setLastSecurityUpdate(Date.now());
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
});
|
2025-08-17 02:22:55 -04:00
|
|
|
} else {
|
2025-08-17 20:38:47 -04:00
|
|
|
setLastSecurityUpdate(0);
|
2025-08-17 02:22:55 -04:00
|
|
|
}
|
2025-08-17 20:38:47 -04:00
|
|
|
};
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('security-level-updated', handleSecurityUpdate);
|
|
|
|
|
document.removeEventListener('real-security-calculated', handleRealSecurityCalculated);
|
2025-08-17 02:22:55 -04:00
|
|
|
};
|
2025-08-17 20:38:47 -04:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// REST of the component logic
|
|
|
|
|
// ============================================
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2025-09-23 20:01:02 -04:00
|
|
|
// All security features are enabled by default - no session management needed
|
|
|
|
|
setHasActiveSession(true);
|
|
|
|
|
setCurrentTimeLeft(0);
|
|
|
|
|
setSessionType('premium'); // All features enabled
|
|
|
|
|
}, []);
|
2025-08-17 02:22:55 -04:00
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
React.useEffect(() => {
|
2025-09-23 20:01:02 -04:00
|
|
|
// All security features are enabled by default
|
|
|
|
|
setHasActiveSession(true);
|
|
|
|
|
setCurrentTimeLeft(0);
|
|
|
|
|
setSessionType('premium'); // All features enabled
|
2025-10-13 11:13:11 -04:00
|
|
|
}, []);
|
2025-08-14 23:34:54 -04:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
const handleForceUpdate = (event) => {
|
2025-09-23 20:01:02 -04:00
|
|
|
// All security features are enabled by default
|
|
|
|
|
setHasActiveSession(true);
|
|
|
|
|
setCurrentTimeLeft(0);
|
|
|
|
|
setSessionType('premium'); // All features enabled
|
2025-08-14 23:34:54 -04:00
|
|
|
};
|
|
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
// Connection cleanup handler (use existing event from module)
|
|
|
|
|
const handleConnectionCleaned = () => {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
setRealSecurityLevel(null);
|
|
|
|
|
setLastSecurityUpdate(0);
|
|
|
|
|
|
|
|
|
|
setHasActiveSession(false);
|
|
|
|
|
setCurrentTimeLeft(0);
|
|
|
|
|
setSessionType('unknown');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handlePeerDisconnect = () => {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
setRealSecurityLevel(null);
|
|
|
|
|
setLastSecurityUpdate(0);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
const handleDisconnected = () => {
|
|
|
|
|
|
|
|
|
|
setRealSecurityLevel(null);
|
|
|
|
|
setLastSecurityUpdate(0);
|
|
|
|
|
setHasActiveSession(false);
|
|
|
|
|
setCurrentTimeLeft(0);
|
|
|
|
|
setSessionType('unknown');
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
document.addEventListener('force-header-update', handleForceUpdate);
|
2025-08-17 20:38:47 -04:00
|
|
|
document.addEventListener('peer-disconnect', handlePeerDisconnect);
|
|
|
|
|
document.addEventListener('connection-cleaned', handleConnectionCleaned);
|
2025-09-23 20:01:02 -04:00
|
|
|
document.addEventListener('disconnected', handleDisconnected);
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('force-header-update', handleForceUpdate);
|
|
|
|
|
document.removeEventListener('peer-disconnect', handlePeerDisconnect);
|
|
|
|
|
document.removeEventListener('connection-cleaned', handleConnectionCleaned);
|
2025-09-23 20:01:02 -04:00
|
|
|
document.removeEventListener('disconnected', handleDisconnected);
|
2025-08-17 20:38:47 -04:00
|
|
|
};
|
2025-09-23 20:01:02 -04:00
|
|
|
}, []);
|
2025-08-14 23:34:54 -04:00
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
// ============================================
|
|
|
|
|
// SECURITY INDICATOR CLICK HANDLER
|
|
|
|
|
// ============================================
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
const handleSecurityClick = async (event) => {
|
2025-09-04 17:25:01 -04:00
|
|
|
// Check if it's a right-click or Ctrl+click to disconnect
|
|
|
|
|
if (event && (event.button === 2 || event.ctrlKey || event.metaKey)) {
|
|
|
|
|
if (onDisconnect && typeof onDisconnect === 'function') {
|
|
|
|
|
onDisconnect();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
// Prevent default behavior
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Run real security tests if webrtcManager is available
|
|
|
|
|
let realTestResults = null;
|
|
|
|
|
if (webrtcManager && window.EnhancedSecureCryptoUtils) {
|
|
|
|
|
try {
|
|
|
|
|
realTestResults = await window.EnhancedSecureCryptoUtils.calculateSecurityLevel(webrtcManager);
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
} catch (error) {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If no real test results and no existing security level, show progress message
|
|
|
|
|
if (!realTestResults && !realSecurityLevel) {
|
2025-08-17 20:38:47 -04:00
|
|
|
alert('Security verification in progress...\nPlease wait for real-time cryptographic verification to complete.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
// Use real test results if available, otherwise fall back to current data
|
|
|
|
|
let securityData = realTestResults || realSecurityLevel;
|
|
|
|
|
|
|
|
|
|
// If still no security data, create a basic fallback
|
|
|
|
|
if (!securityData) {
|
|
|
|
|
securityData = {
|
|
|
|
|
level: 'UNKNOWN',
|
|
|
|
|
score: 0,
|
|
|
|
|
color: 'gray',
|
|
|
|
|
verificationResults: {},
|
|
|
|
|
timestamp: Date.now(),
|
|
|
|
|
details: 'Security verification not available',
|
|
|
|
|
isRealData: false,
|
|
|
|
|
passedChecks: 0,
|
2025-10-13 01:35:32 -04:00
|
|
|
totalChecks: 0
|
2025-09-23 20:01:02 -04:00
|
|
|
};
|
2025-10-30 15:16:36 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-17 20:38:47 -04:00
|
|
|
// Detailed information about the REAL security check
|
2025-10-02 01:43:32 -04:00
|
|
|
let message = `REAL-TIME SECURITY VERIFICATION\n\n`;
|
2025-09-23 20:01:02 -04:00
|
|
|
message += `Security Level: ${securityData.level} (${securityData.score}%)\n`;
|
|
|
|
|
message += `Verification Time: ${new Date(securityData.timestamp).toLocaleTimeString()}\n`;
|
|
|
|
|
message += `Data Source: ${securityData.isRealData ? 'Real Cryptographic Tests' : 'Simulated Data'}\n\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
if (securityData.verificationResults) {
|
2025-08-17 20:38:47 -04:00
|
|
|
message += 'DETAILED CRYPTOGRAPHIC TESTS:\n';
|
|
|
|
|
message += '=' + '='.repeat(40) + '\n';
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
const passedTests = Object.entries(securityData.verificationResults).filter(([key, result]) => result.passed);
|
|
|
|
|
const failedTests = Object.entries(securityData.verificationResults).filter(([key, result]) => !result.passed);
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
if (passedTests.length > 0) {
|
2025-10-02 01:43:32 -04:00
|
|
|
message += 'PASSED TESTS:\n';
|
2025-08-17 20:38:47 -04:00
|
|
|
passedTests.forEach(([key, result]) => {
|
|
|
|
|
const testName = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
|
2025-09-23 20:01:02 -04:00
|
|
|
message += ` ${testName}: ${result.details || 'Test passed'}\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
});
|
|
|
|
|
message += '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (failedTests.length > 0) {
|
2025-10-02 01:43:32 -04:00
|
|
|
message += 'FAILED/UNAVAILABLE TESTS:\n';
|
2025-08-17 20:38:47 -04:00
|
|
|
failedTests.forEach(([key, result]) => {
|
|
|
|
|
const testName = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
|
2025-09-23 20:01:02 -04:00
|
|
|
message += ` ${testName}: ${result.details || 'Test failed or unavailable'}\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
});
|
|
|
|
|
message += '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message += `SUMMARY:\n`;
|
2025-09-23 20:01:02 -04:00
|
|
|
message += `Passed: ${securityData.passedChecks}/${securityData.totalChecks} tests\n`;
|
|
|
|
|
message += `Score: ${securityData.score}/${securityData.maxPossibleScore || 100} points\n\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
// Real security features status
|
2025-10-02 01:43:32 -04:00
|
|
|
message += `SECURITY FEATURES STATUS:\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
message += '=' + '='.repeat(40) + '\n';
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
if (securityData.verificationResults) {
|
|
|
|
|
const features = {
|
|
|
|
|
'ECDSA Digital Signatures': securityData.verificationResults.verifyECDSASignatures?.passed || false,
|
|
|
|
|
'ECDH Key Exchange': securityData.verificationResults.verifyECDHKeyExchange?.passed || false,
|
|
|
|
|
'AES-GCM Encryption': securityData.verificationResults.verifyEncryption?.passed || false,
|
|
|
|
|
'Message Integrity (HMAC)': securityData.verificationResults.verifyMessageIntegrity?.passed || false,
|
|
|
|
|
'Perfect Forward Secrecy': securityData.verificationResults.verifyPerfectForwardSecrecy?.passed || false,
|
|
|
|
|
'Replay Protection': securityData.verificationResults.verifyReplayProtection?.passed || false,
|
|
|
|
|
'DTLS Fingerprint': securityData.verificationResults.verifyDTLSFingerprint?.passed || false,
|
|
|
|
|
'SAS Verification': securityData.verificationResults.verifySASVerification?.passed || false,
|
|
|
|
|
'Metadata Protection': securityData.verificationResults.verifyMetadataProtection?.passed || false,
|
|
|
|
|
'Traffic Obfuscation': securityData.verificationResults.verifyTrafficObfuscation?.passed || false
|
|
|
|
|
};
|
2025-08-17 20:38:47 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
Object.entries(features).forEach(([feature, isEnabled]) => {
|
|
|
|
|
message += `${isEnabled ? '✅' : '❌'} ${feature}\n`;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback if no verification results
|
|
|
|
|
message += `✅ ECDSA Digital Signatures\n`;
|
|
|
|
|
message += `✅ ECDH Key Exchange\n`;
|
|
|
|
|
message += `✅ AES-GCM Encryption\n`;
|
|
|
|
|
message += `✅ Message Integrity (HMAC)\n`;
|
|
|
|
|
message += `✅ Perfect Forward Secrecy\n`;
|
|
|
|
|
message += `✅ Replay Protection\n`;
|
|
|
|
|
message += `✅ DTLS Fingerprint\n`;
|
|
|
|
|
message += `✅ SAS Verification\n`;
|
|
|
|
|
message += `✅ Metadata Protection\n`;
|
|
|
|
|
message += `✅ Traffic Obfuscation\n`;
|
2025-08-17 20:38:47 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
message += `\n${securityData.details || 'Real cryptographic verification completed'}`;
|
2025-08-17 20:38:47 -04:00
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
if (securityData.isRealData) {
|
2025-08-17 20:38:47 -04:00
|
|
|
message += '\n\n✅ This is REAL-TIME verification using actual cryptographic functions.';
|
|
|
|
|
} else {
|
|
|
|
|
message += '\n\n⚠️ Warning: This data may be simulated. Connection may not be fully established.';
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:01:02 -04:00
|
|
|
// Show in a more user-friendly way
|
|
|
|
|
const modal = document.createElement('div');
|
|
|
|
|
modal.style.cssText = `
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
background: rgba(0,0,0,0.8);
|
|
|
|
|
z-index: 10000;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const content = document.createElement('div');
|
|
|
|
|
content.style.cssText = `
|
|
|
|
|
background: #1a1a1a;
|
|
|
|
|
color: #fff;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
max-width: 80%;
|
|
|
|
|
max-height: 80%;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
white-space: pre-line;
|
|
|
|
|
border: 1px solid #333;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
content.textContent = message;
|
|
|
|
|
modal.appendChild(content);
|
|
|
|
|
|
|
|
|
|
// Close on click outside
|
|
|
|
|
modal.addEventListener('click', (e) => {
|
|
|
|
|
if (e.target === modal) {
|
|
|
|
|
document.body.removeChild(modal);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Close on Escape key
|
|
|
|
|
const handleKeyDown = (e) => {
|
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
|
document.body.removeChild(modal);
|
|
|
|
|
document.removeEventListener('keydown', handleKeyDown);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener('keydown', handleKeyDown);
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(modal);
|
2025-08-17 20:38:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// DISPLAY UTILITIES
|
|
|
|
|
// ============================================
|
|
|
|
|
|
2025-08-11 20:52:14 -04:00
|
|
|
const getStatusConfig = () => {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'connected':
|
|
|
|
|
return {
|
2025-08-14 23:34:54 -04:00
|
|
|
text: 'Connected',
|
|
|
|
|
className: 'status-connected',
|
|
|
|
|
badgeClass: 'bg-green-500/10 text-green-400 border-green-500/20'
|
|
|
|
|
};
|
2025-08-11 20:52:14 -04:00
|
|
|
case 'verifying':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Verifying...',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-verifying',
|
|
|
|
|
badgeClass: 'bg-purple-500/10 text-purple-400 border-purple-500/20'
|
|
|
|
|
};
|
|
|
|
|
case 'connecting':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Connecting...',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-connecting',
|
|
|
|
|
badgeClass: 'bg-blue-500/10 text-blue-400 border-blue-500/20'
|
|
|
|
|
};
|
|
|
|
|
case 'retrying':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Retrying...',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-connecting',
|
|
|
|
|
badgeClass: 'bg-yellow-500/10 text-yellow-400 border-yellow-500/20'
|
|
|
|
|
};
|
|
|
|
|
case 'failed':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Error',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-failed',
|
|
|
|
|
badgeClass: 'bg-red-500/10 text-red-400 border-red-500/20'
|
|
|
|
|
};
|
|
|
|
|
case 'reconnecting':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Reconnecting...',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-connecting',
|
|
|
|
|
badgeClass: 'bg-yellow-500/10 text-yellow-400 border-yellow-500/20'
|
|
|
|
|
};
|
|
|
|
|
case 'peer_disconnected':
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Peer disconnected',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-failed',
|
|
|
|
|
badgeClass: 'bg-orange-500/10 text-orange-400 border-orange-500/20'
|
|
|
|
|
};
|
|
|
|
|
default:
|
|
|
|
|
return {
|
2025-08-12 14:02:20 -04:00
|
|
|
text: 'Not connected',
|
2025-08-11 20:52:14 -04:00
|
|
|
className: 'status-disconnected',
|
|
|
|
|
badgeClass: 'bg-gray-500/10 text-gray-400 border-gray-500/20'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const config = getStatusConfig();
|
2025-09-23 20:01:02 -04:00
|
|
|
const displaySecurityLevel = isConnected ? (realSecurityLevel || securityLevel) : null;
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// DATA RELIABILITY INDICATOR
|
|
|
|
|
// ============================================
|
|
|
|
|
|
|
|
|
|
const getSecurityIndicatorDetails = () => {
|
|
|
|
|
if (!displaySecurityLevel) {
|
|
|
|
|
return {
|
|
|
|
|
tooltip: 'Security verification in progress...',
|
|
|
|
|
isVerified: false,
|
|
|
|
|
dataSource: 'loading'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isRealData = displaySecurityLevel.isRealData !== false;
|
|
|
|
|
const baseTooltip = `${displaySecurityLevel.level} (${displaySecurityLevel.score}%)`;
|
|
|
|
|
|
|
|
|
|
if (isRealData) {
|
|
|
|
|
return {
|
2025-09-04 17:25:01 -04:00
|
|
|
tooltip: `${baseTooltip} - Real-time verification ✅\nRight-click or Ctrl+click to disconnect`,
|
2025-08-17 20:38:47 -04:00
|
|
|
isVerified: true,
|
|
|
|
|
dataSource: 'real'
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
2025-09-04 17:25:01 -04:00
|
|
|
tooltip: `${baseTooltip} - Estimated (connection establishing...)\nRight-click or Ctrl+click to disconnect`,
|
2025-08-17 20:38:47 -04:00
|
|
|
isVerified: false,
|
|
|
|
|
dataSource: 'estimated'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const securityDetails = getSecurityIndicatorDetails();
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// ADDING global methods for debugging
|
|
|
|
|
// ============================================
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2025-10-30 15:16:36 -04:00
|
|
|
window.debugHeaderSecurity = undefined;
|
2025-08-17 20:38:47 -04:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
delete window.debugHeaderSecurity;
|
|
|
|
|
};
|
|
|
|
|
}, [realSecurityLevel, lastSecurityUpdate, isConnected, webrtcManager, displaySecurityLevel, securityDetails]);
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// RENDER
|
|
|
|
|
// ============================================
|
2025-08-11 20:52:14 -04:00
|
|
|
|
|
|
|
|
return React.createElement('header', {
|
|
|
|
|
className: 'header-minimal sticky top-0 z-50'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'container',
|
|
|
|
|
className: 'max-w-7xl mx-auto px-4 sm:px-6 lg:px-8'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'content',
|
|
|
|
|
className: 'flex items-center justify-between h-16'
|
|
|
|
|
}, [
|
2025-08-14 23:34:54 -04:00
|
|
|
// Logo and Title
|
2025-08-11 20:52:14 -04:00
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'logo-section',
|
|
|
|
|
className: 'flex items-center space-x-2 sm:space-x-3'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'logo',
|
|
|
|
|
className: 'icon-container w-8 h-8 sm:w-10 sm:h-10'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('i', {
|
|
|
|
|
className: 'fas fa-shield-halved accent-orange text-sm sm:text-base'
|
|
|
|
|
})
|
|
|
|
|
]),
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'title-section'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('h1', {
|
|
|
|
|
key: 'title',
|
|
|
|
|
className: 'text-lg sm:text-xl font-semibold text-primary'
|
2025-08-14 15:54:11 -04:00
|
|
|
}, 'SecureBit.chat'),
|
2025-08-11 20:52:14 -04:00
|
|
|
React.createElement('p', {
|
|
|
|
|
key: 'subtitle',
|
|
|
|
|
className: 'text-xs sm:text-sm text-muted hidden sm:block'
|
2026-06-18 21:15:43 -04:00
|
|
|
}, 'End-to-end freedom v4.8.15')
|
2025-08-11 20:52:14 -04:00
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
// Status and Controls - Responsive
|
2025-08-11 20:52:14 -04:00
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'status-section',
|
|
|
|
|
className: 'flex items-center space-x-2 sm:space-x-3'
|
|
|
|
|
}, [
|
2025-08-14 23:34:54 -04:00
|
|
|
|
2026-06-15 16:05:31 -04:00
|
|
|
React.createElement('button', {
|
|
|
|
|
key: 'network-settings',
|
|
|
|
|
type: 'button',
|
|
|
|
|
onClick: () => window.dispatchEvent(new CustomEvent('securebit:open-network-settings')),
|
|
|
|
|
title: 'Advanced network settings (STUN/TURN)',
|
|
|
|
|
'aria-label': 'Advanced network settings',
|
|
|
|
|
className: 'w-8 h-8 rounded-full flex items-center justify-center text-muted hover:text-primary hover:bg-white/5 transition-colors duration-200'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('i', { key: 'i', className: 'fas fa-network-wired text-sm' })
|
|
|
|
|
]),
|
|
|
|
|
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel && React.createElement('div', {
|
2025-08-11 20:52:14 -04:00
|
|
|
key: 'security-level',
|
|
|
|
|
className: 'hidden md:flex items-center space-x-2 cursor-pointer hover:opacity-80 transition-opacity duration-200',
|
|
|
|
|
onClick: handleSecurityClick,
|
2025-09-04 17:25:01 -04:00
|
|
|
onContextMenu: (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (onDisconnect && typeof onDisconnect === 'function') {
|
|
|
|
|
onDisconnect();
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-08-17 20:38:47 -04:00
|
|
|
title: securityDetails.tooltip
|
2025-08-11 20:52:14 -04:00
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'security-icon',
|
2025-08-17 20:38:47 -04:00
|
|
|
className: `w-6 h-6 rounded-full flex items-center justify-center relative ${
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'green' ? 'bg-green-500/20' :
|
2025-08-17 20:38:47 -04:00
|
|
|
displaySecurityLevel.color === 'orange' ? 'bg-orange-500/20' :
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'yellow' ? 'bg-yellow-500/20' : 'bg-red-500/20'
|
2025-08-17 20:38:47 -04:00
|
|
|
} ${securityDetails.isVerified ? '' : 'animate-pulse'}`
|
2025-08-11 20:52:14 -04:00
|
|
|
}, [
|
|
|
|
|
React.createElement('i', {
|
|
|
|
|
className: `fas fa-shield-alt text-xs ${
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'green' ? 'text-green-400' :
|
2025-08-17 20:38:47 -04:00
|
|
|
displaySecurityLevel.color === 'orange' ? 'text-orange-400' :
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'yellow' ? 'text-yellow-400' : 'text-red-400'
|
2025-08-11 20:52:14 -04:00
|
|
|
}`
|
|
|
|
|
})
|
|
|
|
|
]),
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'security-info',
|
|
|
|
|
className: 'flex flex-col'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'security-level-text',
|
2025-08-17 20:38:47 -04:00
|
|
|
className: 'text-xs font-medium text-primary flex items-center space-x-1'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('span', {}, `${displaySecurityLevel.level} (${displaySecurityLevel.score}%)`)
|
|
|
|
|
]),
|
2025-08-17 02:22:55 -04:00
|
|
|
React.createElement('div', {
|
2025-08-11 20:52:14 -04:00
|
|
|
key: 'security-details',
|
|
|
|
|
className: 'text-xs text-muted mt-1 hidden lg:block'
|
2025-08-17 20:38:47 -04:00
|
|
|
}, securityDetails.dataSource === 'real' ?
|
|
|
|
|
`${displaySecurityLevel.passedChecks || 0}/${displaySecurityLevel.totalChecks || 0} tests` :
|
|
|
|
|
(displaySecurityLevel.details || `Stage ${displaySecurityLevel.stage || 1}`)
|
|
|
|
|
),
|
2025-08-11 20:52:14 -04:00
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'security-progress',
|
|
|
|
|
className: 'w-16 h-1 bg-gray-600 rounded-full overflow-hidden'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'progress-bar',
|
|
|
|
|
className: `h-full transition-all duration-500 ${
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'green' ? 'bg-green-400' :
|
2025-08-17 20:38:47 -04:00
|
|
|
displaySecurityLevel.color === 'orange' ? 'bg-orange-400' :
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'yellow' ? 'bg-yellow-400' : 'bg-red-400'
|
2025-08-11 20:52:14 -04:00
|
|
|
}`,
|
2025-08-17 02:22:55 -04:00
|
|
|
style: { width: `${displaySecurityLevel.score}%` }
|
2025-08-11 20:52:14 -04:00
|
|
|
})
|
|
|
|
|
])
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
// Mobile Security Indicator
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel && React.createElement('div', {
|
2025-08-11 20:52:14 -04:00
|
|
|
key: 'mobile-security',
|
|
|
|
|
className: 'md:hidden flex items-center'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'mobile-security-icon',
|
2025-08-17 20:38:47 -04:00
|
|
|
className: `w-8 h-8 rounded-full flex items-center justify-center cursor-pointer hover:opacity-80 transition-opacity duration-200 relative ${
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'green' ? 'bg-green-500/20' :
|
2025-08-17 20:38:47 -04:00
|
|
|
displaySecurityLevel.color === 'orange' ? 'bg-orange-500/20' :
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'yellow' ? 'bg-yellow-500/20' : 'bg-red-500/20'
|
2025-08-17 20:38:47 -04:00
|
|
|
} ${securityDetails.isVerified ? '' : 'animate-pulse'}`,
|
|
|
|
|
title: securityDetails.tooltip,
|
2025-09-04 17:25:01 -04:00
|
|
|
onClick: handleSecurityClick,
|
|
|
|
|
onContextMenu: (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (onDisconnect && typeof onDisconnect === 'function') {
|
|
|
|
|
onDisconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-11 20:52:14 -04:00
|
|
|
}, [
|
|
|
|
|
React.createElement('i', {
|
|
|
|
|
className: `fas fa-shield-alt text-sm ${
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'green' ? 'text-green-400' :
|
2025-08-17 20:38:47 -04:00
|
|
|
displaySecurityLevel.color === 'orange' ? 'text-orange-400' :
|
2025-08-17 02:22:55 -04:00
|
|
|
displaySecurityLevel.color === 'yellow' ? 'text-yellow-400' : 'text-red-400'
|
2025-08-11 20:52:14 -04:00
|
|
|
}`
|
|
|
|
|
})
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
// Status Badge
|
2025-08-11 20:52:14 -04:00
|
|
|
React.createElement('div', {
|
|
|
|
|
key: 'status-badge',
|
|
|
|
|
className: `px-2 sm:px-3 py-1.5 rounded-lg border ${config.badgeClass} flex items-center space-x-1 sm:space-x-2`
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('span', {
|
|
|
|
|
key: 'status-dot',
|
|
|
|
|
className: `status-dot ${config.className}`
|
|
|
|
|
}),
|
|
|
|
|
React.createElement('span', {
|
|
|
|
|
key: 'status-text',
|
|
|
|
|
className: 'text-xs sm:text-sm font-medium'
|
2025-09-23 20:01:02 -04:00
|
|
|
}, config.text),
|
2025-08-11 20:52:14 -04:00
|
|
|
]),
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
// Disconnect Button
|
2025-08-11 20:52:14 -04:00
|
|
|
isConnected && React.createElement('button', {
|
|
|
|
|
key: 'disconnect-btn',
|
|
|
|
|
onClick: onDisconnect,
|
|
|
|
|
className: 'p-1.5 sm:px-3 sm:py-1.5 bg-red-500/10 hover:bg-red-500/20 text-red-400 border border-red-500/20 rounded-lg transition-all duration-200 text-sm'
|
|
|
|
|
}, [
|
|
|
|
|
React.createElement('i', {
|
|
|
|
|
className: 'fas fa-power-off sm:mr-2'
|
|
|
|
|
}),
|
|
|
|
|
React.createElement('span', {
|
|
|
|
|
className: 'hidden sm:inline'
|
2025-08-12 14:02:20 -04:00
|
|
|
}, 'Disconnect')
|
2025-08-11 20:52:14 -04:00
|
|
|
])
|
|
|
|
|
])
|
|
|
|
|
])
|
|
|
|
|
])
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-14 23:34:54 -04:00
|
|
|
window.EnhancedMinimalHeader = EnhancedMinimalHeader;
|