Skip to content

Commit

Permalink
1.2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Seeroy committed Jun 24, 2022
1 parent e28ab48 commit 635c18b
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 17 deletions.
102 changes: 97 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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('node:child_process');
Expand Down Expand Up @@ -61,12 +60,15 @@ var servers_instances = [];
var updatesByIntArray = {};
var forgesIns = [];

var currentFileWritings = [];
var currentFileWritingsText = [];

const {
response
} = require('express');

// Kubek version
const version = "v1.2.13";
const version = "v1.2.14";

const rateLimit = require('express-rate-limit');
const authLimiter = rateLimit({
Expand Down Expand Up @@ -116,7 +118,27 @@ io.on("connection", (socket) => {
break;
}
});
socket.on("startFileWrite", (arg) => { // Start file upload after edit (FM)
currentFileWritings[arg.randCode] = "./servers/" + arg.path;
currentFileWritingsText[arg.randCode] = "";
});
socket.on("addFileWrite", (arg) => { // Add fragment to file upload (FM)
if (typeof currentFileWritingsText[arg.randCode] !== "undefined") {
if (currentFileWritingsText[arg.randCode] == "") {
currentFileWritingsText[arg.randCode] = arg.add;
} else {
currentFileWritingsText[arg.randCode] = currentFileWritingsText[arg.randCode] + "\n" + arg.add;
}

}
});
socket.on("finishFileWrite", (arg) => { // Finish write to file (FM)
if (typeof currentFileWritingsText[arg.randCode] !== "undefined") {
fs.writeFileSync(currentFileWritings[arg.randCode], currentFileWritingsText[arg.randCode]);
delete currentFileWritings[arg.randCode];
delete currentFileWritingsText[arg.randCode];
}
});
});

