Change the way commands to the ts3 server are issued
This commit is contained in:
parent
ca5e677b2d
commit
a4a0202859
46 changed files with 112 additions and 140 deletions
|
@ -10,10 +10,9 @@
|
|||
"symfony/yaml": "*",
|
||||
"vlucas/phpdotenv": "^2.3",
|
||||
"jeremykendall/slim-auth": "dev-slim-3.x",
|
||||
"phpmailer/phpmailer": "^5.2",
|
||||
"illuminate/pagination": "^5.5",
|
||||
"par0noid/ts3admin": "^1.0",
|
||||
"planetteamspeak/ts3-php-framework": "^1.1"
|
||||
"planetteamspeak/ts3-php-framework": "^1.1",
|
||||
"nesbot/carbon": "^1.25"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin/"
|
||||
|
|
|
@ -15,5 +15,5 @@ teamspeak_default_query_port=10011
|
|||
teamspeak_default_user="serveradmin"
|
||||
|
||||
# log
|
||||
log_name="app" # values: all strings
|
||||
log_name="ts3web" # values: all strings
|
||||
log_level="INFO" # values: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY
|
|
@ -52,16 +52,22 @@ $container['translator'] = function () use ($translator) {
|
|||
|
||||
// date
|
||||
Carbon::setLocale(getenv('site_language'));
|
||||
Carbon::setToStringFormat(getenv('site_date_format'));
|
||||
|
||||
// logger
|
||||
$container['logger'] = function () {
|
||||
try {
|
||||
$logger = BootstrapHelper::bootLogger();
|
||||
return $logger;
|
||||
};
|
||||
|
||||
$container['logger'] = function () use ($logger) {
|
||||
return $logger;
|
||||
};
|
||||
} catch (Exception $e) {
|
||||
die('Error bootstrapping logger: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// teamspeak
|
||||
$container['ts'] = function () {
|
||||
return new TSInstance();
|
||||
$container['ts'] = function () use ($logger) {
|
||||
return new TSInstance($logger);
|
||||
};
|
||||
|
||||
// auth
|
||||
|
@ -125,9 +131,6 @@ $container['view'] = function ($container) use ($app) {
|
|||
$view->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension($container['translator']));
|
||||
$view->getEnvironment()->getExtension('Twig_Extension_Core')->setDateFormat(getenv('site_date_format'));
|
||||
|
||||
// date
|
||||
Carbon::setToStringFormat(getenv('site_date_format'));
|
||||
|
||||
// env
|
||||
$view->getEnvironment()->addFunction(new Twig_SimpleFunction('getenv', function($value) {
|
||||
$res = getenv($value);
|
||||
|
|
|
@ -12,10 +12,8 @@ final class BanDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$banDeleteResult = $this->ts->getInstance()->banDelete($banId);
|
||||
$this->ts->checkCommandResult($banDeleteResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
|
|
|
@ -12,10 +12,8 @@ final class BansAction extends AbstractAction
|
|||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$banListResult = $this->ts->getInstance()->banList();
|
||||
$this->ts->checkCommandResult($banListResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'bans.twig', [
|
||||
|
|
|
@ -12,10 +12,8 @@ final class ChannelDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$channelDeleteResult = $this->ts->getInstance()->channelDelete($cid);
|
||||
$this->ts->checkCommandResult($channelDeleteResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
|
|
|
@ -12,10 +12,8 @@ final class ChannelGroupDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$groupDeleteResult = $this->ts->getInstance()->channelGroupDelete($cgid);
|
||||
$this->ts->checkCommandResult($groupDeleteResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
|
|
|
@ -12,13 +12,10 @@ final class ChannelGroupInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$clientsResult = $this->ts->getInstance()->channelGroupClientList(null, null, $cgid);
|
||||
$this->ts->checkCommandResult($clientsResult);
|
||||
|
||||
$permissionsResult = $this->ts->getInstance()->channelGroupPermList($cgid, true);
|
||||
$this->ts->checkCommandResult($permissionsResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'channelgroup_info.twig', [
|
||||
|
|
|
@ -12,13 +12,10 @@ final class ChannelInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$channelResult = $this->ts->getInstance()->channelInfo($cid);
|
||||
$this->ts->checkCommandResult($channelResult);
|
||||
|
||||
$clientsResult = $this->ts->getInstance()->channelClientList($cid);
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$files = [];
|
||||
$files['data'] = $this->getAllFilesIn($sid, $cid, '/');
|
||||
|
@ -38,10 +35,8 @@ final class ChannelInfoAction extends AbstractAction
|
|||
{
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$fileResult = $this->ts->getInstance()->ftGetFileList($cid, '', $path);
|
||||
$this->ts->checkCommandResult($fileResult);
|
||||
|
||||
$foundFiles = $fileResult['data'];
|
||||
|
||||
|
|
|
@ -13,10 +13,8 @@ final class ChannelSendAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->sendMessage(2, $cid, $body['message']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
return $response->withRedirect('/channels/' . $sid . '/' . $cid);
|
||||
|
|
|
@ -11,10 +11,8 @@ final class ChannelsAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->channelList();
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'channels.twig', [
|
||||
|
|
|
@ -14,17 +14,14 @@ final class ClientBanAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$getResult = $this->ts->getInstance()->clientGetNameFromDbid($cldbid);
|
||||
$this->ts->checkCommandResult($getResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->banAddByUid(
|
||||
$this->ts->getInstance()->getElement('data', $getResult)['cluid'],
|
||||
(!empty($body['time']) ? $body['time'] : 0),
|
||||
$body['reason']
|
||||
);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('client_info.banned.success', ['%cldbid%' => $cldbid]));
|
||||
return $response->withRedirect('/clients/' . $sid . '/' . $cldbid);
|
||||
|
|
|
@ -12,10 +12,8 @@ final class ClientDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$clientDeleteResult = $this->ts->getInstance()->clientDbDelete($cldbid);
|
||||
$this->ts->checkCommandResult($clientDeleteResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
|
|
|
@ -12,19 +12,14 @@ final class ClientInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$detailsResult = $this->ts->getInstance()->clientDbInfo($cldbid);
|
||||
$this->ts->checkCommandResult($detailsResult);
|
||||
|
||||
$serverGroupsResult = $this->ts->getInstance()->serverGroupsByClientID($cldbid);
|
||||
$this->ts->checkCommandResult($serverGroupsResult);
|
||||
|
||||
$channelGroupsResult = $this->ts->getInstance()->channelGroupClientList(null, $cldbid, null);
|
||||
$this->ts->checkCommandResult($channelGroupsResult);
|
||||
|
||||
$permissionsResult = $this->ts->getInstance()->clientPermList($cldbid, true);
|
||||
$this->ts->checkCommandResult($permissionsResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'client_info.twig', [
|
||||
|
|
|
@ -14,17 +14,14 @@ final class ClientSendAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$getResult = $this->ts->getInstance()->clientGetNameFromDbid($cldbid);
|
||||
$this->ts->checkCommandResult($getResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->messageAdd(
|
||||
$this->ts->getInstance()->getElement('data', $getResult)['cluid'],
|
||||
$body['subject'],
|
||||
$body['message']
|
||||
);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('client_info.sent.success', ['%cldbid%' => $cldbid]));
|
||||
return $response->withRedirect('/clients/' . $sid . '/' . $cldbid);
|
||||
|
|
|
@ -11,10 +11,8 @@ final class ClientsAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->clientDbList();
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'clients.twig', [
|
||||
|
|
|
@ -12,13 +12,11 @@ final class ComplainDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
// search fcldbid
|
||||
$fcldbid = null;
|
||||
|
||||
$searchResult = $this->ts->getInstance()->complainList();
|
||||
$this->ts->checkCommandResult($searchResult);
|
||||
|
||||
foreach ($this->ts->getInstance()->getElement('data', $searchResult) as $complain) {
|
||||
if ($complain['tcldbid'] === $tcldbid) {
|
||||
|
@ -29,7 +27,6 @@ final class ComplainDeleteAction extends AbstractAction
|
|||
|
||||
if (!empty($fcldbid)) {
|
||||
$complainDeleteResult = $this->ts->getInstance()->complainDelete($tcldbid, $fcldbid);
|
||||
$this->ts->checkCommandResult($complainDeleteResult);
|
||||
}
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
|
|
@ -11,10 +11,8 @@ final class ComplainsAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->complainList();
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'complains.twig', [
|
||||
|
|
|
@ -15,10 +15,8 @@ final class GroupAddAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$groupAddResult = $this->ts->getInstance()->serverGroupAddClient($sgid, $cldbid);
|
||||
$this->ts->checkCommandResult($groupAddResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('added'));
|
||||
|
||||
|
|
|
@ -12,10 +12,8 @@ final class GroupDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$groupDeleteResult = $this->ts->getInstance()->serverGroupDelete($sgid);
|
||||
$this->ts->checkCommandResult($groupDeleteResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
|
|
|
@ -12,13 +12,10 @@ final class GroupInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$clientsResult = $this->ts->getInstance()->serverGroupClientList($sgid, true);
|
||||
$this->ts->checkCommandResult($clientsResult);
|
||||
|
||||
$permissionsResult = $this->ts->getInstance()->serverGroupPermList($sgid, true);
|
||||
$this->ts->checkCommandResult($permissionsResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'group_info.twig', [
|
||||
|
|
|
@ -13,10 +13,8 @@ final class GroupRemoveAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$groupRemoveResult = $this->ts->getInstance()->serverGroupDeleteClient($sgid, $cldbid);
|
||||
$this->ts->checkCommandResult($groupRemoveResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('removed'));
|
||||
|
||||
|
|
|
@ -11,13 +11,10 @@ final class GroupsAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$serverGroupsResult = $this->ts->getInstance()->serverGroupList();
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$channelGroupsResult = $this->ts->getInstance()->channelGroupList();
|
||||
$this->ts->checkCommandResult($channelGroupsResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'groups.twig', [
|
||||
|
|
|
@ -9,9 +9,7 @@ final class InstanceAction extends AbstractAction
|
|||
{
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$hostResult = $this->ts->getInstance()->hostInfo();
|
||||
$this->ts->checkCommandResult($hostResult);
|
||||
$instanceResult = $this->ts->getInstance()->instanceInfo();
|
||||
$this->ts->checkCommandResult($instanceResult);
|
||||
|
||||
$data['data'] = array_merge($hostResult['data'], $instanceResult['data']);
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ final class InstanceEditAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->instanceEdit($body);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('instance_edit.edited.success'));
|
||||
return $response->withRedirect('/instance');
|
||||
|
|
|
@ -10,7 +10,6 @@ final class LogsAction extends AbstractAction
|
|||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->logView(100, 1, 1);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'logs.twig', [
|
||||
|
|
|
@ -11,10 +11,9 @@ final class OnlineAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->clientList();
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
$dataResult = $this->ts->getInstance()->clientList('-ip -times -info');
|
||||
$this->ts->getInstance()->logout(); // avoid showing currently used user twice
|
||||
|
||||
$instance = TeamSpeak3::factory(sprintf("serverquery://%s:%s@%s:%s/?server_id=%s",
|
||||
$this->auth->getIdentity()['user'],
|
||||
|
@ -26,6 +25,7 @@ final class OnlineAction extends AbstractAction
|
|||
|
||||
$treeView = new TeamSpeak3_Viewer_Html("/images/viewer/", "/images/flags/", "data:image");
|
||||
$tree = $instance->getViewer($treeView);
|
||||
$instance->logout();
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'online.twig', [
|
||||
|
|
|
@ -14,10 +14,8 @@ final class OnlineBanAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->banClient($clid, (!empty($body['time']) ? $body['time'] : 0), $body['reason']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('online.banned.success', ['%clid%' => $clid]));
|
||||
return $response->withRedirect('/online/' . $sid . '/' . $clid);
|
||||
|
|
|
@ -12,10 +12,8 @@ final class OnlineInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->clientInfo($clid);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'online_info.twig', [
|
||||
|
|
|
@ -14,10 +14,8 @@ final class OnlineKickAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->clientKick($clid, 'server', $body['reason']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('online.kicked.success', ['%clid%' => $clid]));
|
||||
return $response->withRedirect('/online/' . $sid);
|
||||
|
|
|
@ -14,10 +14,8 @@ final class OnlinePokeAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->clientPoke($clid, $body['message']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('online.poked.success', ['%clid%' => $clid]));
|
||||
return $response->withRedirect('/online/' . $sid . '/' . $clid);
|
||||
|
|
|
@ -14,10 +14,8 @@ final class OnlineSendAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->sendMessage(1, $clid, $body['message']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
return $response->withRedirect('/online/' . $sid . '/' . $clid);
|
||||
|
|
|
@ -9,7 +9,6 @@ final class ProfileAction extends AbstractAction
|
|||
{
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$whoisResult = $this->ts->getInstance()->whoAmI();
|
||||
$this->ts->checkCommandResult($whoisResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'profile.twig', [
|
||||
|
|
|
@ -9,7 +9,6 @@ final class ProfileCredentialsChangeAction extends AbstractAction
|
|||
{
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->clientSetServerQueryLogin($this->auth->getIdentity()['user']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('profile_credentials.changed.success', ['%password%' => $dataResult['data']['client_login_password']]));
|
||||
$this->auth->logout();
|
||||
|
|
|
@ -11,7 +11,6 @@ final class ServerCreateAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->serverCreate($body);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('server_create.created.success', ['%token%' => $dataResult['data']['token']]));
|
||||
return $response->withRedirect('/servers');
|
||||
|
|
|
@ -11,10 +11,8 @@ final class ServerDeleteAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->serverDelete($sid);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
return $response->withRedirect('/servers');
|
||||
|
|
|
@ -12,10 +12,8 @@ final class ServerEditAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->serverEdit($body);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('server_edit.edited.success', ['%sid%' => $sid]));
|
||||
return $response->withRedirect('/servers/' . $sid);
|
||||
|
|
|
@ -11,13 +11,10 @@ final class ServerInfoAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$infoResult = $this->ts->getInstance()->serverInfo();
|
||||
$this->ts->checkCommandResult($infoResult);
|
||||
|
||||
$uploadsResult = $this->ts->getInstance()->ftList();
|
||||
$this->ts->checkCommandResult($uploadsResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'server_info.twig', [
|
||||
|
|
|
@ -12,10 +12,8 @@ final class ServerSendAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
$this->ts->checkCommandResult($selectResult);
|
||||
|
||||
$dataResult = $this->ts->getInstance()->sendMessage(3, $sid, $body['message']);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
return $response->withRedirect('/servers/' . $sid);
|
||||
|
|
|
@ -11,7 +11,6 @@ final class ServerStartAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->serverStart($sid);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('servers.started.success', ['%sid%' => $sid]));
|
||||
return $response->withRedirect('/servers');
|
||||
|
|
|
@ -11,7 +11,6 @@ final class ServerStopAction extends AbstractAction
|
|||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->serverStop($sid);
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('servers.stopped.success', ['%sid%' => $sid]));
|
||||
return $response->withRedirect('/servers');
|
||||
|
|
|
@ -9,7 +9,6 @@ final class ServersAction extends AbstractAction
|
|||
{
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$dataResult = $this->ts->getInstance()->serverList();
|
||||
$this->ts->checkCommandResult($dataResult);
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'servers.twig', [
|
||||
|
|
|
@ -25,7 +25,7 @@ class TSAuthAdapter extends \Zend\Authentication\Adapter\AbstractAdapter
|
|||
*/
|
||||
private $ts;
|
||||
|
||||
public function __construct($host, $queryPort, LoggerInterface $logger, $ts)
|
||||
public function __construct($host, $queryPort, LoggerInterface $logger, TSInstance $ts)
|
||||
{
|
||||
$this->host = $host;
|
||||
$this->queryPort = $queryPort;
|
||||
|
@ -45,7 +45,7 @@ class TSAuthAdapter extends \Zend\Authentication\Adapter\AbstractAdapter
|
|||
$password = $this->getCredential();
|
||||
|
||||
if ($this->ts->login($user, $password)) {
|
||||
$this->logger->info(sprintf('%s authenticated with teamspeak instance %s:%s', $user, $this->ts->getHost(), $this->ts->getQueryPort()));
|
||||
$this->logger->info(sprintf('Authenticated as %s', $user));
|
||||
|
||||
$user = ['identity' => $user, 'user' => $user, 'password'=> $password, 'role' => ACL::ACL_DEFAULT_ROLE_ADMIN];
|
||||
return new Result(Result::SUCCESS, $user, array());
|
||||
|
|
68
src/Util/TS3AdminProxy.php
Normal file
68
src/Util/TS3AdminProxy.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
class TS3AdminProxy
|
||||
{
|
||||
private $object;
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* TS3AdminProxy constructor.
|
||||
* @param ts3admin $object
|
||||
* @param $logger \Psr\Log\LoggerInterface
|
||||
*/
|
||||
public function __construct(ts3admin $object, $logger) {
|
||||
$this->object = $object;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function __call($method, $args) {
|
||||
|
||||
// hide sensitive args
|
||||
if (in_array($method, ['login'])) {
|
||||
$this->logger->debug(sprintf('Calling %s', $method));
|
||||
} else {
|
||||
$this->logger->debug(sprintf('Calling %s', $method), $args);
|
||||
}
|
||||
|
||||
// invoke original method
|
||||
$result = call_user_func_array(array($this->object, $method), $args);
|
||||
|
||||
// check result
|
||||
if (is_array($result)) {
|
||||
$this->logger->debug('Received', $result);
|
||||
|
||||
if (array_key_exists('success', $result)) {
|
||||
$success = call_user_func_array(array($this->object, 'getElement'), ['success', $result]);
|
||||
|
||||
if (!$success) {
|
||||
if (array_key_exists('errors', $result)) {
|
||||
$errors = call_user_func_array(array($this->object, 'getElement'), ['errors', $result]);
|
||||
$errorsAsString = implode('. ', $errors);
|
||||
|
||||
if (count($errors) === 1) {
|
||||
|
||||
// catch this
|
||||
if (strpos($errorsAsString, 'ErrorID: 1281 | Message: database empty result set') !== false) {
|
||||
$throw = false;
|
||||
} else {
|
||||
$throw = true;
|
||||
}
|
||||
} else {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
if ($throw) {
|
||||
throw new TSException($errorsAsString);
|
||||
}
|
||||
} else {
|
||||
throw new TSException('An unknown error occurred.');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->logger->debug('Received ' . $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -18,21 +18,31 @@ class TSInstance
|
|||
private $queryPort;
|
||||
|
||||
/**
|
||||
* TeamSpeakWrapper constructor.
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
public function __construct()
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* TeamSpeakWrapper constructor.
|
||||
* @param $logger
|
||||
*/
|
||||
public function __construct($logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
$this->host = getenv('teamspeak_default_host');
|
||||
$this->queryPort = getenv('teamspeak_default_query_port');
|
||||
|
||||
$ts = new ts3admin($this->host, $this->queryPort);
|
||||
$ts = new TS3AdminProxy($ts, $logger);
|
||||
|
||||
if($ts->getElement('success', $ts->connect())) {
|
||||
} else {
|
||||
die('An unknown error occurred. A connection to the teamspeak server could not be established. Check settings.');
|
||||
try {
|
||||
$ts->connect();
|
||||
$this->ts = $ts;
|
||||
$this->logger->debug(sprintf('Connected to %s:%s', $this->host, $this->queryPort));
|
||||
} catch (TSException $e) {
|
||||
die($e);
|
||||
}
|
||||
|
||||
$this->ts = $ts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +55,8 @@ class TSInstance
|
|||
public function login($user, $password)
|
||||
{
|
||||
if (!empty($user) && !empty($password)) {
|
||||
$res = $this->ts->login($user, $password);
|
||||
$this->checkCommandResult($res);
|
||||
$this->ts->login($user, $password);
|
||||
$this->logger->debug(sprintf('Logged in as %s', $user));
|
||||
} else {
|
||||
throw new InvalidArgumentException('User and password not provided');
|
||||
}
|
||||
|
@ -54,39 +64,6 @@ class TSInstance
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any error occurred
|
||||
*
|
||||
* @param $result
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCommandResult($result)
|
||||
{
|
||||
if (!$this->ts->getElement('success', $result)) {
|
||||
|
||||
$errors = $this->ts->getElement('errors', $result);
|
||||
$errorsAsString = implode('. ', $errors);
|
||||
|
||||
if (count($errors) === 1) {
|
||||
|
||||
// catch this
|
||||
if (strpos($errorsAsString, 'ErrorID: 1281 | Message: database empty result set') !== false) {
|
||||
$throw = false;
|
||||
} else {
|
||||
$throw = true;
|
||||
}
|
||||
} else {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
if ($throw) {
|
||||
throw new TSException($errorsAsString);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,12 @@
|
|||
{% if data|length >0 %}
|
||||
{% include 'table.twig' with {'data': data,
|
||||
'hide': [{'key': 'client_type', 'values': ['1']}],
|
||||
'filters': [
|
||||
{'key': 'client_idle_time', 'apply': 'timeInSeconds'},
|
||||
{'key': 'connection_connected_time', 'apply': 'timeInSeconds'},
|
||||
{'key': 'client_created', 'apply': 'timestamp'},
|
||||
{'key': 'client_lastconnected', 'apply': 'timestamp'}
|
||||
],
|
||||
'links': [
|
||||
{'key': 'clid', 'uri': '/online/' ~ sid},
|
||||
{'key': 'cid', 'uri': '/channels/' ~ sid, 'uri_param': 'cid'},
|
||||
|
|
Reference in a new issue