Rev 1445 | 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 | |||
1131 | daniel-mar | 26 | class OIDplusPageRaObjectLog extends OIDplusPagePluginRa |
27 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 /* modifyContent */ |
||
28 | { |
||
635 | daniel-mar | 29 | |
1116 | daniel-mar | 30 | /** |
31 | * @param bool $html |
||
32 | * @return void |
||
33 | */ |
||
34 | public function init(bool $html=true) { |
||
635 | daniel-mar | 35 | } |
36 | |||
1116 | daniel-mar | 37 | /** |
38 | * @param string $id |
||
39 | * @param array $out |
||
40 | * @param bool $handled |
||
41 | * @return void |
||
42 | */ |
||
43 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 44 | } |
45 | |||
1116 | daniel-mar | 46 | /** |
47 | * @param array $json |
||
48 | * @param string|null $ra_email |
||
49 | * @param bool $nonjs |
||
50 | * @param string $req_goto |
||
51 | * @return bool |
||
52 | */ |
||
53 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 54 | //if (!$ra_email) return false; |
55 | //if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
56 | |||
57 | return false; |
||
58 | } |
||
59 | |||
1116 | daniel-mar | 60 | /** |
1131 | daniel-mar | 61 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 |
1116 | daniel-mar | 62 | * @param string $id |
63 | * @param string $title |
||
64 | * @param string $icon |
||
65 | * @param string $text |
||
66 | * @return void |
||
67 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
||
68 | */ |
||
69 | public function modifyContent(string $id, string &$title, string &$icon, string &$text) { |
||
635 | daniel-mar | 70 | $obj = OIDplusObject::parse($id); |
71 | if (!$obj) return; |
||
72 | if (!$obj->userHasWriteRights()) return; |
||
73 | |||
1445 | daniel-mar | 74 | // TODO: !!! correctly implement page scrolling!!! Problem: We cannot use "limit" because this is MySQL. We cannot use "top" because it is SQL server |
75 | // We cannot use id>? and id<? like in admin_log, because users don't have all IDs, just a few, so we cannot filter by ID |
||
635 | daniel-mar | 76 | $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event, lu.severity from ###log lo ". |
77 | "left join ###log_object lu on lu.log_id = lo.id ". |
||
78 | "where lu.object = ? " . |
||
79 | "order by lo.unix_ts desc", array($id)); |
||
80 | $text .= '<h2>'._L('Log messages for object %1',htmlentities($id)).'</h2>'; |
||
1448 | daniel-mar | 81 | |
82 | $text .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
83 | $text .= '<table class="table table-bordered table-striped">'; |
||
84 | $text .= '<thead>'; |
||
85 | $text .= '<tr><th>'._L('Time').'</th><th>'._L('Event').'</th><th>'._L('Affected users').'</th><!--<th>'._L('Affected objects').'</th>--><th>'._L('IP Address').'</th></tr>'; |
||
86 | $text .= '</thead>'; |
||
87 | $text .= '<tbody>'; |
||
88 | |||
790 | daniel-mar | 89 | if ($res->any()) { |
1448 | daniel-mar | 90 | $count = 0; |
635 | daniel-mar | 91 | while ($row = $res->fetch_array()) { |
1448 | daniel-mar | 92 | $count++; |
93 | if ($count > 100) break; // TODO: also allow to watch older entries |
||
94 | |||
95 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
||
96 | |||
635 | daniel-mar | 97 | $users = array(); |
98 | $res2 = OIDplus::db()->query("select username, severity from ###log_user ". |
||
1171 | daniel-mar | 99 | "where log_id = ?", array((int)$row['id'])); |
635 | daniel-mar | 100 | while ($row2 = $res2->fetch_array()) { |
101 | $users[] = $row2['username']; |
||
102 | } |
||
1448 | daniel-mar | 103 | $users = implode("\n",$users); |
635 | daniel-mar | 104 | |
1448 | daniel-mar | 105 | $a = '<span class="severity_'.$row['severity'].'">'; |
106 | $b = '</span>'; |
||
107 | $text .= '<tr>'; |
||
108 | $text .= '<td>'.$a.date('Y-m-d H:i:s', (int)$row['unix_ts']).$b.'</td>'; |
||
109 | $text .= '<td>'.$a.htmlentities($row['event']).$b.'</td>'; |
||
110 | $text .= '<td>'.$a.nl2br(htmlentities($users)).$b.'</td>'; |
||
111 | #$text .= '<td>'.$a.nl2br(htmlentities($objects)).$b.'</td>'; |
||
112 | $text .= '<td>'.$a.htmlentities($addr).$b.'</td>'; |
||
113 | $text .= '<tr>'; |
||
635 | daniel-mar | 114 | } |
115 | } else { |
||
1448 | daniel-mar | 116 | $text .= '<tr><td colspan="4">'._L('There are no log entries on this page').'</td></tr>'; |
635 | daniel-mar | 117 | } |
118 | |||
1448 | daniel-mar | 119 | $text .= '</tbody>'; |
120 | $text .= '</table>'; |
||
121 | $text .= '</div></div>'; |
||
635 | daniel-mar | 122 | } |
123 | |||
1116 | daniel-mar | 124 | /** |
125 | * @param string $request |
||
126 | * @return array|false |
||
127 | */ |
||
128 | public function tree_search(string $request) { |
||
635 | daniel-mar | 129 | return false; |
130 | } |
||
1116 | daniel-mar | 131 | } |