112 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
// Function to extract username from log line
 | 
						|
function extractUsername($line) {
 | 
						|
    preg_match('/<\d+:([^>]+)>/', $line, $matches);
 | 
						|
    return isset($matches[1]) ? $matches[1] : null;
 | 
						|
}
 | 
						|
 | 
						|
// Function to read log file and update list of unique users
 | 
						|
function updateUniqueUsers($filename, &$uniqueUsers) {
 | 
						|
    if (($handle = fopen($filename, "r")) !== false) {
 | 
						|
        while (($line = fgets($handle)) !== false) {
 | 
						|
            $username = extractUsername($line);
 | 
						|
            if ($username !== null && !in_array($username, $uniqueUsers)) {
 | 
						|
                $uniqueUsers[] = $username;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        fclose($handle);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
// Function to save list of unique users to a file
 | 
						|
function saveUniqueUsersToFile($filename, $uniqueUsers) {
 | 
						|
    file_put_contents($filename, implode("\n", $uniqueUsers));
 | 
						|
}
 | 
						|
 | 
						|
// Main script
 | 
						|
$logFilename = '/var/log/mumble-server/mumble-server.log'; // Change this to the path of your log file
 | 
						|
$usersFilename = 'unique_users.txt'; // Change this to the path where you want to store the unique users
 | 
						|
 | 
						|
$uniqueUsers = [];
 | 
						|
 | 
						|
// Load existing unique users from file if it exists
 | 
						|
// Main script continued
 | 
						|
if (file_exists($usersFilename)) {
 | 
						|
    $uniqueUsers = file($usersFilename, FILE_IGNORE_NEW_LINES);
 | 
						|
}
 | 
						|
 | 
						|
// Update list of unique users from the log file
 | 
						|
updateUniqueUsers($logFilename, $uniqueUsers);
 | 
						|
 | 
						|
// Save updated list of unique users back to file
 | 
						|
saveUniqueUsersToFile($usersFilename, $uniqueUsers);
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//<?php
 | 
						|
// Output the list of unique users in a table with numbering and borders
 | 
						|
echo "<style>
 | 
						|
        table {
 | 
						|
            width: 100%;
 | 
						|
            border-collapse: collapse;
 | 
						|
            border-radius: 8px;
 | 
						|
            overflow: hidden;
 | 
						|
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
 | 
						|
        }
 | 
						|
        th, td {
 | 
						|
            padding: 12px 15px;
 | 
						|
            text-align: left;
 | 
						|
            border-bottom: 1px solid #ddd;
 | 
						|
        }
 | 
						|
        th {
 | 
						|
            background-color: #f2f2f2;
 | 
						|
            font-weight: bold;
 | 
						|
            color: #333;
 | 
						|
            border-top: 2px solid #333;
 | 
						|
        }
 | 
						|
        tr:nth-child(even) {
 | 
						|
            background-color: #f9f9f9;
 | 
						|
        }
 | 
						|
        tr:hover {
 | 
						|
            background-color: #f2f2f2;
 | 
						|
        }
 | 
						|
      </style>";
 | 
						|
 | 
						|
echo "<table>";
 | 
						|
echo "<thead><tr><th>#</th><th>Username</th></tr></thead>";
 | 
						|
echo "<tbody>";
 | 
						|
$count = 1;
 | 
						|
foreach ($uniqueUsers as $user) {
 | 
						|
    // Remove the suffix (-1) from usernames
 | 
						|
    $user = str_replace('(-1)', '', $user);
 | 
						|
    echo "<tr><td>$count</td><td>$user</td></tr>";
 | 
						|
    $count++;
 | 
						|
}
 | 
						|
echo "</tbody>";
 | 
						|
echo "</table>";
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
// Output the list of unique users in a table with numbering and borders
 | 
						|
//echo "<table style='border-collapse: collapse;'>";
 | 
						|
//echo "<thead><tr><th style='border: 2px solid black;'># </th><th style='border: 2px solid black;'>Username</th></tr></thead>";
 | 
						|
//echo "<tbody>";
 | 
						|
//$count = 1;
 | 
						|
//foreach ($uniqueUsers as $user) {
 | 
						|
    // Remove the suffix (-1) from usernames
 | 
						|
//    $user = str_replace('(-1)', '', $user);
 | 
						|
//    echo "<tr><td style='border: 1px solid black;'>$count </td><td style='border: 1px solid black;'>$user</td></tr>";
 | 
						|
//   $count++;
 | 
						|
//}
 | 
						|
//echo "</tbody>";
 | 
						|
//echo "</table>";
 | 
						|
?>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |