Rev 1086 | Rev 1131 | 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 | |||
1116 | daniel-mar | 28 | /** |
29 | * @param bool $html |
||
30 | * @return void |
||
31 | */ |
||
32 | public function init(bool $html=true) { |
||
635 | daniel-mar | 33 | } |
34 | |||
1116 | daniel-mar | 35 | /** |
36 | * @param string $id |
||
37 | * @param array $out |
||
38 | * @param bool $handled |
||
39 | * @return void |
||
40 | */ |
||
41 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 42 | } |
43 | |||
1116 | daniel-mar | 44 | /** |
45 | * @param array $json |
||
46 | * @param string|null $ra_email |
||
47 | * @param bool $nonjs |
||
48 | * @param string $req_goto |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 52 | //if (!$ra_email) return false; |
53 | //if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
54 | |||
55 | return false; |
||
56 | } |
||
57 | |||
1116 | daniel-mar | 58 | /** |
59 | * @param string $id |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function implementsFeature(string $id): bool { |
||
635 | daniel-mar | 63 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.2') return true; // modifyContent |
64 | return false; |
||
65 | } |
||
66 | |||
1116 | daniel-mar | 67 | /** |
68 | * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.2 |
||
69 | * @param string $id |
||
70 | * @param string $title |
||
71 | * @param string $icon |
||
72 | * @param string $text |
||
73 | * @return void |
||
74 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
||
75 | */ |
||
76 | public function modifyContent(string $id, string &$title, string &$icon, string &$text) { |
||
635 | daniel-mar | 77 | $obj = OIDplusObject::parse($id); |
78 | if (!$obj) return; |
||
79 | if (!$obj->userHasWriteRights()) return; |
||
80 | |||
81 | // TODO: I want that this content comes before the WHOIS modifyContent. |
||
82 | // The problem is that first all public and then all RA plugins get loaded, not mixed by their priority |
||
83 | $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event, lu.severity from ###log lo ". |
||
84 | "left join ###log_object lu on lu.log_id = lo.id ". |
||
85 | "where lu.object = ? " . |
||
86 | "order by lo.unix_ts desc", array($id)); |
||
87 | $text .= '<h2>'._L('Log messages for object %1',htmlentities($id)).'</h2>'; |
||
790 | daniel-mar | 88 | if ($res->any()) { |
635 | daniel-mar | 89 | $text .= '<pre>'; |
90 | while ($row = $res->fetch_array()) { |
||
91 | $users = array(); |
||
92 | $res2 = OIDplus::db()->query("select username, severity from ###log_user ". |
||
93 | "where log_id = ?", array($row['id'])); |
||
94 | while ($row2 = $res2->fetch_array()) { |
||
95 | $users[] = $row2['username']; |
||
96 | } |
||
97 | $users = count($users) > 0 ? ", ".implode('/',$users) : ''; |
||
98 | |||
99 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
||
100 | |||
101 | $text .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users) . ")</span>\n"; |
||
102 | } |
||
103 | $text .= '</pre>'; |
||
104 | |||
105 | // TODO: List logs in a table instead of a <pre> text |
||
106 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
||
107 | } else { |
||
108 | $text .= '<p>'._L('Currently there are no log entries').'</p>'; |
||
109 | } |
||
110 | |||
111 | } |
||
112 | |||
1116 | daniel-mar | 113 | /** |
114 | * @param string $request |
||
115 | * @return array|false |
||
116 | */ |
||
117 | public function tree_search(string $request) { |
||
635 | daniel-mar | 118 | return false; |
119 | } |
||
1116 | daniel-mar | 120 | } |