Subversion Repositories ALCASAR

Rev

Rev 2841 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2841 Rev 2883
1
<?php
1
<?php
2
 
-
 
-
 
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
 
6
 
7
$isConnected = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($2 == "'.$user_ip.'") {print $5}'));
7
$isConnected = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($2 == "'.$user_ip.'") {print $5}'));
8
if ($isConnected === '0') {
8
if ($isConnected === '0') {
9
	exit();
9
	exit();
10
}
10
}
11
 
11
 
12
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
12
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
13
	// Creating file and write user @IP.
13
	// Creating file and write user @IP.
14
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
14
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
15
} else {
15
} else {
16
	// If we found duplicate user IP, it will not be writen again
16
	// If we found duplicate user IP, it will not be writen again
17
	$found = false;
17
	$found = false;
18
	$fh = fopen($filename, 'r');
18
	$fh = fopen($filename, 'r');
19
	while (!feof($fh)) {
19
	while (!feof($fh)) {
20
		$line = fgets($fh, 1024);
20
		$line = fgets($fh, 1024);
21
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
21
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
22
			$found = true;
22
			$found = true;
23
			break;
23
			break;
24
		}
24
		}
25
	}
25
	}
26
	fclose($fh);
26
	fclose($fh);
27
 
-
 
28
	// else we write user IP in the file
27
	// else we write user IP in the file
29
	if (!$found) {
28
	if (!$found) {
30
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
29
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
31
	}
30
	}
32
}
31
}
33
 
32