Main Merge Stable #29

Merged
Sirherobrine23 merged 10 commits from main into stable 2021-02-08 23:47:47 +00:00
11 changed files with 189 additions and 1684 deletions

21
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,21 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/javascript-node/.devcontainer/base.Dockerfile
# [Choice] Node.js version: 14, 12, 10
ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install curl wget git zsh libnss3 libatk-bridge2.0-0 gconf-service libasound2 libatk1.0-0 libc6 \
libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 \
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils libgbm-dev
RUN wget https://github.com/cli/cli/releases/download/v1.6.0-pre.3/gh_1.6.0-pre.3_linux_amd64.deb -O /tmp/gh.deb && dpkg -i /tmp/gh.deb
# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"

View File

@ -0,0 +1,50 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/javascript-node
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 10, 12, 14
"args": {
"VARIANT": "14"
}
},
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/usr/bin/zsh"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"formulahendry.auto-rename-tag",
"ms-vscode-remote.remote-containers",
"benshabatnoam.google-translate-ext",
"wix.vscode-import-cost",
"eg2.vscode-npm-script",
"christian-kohler.npm-intellisense",
"christian-kohler.path-intellisense",
"kodetech.electron-debug",
"coenraads.bracket-pair-colorizer",
"aaron-bond.better-comments",
"msjsdiag.debugger-for-chrome",
"smcpeak.default-keys-windows"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
19132,
19133,
1932,
28574,
3000,
6565
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm install --no-save",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}

View File

@ -19,6 +19,11 @@ module.exports = () => {
app.use(cors());
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
app.use(limiter);
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/configs", (req, res) => {
return res.send(bds.get_config());
});
app.get("/info", (req, res) => {
const text = fs.readFileSync(localStorage.getItem("old_log_file"), "utf8");
const versions = bds.version_raw
@ -49,24 +54,89 @@ module.exports = () => {
app.get("/", (req, res) => {
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(__dirname+'/../package.json').version}`);
});
app.get("/themes", (req, res) => {
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json").then(response => response.json()).then(array => {
var themes_json;
for (let index = 0; index < array.length; index++) {
const name = array[index].name;
const zip_url = array[index].zip_url;
const git_url = array[index].git_url;
themes_json += `{Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}},`
app.post("/service", (req, res) => {
const body = req.body
const command_bds = body.command
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
if (body.token == element){
pass = true
} else {
token_verify++
}
return res.send(themes_json);
});
}
if (pass){
if (command_bds === 'start'){
var bds_init = bds.start()
var command_status = `Bds Started`
} else if (command_bds === 'stop'){
bds.stop()
var command_status = `Stopping the bds server`
} else {
var command_status = `no command identified`
}
res.send({
"status": 200,
"bds_status": command_status
})
} else {
res.send({
"status": 401,
"message": `Not authorized: ${body.token}`
})
}
});
app.get("/bds_dirs/", (req, res) => {
return res.send(fs.readdirSync(bds.bds_dir_bedrock));
app.post("/bds_download", (req, res) => {
const body = req.body
const ver = body.version
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
if (body.token == element){
pass = true
} else {
token_verify++
}
}
if (pass){
var STA = `wait`
var EMN = bds.download(ver)
} else {
var STA = `401`,
EMN = `Unauthorized Token`
}
res.send({
"status": STA,
"message": EMN
})
});
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
const http_port = "1932"
app.listen(http_port);
app.post("/bds_command", (req, res) => {
const body = req.body
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
// req.connection.remoteAddress
if (body.token == element){pass = true} else {token_verify++}
}
if (pass){
const command = body.command
const teste = bds.command(command)
res.send({
"status": 200,
"command": body.command,
"log": teste,
"message": `authorized to ${body.token}`
})
} else {
res.send({
"status": 401,
"message": "not authorized"
})
}
});
app.listen(1932);
}

View File

@ -1,26 +0,0 @@
module.exports = () => {
global.bds_api_start = true
const express = require("express");
const app = express();
var cors = require('cors');
app.use(cors());
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/:DI", (req, res) => {
return res.send(`
<html>
<head></head>
<body>
<a>token Save</a>
<p>
<textarea disabled>
${req.params.DI}
</textarea>
</p>
</body>
</html>
`);
});
app.listen(2212);
}

View File

@ -6,22 +6,27 @@ module.exports = () => {
const app = express();
var cors = require('cors');
app.use(cors());
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
app.get("/", (req, res) => {
if (typeof bds_log_string === 'undefined'){
var text = 'The server is stopped';
var sucess = false
if (fs.existsSync(localStorage.getItem("old_log_file"))){
var text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
var log_file = localStorage.getItem("old_log_file")
var sucess = true
} else {
var text = `The server is stopped`
var sucess = false
}
} else {
var text = bds_log_string
var log_file = "string"
var sucess = true
}
res.json({
"sucess": sucess,
"log": text,
"log_file": localStorage.getItem("old_log_file"),
"log_file": log_file,
"requeset_date": bds.date()
});
});
const http_port = "6565"
app.listen(http_port);
app.listen(6565);
}

View File

@ -1,114 +0,0 @@
module.exports = () => {
global.bds_api_post_start = true
const express = require("express");
const bds = require("../index");
const fs = require("fs");
const app = express();
var cors = require('cors');
const path = require("path")
const bodyParser = require("body-parser");
const rateLimit = require("express-rate-limit");
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
// see https://expressjs.com/en/guide/behind-proxies.html
// app.set('trust proxy', 1);
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
app.use(cors());
app.use(limiter);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
app.post("/info", (req, res) => {
const body = req.body
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
var teste = 'Sucess'
for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
if (pass){
if (fs.existsSync(process.cwd()+"/package.json")){
var api_v = require(process.cwd()+"/package.json").version
var name = bds.get_config().level_name
} else {
var api_v = null
var name = 'Bds_Maneger_api'
}
res.send({
"status": 200,
"api_version": api_v,
"name": name
})
} else {
res.send({
"status": 401,
"message": `Not authorized: ${body.token}`
})
}
});
app.get("/bds/:command", (req, res) => {
const body = req.body
const command_bds = '';
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
res.send({
"command": req.params.command
})
// for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
// if (pass){
// if (command_bds === 'start'){
// var bds_init = bds.start()
// var command_status = `Bds Started`
// } else if (command_bds === 'stop'){
// bds.stop()
// var command_status = `Stopping the bds server`
// } else if (command_bds === 'reload'){
// const bds_status = bds.detect()
// if (bds_detect){
// bds.stop()
// }
// var bds_init = bds.start()
// var command_status = `Reloading`
// } else {
// var command_status = `no command identified`
// }
// res.send({
// "status": 200,
// "bds_status": command_status
// })
// } else {
// res.send({
// "status": 401,
// "message": `Not authorized: ${body.token}`
// })
// }
});
app.post("/bds_command", (req, res) => {
const body = req.body
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
// req.connection.remoteAddress
if (body.token == element){pass = true} else {token_verify++}
}
if (pass){
const command = body.command
const teste = bds.command(command)
res.send({
"status": 200,
"command": body.command,
"log": teste,
"message": `authorized to ${body.token}`
})
} else {
res.send({
"status": 401,
"message": "not authorized"
})
}
});
const http_port = "28574"
app.listen(http_port);
}

View File

@ -1,17 +0,0 @@
module.exports = () => {
require("express");
if (typeof fetch === "undefined"){
var fetch = require("node-fetch")
}
const themes = "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json"
fetch(themes).then(response => response.json()).then(array => {
for (let index = 0; index < array.length; index++) {
const name = array[index].name;
const zip_url = array[index].zip_url;
const git_url = array[index].git_url;
console.log(`Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}`)
}
}).catch(function(error) {
console.log(`Could not get credentials, Error: \"${error.message}\"`);
});
}

