Rev 790 | Rev 801 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 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 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminLogEvents extends OIDplusPagePluginAdmin { |
||
23 | |||
24 | public function init($html=true) { |
||
25 | } |
||
26 | |||
27 | public function gui($id, &$out, &$handled) { |
||
28 | if ($id == 'oidplus:system_log') { |
||
29 | $handled = true; |
||
30 | $out['title'] = _L('All log messages'); |
||
800 | daniel-mar | 31 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,true).'img/main_icon.png' : ''; |
635 | daniel-mar | 32 | |
33 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
800 | daniel-mar | 34 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 35 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
36 | return; |
||
37 | } |
||
38 | |||
39 | $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ###log lo ". |
||
40 | "order by lo.unix_ts desc"); |
||
790 | daniel-mar | 41 | if ($res->any()) { |
635 | daniel-mar | 42 | $out['text'] = '<pre>'; |
43 | while ($row = $res->fetch_array()) { |
||
44 | $severity = 0; |
||
45 | // --- |
||
46 | $users = array(); |
||
47 | $res2 = OIDplus::db()->query("select username, severity from ###log_user ". |
||
48 | "where log_id = ?", array($row['id'])); |
||
49 | while ($row2 = $res2->fetch_array()) { |
||
50 | $users[] = $row2['username']; |
||
51 | if ($row2['username'] == 'admin') $severity = $row2['severity']; |
||
52 | } |
||
53 | $users = count($users) > 0 ? '; '._L('affected users: %1',implode(', ',$users)) : ''; |
||
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 | } |
||
61 | $objects = count($objects) > 0 ? '; '._L('affected objects: %1',implode(', ',$objects)) : ''; |
||
62 | // --- |
||
63 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
||
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"; |
||
66 | } |
||
67 | $out['text'] .= '</pre>'; |
||
68 | } else { |
||
69 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
||
70 | } |
||
71 | |||
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='') { |
||
78 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
79 | |||
800 | daniel-mar | 80 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
81 | $tree_icon = OIDplus::webpath(__DIR__,true).'img/main_icon16.png'; |
||
635 | 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, |
||
89 | 'text' => _L('All log messages') |
||
90 | ); |
||
91 | |||
92 | return true; |
||
93 | } |
||
94 | |||
95 | public function tree_search($request) { |
||
96 | return false; |
||
97 | } |
||
98 | } |