Subversion Repositories ALCASAR

Rev

Rev 2401 | Rev 2883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2009 raphael.pi 1
<?php
2
 
2394 tom.houday 3
// store user @IP who can join this page (still have their status.php tab open) in a file.
2841 rexy 4
$filename = '/tmp/current_users.txt';
2394 tom.houday 5
$user_ip = $_SERVER['REMOTE_ADDR'];
2009 raphael.pi 6
 
2401 tom.houday 7
$isConnected = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($2 == "'.$user_ip.'") {print $5}'));
8
if ($isConnected === '0') {
9
	exit();
10
}
11
 
2394 tom.houday 12
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
13
	// Creating file and write user @IP.
14
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
15
} else {
16
	// If we found duplicate user IP, it will not be writen again
17
	$found = false;
18
	$fh = fopen($filename, 'r');
19
	while (!feof($fh)) {
20
		$line = fgets($fh, 1024);
21
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
22
			$found = true;
23
			break;
24
		}
25
	}
26
	fclose($fh);
27
 
28
	// else we write user IP in the file
29
	if (!$found) {
30
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
31
	}
2009 raphael.pi 32
}