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
|
<?php
/** @var ?string $uuid */
/** @var ?string $ip */
// Location handling: figure out location
if (Request::any('force', 0, 'int') === 1 && Request::any('module', false, 'string') === 'statistics') {
// Force location for testing, but require logged in admin
if (User::load()) {
$uuid = Request::any('value', null, 'string');
}
}
if ($uuid === null) // Required at this point, bail out if not given
return;
// Query machine specific settings
$res = Database::simpleQuery("SELECT setting, value FROM setting_machine WHERE machineuuid = :uuid", ['uuid' => $uuid]);
foreach ($res as $row) {
ConfigHolder::add($row['setting'], $row['value'], 500);
}
if ($ip !== null) {
// Statistics about booted system
ConfigHolder::addPostHook(function () use ($ip, $uuid) {
$type = Request::get('type', 'default', 'string');
// System
if ($type !== 'default') {
Database::exec("INSERT INTO statistic (dateline, typeid, clientip, machineuuid, username, data)
VALUES (UNIX_TIMESTAMP(), :type, :ip, :uuid, '', :data)",
['type' => 'boot-system', 'ip' => $ip, 'uuid' => $uuid, 'data' => $type]);
}
// Runmode
$mode = ConfigHolder::get('SLX_RUNMODE_MODULE');
if (!empty($mode)) {
Database::exec("INSERT INTO statistic (dateline, typeid, clientip, machineuuid, username, data)
VALUES (UNIX_TIMESTAMP(), :type, :ip, :uuid, '', :data)",
['type' => 'boot-runmode', 'ip' => $ip, 'uuid' => $uuid, 'data' => $mode]);
}
});
}
|