Subversion Repositories oidplus

Rev

Rev 148 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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.  
  20. if (!defined('IN_OIDPLUS')) die();
  21.  
  22. class OIDplusPageAdminLogEvents extends OIDplusPagePlugin {
  23.         public function type() {
  24.                 return 'admin';
  25.         }
  26.  
  27.         public function priority() {
  28.                 return 600;
  29.         }
  30.  
  31.         public function action(&$handled) {
  32.         }
  33.  
  34.         public function init($html=true) {
  35.         }
  36.  
  37.         public function cfgSetValue($name, $value) {
  38.         }
  39.  
  40.         public function gui($id, &$out, &$handled) {
  41.                 if ($id == 'oidplus:system_log') {
  42.                         $handled = true;
  43.  
  44.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  45.                                 $out['icon'] = 'img/error_big.png';
  46.                                 $out['text'] .= '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as administrator.</p>';
  47.                                 return $out;
  48.                         }
  49.  
  50.                         $out['title'] = "All log messages";
  51.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
  52.  
  53.                         $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ".OIDPLUS_TABLENAME_PREFIX."log lo ".
  54.                                                     "left join ".OIDPLUS_TABLENAME_PREFIX."log_user lu on lu.log_id = lo.id ".
  55.                                                     //"where lu.user = 'admin' " .
  56.                                                                                 "order by lo.unix_ts desc");
  57.                         if (OIDplus::db()->num_rows($res) > 0) {
  58.                                 $out['text'] = '<pre>';
  59.                                 while ($row = OIDplus::db()->fetch_array($res)) {
  60.                                         $users = array();
  61.                                         $res2 = OIDplus::db()->query("select user from ".OIDPLUS_TABLENAME_PREFIX."log_user ".
  62.                                                                      "where log_id = ?", array($row['id']));
  63.                                         while ($row2 = OIDplus::db()->fetch_array($res2)) {
  64.                                                 $users[] = $row2['user'];
  65.                                         }
  66.                                         $users = count($users) > 0 ? ", ".implode('/',$users) : '';
  67.  
  68.                                         $addr = empty($row['addr']) ? 'no address' : $row['addr'];
  69.  
  70.                                         $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users) . ")\n";
  71.                                 }
  72.                                 $out['text'] .= '</pre>';
  73.                         } else {
  74.                                 $out['text'] .= '<p>Currently there are no log entries</p>';
  75.                         }
  76.  
  77.                         // TODO: List logs in a table instead of a <pre> text
  78.                         // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
  79.                 }
  80.         }
  81.  
  82.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  83.                 if (file_exists(__DIR__.'/treeicon.png')) {
  84.                         $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png';
  85.                 } else {
  86.                         $tree_icon = null; // default icon (folder)
  87.                 }
  88.  
  89.                 $json[] = array(
  90.                         'id' => 'oidplus:system_log',
  91.                         'icon' => $tree_icon,
  92.                         'text' => 'All log events'
  93.                 );
  94.  
  95.                 return true;
  96.         }
  97.  
  98.         public function tree_search($request) {
  99.                 return false;
  100.         }
  101. }
  102.  
  103. OIDplus::registerPagePlugin(new OIDplusPageAdminLogEvents());
  104.