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

Commit 1185e47

Browse files
author
Moritz Walter
committed
add websocket, cluster/task/console page and remove some shit @derklaro code :p
1 parent 6d83786 commit 1185e47

File tree

10 files changed

+453
-58
lines changed

10 files changed

+453
-58
lines changed

config/config-sample.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
$config = array(
4+
"url" => array(
5+
"main" => "www.domain.de",
6+
"ssl" => "https://",
7+
"pfad" => "",
8+
"without_sub" => "domain.de",
9+
"force" => "true",
10+
),
11+
"cloudnet" => array(
12+
"protocol" => "http://",
13+
"ip" => "",
14+
"port" => "",
15+
"path" => "/api/v2",
16+
"socket" => array(
17+
"protocol" => "ws://",
18+
"ip" => "",
19+
"port" => "",
20+
"path" => ""
21+
)
22+
),
23+
24+
"name" => "CloudNet3 Webinterface",
25+
26+
);

pages/header.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<head>
44
<meta charset="UTF-8"/>
55
<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>
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>
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>
@@ -41,21 +41,19 @@ class=""/></svg>
4141
</div>
4242
<nav :class="{'block': open, 'hidden': !open}" class="flex-grow md:block px-4 pb-4 md:pb-0 md:overflow-y-auto">
4343
<a class="block px-4 py-2 mt-2 text-sm font-semibold dark:text-white dark:bg-gray-900 text-gray-900 bg-gray-100 rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
44-
href="#">Dashboard</a>
44+
href="<?= \webinterface\main::getUrl(); ?>">Dashboard</a>
4545
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
46-
href="cluster.html">Cluster</a>
46+
href="<?= \webinterface\main::getUrl().'/cluster'; ?>">Cluster</a>
4747
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
48-
href="tasks.html">Tasks</a>
48+
href="<?= \webinterface\main::getUrl().'/tasks'; ?>">Tasks</a>
4949
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
50-
href="groups.html">Groups</a>
50+
href="<?= \webinterface\main::getUrl().'/groups'; ?>">Groups</a>
5151
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
52-
href="service.html">Services</a>
52+
href="<?= \webinterface\main::getUrl().'/permissions'; ?>">Permissions</a>
5353
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
54-
href="permissions.html">Permissions</a>
54+
href="<?= \webinterface\main::getUrl().'/players'; ?>">Players</a>
5555
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
56-
href="players.html">Players</a>
57-
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-400 bg-transparent rounded-lg hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline"
58-
href="modules.html">Modules</a>
56+
href="<?= \webinterface\main::getUrl().'/modules'; ?>">Modules</a>
5957
<div :class="{'block': open, 'hidden': !open}"
6058
class="flex-grow md:block px-4 pb-4 md:pb-0 md:overflow-y-auto">
6159
<a class="flex items-center py-2 px-8 dark:text-gray-100 hover:dark:text-gray-200 text-gray-800 hover:text-gray-900"