app.use(fileUpload());
Expand Down Expand Up @@ -815,6 +837,10 @@ function startServer(server) {
statuss = "started";
console.log(additional.getTimeFormatted(), "STARTED SERVER:", server.green);
}
if (data.match(/\[INFO] Listening on/gm)) {
statuss = "started";
console.log(additional.getTimeFormatted(), "STARTED SERVER:", server.green);
}
if (data.indexOf("Saving players") >= 0) {
console.log(additional.getTimeFormatted(), "STOPPING SERVER:", server.green);
statuss = "stopping";
Expand Down Expand Up @@ -954,9 +980,10 @@ app.get("/core/list", (request, response) => {
} else {
showRequestInLogs(request);
response.set('Content-Type', 'application/json');
possbileCores = ['Spigot', 'Paper'];
possbileCores = ['Spigot', 'Paper', 'BungeeCord'];
paperVers = [];
spigotVers = [];
bungeeVers = ["Latest (> 1.7.10)", "1.7.10", "1.6.4", "1.5.2"];
cores.getPaperCores(function (cores_p) {
cores_p = cores_p.reverse();
cores_p.forEach(function (core) {
Expand All @@ -969,7 +996,8 @@ app.get("/core/list", (request, response) => {
let jsn = {
possible: possbileCores,
paper: paperVers,
spigot: spigotVers
spigot: spigotVers,
bungeecord: bungeeVers
}
response.send(jsn);
});
Expand All @@ -996,6 +1024,40 @@ app.get('/core/spigot/list', (request, response) => {
}
});

app.get('/core/bungee/search', (request, response) => {
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");
if (cfg['internet-access'] == false && ip != "127.0.0.1") {
response.send("Cannot be accessed from the internet");
} else {
if (typeof request.cookies !== "undefined" && typeof request.cookies["__auth__"] !== "undefined" && !isAuth(request.cookies["__auth__"])) {
response.redirect("/login.html");
} else {
showRequestInLogs(request);
r = "";
if (typeof request.query.core !== "undefined") {
switch (request.query.core) {
case "Latest":
r = "https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar";
break;
case "Bungeecord 1.7.10":
r = "https://ci.md-5.net/job/BungeeCord/1119/artifact/bootstrap/target/BungeeCord.jar";
break;
case "Bungeecord 1.6.4":
r = "https://ci.md-5.net/job/BungeeCord/701/artifact/bootstrap/target/BungeeCord.jar";
break;
case "Bungeecord 1.5.2":
r = "https://ci.md-5.net/job/BungeeCord/548/artifact/proxy/target/BungeeCord.jar";
break;
}
response.send(r);
} else {
response.send(false);
}
}
}
});

app.get('/server/list', (request, response) => {
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");
Expand Down Expand Up @@ -1439,6 +1501,36 @@ app.get("/fmapi/newdirFM", (request, response) => {
}
});

app.post('/fmapi/uploadFM', (request, response) => {
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");
if (cfg['internet-access'] == false && ip != "127.0.0.1") {
response.send("Cannot be accessed from the internet");
} else {
if (typeof request.cookies !== "undefined" && typeof request.cookies["__auth__"] !== "undefined" && !isAuth(request.cookies["__auth__"])) {
response.redirect("/login.html");
} else {
let sampleFile;
let uploadPath;

if (!request.files || Object.keys(request.files).length === 0) {
return response.status(400).send('No files were uploaded.');
}

sampleFile = request.files['g-file-input'];
uploadPath = "./servers/" + request.query["server"] + request.query["path"] + sampleFile.name;
showRequestInLogs(request);

sampleFile.mv(uploadPath, function (err) {
if (err)
return response.status(400).send(err);

response.send("uploaded");
});
}
}
});

app.get("/forgeInstaller", (request, response) => {
ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
ip = ip.replace("::ffff:", "").replace("::1", "127.0.0.1");
Expand Down Expand Up @@ -1485,7 +1577,7 @@ function startForgeInstaller(server, file) {
}

fi.on('close', (code) => {
if(code == 0){
if (code == 0) {
console.log(colors.green("Forge installed successfully on " + server));
forgesIns[server] = "ok,installed";
fs.unlinkSync(fp);
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"{{new-directory}}": "NEW DIRECTORY",
"{{resonerr}}": "Restart server on crash (detecting by error code)",
"{{ifuuplForge}}": "If you upload the Forge installation file here, the installation will be done automatically when you create the server",
"{{ifuuplWarn}}": "Supported versions of Forge: 1.5.2 - 1.16.5 | Tested versions: 1.12.2, 1.16.5"
"{{ifuuplWarn}}": "Supported versions of Forge: 1.5.2 - 1.16.5 | Tested versions: 1.12.2, 1.16.5",
"{{uploadFile}}": "UPLOAD FILE"
}
3 changes: 2 additions & 1 deletion translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"{{new-directory}}": "NIEUWE DIRECTORY",
"{{resonerr}}": "Herstart server bij crash (gecontroleerd door afsluitcode)",
"{{ifuuplForge}}": "Als u het Forge-installatiebestand hier uploadt, wordt de installatie automatisch uitgevoerd wanneer u de server maakt",
"{{ifuuplWarn}}": "Ondersteunde versies van Forge: 1.5.2 - 1.16.5 | Geteste versies: 1.12.2, 1.16.5"
"{{ifuuplWarn}}": "Ondersteunde versies van Forge: 1.5.2 - 1.16.5 | Geteste versies: 1.12.2, 1.16.5",
"{{uploadFile}}": "UPLOAD BESTAND"
}
3 changes: 2 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"{{new-directory}}": "НОВАЯ ДИРЕКТОРИЯ",
"{{resonerr}}": "Перезапускать сервер при краше (проверяется по коду выхода)",
"{{ifuuplForge}}": "Если вы загрузите сюда установочный файл Forge, установка будет произведена автоматически при создании сервера",
"{{ifuuplWarn}}": "Поддерживаемые версии Forge: 1.5.2 - 1.16.5 | Протестированные версии: 1.12.2, 1.16.5"
"{{ifuuplWarn}}": "Поддерживаемые версии Forge: 1.5.2 - 1.16.5 | Протестированные версии: 1.12.2, 1.16.5",
"{{uploadFile}}": "ЗАГРУЗИТЬ ФАЙЛ"
}
Binary file added www/assets/cores/bungeecord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 75 additions & 9 deletions www/file-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<div id="oldc">
<p class="fs-1 fw-bold">File manager</p>
<div class="cdirDiv"></div><br>
<button type="button" class="btn btn-link" data-mdb-ripple-color="dark" onclick=newdirFM()>{{new-directory}}</button>
<button type="button" class="btn btn-link" data-mdb-ripple-color="dark"
onclick=newdirFM()>{{new-directory}}</button>

<button type="button" class="btn btn-primary" onclick=uploadFM()>{{uploadFile}}</button>
<table class="table table-hover">
<thead>
<tr>
Expand All @@ -50,6 +53,11 @@
<tbody id="fmtable"></tbody>
</table>

<form id="g-file-form" enctype="multipart/form-data">
<input name="g-file-input" id="g-file-input"
style="position: absolute; left: -2582px; right: 0; top: 0; bottom: 0; z-index: -285;" type="file">
</form>

<div class="modal top fade" id="feModal" tabindex="-1" aria-labelledby="feModalLabel" aria-hidden="true"
data-mdb-backdrop="static" data-mdb-keyboard="false">
<div class="modal-dialog modal-xl modal-dialog-centered">
Expand Down Expand Up @@ -113,7 +121,7 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>
})
}

function newdirFM(){
function newdirFM() {
Swal.fire({
title: '{{new-directory}}',
input: 'text',
Expand Down Expand Up @@ -146,6 +154,36 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>
})
}

function uploadFM() {
$("#g-file-input").trigger('click');
$("#g-file-input").off("change");
$("#g-file-input").change(function () {
var formData = new FormData($("#g-file-form")[0]);
jQuery.ajax({
url: '/fmapi/uploadFM?server=' + currentServer + "&path=" + encodeURI(curDir),
type: "POST",
data: formData,
success: function (data) {
Swal.fire(
'{{success}}',
'success'
).then((result) => {
window.location = "";
});
},
error: function (data) {
Swal.fire(
'{{error}}',
'error'
);
},
cache: false,
contentType: false,
processData: false,
});
});
}

function renameFM(path) {
fn = path.split("/").slice(-1)[0];

Expand Down Expand Up @@ -183,9 +221,36 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>

function saveFile() {
fn = $("#feModalLabel").text();
path = curDir + fn;
$.get("/fmapi/saveFile?server=" + currentServer + "&path=" + path + "&text=" + btoa($(
"#feModal .modal-body textarea").val()), function () {});
path = currentServer + curDir + fn;
randCode = genID(20);

socket.emit("startFileWrite", {
path: path,
randCode: randCode
});

textSplit = $("#feModal .modal-body textarea").val().split("\n");
textSplit.forEach(function (seg) {
socket.emit("addFileWrite", {
add: seg,
randCode: randCode
});
});

socket.emit("finishFileWrite", {
randCode: randCode
});
}

function genID(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}

function refreshDir() {
Expand Down Expand Up @@ -213,15 +278,15 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>
data.forEach(function (file) {
size = 0;
if (file.size < 1024 * 1024) {
size = Math.round(file.size / 1024 * 10) / 10 + " Kb";
size = Math.round(file.size / 1024 * 10) / 10 + " Kb";
}
if (file.size < 1024) {
size = file.size + " B";
}
if (file.size >= 1024 * 1024) {
size = Math.round(file.size / 1024 / 1024 * 10) / 10 + " Mb";
}
if (file.size >= 1024 * 1024 * 1024) {
if (file.size >= 1024 * 1024 * 1024) {
size = Math.round(file.size / 1024 / 1024 / 1024 * 10) / 10 + " Gb";
}
if (file.type == "directory") {
Expand Down Expand Up @@ -249,7 +314,8 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>
}
$("#fmtable").append(
'<tr data-type="' + file.type +
'"><td style="width: 20px;"><span class="material-icons">' + icon + '</span></td><td class="fn" style="padding-top: 18px;">' +
'"><td style="width: 20px;"><span class="material-icons">' + icon +
'</span></td><td class="fn" style="padding-top: 18px;">' +
file.name + '</td><td>' + size + '</td><td>' + act + '</td></tr>');
});
$("#fmtable").unbind("click");
Expand All @@ -260,7 +326,7 @@ <h5 class="modal-title" id="feModalLabel">Modal title</h5>
}
if ($(this).data("type") == "file") {
ext = $(this).find(".fn")[0].innerText.split(".").slice(-1)[0];
allowedExt = ["txt", "log", "yml", "xml", "cfg", "conf", "config", "json", "yaml", "properties"];
allowedExt = ["txt", "log", "yml", "xml", "cfg", "conf", "config", "json", "yaml", "properties", "sh", "bat"];
if (allowedExt.indexOf(ext) >= 0) {
$("#feModalLabel").text($(this).find(".fn")[0].innerText);
$.get("/fmapi/getFile?server=" + currentServer + "&path=" + curDir + $(this).find(".fn")[0]
Expand Down
15 changes: 15 additions & 0 deletions www/new.server.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@
}, 100);
}
});
} else if (core.substring(0, 1) == "B") {
alert("Currently console not working on BungeeCord! idk how to fix it :(\nНа данный момент консоль у BungeeCord нормально не работает!");
if(core.substring(0, 15) == "Bungeecord Late"){
core = "Latest";
}
$.get("/core/bungee/search?core=" + encodeURI(core), function (data) {
if (data != "") {
$("#progress-card p").html("Downloading core");
$.get("/file/download?url=" + data + "&server=" + sname + "&filename=" + data.substring(data
.lastIndexOf('/') + 1) + "&type=core");
rr = setInterval(function () {
getProgress(data.substring(data.lastIndexOf('/') + 1), sname, startLine, port, onlineMode)
}, 100);
}
});
} else if (core.substring(0, 2) == "Ow" || core.substring(0, 2) == "Fo" && $("#g-core-input").val().toString()
.length > 2) {
var formData = new FormData($("#g-core-form")[0]);
Expand Down

0 comments on commit 635c18b

Please sign in to comment.