Use session for selecting a server
This commit is contained in:
parent
fab76db397
commit
9446d0280a
13 changed files with 127 additions and 54 deletions
|
@ -12,7 +12,8 @@
|
||||||
"jeremykendall/slim-auth": "dev-slim-3.x",
|
"jeremykendall/slim-auth": "dev-slim-3.x",
|
||||||
"par0noid/ts3admin": "^1.0",
|
"par0noid/ts3admin": "^1.0",
|
||||||
"planetteamspeak/ts3-php-framework": "^1.1",
|
"planetteamspeak/ts3-php-framework": "^1.1",
|
||||||
"nesbot/carbon": "^1.25"
|
"nesbot/carbon": "^1.25",
|
||||||
|
"bryanjhv/slim-session": "^3.5"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"bin-dir": "bin/"
|
"bin-dir": "bin/"
|
||||||
|
|
|
@ -28,11 +28,12 @@ class ACL extends \Zend\Permissions\Acl\Acl
|
||||||
'/instance',
|
'/instance',
|
||||||
'/instance/edit',
|
'/instance/edit',
|
||||||
|
|
||||||
'/logs',
|
'/logs[/{sid}]',
|
||||||
|
|
||||||
'/servers',
|
'/servers',
|
||||||
'/servers/create',
|
'/servers/create',
|
||||||
'/servers/{sid}',
|
'/servers/{sid}',
|
||||||
|
'/servers/select/{sid}',
|
||||||
'/servers/delete/{sid}',
|
'/servers/delete/{sid}',
|
||||||
'/servers/start/{sid}',
|
'/servers/start/{sid}',
|
||||||
'/servers/stop/{sid}',
|
'/servers/stop/{sid}',
|
||||||
|
|
|
@ -56,7 +56,7 @@ $app->get('/profile/credentials', ProfileCredentialsChangeAction::class);
|
||||||
$container[LogsAction::class] = function ($container) {
|
$container[LogsAction::class] = function ($container) {
|
||||||
return new LogsAction($container);
|
return new LogsAction($container);
|
||||||
};
|
};
|
||||||
$app->get('/logs', LogsAction::class);
|
$app->get('/logs[/{sid}]', LogsAction::class);
|
||||||
|
|
||||||
// instance
|
// instance
|
||||||
$container[InstanceAction::class] = function ($container) {
|
$container[InstanceAction::class] = function ($container) {
|
||||||
|
@ -80,6 +80,11 @@ $container[ServerCreateAction::class] = function ($container) {
|
||||||
};
|
};
|
||||||
$app->post('/servers/create', ServerCreateAction::class);
|
$app->post('/servers/create', ServerCreateAction::class);
|
||||||
|
|
||||||
|
$container[ServerSelectAction::class] = function ($container) {
|
||||||
|
return new ServerSelectAction($container);
|
||||||
|
};
|
||||||
|
$app->get('/servers/select/{sid}', ServerSelectAction::class);
|
||||||
|
|
||||||
$container[ServerDeleteAction::class] = function ($container) {
|
$container[ServerDeleteAction::class] = function ($container) {
|
||||||
return new ServerDeleteAction($container);
|
return new ServerDeleteAction($container);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,13 +53,22 @@ validate_valid_url: "The %field% field is required to be a valid URL."
|
||||||
# menu
|
# menu
|
||||||
menu.instance: "Instance"
|
menu.instance: "Instance"
|
||||||
menu.servers: "Servers"
|
menu.servers: "Servers"
|
||||||
menu.logs: "Logs"
|
menu.logs: "Instance Log"
|
||||||
menu.profile: "Profile"
|
menu.profile: "Profile"
|
||||||
|
|
||||||
|
menu.servers.info: "Info"
|
||||||
|
menu.servers.online: "Online"
|
||||||
|
menu.servers.channels: "Channels"
|
||||||
|
menu.servers.clients: "Clients"
|
||||||
|
menu.servers.groups: "Groups"
|
||||||
|
menu.servers.bans: "Bans"
|
||||||
|
menu.servers.complains: "Complains"
|
||||||
|
menu.servers.logs: "Log"
|
||||||
|
|
||||||
# titles
|
# titles
|
||||||
instance.title: "Instance"
|
instance.title: "Instance"
|
||||||
servers.title: "Servers"
|
servers.title: "Servers"
|
||||||
logs.title: "Latest 100 Logs"
|
logs.title: "Latest 100 Log Entries"
|
||||||
server_info.title: "Server Info"
|
server_info.title: "Server Info"
|
||||||
online.title: "Online Clients"
|
online.title: "Online Clients"
|
||||||
online_info.title: "Online Info"
|
online_info.title: "Online Info"
|
||||||
|
@ -94,11 +103,7 @@ instance_edit.edited.success: "Edited instance."
|
||||||
servers.noneselected: "Cannot find server."
|
servers.noneselected: "Cannot find server."
|
||||||
servers.start: "Start"
|
servers.start: "Start"
|
||||||
servers.stop: "Stop"
|
servers.stop: "Stop"
|
||||||
servers.channels: "Channels"
|
servers.select: "Select"
|
||||||
servers.clients: "Clients"
|
|
||||||
servers.groups: "Groups"
|
|
||||||
servers.bans: "Bans"
|
|
||||||
servers.complains: "Complains"
|
|
||||||
servers.delete: "Delete"
|
servers.delete: "Delete"
|
||||||
servers.started.success: "Started virtual server %sid%."
|
servers.started.success: "Started virtual server %sid%."
|
||||||
servers.stopped.success: "Stopped virtual server %sid%."
|
servers.stopped.success: "Stopped virtual server %sid%."
|
||||||
|
|
|
@ -75,14 +75,22 @@ $container['authAdapter'] = function ($container) {
|
||||||
$adapter = new TSAuthAdapter(getenv('teamspeak_default_host'), getenv('teamspeak_default_query_port'), $container['logger'], $container['ts']);
|
$adapter = new TSAuthAdapter(getenv('teamspeak_default_host'), getenv('teamspeak_default_query_port'), $container['logger'], $container['ts']);
|
||||||
return $adapter;
|
return $adapter;
|
||||||
};
|
};
|
||||||
|
|
||||||
$container['acl'] = function () {
|
$container['acl'] = function () {
|
||||||
return new ACL();
|
return new ACL();
|
||||||
};
|
};
|
||||||
|
|
||||||
$container->register(new \JeremyKendall\Slim\Auth\ServiceProvider\SlimAuthProvider());
|
$container->register(new \JeremyKendall\Slim\Auth\ServiceProvider\SlimAuthProvider());
|
||||||
$app->add($app->getContainer()->get('slimAuthRedirectMiddleware'));
|
$app->add($app->getContainer()->get('slimAuthRedirectMiddleware'));
|
||||||
|
|
||||||
|
// session
|
||||||
|
$app->add(new \Slim\Middleware\Session([
|
||||||
|
'name' => 'dummy_session',
|
||||||
|
'autorefresh' => true,
|
||||||
|
'lifetime' => '1 hour'
|
||||||
|
]));
|
||||||
|
$container['session'] = function () {
|
||||||
|
return new \SlimSession\Helper;
|
||||||
|
};
|
||||||
|
|
||||||
// view
|
// view
|
||||||
$container['flash'] = function () {
|
$container['flash'] = function () {
|
||||||
return new Slim\Flash\Messages;
|
return new Slim\Flash\Messages;
|
||||||
|
@ -137,6 +145,16 @@ $container['view'] = function ($container) use ($app) {
|
||||||
return $res;
|
return $res;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// session exist
|
||||||
|
$view->getEnvironment()->addFunction(new Twig_SimpleFunction('session_exists', function($key) use ($container) {
|
||||||
|
return $container['session']->exists($key);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// session get
|
||||||
|
$view->getEnvironment()->addFunction(new Twig_SimpleFunction('session_get', function($key) use ($container) {
|
||||||
|
return $container['session']->get($key);
|
||||||
|
}));
|
||||||
|
|
||||||
// flash
|
// flash
|
||||||
$view['flash'] = $container['flash'];
|
$view['flash'] = $container['flash'];
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ abstract class AbstractAction
|
||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \SlimSession\Helper
|
||||||
|
*/
|
||||||
|
protected $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TSInstance
|
* @var TSInstance
|
||||||
*/
|
*/
|
||||||
|
@ -58,6 +63,8 @@ abstract class AbstractAction
|
||||||
$this->auth = $container->get('authenticator');
|
$this->auth = $container->get('authenticator');
|
||||||
$this->acl = $container->get('acl');
|
$this->acl = $container->get('acl');
|
||||||
$this->translator = $container->get('translator');
|
$this->translator = $container->get('translator');
|
||||||
|
|
||||||
|
$this->session = $container->get('session');
|
||||||
$this->ts = $container->get('ts');
|
$this->ts = $container->get('ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,9 @@ final class AuthLogoutAction extends AbstractAction
|
||||||
|
|
||||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||||
$this->ts->getInstance()->logout();
|
$this->ts->getInstance()->logout();
|
||||||
|
|
||||||
$this->auth->logout();
|
$this->auth->logout();
|
||||||
|
$this->session->clear();
|
||||||
|
|
||||||
return $response->withRedirect('/login');
|
return $response->withRedirect('/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,9 +7,15 @@ final class LogsAction extends AbstractAction
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request, Response $response, $args)
|
public function __invoke(Request $request, Response $response, $args)
|
||||||
{
|
{
|
||||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
$sid = $args['sid'];
|
||||||
|
|
||||||
|
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||||
|
if (empty($sid)) {
|
||||||
$dataResult = $this->ts->getInstance()->logView(100, 1, 1);
|
$dataResult = $this->ts->getInstance()->logView(100, 1, 1);
|
||||||
|
} else {
|
||||||
|
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||||
|
$dataResult = $this->ts->getInstance()->logView(100, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// render GET
|
// render GET
|
||||||
$this->view->render($response, 'logs.twig', [
|
$this->view->render($response, 'logs.twig', [
|
||||||
|
|
|
@ -8,6 +8,11 @@ final class ProfileAction extends AbstractAction
|
||||||
public function __invoke(Request $request, Response $response, $args)
|
public function __invoke(Request $request, Response $response, $args)
|
||||||
{
|
{
|
||||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||||
|
|
||||||
|
if ($this->session->exists('sid')) {
|
||||||
|
$selectResult = $this->ts->getInstance()->selectServer($this->session->get('sid'), 'serverId');
|
||||||
|
}
|
||||||
|
|
||||||
$whoisResult = $this->ts->getInstance()->whoAmI();
|
$whoisResult = $this->ts->getInstance()->whoAmI();
|
||||||
|
|
||||||
// render GET
|
// render GET
|
||||||
|
|
20
src/Control/Actions/ServerSelectAction.php
Normal file
20
src/Control/Actions/ServerSelectAction.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Slim\Http\Request;
|
||||||
|
use Slim\Http\Response;
|
||||||
|
|
||||||
|
final class ServerSelectAction extends AbstractAction
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
$sid = $args['sid'];
|
||||||
|
|
||||||
|
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||||
|
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||||
|
|
||||||
|
$this->session->set('sid', $sid);
|
||||||
|
|
||||||
|
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||||
|
return $response->withRedirect('/servers');
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,15 +4,46 @@
|
||||||
<a href="/instance">
|
<a href="/instance">
|
||||||
<li class="active withripple" data-target="#page">{% trans %}menu.instance{% endtrans %}</li>
|
<li class="active withripple" data-target="#page">{% trans %}menu.instance{% endtrans %}</li>
|
||||||
</a>
|
</a>
|
||||||
<a href="/servers">
|
|
||||||
<li class="active withripple" data-target="#page">{% trans %}menu.servers{% endtrans %}</li>
|
|
||||||
</a>
|
|
||||||
<a href="/logs">
|
<a href="/logs">
|
||||||
<li class="active withripple" data-target="#page">{% trans %}menu.logs{% endtrans %}</li>
|
<li class="active withripple" data-target="#page">{% trans %}menu.logs{% endtrans %}</li>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="/servers">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{% if session_exists('sid') %}
|
||||||
|
<hr/>
|
||||||
|
<a href="/servers/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.info{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/online/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.online{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/clients/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.clients{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/groups/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.groups{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/channels/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.channels{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/bans/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.bans{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/complains/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.complains{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<a href="/logs/{{ session_get('sid') }}">
|
||||||
|
<li class="active withripple" data-target="#page">{% trans %}menu.servers.logs{% endtrans %}</li>
|
||||||
|
</a>
|
||||||
|
<hr/>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<a href="/profile">
|
<a href="/profile">
|
||||||
<li class="active withripple" data-target="#page">{% trans %}menu.profile{% endtrans %}</li>
|
<li class="active withripple" data-target="#page">{% trans %}menu.profile{% endtrans %}</li>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/logout">
|
<a href="/logout">
|
||||||
<li class="active withripple" data-target="#page">{% trans %}menu.logout{% endtrans %}</li>
|
<li class="active withripple" data-target="#page">{% trans %}menu.logout{% endtrans %}</li>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1 class="header">{{ title }}</h1>
|
<h1 class="header">{{ title }}</h1>
|
||||||
<pre class="small">
|
<div class="small">
|
||||||
{% for log in data %}
|
{% for log in data %}
|
||||||
{{ log.l }}
|
<p>{{ log.l }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</pre>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
<h2 class="header">{% trans %}servers.h.details{% endtrans %}</h2>
|
<h2 class="header">{% trans %}servers.h.details{% endtrans %}</h2>
|
||||||
{% if data|length > 0 %}
|
{% if data|length > 0 %}
|
||||||
<div class="small">
|
|
||||||
{% include 'table.twig' with {'data': data,
|
{% include 'table.twig' with {'data': data,
|
||||||
'filters': [
|
'filters': [
|
||||||
{'key': 'virtualserver_uptime', 'apply': 'timeInSeconds'},
|
{'key': 'virtualserver_uptime', 'apply': 'timeInSeconds'},
|
||||||
|
@ -15,6 +14,12 @@
|
||||||
{'key': 'virtualserver_clientsonline', 'uri': '/online', 'uri_param': 'virtualserver_id'}
|
{'key': 'virtualserver_clientsonline', 'uri': '/online', 'uri_param': 'virtualserver_id'}
|
||||||
],
|
],
|
||||||
'additional_links': [
|
'additional_links': [
|
||||||
|
{
|
||||||
|
'header_label': 'servers.select'|trans,
|
||||||
|
'label': '<i class="material-icons">check_circle</i>',
|
||||||
|
'uri': '/servers/select',
|
||||||
|
'uri_param': 'virtualserver_id'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'header_label': 'servers.start'|trans,
|
'header_label': 'servers.start'|trans,
|
||||||
'label': '<i class="material-icons">arrow_forward</i>',
|
'label': '<i class="material-icons">arrow_forward</i>',
|
||||||
|
@ -27,36 +32,6 @@
|
||||||
'uri': '/servers/stop',
|
'uri': '/servers/stop',
|
||||||
'uri_param': 'virtualserver_id'
|
'uri_param': 'virtualserver_id'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'header_label': 'servers.clients'|trans,
|
|
||||||
'label': '<i class="material-icons">account_circle</i>',
|
|
||||||
'uri': '/clients',
|
|
||||||
'uri_param': 'virtualserver_id'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'header_label': 'servers.groups'|trans,
|
|
||||||
'label': '<i class="material-icons">group</i>',
|
|
||||||
'uri': '/groups',
|
|
||||||
'uri_param': 'virtualserver_id'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'header_label': 'servers.channels'|trans,
|
|
||||||
'label': '<i class="material-icons">settings_voice</i>',
|
|
||||||
'uri': '/channels',
|
|
||||||
'uri_param': 'virtualserver_id'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'header_label': 'servers.bans'|trans,
|
|
||||||
'label': '<i class="material-icons">account_box</i>',
|
|
||||||
'uri': '/bans',
|
|
||||||
'uri_param': 'virtualserver_id'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'header_label': 'servers.complains'|trans,
|
|
||||||
'label': '<i class="material-icons">report_problem</i>',
|
|
||||||
'uri': '/complains',
|
|
||||||
'uri_param': 'virtualserver_id'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
'header_label': 'servers.delete'|trans,
|
'header_label': 'servers.delete'|trans,
|
||||||
'label': '<i class="material-icons">delete</i>',
|
'label': '<i class="material-icons">delete</i>',
|
||||||
|
@ -69,8 +44,6 @@
|
||||||
{% include 'no_entities.twig' %}
|
{% include 'no_entities.twig' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2 class="header">{% trans %}servers.h.create{% endtrans %}</h2>
|
<h2 class="header">{% trans %}servers.h.create{% endtrans %}</h2>
|
||||||
{% include 'form.twig' with {
|
{% include 'form.twig' with {
|
||||||
'additional_forms': [
|
'additional_forms': [
|
||||||
|
|
Reference in a new issue