Subversion Repositories oidplus

Rev

Rev 360 | 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
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
117 daniel-mar 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminLogEvents extends OIDplusPagePluginAdmin {
23
 
117 daniel-mar 24
        public function init($html=true) {
25
        }
26
 
27
        public function gui($id, &$out, &$handled) {
28
                if ($id == 'oidplus:system_log') {
29
                        $handled = true;
360 daniel-mar 30
                        $out['title'] = _L('All log messages');
241 daniel-mar 31
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
117 daniel-mar 32
 
33
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
34
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 35
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 36
                                return;
117 daniel-mar 37
                        }
38
 
261 daniel-mar 39
                        $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ###log lo ".
153 daniel-mar 40
                                                    "order by lo.unix_ts desc");
236 daniel-mar 41
                        if ($res->num_rows() > 0) {
117 daniel-mar 42
                                $out['text'] = '<pre>';
236 daniel-mar 43
                                while ($row = $res->fetch_array()) {
288 daniel-mar 44
                                        $severity = 0;
45
                                        // ---
117 daniel-mar 46
                                        $users = array();
288 daniel-mar 47
                                        $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
150 daniel-mar 48
                                                                     "where log_id = ?", array($row['id']));
236 daniel-mar 49
                                        while ($row2 = $res2->fetch_array()) {
239 daniel-mar 50
                                                $users[] = $row2['username'];
288 daniel-mar 51
                                                if ($row2['username'] == 'admin') $severity = $row2['severity'];
117 daniel-mar 52
                                        }
360 daniel-mar 53
                                        $users = count($users) > 0 ? '; '._L('affected users: %1',implode(', ',$users)) : '';
288 daniel-mar 54
                                        // ---
55
                                        $objects = array();
56
                                        $res2 = OIDplus::db()->query("select object, severity from ###log_object ".
57
                                                                     "where log_id = ?", array($row['id']));
58
                                        while ($row2 = $res2->fetch_array()) {
59
                                                $objects[] = $row2['object'];
60
                                        }
360 daniel-mar 61
                                        $objects = count($objects) > 0 ? '; '._L('affected objects: %1',implode(', ',$objects)) : '';
288 daniel-mar 62
                                        // ---
360 daniel-mar 63
                                        $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
288 daniel-mar 64
                                        // ---
65
                                        $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 66
                                }
67
                                $out['text'] .= '</pre>';
68
                        } else {
360 daniel-mar 69
                                $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>';
117 daniel-mar 70
                        }
148 daniel-mar 71
 
117 daniel-mar 72
                        // TODO: List logs in a table instead of a <pre> text
73
                        // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
74
                }
75
        }
76
 
77
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 78
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
288 daniel-mar 79
 
117 daniel-mar 80
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 81
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
117 daniel-mar 82
                } else {
83
                        $tree_icon = null; // default icon (folder)
84
                }
85
 
86
                $json[] = array(
87
                        'id' => 'oidplus:system_log',
88
                        'icon' => $tree_icon,
360 daniel-mar 89
                        'text' => _L('All log messages')
117 daniel-mar 90
                );
91
 
92
                return true;
93
        }
94
 
95
        public function tree_search($request) {
96
                return false;
97
        }
360 daniel-mar 98
}