Browse Source

add online sessions info

main 1.1.0
ghost 1 year ago
parent
commit
fd3a601412
  1. 5
      .env
  2. 1
      config/services.yaml
  3. 45
      src/Controller/ModuleController.php
  4. 5
      templates/default/layout.html.twig
  5. 2
      templates/default/module/info.html.twig

5
.env

@ -19,7 +19,7 @@ APP_ENV=dev @@ -19,7 +19,7 @@ APP_ENV=dev
APP_SECRET=EDIT_ME
###< symfony/framework-bundle ###
APP_VERSION=1.0.3
APP_VERSION=1.1.0
APP_NAME=KevaChat
@ -61,6 +61,9 @@ APP_KEVACOIN_ROOM_NAMESPACE_DEFAULT=EDIT_ME @@ -61,6 +61,9 @@ APP_KEVACOIN_ROOM_NAMESPACE_DEFAULT=EDIT_ME
# Allow users to read external node rooms
APP_KEVACOIN_ROOM_NAMESPACES_EXTERNAL=
# Online session expiration timeout
APP_SESSION_ONLINE_TIMEOUT=900
# Allow remotes to create new rooms (namespaces)
APP_ADD_ROOM_REMOTE_IP_REGEX=/.*/

1
config/services.yaml

@ -23,6 +23,7 @@ parameters: @@ -23,6 +23,7 @@ parameters:
app.kevacoin.explorer.url: '%env(APP_KEVACOIN_EXPLORER_URL)%'
app.kevacoin.mine.pool.url: '%env(APP_KEVACOIN_MINE_POOL_URL)%'
app.kevacoin.mine.solo.url: '%env(APP_KEVACOIN_MINE_SOLO_URL)%'
app.session.online.timeout: '%env(APP_SESSION_ONLINE_TIMEOUT)%'
app.add.room.remote.ip.regex: '%env(APP_ADD_ROOM_REMOTE_IP_REGEX)%'
app.add.post.remote.ip.regex: '%env(APP_ADD_POST_REMOTE_IP_REGEX)%'
app.add.post.remote.ip.delay: '%env(APP_ADD_POST_REMOTE_IP_DELAY)%'

45
src/Controller/ModuleController.php

@ -10,8 +10,11 @@ use Symfony\Component\HttpFoundation\Request; @@ -10,8 +10,11 @@ use Symfony\Component\HttpFoundation\Request;
class ModuleController extends AbstractController
{
public function info(): Response
public function info(
Request $request
): Response
{
// Connect kevacoin
$client = new \Kevachat\Kevacoin\Client(
$this->getParameter('app.kevacoin.protocol'),
$this->getParameter('app.kevacoin.host'),
@ -20,9 +23,49 @@ class ModuleController extends AbstractController @@ -20,9 +23,49 @@ class ModuleController extends AbstractController
$this->getParameter('app.kevacoin.password')
);
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
// Get sessions registry
$online = md5(
sprintf(
'%s.ModuleController::info:sessions',
__DIR__
)
);
// Drop offline sessions
$sessions = [];
foreach ((array) $memcached->get($online) as $ip => $time)
{
if (time() - $time < $this->getParameter('app.session.online.timeout'))
{
$sessions[$ip] = $time;
}
}
// Update current session time
$sessions[$request->getClientIp()] = time();
// Update session registry
$memcached->set(
$online,
$sessions,
$this->getParameter('app.session.online.timeout')
);
// Render the template
return $this->render(
'default/module/info.html.twig',
[
'online' => count(
$sessions
),
'wallet' =>
[
'balance' => (float) $client->getBalance(),

5
templates/default/layout.html.twig

@ -20,7 +20,10 @@ @@ -20,7 +20,10 @@
{{
render(
controller(
'App\\Controller\\ModuleController::info'
'App\\Controller\\ModuleController::info',
{
request : request
}
)
)
}}

2
templates/default/module/info.html.twig

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
<div>
{{ 'online:' | trans }} {{ online }}
/
{{ 'block:' | trans }} {{ wallet.block }}
/
{{ 'balance:' | trans }} {{ wallet.balance }}

Loading…
Cancel
Save