Subversion Repositories oidplus

Rev

Rev 1445 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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.  
  20. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPageRaObjectLog extends OIDplusPagePluginRa
  27.         implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 /* modifyContent */
  28. {
  29.  
  30.         /**
  31.          * @param bool $html
  32.          * @return void
  33.          */
  34.         public function init(bool $html=true) {
  35.         }
  36.  
  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) {
  44.         }
  45.  
  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 {
  54.                 //if (!$ra_email) return false;
  55.                 //if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false;
  56.  
  57.                 return false;
  58.         }
  59.  
  60.         /**
  61.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2
  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) {
  70.                 $obj = OIDplusObject::parse($id);
  71.                 if (!$obj) return;
  72.                 if (!$obj->userHasWriteRights()) return;
  73.  
  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
  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>';
  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.  
  89.                 if ($res->any()) {
  90.                         $count = 0;
  91.                         while ($row = $res->fetch_array()) {
  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.  
  97.                                 $users = array();
  98.                                 $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
  99.                                                              "where log_id = ?", array((int)$row['id']));
  100.                                 while ($row2 = $res2->fetch_array()) {
  101.                                         $users[] = $row2['username'];
  102.                                 }
  103.                                 $users = implode("\n",$users);
  104.  
  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>';
  114.                         }
  115.                 } else {
  116.                         $text .= '<tr><td colspan="4">'._L('There are no log entries on this page').'</td></tr>';
  117.                 }
  118.  
  119.                 $text .= '</tbody>';
  120.                 $text .= '</table>';
  121.                 $text .= '</div></div>';
  122.         }
  123.  
  124.         /**
  125.          * @param string $request
  126.          * @return array|false
  127.          */
  128.         public function tree_search(string $request) {
  129.                 return false;
  130.         }
  131. }
  132.