Location: PHPKode > projects > TS2WebAdmin > ts2webadmin/app/mod_serverlog.php
<?php

/**
 * TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
 *
 * $Id: mod_serverset.php 2009-09-03 20:23:12 sven $
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package   TS2WebAdmin
 * @version   2.0.0-alpha2
 * @author    Sven 'ScP' Paulsen
 * @copyright Copyright (c) 2009 by Planet TeamSpeak. All rights reserved.    
 */

/* check if file is included correctly */
defined('TS2WA_VALID') || die('Access denied...');

/**
 * @package  TS2WebAdmin_Module_Serverset
 * @category TS2WebAdmin_Module
 */
class TS2WebAdmin_Module_Serverlog extends TS2WebAdmin_Module
{
  /**
   * Module requires SA permissions.
   * 
   * @return void
   */
  function checkLogin()
  {
    $this->isAuthorized(TS2WA_LOGIN_SERVERADMIN);
  }

  /**
   * Displays a list of entries from the server log.
   * 
   * @return void
   */
  function indexAction()
  {
    $this->setSubMenu('server');
    
    $server_id = intval($this->_app->getSessionParam('server_id', 0));
    
    if(!$server_info = $this->_ts2->sql_serverInfo($server_id)) {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $logs = $this->_ts2->sadmin_logRead(3000);
    
    if(!is_array($logs))
    {
      $this->_app->raiseError('Error loading server log', 500, $this->_ts2->debug_lastreply());
    }
        
    $patterns = array(
      'web : superserveradmin connected',
      'tcpquery : superserveradmin connected',
      '*remark by ' . $this->_app->getConfigParam('server_username', '') . '* TS2WebAdmin client connected',
    );
    
    foreach($logs as $key => $val)
    {
      foreach($patterns as $pattern)
      {
        if(strstr($val['event'], $pattern) !== FALSE || $val['server'] != $server_id) unset($logs[$key]);
      }
    }
    
    $this->assign('logs', array_reverse($logs));
    $this->assign('serverinfo', $server_info);
  }
  
  /**
   * Displays a list of entries from the server log matching a searched string.
   * 
   * @return void
   */
  function searchAction()
  {
    $this->setSubMenu('server');
    $this->setTplFile('serverlog');
    
    $server_id = intval($this->_app->getSessionParam('server_id', 0));

    if(!$server_info = $this->_ts2->sql_serverInfo($server_id))
    {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $search_pattern = $this->_app->getParam('pattern', FALSE);
    
    if($search_pattern === FALSE || $search_pattern == 'search...')
    {
      $this->redirect('globallog');
    }
    
    $logs = $this->_ts2->sadmin_logFind($search_pattern);
    
    if(!is_array($logs))
    {
      $this->_app->raiseError('Error loading server log', 500, $this->_ts2->debug_lastreply());
    }
        
    $patterns = array(
      'web : superserveradmin connected',
      'tcpquery : superserveradmin connected',
      '*remark by ' . $this->_app->getConfigParam('server_username', '') . '* TS2WebAdmin client connected',
    );
    
    foreach($logs as $key => $val)
    {
      foreach($patterns as $pattern)
      {
        if(strstr($val['event'], $pattern) !== FALSE || $val['server'] != $server_id) unset($logs[$key]);
      }
    }
    
    $this->assign('logs', array_reverse($logs));
    $this->assign('serverinfo', $server_info);
  }
  
  
}
Return current item: TS2WebAdmin