From 66aac2e67e35bd987bc3750b63f2734e47d0d57d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Nov 2015 12:13:36 +0100 Subject: Implement statistics logging DB scheme update is still missing, might still change a little... --- apis/clientlog.inc.php | 75 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'apis') diff --git a/apis/clientlog.inc.php b/apis/clientlog.inc.php index 43f31917..3f1e02ea 100644 --- a/apis/clientlog.inc.php +++ b/apis/clientlog.inc.php @@ -1,10 +1,81 @@ 17) die("Invalid MAC.\n"); + if ($uptime < 0 || $uptime > 4000000) die("Implausible uptime.\n"); + $realcores = Request::post('realcores', 0, 'integer'); + if ($realcores < 0 || $realcores > 512) $realcores = 0; + $mbram = Request::post('mbram', 0, 'integer'); + if ($mbram < 0 || $mbram > 102400) $mbram = 0; + $kvmstate = Request::post('kvmstate', 'UNKNOWN', 'string'); + $valid = array('UNKNOWN', 'UNSUPPORTED', 'DISABLED', 'ENABLED'); + if (!in_array($kvmstate, $valid)) $kvmstate = 'UNKNOWN'; + $cpumodel = Request::post('cpumodel', '', 'string'); + $id44mb = Request::post('id44mb', 0, 'integer'); + if ($id44mb < 0 || $id44mb > 10240000) $id44mb = 0; + $hostname = gethostbyaddr($ip); + if (!is_string($hostname) || $hostname === $ip) { + $hostname = ''; + } + $data = Request::post('data', '', 'string'); + Database::exec('INSERT INTO machine ' + . '(machineuuid, macaddr, clientip, firstseen, lastseen, logintime, position, lastboot, realcores, mbram,' + . ' kvmstate, cpumodel, id44mb, data, hostname) VALUES ' + . "(:uuid, :macaddr, :clientip, :firstseen, :lastseen, 0, '', :lastboot, :realcores, :mbram," + . ' :kvmstate, :cpumodel, :id44mb, :data, :hostname)' + . ' ON DUPLICATE KEY UPDATE' + . ' macaddr = VALUES(macaddr),' + . ' clientip = VALUES(clientip),' + . ' lastseen = VALUES(lastseen),' + . ' logintime = 0,' + . ' lastboot = VALUES(lastboot),' + . ' realcores = VALUES(realcores),' + . ' mbram = VALUES(mbram),' + . ' kvmstate = VALUES(kvmstate),' + . ' cpumodel = VALUES(cpumodel),' + . ' id44mb = VALUES(id44mb),' + . ' data = VALUES(data),' + . " hostname = If(VALUES(hostname) = '', hostname, VALUES(hostname))", array( + 'uuid' => $uuid, + 'macaddr' => $macaddr, + 'clientip' => $ip, + 'firstseen' => $NOW, + 'lastseen' => $NOW, + 'lastboot' => $NOW - $uptime, + 'realcores' => $realcores, + 'mbram' => $mbram, + 'kvmstate' => $kvmstate, + 'cpumodel' => $cpumodel, + 'id44mb' => $id44mb, + 'data' => $data, + 'hostname' => $hostname, + )); + } + die("OK.\n"); +} + +/* + * Normal logging + */ + +if (!isset($_POST['description'])) die('Missing options..'); + $description = $_POST['description']; $longdesc = ''; if (isset($_POST['longdesc'])) $longdesc = $_POST['longdesc']; -- cgit v1.2.3-55-g7522