Rev 1279 | 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 | |||
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>'; |
||
1445 | daniel-mar | 81 | $max_ent = 0; |
790 | daniel-mar | 82 | if ($res->any()) { |
635 | daniel-mar | 83 | $text .= '<pre>'; |
84 | while ($row = $res->fetch_array()) { |
||
1445 | daniel-mar | 85 | $max_ent++; |
86 | if ($max_ent > 100) break; // TODO: also allow to watch older entries |
||
635 | daniel-mar | 87 | $users = array(); |
88 | $res2 = OIDplus::db()->query("select username, severity from ###log_user ". |
||
1171 | daniel-mar | 89 | "where log_id = ?", array((int)$row['id'])); |
635 | daniel-mar | 90 | while ($row2 = $res2->fetch_array()) { |
91 | $users[] = $row2['username']; |
||
92 | } |
||
93 | $users = count($users) > 0 ? ", ".implode('/',$users) : ''; |
||
94 | |||
95 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
||
96 | |||
1223 | daniel-mar | 97 | $text .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', (int)$row['unix_ts']) . ': ' . htmlentities($row["event"]??'')." (" . htmlentities($addr.$users) . ")</span>\n"; |
635 | daniel-mar | 98 | } |
99 | $text .= '</pre>'; |
||
100 | |||
101 | // TODO: List logs in a table instead of a <pre> text |
||
102 | } else { |
||
103 | $text .= '<p>'._L('Currently there are no log entries').'</p>'; |
||
104 | } |
||
105 | |||
106 | } |
||
107 | |||
1116 | daniel-mar | 108 | /** |
109 | * @param string $request |
||
110 | * @return array|false |
||
111 | */ |
||
112 | public function tree_search(string $request) { |
||
635 | daniel-mar | 113 | return false; |
114 | } |
||
1116 | daniel-mar | 115 | } |