Subversion Repositories oidplus

Rev

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