Rev 801 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 801 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusPageRaLogEvents extends OIDplusPagePluginRa { |
22 | class OIDplusPageRaLogEvents extends OIDplusPagePluginRa { |
23 | 23 | ||
24 | public function init($html=true) { |
24 | public function init($html=true) { |
25 | } |
25 | } |
26 | 26 | ||
27 | public function gui($id, &$out, &$handled) { |
27 | public function gui($id, &$out, &$handled) { |
28 | if (explode('$',$id)[0] == 'oidplus:ra_log') { |
28 | if (explode('$',$id)[0] == 'oidplus:ra_log') { |
29 | $handled = true; |
29 | $handled = true; |
30 | 30 | ||
31 | $ra_email = explode('$',$id)[1]; |
31 | $ra_email = explode('$',$id)[1]; |
32 | 32 | ||
33 | $out['title'] = _L('Log messages for RA %1',$ra_email); |
33 | $out['title'] = _L('Log messages for RA %1',$ra_email); |
34 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
34 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
35 | 35 | ||
36 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
36 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
37 | $out['icon'] = 'img/error.png'; |
37 | $out['icon'] = 'img/error.png'; |
38 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
38 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
39 | return; |
39 | return; |
40 | } |
40 | } |
41 | 41 | ||
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
43 | if (!$res->any()) { |
43 | if (!$res->any()) { |
44 | $out['icon'] = 'img/error.png'; |
44 | $out['icon'] = 'img/error.png'; |
45 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
45 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
46 | return; |
46 | return; |
47 | } |
47 | } |
48 | 48 | ||
49 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event, lu.severity from ###log lo ". |
49 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event, lu.severity from ###log lo ". |
50 | "left join ###log_user lu on lu.log_id = lo.id ". |
50 | "left join ###log_user lu on lu.log_id = lo.id ". |
51 | "where lu.username = ? " . |
51 | "where lu.username = ? " . |
52 | "order by lo.unix_ts desc", array($ra_email)); |
52 | "order by lo.unix_ts desc", array($ra_email)); |
53 | if ($res->any()) { |
53 | if ($res->any()) { |
54 | $out['text'] = '<pre>'; |
54 | $out['text'] = '<pre>'; |
55 | while ($row = $res->fetch_array()) { |
55 | while ($row = $res->fetch_array()) { |
56 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
56 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
57 | 57 | ||
58 | $out['text'] .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")</span>\n"; |
58 | $out['text'] .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")</span>\n"; |
59 | } |
59 | } |
60 | $out['text'] .= '</pre>'; |
60 | $out['text'] .= '</pre>'; |
61 | } else { |
61 | } else { |
62 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
62 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
63 | } |
63 | } |
64 | 64 | ||
65 | // TODO: List logs in a table instead of a <pre> text |
65 | // TODO: List logs in a table instead of a <pre> text |
66 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
66 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
67 | } |
67 | } |
68 | } |
68 | } |
69 | 69 | ||
70 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
70 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
71 | if (!$ra_email) return false; |
71 | if (!$ra_email) return false; |
72 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
72 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
73 | 73 | ||
74 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
74 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
75 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
75 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
76 | } else { |
76 | } else { |
77 | $tree_icon = null; // default icon (folder) |
77 | $tree_icon = null; // default icon (folder) |
78 | } |
78 | } |
79 | 79 | ||
80 | $json[] = array( |
80 | $json[] = array( |
81 | 'id' => 'oidplus:ra_log$'.$ra_email, |
81 | 'id' => 'oidplus:ra_log$'.$ra_email, |
82 | 'icon' => $tree_icon, |
82 | 'icon' => $tree_icon, |
83 | 'text' => _L('RA log events') |
83 | 'text' => _L('RA log events') |
84 | ); |
84 | ); |
85 | 85 | ||
86 | return true; |
86 | return true; |
87 | } |
87 | } |
88 | 88 | ||
89 | public function tree_search($request) { |
89 | public function tree_search($request) { |
90 | return false; |
90 | return false; |
91 | } |
91 | } |
92 | } |
92 | } |