Skip to content

Commit c8c0a3c

Browse files
committed
1.2.5
1 parent 44cbb60 commit c8c0a3c

9 files changed

Lines changed: 273 additions & 4 deletions

File tree

app.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ var colors = require('colors');
2626
const spawn = require("cross-spawn");
2727
var iconvlite = require('iconv-lite');
2828
var ip_local = require("ip");
29+
const os = require("os");
2930
const ip_public = require('external-ip')();
31+
const nodeDiskInfo = require('node-disk-info');
3032

3133
var cfg = config.readConfig();
3234

@@ -59,7 +61,7 @@ const {
5961
} = require('express');
6062

6163
// Kubek version
62-
const version = "v1.2.4";
64+
const version = "v1.2.5";
6365

6466
const rateLimit = require('express-rate-limit');
6567
const authLimiter = rateLimit({
@@ -1086,6 +1088,48 @@ app.get("/kubek/config", (request, response) => {
10861088
}
10871089
});
10881090

1091+
app.get("/kubek/hardware", (request, response) => {
1092+
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
1093+
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");
1094+
if (cfg['internet-access'] == false && ip != "127.0.0.1") {
1095+
response.send("Cannot be accessed from the internet");
1096+
} else {
1097+
if (typeof request.cookies !== "undefined" && typeof request.cookies["__auth__"] !== "undefined" && !isAuth(request.cookies["__auth__"])) {
1098+
response.redirect("/login.html");
1099+
} else {
1100+
nodeDiskInfo.getDiskInfo()
1101+
.then(disks => {
1102+
cpu = os.cpus()[0]['model'];
1103+
cp_unq = os.cpus();
1104+
let pform_unq = {
1105+
name: os.type(),
1106+
release: os.release(),
1107+
arch: process.arch,
1108+
version: os.version()
1109+
}
1110+
1111+
let cpu_unq = {
1112+
model: cp_unq[0].model,
1113+
speed: cp_unq[0].speed,
1114+
cores: cp_unq.length
1115+
}
1116+
1117+
hardware = {
1118+
platform: pform_unq,
1119+
totalmem: Math.round(os.totalmem() / 1024 / 1024),
1120+
cpu: cpu_unq,
1121+
enviroment: process.env,
1122+
disks: disks
1123+
}
1124+
response.send(hardware);
1125+
})
1126+
.catch(reason => {
1127+
console.error(reason);
1128+
});
1129+
}
1130+
}
1131+
});
1132+
10891133
app.get("/kubek/saveConfig", (request, response) => {
10901134
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
10911135
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"minecraft-status": "^1.1.0",
2626
"morgan": "^1.10.0",
2727
"multer": "^1.4.4",
28+
"node-disk-info": "^1.3.0",
2829
"nodemon": "^2.0.15",
2930
"os-utils": "0.0.14",
3031
"pidusage": "^3.0.0",

translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
"{{signinbtn}}": "Sign in",
6767
"{{autherror}}": "Authorization error",
6868
"{{savelogs}}": "Save logs",
69-
"{{allowintacc}}": "Allow access from other IPs (needs restart to work properly)"
69+
"{{allowintacc}}": "Allow access from other IPs (needs restart to work properly)",
70+
"{{hardware-info}}": "System information"
7071
}

translations/nl.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
"{{signinbtn}}": "Log in",
6767
"{{autherror}}": "Authenticatie fout",
6868
"{{savelogs}}": "Logs opslaan",
69-
"{{allowintacc}}": "Toegang vanaf andere IP's toestaan (opnieuw opstarten is vereist om correct te werken)"
69+
"{{allowintacc}}": "Toegang vanaf andere IP's toestaan (opnieuw opstarten is vereist om correct te werken)",
70+
"{{hardware-info}}": "Systeem informatie"
7071
}

translations/ru.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
"{{signinbtn}}": "Войти",
6767
"{{autherror}}": "Ошибка авторизации",
6868
"{{savelogs}}": "Сохранять логи",
69-
"{{allowintacc}}": "Разрешить доступ с других IP (нужен перезапуск для правильной работы)"
69+
"{{allowintacc}}": "Разрешить доступ с других IP (нужен перезапуск для правильной работы)",
70+
"{{hardware-info}}": "О системе"
7071
}

