Subversion Repositories oidplus

Rev

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