Rev 2394 | Rev 2841 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log
<?php
// store user @IP who can join this page (still have their status.php tab open) in a file.
$filename = '/var/tmp/havp/current_users.txt';
$user_ip = $_SERVER['REMOTE_ADDR'];
$isConnected = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($2 == "'.$user_ip.'") {print $5}'));
if ($isConnected === '0') {
exit();
}
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
// Creating file and write user @IP.
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
} else {
// If we found duplicate user IP, it will not be writen again
$found = false;
$fh = fopen($filename, 'r');
while (!feof($fh)) {
$line = fgets($fh, 1024);
if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
$found = true;
break;
}
}
fclose($fh);
// else we write user IP in the file
if (!$found) {
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
}
}