www/css/pages/hardware-info.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#env-table tbody th,
2+
#env-table tbody td {
3+
padding: 0.2rem 1.3rem;
4+
}

www/hardware-info.html

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<head>
2+
<!-- Meta -->
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5+
<title>Kubek - Minecraft Servers</title>
6+
7+
<!-- MDB -->
8+
<script src="js/mdb.min.js"></script>
9+
<link rel="stylesheet" href="css/mdb.min.css">
10+
11+
<!-- Others -->
12+
<script src="js/jquery-3.6.0.min.js"></script>
13+
<link rel="stylesheet" href="css/animate.min.css" />
14+
<link rel="stylesheet" href="css/toastify.min.css" />
15+
<script src="js/socket.io.min.js"></script>
16+
<script src="js/toastify-js.js"></script>
17+
<script src="js/sweetalert2.all.min.js"></script>
18+
19+
<!-- Own -->
20+
<link rel="stylesheet" href="css/globals.css" />
21+
<link rel="stylesheet" href="css/template.nav.css" />
22+
<script src="js/funcs.js"></script>
23+
24+
<!-- Fonts and icons -->
25+
<link rel="preconnect" href="https://fonts.googleapis.com">
26+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
27+
<link
28+
href="https://fonts.googleapis.com/css2?family=Open Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
29+
rel="stylesheet">
30+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
31+
32+
<!-- Page unique -->
33+
<link rel="stylesheet" href="css/pages/hardware-info.css">
34+
</head>
35+
36+
<body>
37+
<div id="oldc">
38+
<p class="fs-1 fw-bold">Software summary</p>
39+
<table class="table">
40+
<tbody>
41+
<tr>
42+
<th style="text-align:left;">
43+
<div class="d-flex align-items-center">
44+
<span class="material-icons">wysiwyg</span>
45+
<span style="margin-left: 16px;">OS Name</span>
46+
</div>
47+
</th>
48+
<td style="text-align:right;" id="os-name">Unknown</td>
49+
</tr>
50+
<tr>
51+
<th style="text-align:left;">
52+
<div class="d-flex align-items-center">
53+
<span class="material-icons">wysiwyg</span>
54+
<span style="margin-left: 16px;">OS Build</span>
55+
</div>
56+
</th>
57+
<td style="text-align:right;" id="os-build">Unknown</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
<p class="fs-1 fw-bold">CPU and memory</p>
62+
<table class="table">
63+
<tbody>
64+
<tr>
65+
<th style="text-align:left;">
66+
<div class="d-flex align-items-center">
67+
<span class="material-icons">memory</span>
68+
<span style="margin-left: 16px;">Total RAM</span>
69+
</div>
70+
</th>
71+
<td style="text-align:right;" id="totalmem">Unknown</td>
72+
</tr>
73+
<tr>
74+
<th style="text-align:left;">
75+
<div class="d-flex align-items-center">
76+
<span class="material-icons">memory</span>
77+
<span style="margin-left: 16px;">CPU Model</span>
78+
</div>
79+
</th>
80+
<td style="text-align:right;" id="cpu-model">Unknown</td>
81+
</tr>
82+
<tr>
83+
<th style="text-align:left;">
84+
<div class="d-flex align-items-center">
85+
<span class="material-icons">memory</span>
86+
<span style="margin-left: 16px;">CPU Speed</span>
87+
</div>
88+
</th>
89+
<td style="text-align:right;" id="cpu-speed">Unknown</td>
90+
</tr>
91+
</tbody>
92+
</table>
93+
<p class="fs-1 fw-bold">Local disks</p>
94+
<table class="table" id="disks-table">
95+
<thead>
96+
<tr>
97+
<th>Letter</th>
98+
<th>Type</th>
99+
<th>Used</th>
100+
<th>Free</th>
101+
<th>Total </th>
102+
<th>Used %</th>
103+
</tr>
104+
</thead>
105+
<tbody></tbody>
106+
</table>
107+
<p class="fs-1 fw-bold">Enviroment values</p>
108+
<table class="table" id="env-table">
109+
<tbody></tbody>
110+
</table>
111+
</div>
112+
</body>
113+
114+
<script>
115+
var socket;
116+
$(document).ready(function () {
117+
loadTemplate(function () {
118+
hideLoading();
119+
});
120+
socket = openSocket();
121+
socket.on("handshake", function () {
122+
console.log("Socket handshake success");
123+
socket.emit("update", {
124+
type: "servers"
125+
});
126+
$.get("/kubek/hardware", function (hw) {
127+
for (var key in hw.enviroment) {
128+
value = hw.enviroment[key];
129+
$("#env-table tbody").append('<tr><th style="text-align:left;">' + key +
130+
'</th><td style="text-align:right;">' + value + '</td></tr>');
131+
}
132+
hw.disks.forEach(function (disk){
133+
console.log(disk);
134+
type = disk['_filesystem'];
135+
letter = disk['_mounted'];
136+
total = Math.round(disk['_blocks'] / 1024 / 1024 / 1024) + " GB";
137+
used = Math.round(disk['_used'] / 1024 / 1024 / 1024) + " GB";
138+
free = Math.round(disk['_available'] / 1024 / 1024 / 1024) + " GB";
139+
percent = disk['_capacity'];
140+
$("#disks-table tbody").append('<tr><td>' + letter + '</td><td>' + type + '</td><td>' + used + '</td><td>' + free + '</td><td>' + total + '</td><td>' + percent + '</td></tr>');
141+
});
142+
$("#os-name").text(hw.platform.version + " (" + hw.platform.arch + ")");
143+
$("#os-build").text(hw.platform.release);
144+
$("#totalmem").text(hw.totalmem + " Mb");
145+
$("#cpu-model").text(hw.cpu.model + " (" + hw.cpu.cores + " cores)");
146+
$("#cpu-speed").text(hw.cpu.speed + " MHz");
147+
});
148+
});
149+
socket.on("handleUpdate", function (arg) {
150+
type = arg.type;
151+
data = arg.data;
152+
switch (type) {
153+
case "servers":
154+
if (data[currentServer].status == "stopped") {
155+
$("#server-status").removeClass("badge-success badge-warning");
156+
$("#server-status").addClass("badge-danger");
157+
$("#server-status").html("Offline");
158+
$("#server-start-button").show();
159+
$("#server-stop-button").hide();
160+
} else if (data[currentServer].status == "started") {
161+
$("#server-status").removeClass("badge-danger badge-warning");
162+
$("#server-status").addClass("badge-success");
163+
$("#server-status").html("Online");
164+
$("#server-start-button").hide();
165+
$("#server-stop-button").show();
166+
} else if (data[currentServer].status == "starting") {
167+
$("#server-status").removeClass("badge-success badge-danger");
168+
$("#server-status").addClass("badge-warning");
169+
$("#server-status").html("Starting");
170+
$("#server-start-button").hide();
171+
$("#server-stop-button").hide();
172+
} else if (data[currentServer].status == "stopping") {
173+
$("#server-status").removeClass("badge-success badge-danger");
174+
$("#server-status").addClass("badge-warning");
175+
$("#server-status").html("Stopping");
176+
$("#server-start-button").hide();
177+
$("#server-stop-button").hide();
178+
}
179+
break;
180+
case "downloadTasks":
181+
$(".ntc-pool").html("");
182+
Object.keys(data).forEach(function (k) {
183+
$(".ntc-pool").append(
184+
'<div class="ntc ntc-poolbox" style="background: rgb(43,53,63); color: white;"><div class="ntb">Downloading ' +
185+
k + ' (' + data[k] + '%)</div><div class="ntb"><progress max="100" value="' + data[k] +
186+
'" class="pnf"></progress></div></div>');
187+
});
188+
break;
189+
}
190+
});
191+
});
192+
</script>

www/template.inc.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
<div><span class="material-icons">tune</span></div>
7373
<div class="flex-fill">{{kubek-settings}}</div>
7474
</li>
75+
<li class="list-group-item item h-100 d-flex justify-content-start align-items-center"
76+
data-url="/hardware-info.html">
77+
<div><span class="material-icons">device_unknown</span></div>
78+
<div class="flex-fill">{{hardware-info}}</div>
79+
</li>
7580
</ul>
7681
</div>
7782
</div>

0 commit comments

Comments
 (0)