Archived
1
0
Fork 0

cosmetic changes, tree view for online clients

This commit is contained in:
Varakh 2018-04-03 21:21:47 +02:00
parent 5db640e888
commit 0ffba9676b
9 changed files with 41 additions and 133 deletions

View file

@ -12,7 +12,8 @@
"jeremykendall/slim-auth": "dev-slim-3.x",
"phpmailer/phpmailer": "^5.2",
"illuminate/pagination": "^5.5",
"par0noid/ts3admin": "^1.0"
"par0noid/ts3admin": "^1.0",
"planetteamspeak/ts3-php-framework": "^1.1"
},
"config": {
"bin-dir": "bin/"

View file

@ -60,8 +60,10 @@ $container['logger'] = function () {
};
// teamspeak
$container['ts'] = function () {
return new TSInstance();
$ts = new TSInstance();
$_SESSION['_TS3'] = serialize($ts);
$container['ts'] = function () use ($ts) {
return $ts;
};
// auth
@ -138,7 +140,7 @@ $container['view'] = function ($container) use ($app) {
$view['flash'] = $container['flash'];
// currentUser, currentRole, ACL.isPermitted
$view['currentUser'] = ($container['authenticator']->hasIdentity() ? $container['authenticator']->getIdentity() : NULL); // currentUser in Twig
$view['currentUser'] = ($container['authenticator']->hasIdentity() ? $container['authenticator']->getIdentity() : NULL); // currentUser in twig
$view['currentRole'] = (!empty($user) ? $role = $user->role : $role = ACL::ACL_DEFAULT_ROLE_GUEST);
$view->getEnvironment()->addFunction(new Twig_SimpleFunction('isPermitted', function ($currentRole, $targetRole) use ($container) {

View file

@ -1,6 +1,5 @@
/* START: for rendering within block you should keep the following */
img {
display: block;
max-width: 100%;
height: auto;
}

View file

@ -16,10 +16,22 @@ final class OnlineAction extends AbstractAction
$dataResult = $this->ts->getInstance()->clientList();
$this->ts->checkCommandResult($dataResult);
$instance = TeamSpeak3::factory(sprintf("serverquery://%s:%s@%s:%s/?server_id=%s",
$this->auth->getIdentity()['user'],
$this->auth->getIdentity()['password'],
$this->ts->getHost(),
$this->ts->getQueryPort(),
$sid)
);
$treeView = new TeamSpeak3_Viewer_Html("/images/viewer/", "/images/flags/", "data:image");
$tree = $instance->getViewer($treeView);
// render GET
$this->view->render($response, 'online.twig', [
'title' => $this->translator->trans('online.title'),
'data' => $this->ts->getInstance()->getElement('data', $dataResult),
'tree' => $tree,
'sid' => $sid
]);
}

View file

@ -1,35 +0,0 @@
<?php
class MailHelper
{
/**
* @param $receiverMail
* @param $subject
* @param $body
* @return bool
* @throws phpmailerException
*/
public static function sendMail($receiverMail, $subject, $body)
{
if (!empty(getenv('mail_enabled')) && getenv('mail_enabled') == 'true') {
$mailer = new PHPMailer();
$mailer->CharSet = 'UTF-8';
$mailer->ContentType = 'text/plain';
$mailer->isSMTP();
$mailer->SMTPSecure = getenv('mail_secure');
$mailer->SMTPAuth = getenv('mail_auth');
$mailer->Host = getenv('mail_host');
$mailer->Port = getenv('mail_port');
$mailer->Username = getenv('mail_username');
$mailer->Password = getenv('mail_password');
$mailer->From = getenv('mail_from');
$mailer->FromName = getenv('mail_from_name');
$mailer->addAddress($receiverMail);
$mailer->Subject = $subject;
$mailer->Body = $body;
return $mailer->send();
} else {
return false;
}
}
}

View file

@ -1,82 +0,0 @@
<?php
/**
* Class Pagination
* @desc Helper class for paginating Slim View and Eloquent Pagination
*/
class Pagination
{
const PAGE_NAME = 'page';
const PER_PAGE = 10;
const RENDER_TEMPLATE = 'pagination.twig';
private $request;
private $view;
private $pageName;
private $pageNameAfter;
/**
* Pagination constructor.
* @param \Slim\Http\Request $request
* @param \Slim\Views\Twig $view
* @param string $pageName
* @param null $pageNameAfter (e.g. for HTML anchors with #tag)
*/
public function __construct(\Slim\Http\Request &$request, \Slim\Views\Twig &$view, $pageName = self::PAGE_NAME, $pageNameAfter = NULL)
{
$this->request = $request;
$this->view = $view;
$this->pageName = $pageName;
$this->pageNameAfter = $pageNameAfter;
}
/**
* Get current page from pageName parameter
* @return int|mixed
*/
public function resolveCurrentPage()
{
$page = $this->request->getParam($this->pageName, 1);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return $page;
}
return 1;
}
/**
* Fetches required information for rendering, used Eloquent Paginator. The array keys should match your view
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @return array
*/
public function fetchPaginationDetails(\Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator)
{
return [
'currentPage' => $paginator->currentPage(),
'lastPage' => ceil($paginator->total()/$paginator->perPage()),
'paginationPath' => $this->request->getUri()->getPath() . '?' . $this->pageName . '=',
'pageName' => $this->pageName,
'pageNameAfter' => $this->pageNameAfter
];
}
/**
* @return string
*/
public function getPageName()
{
return $this->pageName;
}
/**
* Generate links with the help of the given $view
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @param string $template
* @return string (html)
*/
public function links(\Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator, $template = self::RENDER_TEMPLATE)
{
return $this->view->fetch($template, $this->fetchPaginationDetails($paginator));
}
}

View file

@ -2,15 +2,24 @@
{% block content %}
<h1 class="header">{{ title }}</h1>
{% if data|length >0 %}
{% include 'table.twig' with {'data': data,
'hide': [{'key': 'client_type', 'values': ['1']}],
'links': [
{'key': 'clid', 'uri': '/online/' ~ sid},
{'key': 'client_database_id', 'uri': '/clients/' ~ sid, 'uri_param': 'client_database_id'}
],
} %}
{% else %}
{% include 'no_entities.twig' %}
{% endif %}
<div class="row">
<div class="col-md-4 small">
{{ tree|raw }}
</div>
<div class="col-md-8">
{% if data|length >0 %}
{% include 'table.twig' with {'data': data,
'hide': [{'key': 'client_type', 'values': ['1']}],
'links': [
{'key': 'clid', 'uri': '/online/' ~ sid},
{'key': 'cid', 'uri': '/channels/' ~ sid, 'uri_param': 'cid'},
{'key': 'client_database_id', 'uri': '/clients/' ~ sid, 'uri_param': 'client_database_id'}
],
} %}
{% else %}
{% include 'no_entities.twig' %}
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -49,6 +49,8 @@
{'key': 'virtualserver_port', 'type': 'number', 'uri': '/servers/edit/' ~ sid, 'uri_method': 'post', 'submit_label': '<i class="material-icons">check_circle</i>'},
{'key': 'virtualserver_weblist_enabled', 'type': 'checkbox', 'uri': '/servers/edit/' ~ sid, 'uri_method': 'post', 'submit_label': '<i class="material-icons">check_circle</i>'},
{'key': 'virtualserver_autostart', 'type': 'checkbox', 'uri': '/servers/edit/' ~ sid, 'uri_method': 'post', 'submit_label': '<i class="material-icons">check_circle</i>'},
{'key': 'virtualserver_min_android_version', 'type': 'number', 'uri': '/servers/edit/' ~ sid, 'uri_method': 'post', 'submit_label': '<i class="material-icons">check_circle</i>'},
{'key': 'virtualserver_min_ios_version', 'type': 'number', 'uri': '/servers/edit/' ~ sid, 'uri_method': 'post', 'submit_label': '<i class="material-icons">check_circle</i>'},
]
} %}