pages/small-header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<head>
44
<meta charset="UTF-8"/>
55
<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>
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>
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/cluster.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<main class="w-full flex-grow p-6">
2+
<div class="py-3">
3+
<main class="h-full overflow-y-auto">
4+
<div class="container mx-auto grid">
5+
<div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
6+
<!-- Nodes start -->
7+
<?php
8+
$nodes = \webinterface\main::buildDefaultRequest("cluster", "GET");
9+
10+
11+
foreach ($nodes['nodes'] as $node) { ?>
12+
13+
<div class="min-w-0 p-4 dark:bg-gray-800 bg-white rounded-lg shadow-lg border-t-4 border-green-600">
14+
<div class="flex items-center justify-between">
15+
<h4 class="mb-4 font-semibold text-blue-500"><?= $node['node']['uniqueId']; ?></h4>
16+
<!-- State Starting: bg-yellow-600 // State Stop: bg-red-600 -->
17+
<?php if($node['available'] == true){ ?>
18+
<span class="text-sm text-center text-white h-6 w-16 bg-green-600 rounded-full">Online</span>
19+
<?php } else { ?>
20+
<span class="text-sm text-center text-white h-6 w-16 bg-red-600 rounded-full">Offline</span>
21+
<?php } ?>
22+
</div>
23+
<div class="flex">
24+
<span class="text-gray-400">•</span>
25+
<p class="flex-1 dark:text-white text-gray-900 items-center pl-2">Memory Usage: <?= $node['nodeInfoSnapshot']['usedMemory']; ?>MB/<?= $node['nodeInfoSnapshot']['maxMemory']; ?>MB<br></p>
26+
</div>
27+
<div class="flex">
28+
<span class="text-gray-400">•</span>
29+
<p class="flex-1 dark:text-white text-gray-900 items-center pl-2">CPU Usage: <?= min(round($node['nodeInfoSnapshot']['processSnapshot']['cpuUsage'] * 100), 100); ?>%<br></p>
30+
</div>
31+
<div class="flex">
32+
<span class="text-gray-400">•</span>
33+
<p class="flex-1 dark:text-white text-gray-900 items-center pl-2">Version: <?= $node['nodeInfoSnapshot']['version'] ?><br></p>
34+
</div>
35+
<div class="flex">
36+
<span class="text-gray-400">•</span>
37+
<p class="flex-1 dark:text-white text-gray-900 items-center pl-2">Host: <?= $node['node']['listeners'][0]['host'].":".$node['node']['listeners'][0]['port']; ?> <br></p>
38+
</div>
39+
<div class="flex justify-center mt-4 space-x-3 text-sm text-white">
40+
<div class="flex items-center">
41+
<form method="post">
42+
<input name="action" value="stopNode" type="hidden">
43+
<input name="node_id" value="<?= $node['node']['uniqueId']; ?>" type="hidden">
44+
<input name="csrf" value="<?= $_SESSION['cn3-wi-csrf'] ?>" type="hidden">
45+
46+
<button type="submit" class="h-10 bg-blue-500 text-white rounded-md px-4 py-2 m-2 hover:bg-blue-600 focus:outline-none focus:shadow-outline">Shutdown</button>
47+
</form>
48+
<form method="post">
49+
<input name="action" value="deleteNode" type="hidden">
50+
<input name="node_id" value="<?= $node['node']['uniqueId']; ?>" type="hidden">
51+
<input name="csrf" value="<?= $_SESSION['cn3-wi-csrf'] ?>" type="hidden">
52+
53+
<button type="submit" class="h-10 bg-blue-500 text-white rounded-md px-4 py-2 m-2 hover:bg-blue-600 focus:outline-none focus:shadow-outline">Delete</button>
54+
</form>
55+
</div>
56+
</div>
57+
</div>
58+
<?php } ?>
59+
<!-- Nodes end-->
60+
</div>
61+
</div>
62+
</main>
63+
</div>
64+
65+
<div class="py-3">
66+
<main class="h-full overflow-y-auto">
67+
<div class="container mx-auto grid">
68+
<div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-1">
69+
<!-- Create Node -->
70+
<div class="w-full">
71+
<div class="coding inverse-toggle px-5 pt-4 shadow-lg text-gray-100 dark:bg-gray-800 bg-white pb-6 pt-4 rounded-lg leading-normal overflow-hidden">
72+
<div class="top mb-2 flex">
73+
<h4 class="mb-2 font-semibold dark:text-white text-gray-900">Create Node</h4>
74+
</div>
75+
<div class="flex-1 flex flex-col md:flex-row text-sm font-mono subpixel-antialiased">
76+
<div class="w-full flex-1 mx-2">
77+
<input placeholder="Name" class="my-2 p-2 dark:bg-gray-900 bg-gray-100 flex border dark:border-gray-900 border-gray-100 rounded px-2 appearance-none outline-none w-full dark:text-white text-gray-900 focus:ring-2 focus:ring-blue-600">
78+
</div>
79+
<div class="w-full flex-1 mx-2">
80+
<input placeholder="Host" class="my-2 p-2 dark:bg-gray-900 bg-gray-100 flex border dark:border-gray-900 border-gray-100 rounded px-2 appearance-none outline-none w-full dark:text-white text-gray-900 focus:ring-2 focus:ring-blue-600">
81+
</div>
82+
<div class="w-full flex-1 mx-2">
83+
<input placeholder="Port" class="my-2 p-2 dark:bg-gray-900 bg-gray-100 flex border dark:border-gray-900 border-gray-100 rounded px-2 appearance-none outline-none w-full dark:text-white text-gray-900 focus:ring-2 focus:ring-blue-600">
84+
</div>
85+
</div>
86+
<button type="button" class="h-10 bg-blue-500 text-white rounded-md px-4 py-2 m-2 hover:bg-blue-600 focus:outline-none focus:shadow-outline">Create</button>
87+
</div>
88+
</div>
89+
</div>
90+
</div>
91+
</main>
92+
</div>
93+
</main>

