Subversion Repositories oidplus

Rev

Rev 1050 | Rev 1116 | 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 OIDplusPageAdminLogEvents extends OIDplusPagePluginAdmin {
  27.  
  28.         public function init($html=true) {
  29.         }
  30.  
  31.         public function gui($id, &$out, &$handled) {
  32.                 if ($id == 'oidplus:system_log') {
  33.                         $handled = true;
  34.                         $out['title'] = _L('All log messages');
  35.                         $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
  36.  
  37.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  38.                                 $out['icon'] = 'img/error.png';
  39.                                 $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
  40.                                 return;
  41.                         }
  42.  
  43.                         $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ###log lo ".
  44.                                                     "order by lo.unix_ts desc");
  45.                         if ($res->any()) {
  46.                                 $out['text'] = '<pre>';
  47.                                 while ($row = $res->fetch_array()) {
  48.                                         $severity = 0;
  49.                                         // ---
  50.                                         $users = array();
  51.                                         $res2 = OIDplus::db()->query("select username, severity from ###log_user ".
  52.                                                                      "where log_id = ?", array($row['id']));
  53.                                         while ($row2 = $res2->fetch_array()) {
  54.                                                 $users[] = $row2['username'];
  55.                                                 if ($row2['username'] == 'admin') $severity = $row2['severity'];
  56.                                         }
  57.                                         $users = count($users) > 0 ? '; '._L('affected users: %1',implode(', ',$users)) : '';
  58.                                         // ---
  59.                                         $objects = array();
  60.                                         $res2 = OIDplus::db()->query("select object, severity from ###log_object ".
  61.                                                                      "where log_id = ?", array($row['id']));
  62.                                         while ($row2 = $res2->fetch_array()) {
  63.                                                 $objects[] = $row2['object'];
  64.                                         }
  65.                                         $objects = count($objects) > 0 ? '; '._L('affected objects: %1',implode(', ',$objects)) : '';
  66.                                         // ---
  67.                                         $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
  68.                                         // ---
  69.                                         $out['text'] .= '<span class="severity_'.$severity.'">' . date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users.$objects) . ")</span>\n";
  70.                                 }
  71.                                 $out['text'] .= '</pre>';
  72.                         } else {
  73.                                 $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>';
  74.                         }
  75.  
  76.                         // TODO: List logs in a table instead of a <pre> text
  77.                         // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
  78.                 }
  79.         }
  80.  
  81.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  82.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  83.  
  84.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  85.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  86.                 } else {
  87.                         $tree_icon = null; // default icon (folder)
  88.                 }
  89.  
  90.                 $json[] = array(
  91.                         'id' => 'oidplus:system_log',
  92.                         'icon' => $tree_icon,
  93.                         'text' => _L('All log messages')
  94.                 );
  95.  
  96.                 return true;
  97.         }
  98.  
  99.         public function tree_search($request) {
  100.                 return false;
  101.         }
  102. }