-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats.php
114 lines (101 loc) · 3.1 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
$website = "http://yourgridurl.xxx";
$loginscreen = "path_to_your_login_screen";
$robustURL = "yourgridurl"; //FQDN or IP to your grid/robust server
$robustPORT = "8002"; //port for your robust
$website = "http://yourwebsiteurl.xxx";
$loginuri = "http://".$robustURL.":".$robustPORT."";
//your database info
$host = "localhost";
$user = "username";
$pass = "pass";
$dbname = "dbname";
// Online / Offline with socket
$socket = @fsockopen($robustURL, $robustPORT, $errno, $errstr, 1);
if (is_resource($socket))
{
$gstatus = "ONLINE";
$color = "green";
}
else {
$gstatus = "OFFLINE";
$color = "red";
}
@fclose($socket);
$mysqli = new mysqli($host,$user,$pass,$dbname);
$presenceuseraccount = 0;
$monthago = time() - 2592000;
if ($hguser = $mysqli->query("SELECT UserID, Login FROM GridUser WHERE UserID LIKE '%htt%' AND Login < 'time() - 2592000'"))
{
$preshguser= $hguser->num_rows;
}
$nowonlinescounter = 0;
if ($preso = $mysqli->query("SELECT UserID FROM Presence")) {
$nowonlinescounter = $preso->num_rows;
}
$pastmonth = 0;
if ($tpres = $mysqli->query("SELECT DISTINCT * FROM GridUser WHERE Logout < '".$monthago."'")) {
$pastmonth = $tpres->num_rows;
}
$totalaccounts = 0;
if ($useraccounts = $mysqli->query("SELECT * FROM UserAccounts")) {
$totalaccounts = $useraccounts->num_rows;
}
$totalregions = 0;
$totalvarregions = 0;
$totalsingleregions = 0;
$totalsize = 0;
if($regiondb = $mysqli->query("SELECT * FROM regions")) {
while ($regions = $regiondb->fetch_array()) {
++$totalregions;
if ($regions['sizeX'] == 256) {
++$totalsingleregions;
}else{
++$totalvarregions;
}
$rsize = $regions['sizeX'] * $regions['sizeY'];
$totalsize += $rsize / 1000;
}
}
$arr = ['GridStatus' => '<b><font color="'.$color.'">'.$gstatus.'</b></font>',
'Online_Now' => number_format($nowonlinescounter),
'HG_Visitors_Last_30_Days' => number_format($preshguser),
'Local_Users_Last_30_Days' => number_format($pastmonth),
'Total_Active_Last_30_Days' => number_format($pastmonth + $preshguser),
'Registered_Users' => number_format($totalaccounts),
'Regions' => number_format($totalregions),
'Var_Regions' => number_format($totalvarregions),
'Single_Regions' => number_format($totalsingleregions),
'Total_LandSize(km2)' => number_format($totalsize),
'Login_URL' => $loginuri,
'Website' => '<i><a href='.$website.'>'.$website.'</a></i>',
'Login_Screen' => '<i><a href='.$loginscreen.'>'.$loginscreen.'</a></i>'];
if ($_GET['format'] == "json") {
header('Content-type: application/json');
echo json_encode($arr);
}else if ($_GET['format'] == "xml") {
function array2xml($array, $wrap='Stats', $upper=true) {
$xml = '';
if ($wrap != null) {
$xml .= "<$wrap>\n";
}
foreach ($array as $key=>$value) {
if ($upper == true) {
$key = strtoupper($key);
}
$xml .= "<$key>" . htmlspecialchars(trim($value)) . "</$key>";
}
if ($wrap != null) {
$xml .= "\n</$wrap>\n";
}
return $xml;
}
header('Content-type: text/xml');
print array2xml($arr);
}else{
foreach($arr as $k => $v) {
echo '<B>'.$k.': </B>'.$v.'<br>';
}
}
$mysqli->close();
?>