Subversion Repositories oidplus

Rev

Rev 1171 | Rev 1223 | Go to most recent revision | 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: I want that this content comes before the WHOIS modifyContent.
  75.                 //       The problem is that first all public and then all RA plugins get loaded, not mixed by their priority
  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.                 if ($res->any()) {
  82.                         $text .= '<pre>';
  83.                         while ($row = $res->fetch_array()) {
  84.                                 $users = array();
  85.                                 $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
  86.                                                              "where log_id = ?", array((int)$row['id']));
  87.                                 while ($row2 = $res2->fetch_array()) {
  88.                                         $users[] = $row2['username'];
  89.                                 }
  90.                                 $users = count($users) > 0 ? ", ".implode('/',$users) : '';
  91.  
  92.                                 $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
  93.  
  94.                                 $text .= '<span class="severity_'.$row['severity'].'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"]??'')." (" . htmlentities($addr.$users) . ")</span>\n";
  95.                         }
  96.                         $text .= '</pre>';
  97.  
  98.                         // TODO: List logs in a table instead of a <pre> text
  99.                         // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
  100.                 } else {
  101.                         $text .= '<p>'._L('Currently there are no log entries').'</p>';
  102.                 }
  103.  
  104.         }
  105.  
  106.         /**
  107.          * @param string $request
  108.          * @return array|false
  109.          */
  110.         public function tree_search(string $request) {
  111.                 return false;
  112.         }
  113. }
  114.