Archived
1
0
Fork 0

Use session for selecting a server

This commit is contained in:
Varakh 2018-04-05 12:30:06 +02:00
parent fab76db397
commit 9446d0280a
13 changed files with 127 additions and 54 deletions

View file

@ -12,7 +12,8 @@
"jeremykendall/slim-auth": "dev-slim-3.x",
"par0noid/ts3admin": "^1.0",
"planetteamspeak/ts3-php-framework": "^1.1",
"nesbot/carbon": "^1.25"
"nesbot/carbon": "^1.25",
"bryanjhv/slim-session": "^3.5"
},
"config": {
"bin-dir": "bin/"

View file

@ -28,11 +28,12 @@ class ACL extends \Zend\Permissions\Acl\Acl
'/instance',
'/instance/edit',
'/logs',
'/logs[/{sid}]',
'/servers',
'/servers/create',
'/servers/{sid}',
'/servers/select/{sid}',
'/servers/delete/{sid}',
'/servers/start/{sid}',
'/servers/stop/{sid}',

View file

@ -56,7 +56,7 @@ $app->get('/profile/credentials', ProfileCredentialsChangeAction::class);
$container[LogsAction::class] = function ($container) {
return new LogsAction($container);
};
$app->get('/logs', LogsAction::class);
$app->get('/logs[/{sid}]', LogsAction::class);
// instance
$container[InstanceAction::class] = function ($container) {
@ -80,6 +80,11 @@ $container[ServerCreateAction::class] = function ($container) {
};
$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) {
return new ServerDeleteAction($container);
};

View file

@ -53,13 +53,22 @@ validate_valid_url: "The %field% field is required to be a valid URL."
# menu
menu.instance: "Instance"
menu.servers: "Servers"
menu.logs: "Logs"
menu.logs: "Instance Log"
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
instance.title: "Instance"
servers.title: "Servers"
logs.title: "Latest 100 Logs"
logs.title: "Latest 100 Log Entries"
server_info.title: "Server Info"
online.title: "Online Clients"
online_info.title: "Online Info"
@ -94,11 +103,7 @@ instance_edit.edited.success: "Edited instance."
servers.noneselected: "Cannot find server."
servers.start: "Start"
servers.stop: "Stop"
servers.channels: "Channels"
servers.clients: "Clients"
servers.groups: "Groups"
servers.bans: "Bans"
servers.complains: "Complains"
servers.select: "Select"
servers.delete: "Delete"
servers.started.success: "Started virtual server %sid%."
servers.stopped.success: "Stopped virtual server %sid%."

View file

@ -75,14 +75,22 @@ $container['authAdapter'] = function ($container) {
$adapter = new TSAuthAdapter(getenv('teamspeak_default_host'), getenv('teamspeak_default_query_port'), $container['logger'], $container['ts']);
return $adapter;
};
$container['acl'] = function () {
return new ACL();
};
$container->register(new \JeremyKendall\Slim\Auth\ServiceProvider\SlimAuthProvider());
$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
$container['flash'] = function () {
return new Slim\Flash\Messages;
@ -137,6 +145,16 @@ $container['view'] = function ($container) use ($app) {
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
$view['flash'] = $container['flash'];

View file

@ -41,6 +41,11 @@ abstract class AbstractAction
*/
protected $translator;
/**
* @var \SlimSession\Helper
*/
protected $session;
/**
* @var TSInstance
*/
@ -58,6 +63,8 @@ abstract class AbstractAction
$this->auth = $container->get('authenticator');
$this->acl = $container->get('acl');
$this->translator = $container->get('translator');
$this->session = $container->get('session');
$this->ts = $container->get('ts');
}

View file

@ -11,8 +11,9 @@ final class AuthLogoutAction extends AbstractAction
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
$this->ts->getInstance()->logout();
$this->auth->logout();
$this->session->clear();
return $response->withRedirect('/login');
}
}

View file

@ -7,9 +7,15 @@ final class LogsAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
$sid = $args['sid'];
$dataResult = $this->ts->getInstance()->logView(100, 1, 1);
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
if (empty($sid)) {
$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
$this->view->render($response, 'logs.twig', [

View file

@ -8,6 +8,11 @@ final class ProfileAction extends AbstractAction
public function __invoke(Request $request, Response $response, $args)
{
$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();
// render GET

View 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');
}
}

View file

@ -4,15 +4,46 @@
<a href="/instance">
<li class="active withripple" data-target="#page">{% trans %}menu.instance{% endtrans %}</li>
</a>
<a href="/servers">
<li class="active withripple" data-target="#page">{% trans %}menu.servers{% endtrans %}</li>
</a>
<a href="/logs">
<li class="active withripple" data-target="#page">{% trans %}menu.logs{% endtrans %}</li>
</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">
<li class="active withripple" data-target="#page">{% trans %}menu.profile{% endtrans %}</li>
</a>
<a href="/logout">
<li class="active withripple" data-target="#page">{% trans %}menu.logout{% endtrans %}</li>
</a>

View file

@ -2,9 +2,9 @@
{% block content %}
<h1 class="header">{{ title }}</h1>
<pre class="small">
<div class="small">
{% for log in data %}
{{ log.l }}
<p>{{ log.l }}</p>
{% endfor %}
</pre>
</div>
{% endblock %}

View file

@ -5,7 +5,6 @@
<h2 class="header">{% trans %}servers.h.details{% endtrans %}</h2>
{% if data|length > 0 %}
<div class="small">
{% include 'table.twig' with {'data': data,
'filters': [
{'key': 'virtualserver_uptime', 'apply': 'timeInSeconds'},
@ -15,6 +14,12 @@
{'key': 'virtualserver_clientsonline', 'uri': '/online', 'uri_param': 'virtualserver_id'}
],
'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,
'label': '<i class="material-icons">arrow_forward</i>',
@ -27,36 +32,6 @@
'uri': '/servers/stop',
'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,
'label': '<i class="material-icons">delete</i>',
@ -69,8 +44,6 @@
{% include 'no_entities.twig' %}
{% endif %}
</div>
<h2 class="header">{% trans %}servers.h.create{% endtrans %}</h2>
{% include 'form.twig' with {
'additional_forms': [