View File

@ -42,11 +42,14 @@ if (arch == "x64"){
const path = require("path")
const fs = require("fs");
const package_root = path.join(process.cwd(), "package.json")
const package_root_builder = path.resolve(".", "resources", "app", "package.json")
if (process.platform == "win32") {
var home = process.env.USERPROFILE;
var desktop = path.join(home, "Desktop")
if (fs.existsSync(package_root)){
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)
} else if (package_root_builder){
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root_builder).name)
} else {
console.warn(`Temporary Storages, some functions will be lost after restarting the system`);
var cache_dir = path.join(process.env.TMP, `bds_tmp_configs`);
@ -57,6 +60,8 @@ if (process.platform == "win32") {
var home = process.env.HOME;
if (fs.existsSync(package_root)){
var cache_dir = path.join(home, ".config", require(package_root).name);
} else if (fs.existsSync(package_root_builder)) {
var cache_dir = path.join(home, ".config", require(package_root_builder).name);
} else {
console.warn(`Temporary Storages, some functions will be lost after restarting the system`);
var cache_dir = `/tmp/bds_tmp_configs`;
@ -189,7 +194,6 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
if (typeof bds_api_start === "undefined"){
require("./API/api")();
require("./API/log")();
require("./API/remote_access")();
}
} else {
console.warn(`The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)

View File

@ -157,7 +157,8 @@ function bds_get_config(){
if (bds.platform === "bedrock") var config_path = path.join(bds.bds_dir_bedrock, "server.properties")
else var config_path = path.join(bds.bds_dir_java, "server.properties")
return propertiesToJSON(fs.readFileSync(config_path, "utf8").replaceAll("-","_"));
var config = fs.readFileSync(config_path, "utf8").split("-").join("_")
return propertiesToJSON(config);
}
module.exports.config_example = () =>{
return {

1511
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "bds_maneger_api",
"version": "1.5.2",
"version": "1.5.3",
"description": "scripts to manage minecraft bedrock server",
"private": false,
"main": "index.js",
@ -42,7 +42,7 @@
"qr-image": "^3.2.0",
"qrcode": "^1.4.4",
"shelljs": "^0.8.4",
"systeminformation": "^5.0.2",
"systeminformation": "^5.0.10",
"telegraf": "^4.0.0"
}
}