Subversion Repositories ALCASAR

Rev

Rev 2883 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2009 raphael.pi 1
<?php
2883 rexy 2
// this script is executed by status page (controler.js) of each users
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'];
3173 rexy 6
if (!filter_var($user_ip, FILTER_VALIDATE_IP)){
7
	echo "<b>invalide @IP</b><br />\n";
8
	exit();
9
}
2009 raphael.pi 10
 
2401 tom.houday 11
$isConnected = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($2 == "'.$user_ip.'") {print $5}'));
12
if ($isConnected === '0') {
13
	exit();
14
}
15
 
2394 tom.houday 16
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
17
	// Creating file and write user @IP.
18
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
19
} else {
20
	// If we found duplicate user IP, it will not be writen again
21
	$found = false;
22
	$fh = fopen($filename, 'r');
23
	while (!feof($fh)) {
24
		$line = fgets($fh, 1024);
25
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
26
			$found = true;
27
			break;
28
		}
29
	}
30
	fclose($fh);
31
	// else we write user IP in the file
32
	if (!$found) {
33
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
34
	}
2009 raphael.pi 35
}