pages/webinterface/index.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?php
22

3-
use webinterface\main;
43

5-
$nodes = main::buildDefaultRequest("cluster", "GET");
4+
$nodes = \webinterface\main::buildDefaultRequest("cluster", "GET");
65

76
$services = 0;
8-
$currentVersion = "Unknown";
97

108
$connectedNodeCount = 0;
119
$totalNodeCount = sizeof($nodes);
@@ -23,7 +21,6 @@
2321

2422
$connectedNodeCount++;
2523

26-
$currentVersion = $node['nodeInfoSnapshot']['version'];
2724
$services += $node['nodeInfoSnapshot']['currentServicesCount'];
2825

2926
$memory_max += $node['nodeInfoSnapshot']['maxMemory'];
@@ -151,14 +148,21 @@
151148
</div>
152149
</div>
153150
<!-- Status -->
151+
<?php $version = \webinterface\main::testIfLatestVersion(); ?>
152+
<?php if(!$version['success']){ ?>
154153
<div class="min-w-0 p-4 text-white bg-gradient-to-br from-red-600 to-red-800 rounded-lg shadow-xs">
155154
<h4 class="mb-4 font-bold">Warning!</h4>
156155
<p>
157-
Currently you are using an outdated CloudNet version (<?= $currentVersion ?>), to keep the Cloud up to
156+
<?php if($version['response']['error_code'] == 202){ ?>
157+
Currently you are using an outdated Webinterface version (<?= $version['response']['error_extra']['current'] ?>), to keep the Webinterface up to
158158
date and
159-
to get support, you can activate the auto updater in the launcher.cnl file.
159+
to get support, update to the latest version (<?= $version['response']['error_extra']['latest'] ?>).
160+
<?php } else if($version['response']['error_code'] == 503){ ?>
161+
The TheSystems control server is currently unavailable.
162+
<?php } ?>
160163
</p>
161164
</div>
165+
<?php } ?>
162166
</div>
163167
</div>
164168
</main>

pages/webinterface/login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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">
45
<div class="flex font-bold justify-center mt-6">
56
<img class="h-20 w-20"
67
src="https://raw.githubusercontent.com/sefyudem/Responsive-Login-Form/master/img/avatar.svg">

pages/webinterface/task/console.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
2+
<script>
3+
function showMessage(messageHTML) {
4+
$('#socket_event').prepend(messageHTML);
5+
}
6+
let websocket;
7+
8+
$(document).ready(function () {
9+
function ws_connect() {
10+
websocket = new WebSocket("<?= \webinterface\main::provideSocketUrl()."/service/".$service_name."/liveLog"; ?>");
11+
12+
websocket.onmessage = function (event) {
13+
showMessage(event.data);
14+
};
15+
16+
websocket.onclose = function (e) {
17+
showMessage('<div class="dark:text-gray-200 text-gray-800 text-sm">Cannot connect</div>');
18+
};
19+
20+
websocket.onerror = function (err) {
21+
websocket.close();
22+
23+
};
24+
};
25+
ws_connect();
26+
});
27+
28+
</script>
29+
30+
31+
<main class="w-full flex-grow p-6">
32+
33+
<div class="py-3">
34+
<main class="h-full overflow-y-auto">
35+
<div class="container mx-auto grid">
36+
<div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-1">
37+
<!-- Create Node -->
38+
<div class="w-full">
39+
<div class="coding inverse-toggle px-5 pt-4 shadow-lg text-gray-100 dark:bg-gray-800 bg-white pb-6 pt-4 rounded-lg leading-normal overflow-hidden">
40+
41+
<div id="socket_event"></div>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
</main>
47+
</div>
48+
</main>

0 commit comments

Comments
 (0)