Subversion Repositories oidplus

Rev

Rev 321 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
117 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
256 daniel-mar 20
class OIDplusPageAdminLogEvents extends OIDplusPagePluginAdmin {
21
 
117 daniel-mar 22
        public function init($html=true) {
23
        }
24
 
25
        public function gui($id, &$out, &$handled) {
26
                if ($id == 'oidplus:system_log') {
27
                        $handled = true;
360 daniel-mar 28
                        $out['title'] = _L('All log messages');
241 daniel-mar 29
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
117 daniel-mar 30
 
31
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
32
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 33
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 34
                                return;
117 daniel-mar 35
                        }
36
 
261 daniel-mar 37
                        $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ###log lo ".
153 daniel-mar 38
                                                    "order by lo.unix_ts desc");
236 daniel-mar 39
                        if ($res->num_rows() > 0) {
117 daniel-mar 40
                                $out['text'] = '<pre>';
236 daniel-mar 41
                                while ($row = $res->fetch_array()) {
288 daniel-mar 42
                                        $severity = 0;
43
                                        // ---
117 daniel-mar 44
                                        $users = array();
288 daniel-mar 45
                                        $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
150 daniel-mar 46
                                                                     "where log_id = ?", array($row['id']));
236 daniel-mar 47
                                        while ($row2 = $res2->fetch_array()) {
239 daniel-mar 48
                                                $users[] = $row2['username'];
288 daniel-mar 49
                                                if ($row2['username'] == 'admin') $severity = $row2['severity'];
117 daniel-mar 50
                                        }
360 daniel-mar 51
                                        $users = count($users) > 0 ? '; '._L('affected users: %1',implode(', ',$users)) : '';
288 daniel-mar 52
                                        // ---
53
                                        $objects = array();
54
                                        $res2 = OIDplus::db()->query("select object, severity from ###log_object ".
55
                                                                     "where log_id = ?", array($row['id']));
56
                                        while ($row2 = $res2->fetch_array()) {
57
                                                $objects[] = $row2['object'];
58
                                        }
360 daniel-mar 59
                                        $objects = count($objects) > 0 ? '; '._L('affected objects: %1',implode(', ',$objects)) : '';
288 daniel-mar 60
                                        // ---
360 daniel-mar 61
                                        $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
288 daniel-mar 62
                                        // ---
63
                                        $out['text'] .= '<span class="severity_'.$severity.'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users.$objects) . ")</span>\n";
117 daniel-mar 64
                                }
65
                                $out['text'] .= '</pre>';
66
                        } else {
360 daniel-mar 67
                                $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>';
117 daniel-mar 68
                        }
148 daniel-mar 69
 
117 daniel-mar 70
                        // TODO: List logs in a table instead of a <pre> text
71
                        // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
72
                }
73
        }
74
 
75
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 76
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
288 daniel-mar 77
 
117 daniel-mar 78
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 79
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
117 daniel-mar 80
                } else {
81
                        $tree_icon = null; // default icon (folder)
82
                }
83
 
84
                $json[] = array(
85
                        'id' => 'oidplus:system_log',
86
                        'icon' => $tree_icon,
360 daniel-mar 87
                        'text' => _L('All log messages')
117 daniel-mar 88
                );
89
 
90
                return true;
91
        }
92
 
93
        public function tree_search($request) {
94
                return false;
95
        }
360 daniel-mar 96
}