diff --git a/composer.json b/composer.json index 048baa6..c03a29f 100644 --- a/composer.json +++ b/composer.json @@ -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/" diff --git a/config/env.example b/config/env.example index bb2863a..64b8b56 100644 --- a/config/env.example +++ b/config/env.example @@ -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 \ No newline at end of file diff --git a/public/index.php b/public/index.php index ae306c4..f792629 100644 --- a/public/index.php +++ b/public/index.php @@ -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); diff --git a/src/Control/Actions/BanDeleteAction.php b/src/Control/Actions/BanDeleteAction.php index 63c3c46..e89aae8 100644 --- a/src/Control/Actions/BanDeleteAction.php +++ b/src/Control/Actions/BanDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/BansAction.php b/src/Control/Actions/BansAction.php index bc2d56c..d0911a3 100644 --- a/src/Control/Actions/BansAction.php +++ b/src/Control/Actions/BansAction.php @@ -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', [ diff --git a/src/Control/Actions/ChannelDeleteAction.php b/src/Control/Actions/ChannelDeleteAction.php index d4a1291..ae4b9c1 100644 --- a/src/Control/Actions/ChannelDeleteAction.php +++ b/src/Control/Actions/ChannelDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/ChannelGroupDeleteAction.php b/src/Control/Actions/ChannelGroupDeleteAction.php index 9073308..b5d1c45 100644 --- a/src/Control/Actions/ChannelGroupDeleteAction.php +++ b/src/Control/Actions/ChannelGroupDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/ChannelGroupInfoAction.php b/src/Control/Actions/ChannelGroupInfoAction.php index 81485dc..a62b7f5 100644 --- a/src/Control/Actions/ChannelGroupInfoAction.php +++ b/src/Control/Actions/ChannelGroupInfoAction.php @@ -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', [ diff --git a/src/Control/Actions/ChannelInfoAction.php b/src/Control/Actions/ChannelInfoAction.php index d48e1f2..95ce667 100644 --- a/src/Control/Actions/ChannelInfoAction.php +++ b/src/Control/Actions/ChannelInfoAction.php @@ -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']; diff --git a/src/Control/Actions/ChannelSendAction.php b/src/Control/Actions/ChannelSendAction.php index 99eafbc..721b20b 100644 --- a/src/Control/Actions/ChannelSendAction.php +++ b/src/Control/Actions/ChannelSendAction.php @@ -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); diff --git a/src/Control/Actions/ChannelsAction.php b/src/Control/Actions/ChannelsAction.php index 1aa52b7..a766e33 100644 --- a/src/Control/Actions/ChannelsAction.php +++ b/src/Control/Actions/ChannelsAction.php @@ -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', [ diff --git a/src/Control/Actions/ClientBanAction.php b/src/Control/Actions/ClientBanAction.php index 9645b4c..d0d0e5b 100644 --- a/src/Control/Actions/ClientBanAction.php +++ b/src/Control/Actions/ClientBanAction.php @@ -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); diff --git a/src/Control/Actions/ClientDeleteAction.php b/src/Control/Actions/ClientDeleteAction.php index 37e10f9..bad3e59 100644 --- a/src/Control/Actions/ClientDeleteAction.php +++ b/src/Control/Actions/ClientDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/ClientInfoAction.php b/src/Control/Actions/ClientInfoAction.php index e4ee390..f6a8cf2 100644 --- a/src/Control/Actions/ClientInfoAction.php +++ b/src/Control/Actions/ClientInfoAction.php @@ -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', [ diff --git a/src/Control/Actions/ClientSendAction.php b/src/Control/Actions/ClientSendAction.php index a59f05d..3ad6a74 100644 --- a/src/Control/Actions/ClientSendAction.php +++ b/src/Control/Actions/ClientSendAction.php @@ -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); diff --git a/src/Control/Actions/ClientsAction.php b/src/Control/Actions/ClientsAction.php index c932f5f..66796e8 100644 --- a/src/Control/Actions/ClientsAction.php +++ b/src/Control/Actions/ClientsAction.php @@ -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', [ diff --git a/src/Control/Actions/ComplainDeleteAction.php b/src/Control/Actions/ComplainDeleteAction.php index 6f653b1..d31c05e 100644 --- a/src/Control/Actions/ComplainDeleteAction.php +++ b/src/Control/Actions/ComplainDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/ComplainsAction.php b/src/Control/Actions/ComplainsAction.php index 5a1d416..cbd9325 100644 --- a/src/Control/Actions/ComplainsAction.php +++ b/src/Control/Actions/ComplainsAction.php @@ -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', [ diff --git a/src/Control/Actions/GroupAddAction.php b/src/Control/Actions/GroupAddAction.php index 2df3d14..d6c315b 100644 --- a/src/Control/Actions/GroupAddAction.php +++ b/src/Control/Actions/GroupAddAction.php @@ -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')); diff --git a/src/Control/Actions/GroupDeleteAction.php b/src/Control/Actions/GroupDeleteAction.php index 4e29281..32d10b8 100644 --- a/src/Control/Actions/GroupDeleteAction.php +++ b/src/Control/Actions/GroupDeleteAction.php @@ -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')); diff --git a/src/Control/Actions/GroupInfoAction.php b/src/Control/Actions/GroupInfoAction.php index 8caa211..522bdc4 100644 --- a/src/Control/Actions/GroupInfoAction.php +++ b/src/Control/Actions/GroupInfoAction.php @@ -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', [ diff --git a/src/Control/Actions/GroupRemoveAction.php b/src/Control/Actions/GroupRemoveAction.php index b6f2b9a..107abd2 100644 --- a/src/Control/Actions/GroupRemoveAction.php +++ b/src/Control/Actions/GroupRemoveAction.php @@ -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')); diff --git a/src/Control/Actions/GroupsAction.php b/src/Control/Actions/GroupsAction.php index 08f828d..7fc6d38 100644 --- a/src/Control/Actions/GroupsAction.php +++ b/src/Control/Actions/GroupsAction.php @@ -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', [ diff --git a/src/Control/Actions/InstanceAction.php b/src/Control/Actions/InstanceAction.php index f439dc0..3d540cd 100644 --- a/src/Control/Actions/InstanceAction.php +++ b/src/Control/Actions/InstanceAction.php @@ -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']); diff --git a/src/Control/Actions/InstanceEditAction.php b/src/Control/Actions/InstanceEditAction.php index ca8e58c..e078701 100644 --- a/src/Control/Actions/InstanceEditAction.php +++ b/src/Control/Actions/InstanceEditAction.php @@ -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'); diff --git a/src/Control/Actions/LogsAction.php b/src/Control/Actions/LogsAction.php index cd1c330..c76650b 100644 --- a/src/Control/Actions/LogsAction.php +++ b/src/Control/Actions/LogsAction.php @@ -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', [ diff --git a/src/Control/Actions/OnlineAction.php b/src/Control/Actions/OnlineAction.php index d2eb886..9c83bfa 100644 --- a/src/Control/Actions/OnlineAction.php +++ b/src/Control/Actions/OnlineAction.php @@ -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', [ diff --git a/src/Control/Actions/OnlineBanAction.php b/src/Control/Actions/OnlineBanAction.php index 92c7111..602e87b 100644 --- a/src/Control/Actions/OnlineBanAction.php +++ b/src/Control/Actions/OnlineBanAction.php @@ -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); diff --git a/src/Control/Actions/OnlineInfoAction.php b/src/Control/Actions/OnlineInfoAction.php index 004e0bc..c803924 100644 --- a/src/Control/Actions/OnlineInfoAction.php +++ b/src/Control/Actions/OnlineInfoAction.php @@ -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', [ diff --git a/src/Control/Actions/OnlineKickAction.php b/src/Control/Actions/OnlineKickAction.php index 5043f2a..700498f 100644 --- a/src/Control/Actions/OnlineKickAction.php +++ b/src/Control/Actions/OnlineKickAction.php @@ -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); diff --git a/src/Control/Actions/OnlinePokeAction.php b/src/Control/Actions/OnlinePokeAction.php index b4ec583..e55f55a 100644 --- a/src/Control/Actions/OnlinePokeAction.php +++ b/src/Control/Actions/OnlinePokeAction.php @@ -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); diff --git a/src/Control/Actions/OnlineSendAction.php b/src/Control/Actions/OnlineSendAction.php index 8078928..ed0c1f9 100644 --- a/src/Control/Actions/OnlineSendAction.php +++ b/src/Control/Actions/OnlineSendAction.php @@ -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); diff --git a/src/Control/Actions/ProfileAction.php b/src/Control/Actions/ProfileAction.php index 588da84..eac7497 100644 --- a/src/Control/Actions/ProfileAction.php +++ b/src/Control/Actions/ProfileAction.php @@ -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', [ diff --git a/src/Control/Actions/ProfileCredentialsChangeAction.php b/src/Control/Actions/ProfileCredentialsChangeAction.php index 7a8465c..248b4d6 100644 --- a/src/Control/Actions/ProfileCredentialsChangeAction.php +++ b/src/Control/Actions/ProfileCredentialsChangeAction.php @@ -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(); diff --git a/src/Control/Actions/ServerCreateAction.php b/src/Control/Actions/ServerCreateAction.php index 520c174..a8b5b11 100644 --- a/src/Control/Actions/ServerCreateAction.php +++ b/src/Control/Actions/ServerCreateAction.php @@ -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'); diff --git a/src/Control/Actions/ServerDeleteAction.php b/src/Control/Actions/ServerDeleteAction.php index 8817524..17b6ea2 100644 --- a/src/Control/Actions/ServerDeleteAction.php +++ b/src/Control/Actions/ServerDeleteAction.php @@ -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'); diff --git a/src/Control/Actions/ServerEditAction.php b/src/Control/Actions/ServerEditAction.php index 9e02e8d..c4e1396 100644 --- a/src/Control/Actions/ServerEditAction.php +++ b/src/Control/Actions/ServerEditAction.php @@ -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); diff --git a/src/Control/Actions/ServerInfoAction.php b/src/Control/Actions/ServerInfoAction.php index df29fae..a347439 100644 --- a/src/Control/Actions/ServerInfoAction.php +++ b/src/Control/Actions/ServerInfoAction.php @@ -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', [ diff --git a/src/Control/Actions/ServerSendAction.php b/src/Control/Actions/ServerSendAction.php index 0f0067b..b4d2cab 100644 --- a/src/Control/Actions/ServerSendAction.php +++ b/src/Control/Actions/ServerSendAction.php @@ -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); diff --git a/src/Control/Actions/ServerStartAction.php b/src/Control/Actions/ServerStartAction.php index 8a4b4c8..1ceb5fe 100644 --- a/src/Control/Actions/ServerStartAction.php +++ b/src/Control/Actions/ServerStartAction.php @@ -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'); diff --git a/src/Control/Actions/ServerStopAction.php b/src/Control/Actions/ServerStopAction.php index 139d1a7..5de5df2 100644 --- a/src/Control/Actions/ServerStopAction.php +++ b/src/Control/Actions/ServerStopAction.php @@ -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'); diff --git a/src/Control/Actions/ServersAction.php b/src/Control/Actions/ServersAction.php index d75c284..fd7abe3 100644 --- a/src/Control/Actions/ServersAction.php +++ b/src/Control/Actions/ServersAction.php @@ -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', [ diff --git a/src/Util/Auth/TSAuthAdapter.php b/src/Util/Auth/TSAuthAdapter.php index c4462a0..ff8dec2 100644 --- a/src/Util/Auth/TSAuthAdapter.php +++ b/src/Util/Auth/TSAuthAdapter.php @@ -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()); diff --git a/src/Util/TS3AdminProxy.php b/src/Util/TS3AdminProxy.php new file mode 100644 index 0000000..e5532f9 --- /dev/null +++ b/src/Util/TS3AdminProxy.php @@ -0,0 +1,68 @@ +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; + } +} \ No newline at end of file diff --git a/src/Util/TSInstance.php b/src/Util/TSInstance.php index 293e845..808f0b9 100644 --- a/src/Util/TSInstance.php +++ b/src/Util/TSInstance.php @@ -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 */ diff --git a/src/View/material/online.twig b/src/View/material/online.twig index 71bead1..5713d2c 100644 --- a/src/View/material/online.twig +++ b/src/View/material/online.twig @@ -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'},