summaryrefslogtreecommitdiffstats
path: root/apis
diff options
context:
space:
mode:
authorSimon Rettberg2015-11-19 12:13:36 +0100
committerSimon Rettberg2015-11-19 12:13:36 +0100
commit66aac2e67e35bd987bc3750b63f2734e47d0d57d (patch)
treeb9881051c3587a00fa56972c6b449731689cdd68 /apis
parent[request.inc.php] Add optional parameter to control variable type (diff)
downloadslx-admin-66aac2e67e35bd987bc3750b63f2734e47d0d57d.tar.gz
slx-admin-66aac2e67e35bd987bc3750b63f2734e47d0d57d.tar.xz
slx-admin-66aac2e67e35bd987bc3750b63f2734e47d0d57d.zip
Implement statistics logging
DB scheme update is still missing, might still change a little...
Diffstat (limited to 'apis')
-rw-r--r--apis/clientlog.inc.php75
1 files changed, 73 insertions, 2 deletions
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 @@
<?php
-if (!isset($_POST['type']) || !isset($_POST['description'])) die('Missing options');
+if (empty($_POST['type'])) die('Missing options.');
+$type = mb_strtolower($_POST['type']);
$ip = $_SERVER['REMOTE_ADDR'];
if (substr($ip, 0, 7) === '::ffff:') $ip = substr($ip, 7);
-$type = mb_strtolower($_POST['type']);
+
+/*
+ * Power/hw/usage stats
+ */
+
+if ($type{0} === '~') {
+ $uuid = Request::post('uuid', '', 'string');
+ $NOW = time();
+ if ($type === '~poweron') {
+ $macaddr = Request::post('macaddr', '', 'string');
+ $uptime = Request::post('uptime', '', 'integer');
+ if (strlen($uuid) !== 36) die("Invalid UUID.\n");
+ if (strlen($macaddr) > 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'];