<?php
/**
* TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
*
* $Id: mod_index.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_Index
* @category TS2WebAdmin_Module
*/
class TS2WebAdmin_Module_Index extends TS2WebAdmin_Module
{
/**
* Module requires guest permissions.
*
* @return void
*/
function checkLogin()
{
$this->isAuthorized(TS2WA_LOGIN_ANONYMOUS);
}
/**
* Displays a welcome text.
*
* @return void
*/
function indexAction()
{
$this->setSubMenu('index');
}
/**
* Displays host information.
*
* @return void
*/
function hostinfoAction()
{
$this->setSubMenu('index');
$hostinfo = $this->_ts2->info_globalInfo();
$hostinfo['isp_countryname'] = getCountryNameById($hostinfo['isp_countrynumber']);
$hostinfo['total_datareceived'] = convertBytes($hostinfo['total_bytesreceived']);
$hostinfo['total_datasend'] = convertBytes($hostinfo['total_bytessend']);
$hostinfo['total_bwoutlastmin'] = convertBytes($hostinfo['total_bwoutlastmin']);
$hostinfo['total_bwtotallastmin'] = convertBytes(($hostinfo['total_bwoutlastmin']+$hostinfo['total_bwinlastmin'])) . '/s';
$hostinfo['total_bwoutlastmin'] = convertBytes($hostinfo['total_bwoutlastmin']) . '/s';
$hostinfo['total_bwinlastmin'] = convertBytes($hostinfo['total_bwinlastmin']) . '/s';
$hostinfo['total_bwtotallastsec'] = convertBytes(($hostinfo['total_bwoutlastsec']+$hostinfo['total_bwinlastsec'])) . '/s';
$hostinfo['total_bwoutlastsec'] = convertBytes($hostinfo['total_bwoutlastsec']) . '/s';
$hostinfo['total_bwinlastsec'] = convertBytes($hostinfo['total_bwinlastsec']) . '/s';
$hostinfo['sql_handler'] = $this->_app->getConfigParam('server_issqlite', FALSE) ? "SQLite" : "MySQL";
$hostinfo['sql_version'] = $this->_ts2->sql_version($this->_app->getConfigParam('server_issqlite', FALSE));
$this->assign('hostinfo', $hostinfo);
$this->assign('hostaddr', gethostbyname($this->_app->getConfigParam('server_hostname', '0.0.0.0')));
$this->assign('hosttcpq', $this->_app->getConfigParam('server_tcpqport', 0));
$this->assign('hosthttp', $this->_app->getConfigParam('server_httpport', 0));
$this->assign('version', $this->_ts2->info_serverVersion());
}
/**
* Displays server information.
*
* @return void
*/
function serverinfoAction()
{
$this->setSubMenu('index');
$server_id = intval($this->_app->getSessionParam('server_id', 0));
if(!$dbserverinfo = $this->_ts2->sql_serverInfo($server_id)) {
$this->_app->raiseError('Invalid virtual server ID', 500);
}
if($dbserverinfo['b_server_active'] == -1)
{
$serverinfo = $this->_ts2->info_serverInfo();
$dbserverinfo['s_server_uptime'] = formatTime($serverinfo['server_uptime']);
$dbserverinfo['i_server_currentusers'] = $serverinfo['server_currentusers'];
$dbserverinfo['i_server_currentchannels'] = $serverinfo['server_currentchannels'];
$dbserverinfo['b_server_password'] = ($serverinfo['server_password']) ? -1 : 0;
$dbserverinfo['i_server_bytessend'] = $serverinfo['server_bytessend'];
$dbserverinfo['i_server_bytesreceived'] = $serverinfo['server_bytesreceived'];
$dbserverinfo['s_server_datasend'] = convertBytes($serverinfo['server_bytessend']);
$dbserverinfo['s_server_datareceived'] = convertBytes($serverinfo['server_bytesreceived']);
$dbserverinfo['i_server_packetssend'] = $serverinfo['server_packetssend'];
$dbserverinfo['i_server_packetsreceived'] = $serverinfo['server_packetsreceived'];
$dbserverinfo['s_server_bwtotallastmin'] = convertBytes(($serverinfo['server_bwoutlastmin']+$serverinfo['server_bwinlastmin'])) . '/s';
$dbserverinfo['s_server_bwoutlastmin'] = convertBytes($serverinfo['server_bwoutlastmin']) . '/s';
$dbserverinfo['s_server_bwinlastmin'] = convertBytes($serverinfo['server_bwinlastmin']) . '/s';
$dbserverinfo['s_server_bwtotallastsec'] = convertBytes(($serverinfo['server_bwoutlastsec']+$serverinfo['server_bwinlastsec'])) . '/s';
$dbserverinfo['s_server_bwoutlastsec'] = convertBytes($serverinfo['server_bwoutlastsec']) . '/s';
$dbserverinfo['s_server_bwinlastsec'] = convertBytes($serverinfo['server_bwinlastsec']) . '/s';
$dbserverinfo['i_server_codecuseount'] = array();
$channellist = $this->_ts2->info_channelList();
foreach($channellist as $channel)
{
$dbserverinfo['i_server_codecuseount']['codec_' . $channel['codec']] = (isset($dbserverinfo['i_server_codecuseount']['codec_' . $channel['codec']])) ? $dbserverinfo['i_server_codecuseount']['codec_' . $channel['codec']]+1 : 1;
}
}
$dbserverinfo['i_server_currentdbusers'] = $this->_ts2->sql_dbUserCount($server_id);
$dbserverinfo['i_server_currentdbadmins'] = $this->_ts2->sql_dbAdminUserCount($server_id);
$dbserverinfo['i_server_currentdbchannels'] = $this->_ts2->sql_dbChannelCount($server_id);
$this->assign('serverinfo', $dbserverinfo);
$this->assign('hostaddr', gethostbyname($this->_app->getConfigParam('server_hostname', '0.0.0.0')));
$this->assign('hosttcpq', $this->_app->getConfigParam('server_tcpqport', 0));
$this->assign('hosthttp', $this->_app->getConfigParam('server_httpport', 0));
$this->assign('version', $this->_ts2->info_serverVersion());
}
/**
* Displays a server overview page.
*
* @return void
*/
function serverviewAction()
{
$this->setSubMenu('index');
if(!$serverinfo = $this->_ts2->info_serverInfo())
{
$this->_app->raiseError('Server is offline', 500);
}
$serverinfo['server_uptime'] = formatTime($serverinfo['server_uptime']);
$channellist = $this->_ts2->info_channelList();
$playerlist = $this->_ts2->info_playerList();
$tsvRegId = intval($this->_ts2->sql_getServerDescription($serverinfo['server_id']));
$tsvInfosD = $this->_tsv->fetchGraphData($tsvRegId);
$tsvInfosW = $this->_tsv->fetchGraphData($tsvRegId, TRUE);
for($i = 0; $i < count($channellist); $i++)
{
$channellist[$i]['codec_name'] = $this->_ts2->info_getCodec($channellist[$i]['codec']);
$channellist[$i]['flags_string'] = $this->_ts2->info_translateChannelFlag($channellist[$i], TRUE);
$channellist[$i]['channel_count'] = count($this->_ts2->info_channelChannel($channellist[$i]['id']));
$channellist[$i]['player_count'] = count($this->_ts2->info_channelUser($channellist[$i]['id']));
}
for($i = 0; $i < count($playerlist); $i++)
{
$playerlist[$i]['tree_image'] = $this->_ts2->info_playerImage($playerlist[$i]['p_id']);
$playerlist[$i]['flags_string'] = $this->_ts2->info_translatePlayerFlag($playerlist[$i], TRUE);
$playerlist[$i]['logintime'] = formatTime($playerlist[$i]['logintime']);
$playerlist[$i]['idletime'] = formatTime($playerlist[$i]['idletime']);
}
$this->assign('serverinfo', $serverinfo);
$this->assign('channellist', $channellist);
$this->assign('playerlist', $playerlist);
$tsvGraphD = $this->_tsv->updateGraphData($tsvInfosD, 'Users online (last 24 hours)');
$tsvGraphW = $this->_tsv->updateGraphData($tsvInfosW, 'Users online (last week)', TRUE);
$this->assign('tsviewer_regid', $tsvRegId);
$this->assign('tsviewer_infos_d', $tsvGraphD);
$this->assign('tsviewer_graph_d', 'http://chart.apis.google.com/chart?' . httpBuildQuery($tsvGraphD));
$this->assign('tsviewer_infos_w', $tsvGraphW);
$this->assign('tsviewer_graph_w', 'http://chart.apis.google.com/chart?' . httpBuildQuery($tsvGraphW));
$this->assign('usage_max_d', intval(100/$serverinfo['server_maxusers']*$tsvGraphD['chdmax']));
$this->assign('usage_max_w', intval(100/$serverinfo['server_maxusers']*$tsvGraphW['chdmax']));
$this->assign('usage_min_d', intval(100/$serverinfo['server_maxusers']*$tsvGraphD['chdmin']));
$this->assign('usage_min_w', intval(100/$serverinfo['server_maxusers']*$tsvGraphW['chdmin']));
$this->assign('usage_avg_d', intval(100/$serverinfo['server_maxusers']*$tsvGraphD['chdavg']));
$this->assign('usage_avg_w', intval(100/$serverinfo['server_maxusers']*$tsvGraphW['chdavg']));
$this->assign('hostaddr', gethostbyname($this->_app->getConfigParam('server_hostname', '0.0.0.0')));
$this->assign('hosttcpq', $this->_app->getConfigParam('server_tcpqport', 0));
$this->assign('hosthttp', $this->_app->getConfigParam('server_httpport', 0));
$this->assign('version', $this->_ts2->info_serverVersion());
}
/**
* Displays copyright information.
*
* @return void
*/
function copyrightAction()
{
$this->setSubMenu('index');
$this->assign('app_version', TS2WA_VERSION);
$this->assign('ts2_version', $this->_ts2->info_serverVersion());
$this->assign('tsv_version', TSV_VERSION);
$this->assign('cyts_version', CYTS_VERSION);
$this->assign('smarty_version', $this->_tpl->_version);
}
}