summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog/page.inc.php
blob: 56fc97e2799d6d5e43090e8d4d19c3156a090077 (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
<?php

class Page_EventLog extends Page
{

	private $show;

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

		$this->show = Request::any('show', false, 'string');
		if ($this->show === false && Request::isGet()) {
			if (User::hasPermission('view')) {
				$this->show = 'log';
			} elseif (User::hasPermission('filter.rules.view')) {
				$this->show = 'rules';
			} else {
				User::assertPermission('filter.transports.view');
				$this->show = 'transports';
			}
		}
		if ($this->show !== false) {
			$this->show = preg_replace('/[^a-z0-9_\-]/', '', $this->show);
			if (!file_exists('modules/eventlog/pages/' . $this->show . '.inc.php')) {
				Message::addError('main.invalid-action', $this->show);
				Util::redirect('?do=eventlog');
			} else {
				require_once 'modules/eventlog/pages/' . $this->show . '.inc.php';
				SubPage::doPreprocess();
			}
		}
		if (Request::isPost()) {
			Util::redirect('?do=eventlog&show=' . $this->show);
		}
	}

	protected function doRender()
	{
		Render::addTemplate('page-header', ['active_' . $this->show => 'active']);
		if ($this->show !== false) {
			SubPage::doRender();
		}
	}

	protected function doAjax()
	{
		// XXX Should go into rules.inc.php
		User::assertPermission('filter.rules.edit');
		if (Request::any('show') === 'rules') {
			$type = Request::any('type', Request::REQUIRED, 'string');
			$res = Database::simpleQuery('SELECT data FROM notification_sample
            	WHERE type = :type ORDER BY dateline DESC LIMIT 5',
				['type' => $type]);
			$output = [];
			foreach ($res as $row) {
				$row = json_decode($row['data'], true);
				if (is_array($row)) {
					$output += $row;
				}
			}
			ksort($output);
			Header('Content-Type: application/json');
			echo json_encode($output);
		}
	}

}