summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/eventlog/page.inc.php')
-rw-r--r--modules-available/eventlog/page.inc.php85
1 files changed, 47 insertions, 38 deletions
diff --git a/modules-available/eventlog/page.inc.php b/modules-available/eventlog/page.inc.php
index 1c81983c..56fc97e2 100644
--- a/modules-available/eventlog/page.inc.php
+++ b/modules-available/eventlog/page.inc.php
@@ -3,56 +3,65 @@
class Page_EventLog extends Page
{
+ private $show;
+
protected function doPreprocess()
{
User::load();
- User::assertPermission('view');
- User::setLastSeenEvent(Property::getLastWarningId());
- }
- protected function doRender()
- {
- Render::addTemplate("heading");
- $lines = array();
- $paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
- $res = $paginate->exec();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['date'] = Util::prettyTime($row['dateline']);
- $row['icon'] = $this->typeToIcon($row['logtypeid']);
- $row['color'] = $this->typeToColor($row['logtypeid']);
- $lines[] = $row;
+ $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);
}
-
- $paginate->render('_page', array(
- 'list' => $lines
- ));
}
- private function typeToIcon($type)
+ protected function doRender()
{
- switch ($type) {
- case 'info':
- return 'ok';
- case 'warning':
- return 'exclamation-sign';
- case 'failure':
- return 'remove';
- default:
- return 'question-sign';
+ Render::addTemplate('page-header', ['active_' . $this->show => 'active']);
+ if ($this->show !== false) {
+ SubPage::doRender();
}
}
- private function typeToColor($type)
+ protected function doAjax()
{
- switch ($type) {
- case 'info':
- return '';
- case 'warning':
- return 'orange';
- case 'failure':
- return 'red';
- default:
- return '';
+ // 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);
}
}