Subversion Repositories ALCASAR

Rev

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

Rev 2394 Rev 2401
1
<?php
1
<?php
2
 
2
 
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 = '/var/tmp/havp/current_users.txt';
4
$filename = '/var/tmp/havp/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}'));
-
 
8
if ($isConnected === '0') {
-
 
9
	exit();
-
 
10
}
-
 
11
 
7
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
12
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
8
	// Creating file and write user @IP.
13
	// Creating file and write user @IP.
9
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
14
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
10
} else {
15
} else {
11
	// 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
12
	$found = false;
17
	$found = false;
13
	$fh = fopen($filename, 'r');
18
	$fh = fopen($filename, 'r');
14
	while (!feof($fh)) {
19
	while (!feof($fh)) {
15
		$line = fgets($fh, 1024);
20
		$line = fgets($fh, 1024);
16
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
21
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
17
			$found = true;
22
			$found = true;
18
			break;
23
			break;
19
		}
24
		}
20
	}
25
	}
21
	fclose($fh);
26
	fclose($fh);
22
 
27
 
23
	// else we write user IP in the file
28
	// else we write user IP in the file
24
	if (!$found) {
29
	if (!$found) {
25
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
30
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
26
	}
31
	}
27
}
32
}
28
 
33