Rev 2883 | Blame | Compare with Previous | Last modification | View Log
<?php
// this script is executed by status page (controler.js) of each users
// store user @IP who can join this page (still have their status.php tab open) in a file.
$filename = '/tmp/current_users.txt';
$user_ip = $_SERVER['REMOTE_ADDR'];
if (!filter_var($user_ip, FILTER_VALIDATE_IP)){
echo "<b>invalide @IP</b><br />\n";
exit();
}
$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);
}
}