<?php
/**
* TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
*
* $Id: mod_login.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_Error
* @category TS2WebAdmin_Module
*/
class TS2WebAdmin_Module_Login extends TS2WebAdmin_Module
{
/**
* Displays a login form.
*
* @return void
*/
function indexAction()
{
$this->assign('types', $this->_app->getLoginLevels());
}
/**
* Authenticates a user with the servers database.
*
* @return void
*/
function do_loginAction()
{
$this->setNoRender();
$user = $this->_app->getParam('user', 'Guest');
$pass = $this->_app->getParam('pass', 'Guest');
$port = $this->_app->getParam('port', 0);
$type = $this->_app->getParam('type', 0);
$isAuthed = FALSE;
$serverID = $this->_ts2->sadmin_dbServerIdByPort($port);
switch($type)
{
case TS2WA_LOGIN_SUPERADMIN:
$isAuthed = $this->_ts2->sql_dbVerifyAdminAccount($user, $pass, 0, $this->_app->getConfigParam('server_md5patch', FALSE));
break;
case TS2WA_LOGIN_SERVERADMIN:
$isAuthed = $this->_ts2->sql_dbVerifyAdminAccount($user, $pass, $serverID, $this->_app->getConfigParam('server_md5patch', FALSE));
break;
case TS2WA_LOGIN_ANONYMOUS:
$isAuthed = TRUE;
$user = 'Guest';
break;
default:
$this->redirect('login');
break;
}
if(!$isAuthed) {
$this->redirect('login', 'error');
}
$this->_app->setSessionParam('login_lvl', $type);
$this->_app->setSessionParam('login_name', $user);
$this->_app->setSessionParam('login_time', time());
$this->_app->setSessionParam('server_id', $serverID);
$this->_app->setSessionParam('server_port', $port);
$this->_app->setSessionParam('server_hostname', $this->_app->getConfigParam('server_hostname', 0));
$this->_app->setSessionParam('server_tcpqport', $this->_app->getConfigParam('server_tcpqport', 0));
$this->redirect('index');
}
/**
* Ends a users session.
*
* @return void
*/
function do_logoutAction()
{
$this->setNoRender();
session_destroy();
$this->redirect('login');
}
/**
* Displays a login error page.
*
* @return void
*/
function errorAction()
{
$this->assign('types', $this->_app->getLoginLevels());
}
}