diff options
author | Simon Rettberg | 2016-04-29 20:55:59 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-04-29 20:55:59 +0200 |
commit | cbd23b7d191327a7cfb6a98e657659045da71af3 (patch) | |
tree | f029ab85c3ac07d3f2a56b4359fd36c265898d6d /apis/statistics.inc.php | |
parent | More Progress; Merged changes from ufpr up to 775cdbd29f5d0f70946d1d5ff09c091... (diff) | |
download | slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.tar.gz slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.tar.xz slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.zip |
Second half of merge....
Diffstat (limited to 'apis/statistics.inc.php')
-rw-r--r-- | apis/statistics.inc.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apis/statistics.inc.php b/apis/statistics.inc.php new file mode 100644 index 00000000..2be805ba --- /dev/null +++ b/apis/statistics.inc.php @@ -0,0 +1,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));
\ No newline at end of file |