summaryrefslogtreecommitdiffstats
path: root/modules/systemstatus.inc.php
blob: c6d45812f7d670c33099d84682104ccad14b31ea (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

class Page_SystemStatus extends Page
{

	protected function doPreprocess()
	{
		User::load();

		if (!User::isLoggedIn()) {
			Util::redirect('?do=Main');
		}
	}

	protected function doRender()
	{
		Render::addScriptTop('custom');
		Render::addScriptBottom('circles.min');
		Render::addTemplate('systemstatus/_page');
	}

	protected function doAjax()
	{
		User::load();

		if (!User::isLoggedIn())
			return;

		$action = 'ajax' . Request::any('action');
		if (method_exists($this, $action))
			$this->$action();
		else
			echo "Action $action not known in " . get_class();
	}

	protected function ajaxDiskStat()
	{
		$task = Taskmanager::submit('DiskStat');
		$task = Taskmanager::waitComplete($task);

		if (!isset($task['data']['list']) || empty($task['data']['list'])) {
			Taskmanager::addErrorMessage($task);
			Message::renderList();
			return;
		}
		$store = Property::getVmStoreUrl();
		$storeUsage = false;
		$systemUsage = false;
		if ($store !== false) {
			if ($store === '<local>')
				$storePoint = '/';
			else
				$storePoint = '/srv/openslx/nfs';
			foreach ($task['data']['list'] as $entry) {
				if ($entry['mountPoint'] === $storePoint)
					$storeUsage = array(
						'percent' => $entry['usedPercent'],
						'size' => Util::readableFileSize ($entry['sizeKb'] * 1024),
						'color' => dechex(round(($entry['usedPercent'] / 100) * 15)) . dechex(round(((100 - $entry['usedPercent']) / 100) * 15)) . '4'
					);
				if ($entry['mountPoint'] === '/')
					$systemUsage = array(
						'percent' => $entry['usedPercent'],
						'size' => Util::readableFileSize ($entry['sizeKb'] * 1024),
						'color' => dechex(round(($entry['usedPercent'] / 100) * 15)) . dechex(round(((100 - $entry['usedPercent']) / 100) * 15)) . '4'
					);
			}
		}
		echo Render::parse('systemstatus/diskstat', array(
			'store' => $storeUsage,
			'system' => $systemUsage
		));
	}

}