summaryrefslogtreecommitdiffstats
path: root/apis/statistics.inc.php
blob: 2be805ba76adac650235051472ccd37eada63003 (plain) (blame)
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
<?php

$NOW = time();
$cutoff = $NOW - 86400*90;

$res = Database::simpleQuery("SELECT m.machineuuid, m.locationid, m.macaddr, m.clientip, m.lastseen, m.logintime, m.mbram,"
	. " m.kvmstate, m.cpumodel, m.systemmodel, m.id44mb, m.badsectors, m.hostname, GROUP_CONCAT(s.locationid) AS locs"
	. " FROM machine m"
	. " LEFT JOIN subnet s ON (INET_ATON(m.clientip) BETWEEN s.startaddr AND s.endaddr)"
	. " WHERE m.lastseen > $cutoff"
	. " GROUP BY m.machineuuid");

$return = array(
	'now' => $NOW,
	'clients' => array(),
	'locations' => Location::getLocationsAssoc()
);
while ($client = $res->fetch(PDO::FETCH_ASSOC)) {
	if ($NOW - $client['lastseen'] > 610) {
		$client['state'] = 'OFF';
	} elseif ($client['logintime'] == 0) {
		$client['state']  = 'IDLE';
	} else {
		$client['state'] = 'OCCUPIED';
	}
	$return['clients'][] = $client;
}

die(json_encode($return));