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

Commit 938f57e

Browse files
committed
Initial cleanups & rewrites
1 parent 80f34cb commit 938f57e

File tree

11 files changed

+270
-196
lines changed

11 files changed

+270
-196
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: 69 additions & 23 deletions
Large diffs are not rendered by default.

pages/small-header.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
4+
<meta charset="UTF-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
66
<link href="assets/styles.css" rel="stylesheet">
77
<script src="./assets/js/charts-ram.js" defer></script>
88
<script src="./assets/js/charts-cpu.js" defer></script>

pages/webinterface/index.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
<?php
2+
3+
use webinterface\main;
4+
5+
$nodes = main::buildRequest("cluster", $_SESSION['cn3-wi-access_token'], "GET");
6+
7+
$services = 0;
8+
9+
$memory_min = 0;
10+
$memory_max = 0;
11+
12+
$cpu_used = 0;
13+
$cpu_max = 0;
14+
15+
foreach ($nodes['nodes'] as $node) {
16+
if ($node['available'] === false) {
17+
continue;
18+
}
19+
20+
$services += $node['nodeInfoSnapshot']['currentServicesCount'];
21+
22+
$memory_max += $node['nodeInfoSnapshot']['maxMemory'];
23+
$memory_min += $node['nodeInfoSnapshot']['usedMemory'];
24+
25+
$cpu_max += 100;
26+
$cpu_used += min(round($node['nodeInfoSnapshot']['processSnapshot']['cpuUsage'] * 100), 100);
27+
}
28+
?>
29+
130
<main class="w-full flex-grow p-6">
231
<div class="py-1">
332
<main class="h-full overflow-y-auto">
@@ -19,8 +48,8 @@
1948
<img src="assets/icons/server.svg"/>
2049
</div>
2150
<div>
22-
<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>
51+
<p class="mb-2 text-base font-medium text-gray-400">Service count</p>
52+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $services ?></p>
2453
</div>
2554
</div>
2655
<!-- CPU -->
@@ -30,7 +59,8 @@
3059
</div>
3160
<div>
3261
<p class="mb-2 text-base font-medium text-gray-400">CPU</p>
33-
<p class="text-xl font-semibold dark:text-white text-gray-900">55%/100%</p>
62+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $cpu_used ?>
63+
%/<?= $cpu_max; ?>%</p>
3464
</div>
3565
</div>
3666
<!-- Ram -->
@@ -40,7 +70,8 @@
4070
</div>
4171
<div>
4272
<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>
73+
<p class="text-xl font-semibold dark:text-white text-gray-900"><?= $memory_min ?>
74+
MB/<?= $memory_max; ?>MB</p>
4475
</div>
4576
</div>
4677
</div>
@@ -117,7 +148,8 @@
117148
<div class="min-w-0 p-4 text-white bg-gradient-to-br from-red-600 to-red-800 rounded-lg shadow-xs">
118149
<h4 class="mb-4 font-bold">Warning!</h4>
119150
<p>
120-
Currently you are using an outdated CloudNet version (${version}), to keep the Cloud up to date and
151+
Currently you are using an outdated CloudNet version (${version}), to keep the Cloud up to
152+
date and
121153
to get support, you can activate the auto updater in the launcher.cnl file.
122154
</p>
123155
</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/index.php

Lines changed: 50 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +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);
7+
// require some files
8+
require __DIR__ . '/../vendor/autoload.php';
9+
// ensure all necessary files are there
10+
fileController::dieWhenFileMissing();
911

12+
// files
13+
require fileController::getVersionFilePath();
14+
require fileController::getConfigurationPath();
1015

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-
}
37-
38-
$main = new webinterface\main($config, $version);
16+
// create instance of main controller
17+
$main = new main($config, $version);
3918

19+
// create app route controller
4020
$app = System\App::instance();
4121
$app->request = System\Request::instance();
4222
$app->route = System\Route::instance($app->request);
4323

44-
$route = $app->route;
45-
46-
if(isset($_SESSION['cn3-wi-access_token'])){
47-
$route->any('/', function () {
48-
if(isset($_POST['action'])){
49-
if (isset($_POST['csrf'])) {
50-
if ($_POST['csrf'] != $_SESSION['csrf']) {
51-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
52-
die();
53-
}
54-
} else {
55-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
56-
die();
57-
}
24+
// check if we already have a session
25+
session_start();
5826

59-
if($_POST['action'] == "login" AND isset($_POST['username']) AND isset($_POST['password'])){
60-
$action = \webinterface\authorizeController::login($_POST['username'], $_POST['password']);
61-
if($action['success'] == true) {
62-
header('Location: ' . main::getUrl());
63-
} else {
64-
header('Location: ' . main::getUrl() . "/?action&success=false&message=loginFailed");
65-
}
66-
die();
67-
}
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"], '?'));
31+
die();
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();
6843
}
69-
70-
include "../pages/header.php";
71-
include "../pages/webinterface/index.php";
72-
include "../pages/footer.php";
73-
74-
});
75-
} else {
76-
$route->any('/', function () {
77-
if(isset($_POST['action'])){
78-
if (isset($_POST['csrf'])) {
79-
if ($_POST['csrf'] != $_SESSION['csrf']) {
80-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
81-
die();
82-
}
83-
} else {
84-
header('Location: ' . main::getUrl() . "/?action&success=false&message=csrfFailed");
85-
die();
86-
}
87-
88-
if($_POST['action'] == "login" AND isset($_POST['username']) AND isset($_POST['password'])){
89-
$action = \webinterface\authorizeController::login($_POST['username'], $_POST['password']);
90-
if($action['success'] == true) {
91-
header('Location: ' . main::getUrl());
92-
} else {
93-
header('Location: ' . main::getUrl() . "/?action&success=false&message=loginFailed");
94-
}
95-
die();
96-
}
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;
9749
}
50+
}
9851

99-
include "../pages/small-header.php";
100-
include "../pages/webinterface/login.php";
101-
include "../pages/footer.php";
52+
displayLoginPage();
53+
});
54+
$app->route->end();
10255

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

106-
107-
$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)