summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/baseconfig/getconfig.inc.php
blob: e8afeffb5509a0be51065addc54bb01c367933f1 (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
30
31
32
33
34
35
36
<?php

// 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', '', 'string');
	}
}

if (!$uuid) // 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]);
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
	ConfigHolder::add($row['setting'], $row['value'], 500);
}

// 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]);
	}
});