Subversion Repositories oidplus

Rev

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