Subversion Repositories ALCASAR

Rev

Rev 2883 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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