Subversion Repositories oidplus

Rev

Rev 256 | 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 OIDplusPageRaObjectLog extends OIDplusPagePluginRa {
  23.  
  24.         public static function getPluginInformation() {
  25.                 $out = array();
  26.                 $out['name'] = 'Object Log';
  27.                 $out['author'] = 'ViaThinkSoft';
  28.                 $out['version'] = null;
  29.                 $out['descriptionHTML'] = null;
  30.                 return $out;
  31.         }
  32.  
  33.         public function priority() {
  34.                 return 99;
  35.         }
  36.  
  37.         public function action(&$handled) {
  38.                 // Nothing
  39.         }
  40.  
  41.         public function init($html=true) {
  42.         }
  43.  
  44.         public function cfgSetValue($name, $value) {
  45.         }
  46.  
  47.         public function gui($id, &$out, &$handled) {
  48.         }
  49.  
  50.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  51.                 return false;
  52.         }
  53.  
  54.         public function modifyContent($id, &$title, &$icon, &$text) {
  55.                 $obj = OIDplusObject::parse($id);
  56.                 if (!$obj) return;
  57.                 if (!$obj->userHasWriteRights()) return;
  58.  
  59.                 // TODO: I want that this content comes before the WHOIS modifyContent.
  60.                 //       The problem is that first all public and then all RA plugins get loaded, not mixed by their priority
  61.                 $res = OIDplus::db()->query("select lo.id, lo.unix_ts, lo.addr, lo.event from ###log lo ".
  62.                                             "left join ###log_object lu on lu.log_id = lo.id ".
  63.                                             "where lu.object = ? " .
  64.                                             "order by lo.unix_ts desc", array($id));
  65.                 $text .= "<h2>Log messages for object ".htmlentities($id)."</h2>";
  66.                 if ($res->num_rows() > 0) {
  67.                         $text .= '<pre>';
  68.                         while ($row = $res->fetch_array()) {
  69.                                 $users = array();
  70.                                 $res2 = OIDplus::db()->query("select username from ###log_user ".
  71.                                                              "where log_id = ?", array($row['id']));
  72.                                 while ($row2 = $res2->fetch_array()) {
  73.                                         $users[] = $row2['username'];
  74.                                 }
  75.                                 $users = count($users) > 0 ? ", ".implode('/',$users) : '';
  76.  
  77.                                 $addr = empty($row['addr']) ? 'no address' : $row['addr'];
  78.  
  79.                                 $text .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr.$users) . ")\n";
  80.                         }
  81.                         $text .= '</pre>';
  82.  
  83.                         // TODO: List logs in a table instead of a <pre> text
  84.                         // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
  85.                 } else {
  86.                         $text .= '<p>Currently there are no log entries</p>';
  87.                 }
  88.  
  89.         }
  90.  
  91.         public function tree_search($request) {
  92.                 return false;
  93.         }
  94. }
  95.