Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit deb835a

Browse files
author
Moritz Walter
committed
show server and memory
1 parent 80f34cb commit deb835a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

pages/webinterface/index.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
<?= $nodes = \webinterface\main::buildRequest("cluster", $_SESSION['cn3-wi-access_token'], "GET"); ?>
2+
<?php
3+
$services = 0;
4+
$memory_min = 0;
5+
$memory_max = 0;
6+
foreach($nodes['nodes'] as $node){
7+
$services += $node['nodeInfoSnapshot']['currentServicesCount'];
8+
$memory_max += $node['nodeInfoSnapshot']['maxMemory'];
9+
$memory_min += $node['nodeInfoSnapshot']['usedMemory'];
10+
}
11+
?>
112
<main class="w-full flex-grow p-6">
213
<div class="py-1">
314
<main class="h-full overflow-y-auto">
@@ -20,7 +31,7 @@
2031
</div>
2132
<div>
2233
<p class="mb-2 text-base font-medium text-gray-400">Servers</p>
23-
<p class="text-xl font-semibold dark:text-white text-gray-900">10</p>
34+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $services; ?></p>
2435
</div>
2536
</div>
2637
<!-- CPU -->
@@ -40,7 +51,7 @@
4051
</div>
4152
<div>
4253
<p class="mb-2 text-base font-medium text-gray-400">Ram</p>
43-
<p class="text-xl font-semibold dark:text-white text-gray-900">100MB/500MB</p>
54+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $memory_min ?>MB/<?= $memory_max; ?>MB</p>
4455
</div>
4556
</div>
4657
</div>

public/index.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
die('<h1><span style="color: #FF0000">Ein Fehler ist aufgetreten.</span></h1><h3>Die Datei "/config/message.json" konnte nicht gefunden werden</h3><h3>Führe das Setup mit "wisetup" im Master erneut aus!</h3>');
3636
}
3737

38+
if(!isset($_SESSION['cn3-wi-csrf'])) $_SESSION['cn3-wi-csrf'] = uniqid('', true);
39+
3840
$main = new webinterface\main($config, $version);
3941

4042
$app = System\App::instance();
@@ -44,6 +46,14 @@
4446
$route = $app->route;
4547

4648
if(isset($_SESSION['cn3-wi-access_token'])){
49+
$user = main::buildRequest("auth", $_SESSION['cn3-wi-access_token'], "POST");
50+
if(!$user['success']){
51+
unset($_SESSION['cn3-wi-access_token']);
52+
header('Location: '.main::getUrl());
53+
die();
54+
}
55+
56+
4757
$route->any('/', function () {
4858
if(isset($_POST['action'])){
4959
if (isset($_POST['csrf'])) {
@@ -75,8 +85,8 @@
7585
} else {
7686
$route->any('/', function () {
7787
if(isset($_POST['action'])){
78-
if (isset($_POST['csrf'])) {
79-
if ($_POST['csrf'] != $_SESSION['csrf']) {
88+
if (isset($_POST['cn3-wi-csrf'])) {
89+
if ($_POST['cn3-wi-csrf'] != $_SESSION['cn3-wi-csrf']) {
8090
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
8191
die();
8292
}

0 commit comments

Comments
 (0)