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

Commit 6d83786

Browse files
author
Moritz Walter
committed
Merge remote-tracking branch 'origin/1.0_alpha1' into 1.0_alpha1
# Conflicts: # pages/webinterface/index.php # public/index.php
2 parents deb835a + 1c992dd commit 6d83786

File tree

12 files changed

+275
-216
lines changed

12 files changed

+275
-216
lines changed

config/config-sample.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

config/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$version = array(
33
"version" => "1.0_alpha1",
4-
"version_url" => "https://111project.the-systems.eu/api/resource/?resourceid=14&type=allinfos"
4+
"version_url" => "https://project.the-systems.eu/api/resource/?resourceid=14&type=allinfos"
55
);

pages/footer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
</div>
32
</div>
43
</body>
@@ -8,12 +7,11 @@
87
} else {
98
document.querySelector('html').classList.remove('dark')
109
}
11-
1210
</script>
1311
<script>
14-
document.getElementById('switchTheme').addEventListener('click', function() {
12+
document.getElementById('switchTheme').addEventListener('click', function () {
1513
let htmlClasses = document.querySelector('html').classList;
16-
if(localStorage.theme == 'dark') {
14+
if (localStorage.theme == 'dark') {
1715
htmlClasses.remove('dark');
1816
localStorage.removeItem('theme')
1917
} else {

pages/header.php

Lines changed: 72 additions & 26 deletions
Large diffs are not rendered by default.

pages/small-header.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<link href="assets/styles.css" rel="stylesheet">
7-
<script src="./assets/js/charts-ram.js" defer></script>
8-
<script src="./assets/js/charts-cpu.js" defer></script>
4+
<meta charset="UTF-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<link href="../public/assets/styles.css" rel="stylesheet">
7+
<script src="../public/assets/js/charts-ram.js" defer></script>
8+
<script src="../public/assets/js/charts-cpu.js" defer></script>
99
</head>
1010
<body class="dark:bg-gray-900 bg-gray-100">
1111
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>

pages/webinterface/index.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
<?= $nodes = \webinterface\main::buildRequest("cluster", $_SESSION['cn3-wi-access_token'], "GET"); ?>
21
<?php
2+
3+
use webinterface\main;
4+
5+
$nodes = main::buildDefaultRequest("cluster", "GET");
6+
37
$services = 0;
8+
$currentVersion = "Unknown";
9+
10+
$connectedNodeCount = 0;
11+
$totalNodeCount = sizeof($nodes);
12+
413
$memory_min = 0;
514
$memory_max = 0;
6-
foreach($nodes['nodes'] as $node){
15+
16+
$cpu_used = 0;
17+
$cpu_max = 0;
18+
19+
foreach ($nodes['nodes'] as $node) {
20+
if ($node['available'] === false) {
21+
continue;
22+
}
23+
24+
$connectedNodeCount++;
25+
26+
$currentVersion = $node['nodeInfoSnapshot']['version'];
727
$services += $node['nodeInfoSnapshot']['currentServicesCount'];
28+
829
$memory_max += $node['nodeInfoSnapshot']['maxMemory'];
930
$memory_min += $node['nodeInfoSnapshot']['usedMemory'];
31+
32+
$cpu_max += 100;
33+
$cpu_used += min(round($node['nodeInfoSnapshot']['processSnapshot']['cpuUsage'] * 100), 100);
1034
}
1135
?>
36+
1237
<main class="w-full flex-grow p-6">
1338
<div class="py-1">
1439
<main class="h-full overflow-y-auto">
@@ -17,11 +42,11 @@
1742
<!--Users-->
1843
<div class="flex items-center p-4 dark:bg-gray-800 bg-white rounded-lg shadow-lg">
1944
<div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full">
20-
<img src="assets/icons/user.svg"/>
45+
<img src="assets/icons/cluster.png"/>
2146
</div>
2247
<div>
23-
<p class="mb-2 text-base font-medium text-gray-400">Users</p>
24-
<p class="text-xl font-semibold dark:text-white text-gray-900">35/100</p>
48+
<p class="mb-2 text-base font-medium text-gray-400">Connected nodes</p>
49+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $connectedNodeCount ?>/<?= $totalNodeCount ?></p>
2550
</div>
2651
</div>
2752
<!-- Servers -->
@@ -30,8 +55,8 @@
3055
<img src="assets/icons/server.svg"/>
3156
</div>
3257
<div>
33-
<p class="mb-2 text-base font-medium text-gray-400">Servers</p>
34-
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $services; ?></p>
58+
<p class="mb-2 text-base font-medium text-gray-400">Service count</p>
59+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $services ?></p>
3560
</div>
3661
</div>
3762
<!-- CPU -->
@@ -41,7 +66,7 @@
4166
</div>
4267
<div>
4368
<p class="mb-2 text-base font-medium text-gray-400">CPU</p>
44-
<p class="text-xl font-semibold dark:text-white text-gray-900">55%/100%</p>
69+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $cpu_used ?>%/<?= $cpu_max; ?>%</p>
4570
</div>
4671
</div>
4772
<!-- Ram -->
@@ -51,7 +76,8 @@
5176
</div>
5277
<div>
5378
<p class="mb-2 text-base font-medium text-gray-400">Ram</p>
54-
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $memory_min ?>MB/<?= $memory_max; ?>MB</p>
79+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $memory_min ?>
80+
MB/<?= $memory_max; ?>MB</p>
5581
</div>
5682
</div>
5783
</div>
@@ -128,7 +154,8 @@
128154
<div class="min-w-0 p-4 text-white bg-gradient-to-br from-red-600 to-red-800 rounded-lg shadow-xs">
129155
<h4 class="mb-4 font-bold">Warning!</h4>
130156
<p>
131-
Currently you are using an outdated CloudNet version (${version}), to keep the Cloud up to date and
157+
Currently you are using an outdated CloudNet version (<?= $currentVersion ?>), to keep the Cloud up to
158+
date and
132159
to get support, you can activate the auto updater in the launcher.cnl file.
133160
</p>
134161
</div>

pages/webinterface/login.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<div class="w-full h-screen flex items-center justify-center">
22
<form class="w-full md:w-1/3 bg-white rounded-lg" method="post">
33
<input name="action" value="login" type="hidden">
4-
<input name="csrf" value="<?= $_SESSION['cn3-wi-csrf']; ?>" type="hidden">
54
<div class="flex font-bold justify-center mt-6">
65
<img class="h-20 w-20"
76
src="https://raw.githubusercontent.com/sefyudem/Responsive-Login-Form/master/img/avatar.svg">
87
</div>
9-
<h2 class="text-3xl text-center text-gray-700 mb-4">Login Form</h2>
8+
<h2 class="text-3xl text-center text-gray-700 mb-4">Interface login</h2>
109
<div class="px-12 pb-10">
1110
<div class="w-full mb-2">
1211
<div class="flex items-center">
1312
<i class='ml-3 fill-current text-gray-400 text-xs z-10 fas fa-user'></i>
1413
<input type='text' placeholder="Username" name="username"
15-
class="-mx-6 px-8 w-full border rounded px-3 py-2 text-gray-700 focus:outline-none" />
14+
class="-mx-6 px-8 w-full border rounded px-3 py-2 text-gray-700 focus:outline-none"/>
1615
</div>
1716
</div>
1817
<div class="w-full mb-2">
1918
<div class="flex items-center">
2019
<i class='ml-3 fill-current text-gray-400 text-xs z-10 fas fa-lock'></i>
21-
<input type='password' placeholder="Password" name="password"
22-
class="-mx-6 px-8 w-full border rounded px-3 py-2 text-gray-700 focus:outline-none" />
20+
<input type='password' placeholder="Password" name="password" autocomplete="off"
21+
class="-mx-6 px-8 w-full border rounded px-3 py-2 text-gray-700 focus:outline-none"/>
2322
</div>
2423
</div>
25-
<a href="#" class="text-xs text-gray-500 float-right mb-4">Forgot Password?</a>
24+
<br />
2625
<button type="submit"
27-
class="w-full py-2 rounded-full bg-green-600 text-gray-100 focus:outline-none">Login</button>
26+
class="w-full py-2 rounded-full bg-green-600 text-gray-100 focus:outline-none">Login
27+
</button>
2828
</form>
2929
</div>

public/assets/icons/cluster.png

1.23 KB
Loading

public/index.php

Lines changed: 49 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,68 @@
11
<?php
22

33
use webinterface\main;
4+
use webinterface\fileController;
5+
use webinterface\authorizeController;
46

5-
session_start();
6-
7-
define('DS', DIRECTORY_SEPARATOR, true);
8-
define('BASE_PATH', __DIR__ . DS, TRUE);
9-
10-
11-
$path_vendor = __DIR__ . '/../vendor/autoload.php';
12-
$path_config = BASE_PATH . '../config/config.php';
13-
$path_version = BASE_PATH . '../config/version.php';
14-
$path_message = BASE_PATH . '../config/messages.json';
15-
16-
if (file_exists($path_vendor)) {
17-
require $path_vendor;
18-
} else {
19-
echo '<h1><span style="color: #FF0000">Ein Fehler ist aufgetreten.</span></h1><h3>Die Datei "/vendor/autoload.php" konnte nicht gefunden werden.</h3><h3>Führe im Webseiten-Root "composer install" aus!</h3>';
20-
die();
21-
}
22-
23-
if (file_exists($path_config)) {
24-
require $path_config;
25-
} else { die('<h1><span style="color: #FF0000">Ein Fehler ist aufgetreten.</span></h1><h3>Die Datei "/config/config.php" konnte nicht gefunden werden.</h3><h3>Führe das Setup mit "wisetup" im Master erneut aus!</h3>');
26-
}
27-
28-
if (file_exists($path_version)) {
29-
require $path_version;
30-
} else {
31-
die('<h1><span style="color: #FF0000">Ein Fehler ist aufgetreten.</span></h1><h3>Die Datei "/config/version.php" konnte nicht gefunden werden</h3><h3>Führe das Setup mit "wisetup" im Master erneut aus!</h3>');
32-
}
33-
34-
if (!file_exists($path_message)) {
35-
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>');
36-
}
7+
// require some files
8+
require __DIR__ . '/../vendor/autoload.php';
9+
// ensure all necessary files are there
10+
fileController::dieWhenFileMissing();
3711

38-
if(!isset($_SESSION['cn3-wi-csrf'])) $_SESSION['cn3-wi-csrf'] = uniqid('', true);
12+
// files
13+
require fileController::getVersionFilePath();
14+
require fileController::getConfigurationPath();
3915

40-
$main = new webinterface\main($config, $version);
16+
// create instance of main controller
17+
$main = new main($config, $version);
4118

19+
// create app route controller
4220
$app = System\App::instance();
4321
$app->request = System\Request::instance();
4422
$app->route = System\Route::instance($app->request);
4523

46-
$route = $app->route;
24+
// check if we already have a session
25+
session_start();
4726

48-
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());
27+
$app->route->any('/', function () use ($main) {
28+
if (isset($_GET['action']) and $_GET['action'] == "logout") {
29+
session_unset();
30+
header('Location: ' . strtok($_SERVER["REQUEST_URI"], '?'));
5331
die();
54-
}
55-
56-
57-
$route->any('/', function () {
58-
if(isset($_POST['action'])){
59-
if (isset($_POST['csrf'])) {
60-
if ($_POST['csrf'] != $_SESSION['csrf']) {
61-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
62-
die();
63-
}
64-
} else {
65-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
66-
die();
67-
}
68-
69-
if($_POST['action'] == "login" AND isset($_POST['username']) AND isset($_POST['password'])){
70-
$action = \webinterface\authorizeController::login($_POST['username'], $_POST['password']);
71-
if($action['success'] == true) {
72-
header('Location: ' . main::getUrl());
73-
} else {
74-
header('Location: ' . main::getUrl() . "/?action&success=false&message=loginFailed");
75-
}
76-
die();
77-
}
32+
} else if (isset($_SESSION['cn3-wi-access_token'])) {
33+
// try to refresh the session token
34+
$result = $main::buildDefaultRequest("session/refresh");
35+
if ($result['success'] === true) {
36+
// success, use the updated token and redirect to the dashboard
37+
$_SESSION['cn3-wi-access_token'] = $result['token'];
38+
redirectToDashboard();
39+
return;
40+
} else {
41+
// invalid token in session cache, just clear and run login
42+
session_unset();
7843
}
79-
80-
include "../pages/header.php";
81-
include "../pages/webinterface/index.php";
82-
include "../pages/footer.php";
83-
84-
});
85-
} else {
86-
$route->any('/', function () {
87-
if(isset($_POST['action'])){
88-
if (isset($_POST['cn3-wi-csrf'])) {
89-
if ($_POST['cn3-wi-csrf'] != $_SESSION['cn3-wi-csrf']) {
90-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
91-
die();
92-
}
93-
} else {
94-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
95-
die();
96-
}
97-
98-
if($_POST['action'] == "login" AND isset($_POST['username']) AND isset($_POST['password'])){
99-
$action = \webinterface\authorizeController::login($_POST['username'], $_POST['password']);
100-
if($action['success'] == true) {
101-
header('Location: ' . main::getUrl());
102-
} else {
103-
header('Location: ' . main::getUrl() . "/?action&success=false&message=loginFailed");
104-
}
105-
die();
106-
}
44+
} else if (isset($_POST['action']) and $_POST['action'] == "login" and isset($_POST['username']) and isset($_POST['password'])) {
45+
$loginResult = authorizeController::login($_POST['username'], $_POST['password']);
46+
if ($loginResult == LOGIN_RESULT_SUCCESS) {
47+
redirectToDashboard();
48+
return;
10749
}
50+
}
10851

109-
include "../pages/small-header.php";
110-
include "../pages/webinterface/login.php";
111-
include "../pages/footer.php";
52+
displayLoginPage();
53+
});
54+
$app->route->end();
11255

113-
});
56+
function displayLoginPage()
57+
{
58+
include "../pages/small-header.php";
59+
include "../pages/webinterface/login.php";
60+
include "../pages/footer.php";
11461
}
11562

116-
117-
$route->end();
63+
function redirectToDashboard()
64+
{
65+
include "../pages/header.php";
66+
include "../pages/webinterface/index.php";
67+
include "../pages/footer.php";
68+
}

0 commit comments

Comments
 (0)