File size: 2,107 Bytes
037cee4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log Viewer</title>
    <style>
        body { font-family: 'Courier New', monospace; background: #f4f4f4; color: #333; padding: 20px; }
        .ip-log-container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.1); margin-top: 10px; overflow-y: auto; max-height: 60vh; }
        p { margin: 10px 0; padding-left: 10px; }
    </style>
</head>
<body>
    <h1>Real-Time Logs</h1>
    <div id="logs"></div>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        const socket = io();
        const colorMap = {};
        const logContainer = document.getElementById('logs');
        socket.on('log', function(msg) {
            const ip = extractIP(msg);
            if (!colorMap[ip]) {
                // Assign a random color to this IP
                colorMap[ip] = generateRandomColor();
                // Create a new div for this IP
                const ipDiv = document.createElement('div');
                ipDiv.id = `log-${ip}`;
                ipDiv.className = 'ip-log-container';
                ipDiv.style.borderLeft = `10px solid ${colorMap[ip]}`;
                logContainer.appendChild(ipDiv);
            }
            const ipSpecificLogs = document.getElementById(`log-${ip}`);
            const paragraph = document.createElement('p');
            paragraph.textContent = msg;
            ipSpecificLogs.appendChild(paragraph);
            // Scroll to newly added log
            ipSpecificLogs.scrollTop = ipSpecificLogs.scrollHeight;
        });
        function generateRandomColor() {
            const colors = ['red', 'green', 'blue', 'purple', 'orange', 'yellow', 'teal', 'olive'];
            return colors[Math.floor(Math.random() * colors.length)];
        }
        function extractIP(msg) {
            const parts = msg.split(' ');
            return parts.find(part => part.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/));
        }
    </script>
</body>
</html>