Skip to content

Commit

Permalink
1.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Seeroy committed Jun 10, 2022
1 parent 4a2591c commit 7f707e3
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 262 deletions.
46 changes: 39 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ var crypto = require('crypto');
var spParser = require("minecraft-server-properties");
const fs = require('fs');
var colors = require('colors');
const spawn = require("cross-spawn");
//const spawn = require("cross-spawn");
const {
spawn
} = require('node:child_process');
var iconvlite = require('iconv-lite');
var ip_local = require("ip");
const os = require("os");
Expand Down Expand Up @@ -62,7 +65,7 @@ const {
} = require('express');

// Kubek version
const version = "v1.2.10";
const version = "v1.2.11";

const rateLimit = require('express-rate-limit');
const authLimiter = rateLimit({
Expand Down Expand Up @@ -262,6 +265,7 @@ function showRequestInLogs(req) {

app.get("/auth/login", (request, response) => {
cfg = config.readConfig();
showRequestInLogs(request);
if (request.query.password == cfg["owner-password"] && request.query.login == cfg["owner-user"]) {
let options = {
maxAge: 120 * 24 * 60 * 60 * 1000,
Expand Down Expand Up @@ -368,7 +372,8 @@ app.get('/server/completion', (req, res) => {
servers_logs[req.query.server] = "";
servers_instances[req.query.server] = "";
sss = {
status: "stopped"
status: "stopped",
restartOnError: true
};
cge[req.query.server] = sss;
res.send("Success");
Expand Down Expand Up @@ -408,6 +413,7 @@ app.get("/kubek/javaVersions", (request, response) => {
javas = ["java"];
}
response.send(javas);
showRequestInLogs(request);
}
}
});
Expand Down Expand Up @@ -465,6 +471,7 @@ app.get("/server/delete", (request, response) => {
if (typeof request.cookies !== "undefined" && typeof request.cookies["__auth__"] !== "undefined" && !isAuth(request.cookies["__auth__"])) {
response.redirect("/login.html");
} else {
showRequestInLogs(request);
if (typeof (configjson[request.query.server]) !== 'undefined') {
delete configjson[request.query.server];
fs.writeFileSync("./servers/servers.json", JSON.stringify(configjson));
Expand Down Expand Up @@ -584,7 +591,7 @@ app.get('/server/startScript/save', (request, response) => {
} else {
showRequestInLogs(request);
if (typeof (configjson[request.query.server]) !== 'undefined') {
response.send(serverController.saveStartScript(request.query.server, request.query.script));
response.send(serverController.saveStartScript(request.query.server, request.query.script, request.query.resonerr));
} else {
response.send("false");
}
Expand Down Expand Up @@ -717,7 +724,11 @@ function startServer(server) {
if (process.platform == "win32") {
startFile = path.resolve("./servers/" + server + "/start.bat");
if (fs.existsSync(startFile)) {
servers_instances[server] = spawn('"servers/' + server + '/start.bat"');
try {
servers_instances[server] = spawn(startFile);
} catch (error) {
console.error(error);
}
start = true;
} else {
console.log(colors.red(additional.getTimeFormatted() + " " + '"servers/' + server + '/start.bat"' + " not found! Try to delete, and create new server!"));
Expand All @@ -726,7 +737,11 @@ function startServer(server) {
} else if (process.platform == "linux") {
startFile = path.resolve("./servers/" + server + "/start.sh");
if (fs.existsSync(startFile)) {
servers_instances[server] = spawn('sh', ["./servers/" + server + "/start.sh"]);
try {
servers_instances[server] = spawn('sh', [startFile]);
} catch (error) {
console.error(error);
}
start = true;
} else {
console.log(colors.red(additional.getTimeFormatted() + " " + '"servers/' + server + '/start.sh"' + " not found! Try to delete, and create new server!"));
Expand Down Expand Up @@ -755,6 +770,23 @@ function startServer(server) {
if (code != 0) {
servers_logs[server] = servers_logs[server] + "ERROR: Process finished with exit code " + code;
console.log(additional.getTimeFormatted(), "STOPPED SERVER WITH CODE " + code + ":", server.red);
if (configjson[server]['restartOnError'] == true) {
console.log(additional.getTimeFormatted(), "RESTARTING SERVER IN 3 SECONDS:", server.red);
servers_logs[server] = servers_logs[server] + "Restarting server in 3 seconds";
setTimeout(function () {
startServer(server);
}, 3000);
}
fsock = io.sockets.sockets;
for (const socket of fsock) {
socket[1].emit("handleUpdate", {
type: "console",
data: {
server: server,
data: servers_logs[server]
}
});
}
} else {
console.log(additional.getTimeFormatted(), "STOPPED SERVER:", server.green);
}
Expand Down Expand Up @@ -1321,7 +1353,7 @@ app.get("/fmapi/scanDirectory", (request, response) => {
if (typeof request.cookies !== "undefined" && typeof request.cookies["__auth__"] !== "undefined" && !isAuth(request.cookies["__auth__"])) {
response.redirect("/login.html");
} else {
fmapi.scanDirectory(request.query.server, request.query.directory, function(res){
fmapi.scanDirectory(request.query.server, request.query.directory, function (res) {
response.send(res);
});
showRequestInLogs(request);
Expand Down
61 changes: 40 additions & 21 deletions my_modules/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.getStartScript = (name) => {
}
}

exports.saveStartScript = (name, script) => {
exports.saveStartScript = (name, script, resonerr) => {
if (fs.existsSync("./servers/" + name)) {
if (process.platform == "linux") {
datat = fs.readFileSync("./servers/" + name + "/start.sh");
Expand All @@ -37,19 +37,26 @@ exports.saveStartScript = (name, script) => {
} else {
fs.writeFileSync("./servers/" + name + "/start.bat", datat.join("\n"));
}
srv = JSON.parse(fs.readFileSync("./servers/servers.json"));
if(resonerr == "true"){
srv[name]['restartOnError'] = true;
} else {
srv[name]['restartOnError'] = false;
}
fs.writeFileSync("./servers/servers.json", JSON.stringify(srv));
return true;
} else {
return false;
}
}

exports.getServerProperties = (name) => {
if(typeof name !== "undefined" && fs.existsSync("./servers/" + name + "/server.properties")){
data = fs.readFileSync("./servers/" + name + "/server.properties");
return spParser.parse(data.toString());
} else{
return false;
}
if (typeof name !== "undefined" && fs.existsSync("./servers/" + name + "/server.properties")) {
data = fs.readFileSync("./servers/" + name + "/server.properties");
return spParser.parse(data.toString());
} else {
return false;
}
}

exports.saveServerProperties = (name, doc) => {
Expand All @@ -59,21 +66,33 @@ exports.saveServerProperties = (name, doc) => {

exports.queryServer = (name, cb) => {
data = this.getServerProperties(name);
mcutil.fullQuery("127.0.0.1", data["server-port"], 3000)
.then((data) => {
osutils.cpuUsage(function (value) {
data["cpu"] = Math.round(value * 100);
totalmem = os.totalmem();
usedmem = totalmem - os.freemem();
data["usedmem"] = usedmem;
data["totalmem"] = totalmem;
cb(data);
});
})
.catch((error) => {
console.error(error);
cb(error);
if (process.platform == "linux") { // mcutil is not crossplatform
osutils.cpuUsage(function (value) {
data["cpu"] = Math.round(value * 100);
totalmem = os.totalmem();
usedmem = totalmem - os.freemem();
data["usedmem"] = usedmem;
data["totalmem"] = totalmem;
cb(data);
});
} else {
mcutil.fullQuery("127.0.0.1", data["server-port"], 3000)
.then((data) => {
osutils.cpuUsage(function (value) {
data["cpu"] = Math.round(value * 100);
totalmem = os.totalmem();
usedmem = totalmem - os.freemem();
data["usedmem"] = usedmem;
data["totalmem"] = totalmem;
cb(data);
});
})
.catch((error) => {
console.error(error);
cb(error);
});
}

}

exports.listServers = () => {
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
"{{rename}}": "Rename",
"{{aredelete}}": "Are you really want to delete?",
"{{yesdelete}}": "Yes, delete it",
"{{new-directory}}": "NEW DIRECTORY"
"{{new-directory}}": "NEW DIRECTORY",
"{{resonerr}}": "Restart server on crash (detecting by error code)"
}
3 changes: 2 additions & 1 deletion translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
"{{rename}}": "Hernoemen",
"{{aredelete}}": "Wil je echt verwijderen?",
"{{yesdelete}}": "Ja, verwijder het",
"{{new-directory}}": "NIEUWE DIRECTORY"
"{{new-directory}}": "NIEUWE DIRECTORY",
"{{resonerr}}": "Herstart server bij crash (gecontroleerd door afsluitcode)"
}
3 changes: 2 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
"{{rename}}": "Переименовать",
"{{aredelete}}": "Вы действительно хотите удалить?",
"{{yesdelete}}": "Да, удалить",
"{{new-directory}}": "НОВАЯ ДИРЕКТОРИЯ"
"{{new-directory}}": "НОВАЯ ДИРЕКТОРИЯ",
"{{resonerr}}": "Перезапускать сервер при краше (проверяется по коду выхода)"
}
1 change: 0 additions & 1 deletion www/js/MinecraftColorCodes.min.3.7.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var styleMap = {
'§9': 'font-weight:normal;text-decoration:none;color:#3f3ffe',
'§d': 'font-weight:normal;text-decoration:none;color:#fe3ffe',
'§5': 'font-weight:normal;text-decoration:none;color:#be00be',
'§f': 'font-weight:normal;text-decoration:none;color:#ffffff',
'§7': 'font-weight:normal;text-decoration:none;color:#bebebe',
'§8': 'font-weight:normal;text-decoration:none;color:#3f3f3f',
'§0': 'font-weight:normal;text-decoration:none;color:#000000',
Expand Down
Loading

0 comments on commit 7f707e3

Please sign in to comment.