Subversion Repositories oidplus

Rev

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