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 OIDplusPageRaObjectLog extends OIDplusPagePluginRa {
117 daniel-mar 23
 
24
        public function init($html=true) {
25
        }
26
 
27
        public function gui($id, &$out, &$handled) {
28
        }
29
 
30
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 31
                //if (!$ra_email) return false;
32
                //if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) return false;
33
 
117 daniel-mar 34
                return false;
35
        }
36
 
304 daniel-mar 37
        public function implementsFeature($id) {
38
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent
39
                return false;
40
        }
41
 
117 daniel-mar 42
        public function modifyContent($id, &$title, &$icon, &$text) {
304 daniel-mar 43
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.2
44
 
117 daniel-mar 45
                $obj = OIDplusObject::parse($id);
46
                if (!$obj) return;
47
                if (!$obj->userHasWriteRights()) return;
48
 
49
                // TODO: I want that this content comes before the WHOIS modifyContent.
50
                //       The problem is that first all public and then all RA plugins get loaded, not mixed by their priority
288 daniel-mar 51
                $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event, lu.severity from ###log lo ".
261 daniel-mar 52
                                            "left join ###log_object lu on lu.log_id = lo.id ".
150 daniel-mar 53
                                            "where lu.object = ? " .
54
                                            "order by lo.unix_ts desc", array($id));
360 daniel-mar 55
                $text .= '<h2>'._L('Log messages for object %1',htmlentities($id)).'</h2>';
236 daniel-mar 56
                if ($res->num_rows() > 0) {
117 daniel-mar 57
                        $text .= '<pre>';
236 daniel-mar 58
                        while ($row = $res->fetch_array()) {
117 daniel-mar 59
                                $users = array();
288 daniel-mar 60
                                $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
150 daniel-mar 61
                                                             "where log_id = ?", array($row['id']));
236 daniel-mar 62
                                while ($row2 = $res2->fetch_array()) {
239 daniel-mar 63
                                        $users[] = $row2['username'];
117 daniel-mar 64
                                }
65
                                $users = count($users) > 0 ? ", ".implode('/',$users) : '';
66
 
360 daniel-mar 67
                                $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
117 daniel-mar 68
 
288 daniel-mar 69
                                $text .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users) . ")</span>\n";
117 daniel-mar 70
                        }
71
                        $text .= '</pre>';
72
 
73
                        // TODO: List logs in a table instead of a <pre> text
74
                        // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
118 daniel-mar 75
                } else {
360 daniel-mar 76
                        $text .= '<p>'._L('Currently there are no log entries').'</p>';
117 daniel-mar 77
                }
78
 
79
        }
80
 
81
        public function tree_search($request) {
82
                return false;
83
        }
360 daniel-mar 84
}