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