diff --git a/.vscode/launch.json b/.vscode/launch.json index e215a8e..670e0b2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,12 @@ { "version": "0.2.0", "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Start Telegram bot dev", + "program": "${workspaceFolder}/bin/telegram_bot.js" + }, { "type": "node", "request": "launch", @@ -11,17 +17,6 @@ "Docker" ], "port": 9229 - }, - { - "type": "node", - "request": "launch", - "name": "Telegram BOT", - "runtimeExecutable": "npm", - "runtimeArgs": [ - "run", - "dev:telegram" - ], - "port": 9229 } ] } \ No newline at end of file diff --git a/BdsManegerInfo.json b/BdsManegerInfo.json index df0cfc7..8cc15d9 100644 --- a/BdsManegerInfo.json +++ b/BdsManegerInfo.json @@ -17,16 +17,17 @@ "stop": "stop", "op": "op \"{{Player}}\"", "deop": "op \"{{Player}}\"", + "ban": "tp \"{{Player}}\" ~ ~99999 ~", "kick": "kick \"{{Player}}\" \"{{Text}}\"", - "tp": "tp \"{{Player}}\" {{CCO}}" + "tp": "tp \"{{Player}}\" {{X}} {{Y}} {{X}}" }, "java": { "stop": "stop", - "op": "op \"{{Player}}\"", - "deop": "op \"{{Player}}\"", - "ban": "ban 0 0 0", - "kick": "kick \"{{Player}}\" {{Text}}", - "tp": "tp {{Player}} {{CCO}}" + "op": "op {{Player}}", + "deop": "op {{Player}}", + "ban": "ban {{Player}}", + "kick": "kick {{Player}} {{Text}}", + "tp": "tp {{Player}} {{X}} {{Y}} {{X}}" }, "pocketmine": { "stop": "stop", @@ -34,7 +35,7 @@ "deop": "op {{Player}}", "ban": "ban {{Player}}", "kick": "kick {{Player}}", - "tp": "tp {{Player}} {{CCO}}" + "tp": "tp \"{{Player}}\" {{X}} {{Y}} {{X}}" } }, "contributors": [ diff --git a/README.md b/README.md index 4d42a97..6dd9400 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,21 @@ Any contribution is welcome, but before a look at [CONTRIBUTING.md](CONTRIBUTING In Version 1.11.0 there was a big change in the way to get the new settings and that left a good part of the program broken, so for those who are going to upgrade to the latest versions of Bds maneger Core will have to change the settings manually. +## Documentation + +We have a separate repository for all Bds Maneger Project documentation, link here from the main page, Repository link + ## Badges [![Github CodeQL and OSSAR](https://github.com/The-Bds-Maneger/Bds-Maneger-Core/actions/workflows/codeql%20and%20ossar%20analysis.yml/badge.svg)](https://github.com/The-Bds-Maneger/Bds-Maneger-Core/actions/workflows/codeql%20and%20ossar%20analysis.yml) [![Total alerts](https://img.shields.io/lgtm/alerts/g/Bds-Maneger/bds_maneger_api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/alerts/) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Bds-Maneger/bds_maneger_api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/context:javascript) -[![DeepScan grade](https://deepscan.io/api/teams/13683/projects/16691/branches/363172/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=13683&pid=16691&bid=363172) +[![DeepScan grade](https://deepscan.io/api/teams/13683/projects/16691/branches/363172/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=13683&pid=16691&bid=363172) -## Start our Docker image, making everything easier. +## Start our Docker image, making everything easier Windows: + ```cmd $ docker run --rm -d --name BdsManegerCore -v BdsCore:/home/bds/bds_core ^ -p 19132:19132/udp -p 19133:19133/udp -p 1932:1932/tcp ^ @@ -34,6 +39,7 @@ bdsmaneger/core:latest ``` Linux/MacOS: + ```bash $ docker run --rm -d --name BdsManegerCore -v BdsCore/:/home/bds/bds_core \ -p 19132:19132/udp -p 19133:19133/udp -p 1932:1932/tcp \ @@ -51,13 +57,7 @@ bdsmaneger/core:latest ## We also have some Implementation Models for Azure -#### Microsoft Azure Container - -The Azure container is a special machine for Docker Within Azure, it is fully managed by Azure, it only depends on the Docker image, but it has its limitations. - -[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FBds-Maneger%2FThe-Bds-Maneger-Docker%2Fmain%2Fazure%2FBdsMangerCore_docker.json) - -#### Microsoft Azure Virtual machine +### Microsoft Azure Virtual machine Here we have a virtual machine totally dedicated to Bds Maneger Core, it still uses Docker to deploy Docker images. diff --git a/bin/bds_maneger.js b/bin/bds_maneger.js index cd0f040..723dadb 100755 --- a/bin/bds_maneger.js +++ b/bin/bds_maneger.js @@ -1,14 +1,14 @@ #!/usr/bin/env node -if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds_Manger_CLI"; +const readline = require("readline"); + +if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds-Manger-CLI"; process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true; -// Inports -const readline = require("readline"); const bds = require("../index"); const { valid_platform } = require("../lib/BdsSystemInfo"); const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings"); const commandExits = require("../lib/commandExist"); -const download = require("../src/download"); +const download = require("../src/BdsServersDownload"); // Bds Maneger ArgV const argv = require("minimist")(process.argv.slice(2)); diff --git a/bin/telegram_bot.js b/bin/telegram_bot.js old mode 100644 new mode 100755 index 5dd7d92..37ff279 --- a/bin/telegram_bot.js +++ b/bin/telegram_bot.js @@ -1,18 +1,13 @@ -const { Telegraf } = require("telegraf"); const fs = require("fs"); -const path = require("path"); +const { Telegraf, Markup } = require("telegraf"); const bds = require("../index"); -const { GetPlatform, GetPaths } = require("../lib/BdsSettings"); +const { GetPlatform, GetPaths, GetTelegramToken } = require("../lib/BdsSettings"); const { GetKernel, arch, system } = require("../lib/BdsSystemInfo"); const { Detect } = require("../src/CheckKill"); -const TelegramOptions = require("minimist")(process.argv.slice(2)); - -if (TelegramOptions.h || TelegramOptions.help) { - const Help = []; - console.log(Help.join("\n")); - process.exit(0) -} +const { Servers } = require("../lib/ServerURL"); +const { CheckTelegramUser } = require("../src/UsersAndtokenChecks") +// Bot Start And Help messages const HelpAndStart = [ "Hello, welcome to Bds Maneger Telegram Bot", "", @@ -20,119 +15,282 @@ const HelpAndStart = [ "Options:", " /start or /help: This message!", " /basic", - " start, stop", + " start, stop, backup", + " /live_log", + " enabler, disabler", + " /live_log", + " /download", + " Version", " ", ] // Set Telegram Bot -const bot = new Telegraf(bds.telegram_token); +const bot = new Telegraf(GetTelegramToken()); // Start and Help Command bot.start((ctx)=>ctx.reply(HelpAndStart.join("\n"))); bot.help((ctx)=>ctx.reply(HelpAndStart.join("\n"))); -const ChatIDs = {} -function SaveID(id = "a"){return ChatIDs[id] = true} -function RemoveID(id = "a"){return delete ChatIDs[id]} -function GetID(){return ChatIDs} +// User +bot.command("player", ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + + const Server = global.ServerExec; + const CtxOption = ctx.message.text.replace("/player", "").trim(); + const CtxContext = CtxOption.replace(/^kick|^deop|^ban|^op/, "").trim(); + if (CtxOption) { + const Players = CtxContext.split(/, |,/gi).filter(a => a.trim()); + console.log(Players); + if (/kick/.test(CtxOption)){ + if (Players.length >= 1) { + Players.forEach(Player => { + Server.kick(Player); + ctx.reply(`${Player} was kicked`); + }); + } else ctx.reply("and the Players?") + } + else if (/deop/.test(CtxOption)){ + if (Players.length >= 1) { + Players.forEach(Player => { + Server.deop(Player); + ctx.reply(`${Player} was deopped`); + }); + } else ctx.reply("and the Players?") + } + else if (/ban/.test(CtxOption)){ + if (Players.length >= 1) { + Players.forEach(Player => { + Server.ban(Player); + ctx.reply(`${Player} was banned`); + }); + } else ctx.reply("and the Players?") + } + else if (/op/.test(CtxOption)){ + if (Players.length >= 1) { + Players.forEach(Player => { + Server.op(Player); + ctx.reply(`${Player} was opped`); + }); + } else ctx.reply("and the Players?") + } + else if (/list/.test(CtxOption)){ + const Player_Json_path = GetPaths("player"); + let Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"))[GetPlatform()]; + const new_players = {}; + Players_Json.forEach(Player => { + console.log(Player); + if (new_players[Player.Player]) { + new_players[Player.Player].push([`Action: ${Player.Action}`, `Date: ${Player.Date}`].join("\n")); + } else { + new_players[Player.Player] = [ + [`Player: ${Player.Player}`, `Action: ${Player.Action}`, `Date: ${Player.Date}`].join("\n") + ] + } + }); + console.log(new_players); + Object.getOwnPropertyNames(new_players).forEach(Player_Array => { + let Length = Math.abs(new_players[Player_Array].length - 5); + let Player = new_players[Player_Array].slice(0, Length).join("\n") + ctx.reply(Player); + }); + } + else ctx.reply("Invalid option") + } else { + const ReplyOption = Markup.keyboard([ + "/player kick", + "/player deop", + "/player ban", + "/player op", + "/player list", + ]).oneTime().resize(); + ctx.reply("Player Options:", ReplyOption); + } +}); // Basic server -bot.command("basic", ctx => { +bot.command("basic", async ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + const text = ctx.message.text.replace("/basic", "").trim(); - if (/start/.test(text)) { - if (Detect()) ctx.reply("Stop Server"); - else { - try { - const Server = bds.start(); - Server.log(function (data){ - Object.getOwnPropertyNames(GetID()).forEach(Id => { - console.log(Id); - if (ChatIDs[Id]) bot.telegram.sendMessage(Id, data) - }) - }) - return ctx.reply("Server Started") - } catch (err) { - console.log(err) - ctx.reply("We couldn't start the server") - ctx.reply(err.toString()); + if (text) { + // Start Server + if (/start/.test(text)) { + if (Detect()) ctx.reply("Stop Server"); + else { + try { + const Server = bds.start(); + Server.log(function (data){ + for (let stx of global.LiveLog) stx.reply(data); + }); + global.ServerExec = Server; + return ctx.reply("Server Started") + } catch (err) { + console.log(err) + ctx.reply("We couldn't start the server") + ctx.reply(err.toString()); + } } } - } else if (/stop/.test(text)) { - if (Detect()) { - try { - bds.stop() - ctx.reply("Stopping your server") - } catch (err) { - ctx.reply("We had an error for your server"); - ctx.reply(err.toString()); - } - } else ctx.reply("Your server is stopped") - } else return ctx.reply("Invalid option, they are just: start, stop") + // Stop Server + else if (/stop/.test(text)) { + if (Detect()) { + try { + bds.stop() + ctx.reply("Stopping your server") + } catch (err) { + ctx.reply("We had an error for your server"); + ctx.reply(err.toString()); + } + } else ctx.reply("Your server is stopped") + } + // Backup + else if (/backup/.test(text)) { + const Backup = bds.backup(); + ctx.replyWithDocument({ + source: Backup.Buffer, + filename: Backup.file_name, + }) + } + // Invalid option + else return ctx.reply("Invalid option, they are just: start, stop") + } else { + await ctx.deleteMessage(); + const Options = Markup.keyboard([ + "/basic start", + "/basic stop", + "/basic backup", + ]).oneTime().resize(); + ctx.reply("Basic Options", Options); + } }); // Select Platform -bot.command("platform", ctx => { +bot.command("platform", async ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + const text = ctx.message.text.replace("/platform", "").trim(); - try { - bds.BdsSettigs.UpdatePlatform(text); - return ctx.reply(`Platform update to ${text}`) - } catch (err) { - ctx.reply("We were unable to change the platform") - return ctx.reply(err.toString()) + if (text) { + try { + bds.BdsSettigs.UpdatePlatform(text); + return ctx.reply(`Platform update to ${text}`) + } catch (err) { + ctx.reply("We were unable to change the platform") + return ctx.reply(err.toString()) + } + } else { + await ctx.deleteMessage(); + const Keyboard = Markup.keyboard([ + "/platform bedrock", + "/platform java", + "/platform pocketmine", + "/platform jsprismarine" + ]).oneTime().resize(); + ctx.reply("Select Platform", Keyboard) } -}) +}); + +// Download Server +bot.command("download", async ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + + const version = ctx.message.text.replace(/\/download|[a-zA-Z]/gi, "").trim(); + if (version) { + await bds.download(version, true); + ctx.reply(`Sucess install ${GetPlatform()} with version ${version}`); + } else { + await ctx.deleteMessage(); + const KeyboardVersion = Markup.keyboard(Object.getOwnPropertyNames(Servers[GetPlatform()]).map(version => { + return { + text: `/download ${version}` + } + })).oneTime().resize(); + ctx.reply("Select Version to Install", KeyboardVersion); + } +}); + +// Command +bot.command("command", async ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + + const text = ctx.message.text.replace("/command", "").trim(); + if (!(Detect())) return ctx.reply("Your server is stopped"); + if (text) { + try { + global.ServerExec.command(text); + } catch (err) { + ctx.reply("We couldn't execute the command"); + ctx.reply(`${err}`); + } + } else { + await ctx.deleteMessage(); + return ctx.reply("/command "); + } +}); // Send Info bot.command("info", ctx => { const config = bds.get_config(); const InfoRes = [ `Bds Maneger core version: ${bds.package_json.version}`, - "", - "* System Info:", - ` Kernel: ${GetKernel()}`, - ` Arch: ${arch}`, - ` System: ${system}`, - "", - "* Server:", - ` platform: ${GetPlatform()}`, - ` world_name: ${config.world}`, - ` running: ${bds.detect()}`, - ` port: ${config.portv4}`, - ` port6: ${config.portv6}`, - ` max_players: ${config.players}`, - ` whitelist: ${config.whitelist}`, + `Kernel: ${GetKernel()}`, + `Arch: ${arch}`, + `System: ${system}`, + `Platform: ${GetPlatform()}`, + `World_name: ${config.world}`, + `Running: ${bds.detect()}`, + `Port_V4: ${config.portv4}`, + `Port_V6: ${config.portv6}`, + `Max_players: ${config.players}`, + `Whitelist: ${config.whitelist}`, ] - return ctx.reply(InfoRes.join("\n")) -}); - -// Log -bot.command("log", ctx => { - try { - // 4096 - const Log = fs.readFileSync(path.resolve(GetPaths("log"), "latest.log"), "utf8") - if (Log.length >= 4096) ctx.reply(Log.substr(-4096)); - else ctx.reply(Log) - } catch (err) { - ctx.reply(err.toString()) - } + ctx.reply(InfoRes.join("\n\n")); }); // Live Log User -bot.command("live_log", ctx => { - const option = ctx.message.text.replace("/platform", "").trim(); - if (/enable/.test(option)) { - SaveID(ctx.from.id) - console.log(GetID()) - } else if (/disable/.test(option)) { - RemoveID(ctx.from.id) - console.log(GetID()) - } else ctx.reply("Invalid option") - ctx.reply(ctx.chat.id) -}) +global.LiveLog = []; +bot.command("live_log", async ctx => { + // Check admin Username + if (!(CheckTelegramUser(ctx.from.username))) return ctx.reply("you are not an administrator"); + + const option = ctx.message.text.replace("/live_log", "").trim(); + if (option) { + if (/enable/.test(option)) { + global.LiveLog.push(ctx); + return ctx.reply("Sucess"); + } else if (/disable/.test(option)) { + // ctx.from.id + for (let ctx_Logs in global.LiveLog) { + if (global.LiveLog[ctx_Logs].from.id === ctx.from.id) { + delete global.LiveLog[ctx_Logs]; + global.LiveLog = global.LiveLog.filter(a=>a); + return ctx.reply("Ok"); + } + } + return ctx.reply("You are not in the list"); + } + } + await ctx.deleteMessage(); + const ReplyOption = Markup.keyboard([ + "/live_log enable", + "/live_log disable", + ]).oneTime().resize(); + ctx.reply("Enable/Disabled?", ReplyOption); +}); + +// text +bot.on("text", ctx => { + console.log(ctx.message.text); + if (!(/\/.*/gi.test(ctx.message.text))) global.ServerExec.command(`say ${ctx.message.text}`) +}); // catch bot.catch(console.log); // End And Lauch -process.on("exit", bot.stop) -bot.launch() \ No newline at end of file +bot.launch(); +console.log("Telegram was started"); \ No newline at end of file diff --git a/index.js b/index.js index 1161b03..29f8271 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,10 @@ const { resolve } = require("path"); const path = require("path") const fs = require("fs"); -const { randomUUID } = require("crypto"); +const randomUUID = require("uuid").v4; +const { bds_dir } = require("./lib/BdsSettings"); + +if (typeof fetch === "undefined") global.fetch = require("node-fetch"); function date(format) { const today = new Date(), @@ -26,26 +29,42 @@ module.exports.package_path = bds_core_package module.exports.package_json = require("./package.json"); module.exports.extra_json = require("./BdsManegerInfo.json"); -const { bds_dir } = require("./lib/BdsSettings"); - // Inport and Export Arch const { arch } = require("./lib/BdsSystemInfo"); module.exports.arch = arch -const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken, GetTelegramToken } = require("./lib/BdsSettings"); -if (typeof fetch === "undefined") global.fetch = require("node-fetch"); +const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken } = require("./lib/BdsSettings"); -const maneger_ips = require("./src/external_ip") +// Bds Maneger Core Network +const maneger_ips = require("./src/BdsNetwork") module.exports.internal_ip = maneger_ips.internal_ip module.exports.external_ip = maneger_ips.external_ip -module.exports.save_google_id = require("./lib/BdsSettings").CloudConfig.Driver -module.exports.getBdsConfig = GetJsonConfig -module.exports.change_platform = module.exports.platform_update = UpdatePlatform -module.exports.telegram_token_save = UpdateTelegramToken -module.exports.api = require("./src/rest/api"); +module.exports.tmphost = { + host: maneger_ips.host, + Response: maneger_ips.HostResponse +} -// Telegram -module.exports.telegram_token = GetTelegramToken(); +// Get Old Method Config +module.exports.getBdsConfig = GetJsonConfig; + +/** + * Update Current Platform + */ +module.exports.change_platform = module.exports.platform_update = UpdatePlatform; + +/** + * Save Telegram token in Settings File + */ +module.exports.telegram_token_save = UpdateTelegramToken + +/** + * The Bds Maneger Core Internal API REST + * + * @param {number} port - The port number, default is 1932 + * + * @param {function} callback - The callback function after start API + */ +module.exports.api = require("./src/rest/api"); function token_register() { const bds_token_path = path.join(bds_dir, "bds_tokens.json"); @@ -67,17 +86,6 @@ function token_register() { return bdsuid; } -/** - * Update, Get and more to Modifications Bds Settings File - */ -module.exports.BdsSettigs = require("./lib/BdsSettings"); - -// Requires -const { World_BAckup } = require("./src/backups"); -const { config, get_config, config_example } = require("./src/ServerSettings"); -const download = require("./src/download"); -const { start, stop, BdsCommand, CronBackups } = require("./src/basic_server") - /** * Register tokens to use in Bds Maneger REST and other supported applications * @@ -85,6 +93,17 @@ const { start, stop, BdsCommand, CronBackups } = require("./src/basic_server") */ module.exports.token_register = token_register +/** + * Update, Get and more to Modifications Bds Settings File + */ +module.exports.BdsSettigs = require("./lib/BdsSettings"); + +// Requires +const { World_BAckup } = require("./src/BdsBackup"); +const { config, get_config } = require("./src/ServerSettings"); +const download = require("./src/BdsServersDownload"); +const { start, stop, BdsCommand, CronBackups } = require("./src/BdsManegerServer") + /** * Take the current date */ @@ -98,6 +117,7 @@ module.exports.BdsDate = module.exports.date = date module.exports.command = BdsCommand // New management method +// Start Server /** * to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else * @@ -105,10 +125,14 @@ module.exports.command = BdsCommand * server.log(function (log){console.log(log)}) */ module.exports.start = start + +// Stop Server /** * use this command for the server, that's all */ module.exports.stop = stop + +// Create Backup of Bds Maneger Core and Servers along with your maps and settings /** * backup your map locally */ @@ -137,14 +161,13 @@ module.exports.kill = Kill * use download( version, boolean ) // the boolean is for if you want to force the installation of the server * * @example - * bedrock: bds.download("1.16.201.02") + * bedrock: download("1.16.201.02") * - * java: bds.download("1.16.5") + * java: download("1.16.5") * - * any platform: bds.download("latest") // It will download the latest version available for download + * any platform: download("latest") // It will download the latest version available for download */ module.exports.download = download -module.exports.config_example = config_example /** * use this command to modify server settings @@ -164,20 +187,13 @@ module.exports.config_example = config_example }); */ module.exports.set_config = config + /** * takes the server settings in JSON format */ module.exports.get_config = get_config - -/** - * Get temp domain to Server and API (The Domain is even temporary). - */ -module.exports.tmphost = require("./lib/tempHost") - -// Core Applications - /** * Load Crontab Backup */ -module.exports.Cron_Loaded = CronBackups; \ No newline at end of file +module.exports.Cron_Loaded = CronBackups; diff --git a/lib/BdsSettings.js b/lib/BdsSettings.js index ffadb8e..7db3a6d 100644 --- a/lib/BdsSettings.js +++ b/lib/BdsSettings.js @@ -1,13 +1,11 @@ const { join, resolve } = require("path"); const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs"); const { homedir } = require("os"); +const { valid_platform } = require("./BdsSystemInfo"); const yaml = { parse: require("js-yaml").load, stringify: require("js-yaml").dump } -const FetchSync = require("@the-bds-maneger/fetchsync"); -const { external_ip } = require("../src/external_ip"); -const { valid_platform } = require("./BdsSystemInfo"); // PATHs const home = homedir(); @@ -21,7 +19,7 @@ else if (valid_platform["java"]) default_platformConfig = "java"; else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine"; else default_platformConfig = "jsprismarine" - +// Config Base to Bds Maneger Core and others Projects var Config = { paths: { servers: join(bds_dir, "Servers"), @@ -30,11 +28,7 @@ var Config = { player: join(bds_dir, "Players.json") }, bds: { - enable_tmp_host: false, - temelemetry: { - id: null, - load: false - } + enable_tmp_host: false }, server: { platform: default_platformConfig, @@ -122,14 +116,6 @@ if (existsSync(ConfigPath)) Config = { }; else writeFileSync(ConfigPath, yaml.stringify(Config)) process.on("exit", ()=>SaveConfig()) -// Telemetry -if (Config.bds.temelemetry.load) { - if (!(Config.bds.temelemetry.id)) { - Config.bds.temelemetry.id = FetchSync(`https://telemetry.the-bds-maneger.org/getid?external_ip=${JSON.stringify(external_ip)}`).text() - SaveConfig() - } -} - // Paths if (!(existsSync(Config.paths["backups"]))) mkdirSync(Config.paths["backups"], {recursive: true}) if (!(existsSync(Config.paths["log"]))) mkdirSync(Config.paths["log"], {recursive: true}) @@ -149,108 +135,173 @@ for (let Servers of Object.getOwnPropertyNames(ServersPaths)) { } } -module.exports = { - bds_dir: bds_dir, - GetJsonConfig: function(){return Config}, - GetPaths: function(path = null){ - if (!(path)) throw new Error("Set path to get"); - if (!(path === "all" || Config.paths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(Config.paths).join(", ")); - if (path === "all") return Config.paths - return Config.paths[path] - }, - GetServerPaths: function(path = null){ - if (!(path)) throw new Error("Set path to get"); - if (!(ServersPaths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(ServersPaths).join(", ")); - return ServersPaths[path] - }, - GetServerSettings: function(platform = Config.server.platform){ - return Config.server.Settings[platform] - }, - UpdateServerVersion: function(version = null, platform = Config.server.platform){ - if (Config.server.versions[platform] || Config.server.versions[platform] === null) { - Config.server.versions[platform] = version; - SaveConfig() - return Config.server.versions[platform] - } else throw new Error("Platform invalid") - }, - GetServerVersion: function(){return Config.server.versions}, - GetServerBan: function (){return Config.ban}, - GetCronBackup: function(){return Config.server.BackupCron}, - UpdatePlatform: function(platform = Config.server.platform){ - platform = platform.toLocaleLowerCase(); - if (platform === "bedrock") { - Config.server.platform = "bedrock"; - SaveConfig() - } else if (platform === "java") { - Config.server.platform = "java"; - SaveConfig() - } else if (platform === "pocketmine") { - Config.server.platform = "pocketmine"; - SaveConfig() - } else if (platform === "jsprismarine") { - Config.server.platform = "jsprismarine"; - SaveConfig() - } else throw new Error("platform no Exists") - return platform - }, - GetPlatform: function(){return Config.server.platform}, - UpdateTelegramToken: function (token = null){ - if (!(token)) throw new Error("Telegram Token invalid") - Config.telegram.token = token +// return settings by function +function GetJsonConfig(){ + return Config +} + +// get the path from the settings and return by function +function GetPaths(path = null){ + if (!(path)) throw new Error("Set path to get"); + if (!(path === "all" || Config.paths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(Config.paths).join(", ")); + if (path === "all") return Config.paths + return Config.paths[path] +} + +// Get the server paths if you don't send a throw +function GetServerPaths(path = null){ + if (!(path)) throw new Error("Set path to get"); + if (!(ServersPaths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(ServersPaths).join(", ")); + return ServersPaths[path] +} + +// Get the server settings for now it's only being used in Java +function GetServerSettings(platform = Config.server.platform){ + return Config.server.Settings[platform] +} + +// Update the settings and save at the same time so as not to lose any information from the Bds Maneger settings +function UpdateServerVersion(version = null, platform = Config.server.platform){ + if (Config.server.versions[platform] || Config.server.versions[platform] === null) { + Config.server.versions[platform] = version; SaveConfig() - return token - }, - GetTelegramToken: function(){ - return Config.telegram.token - }, - GetTelegramAdmins: function(){ - return Config.telegram.admins - }, - GetTempHost: function(){return Config.bds.enable_tmp_host}, - UpdateTempHost: function(enable = false){ - // Check Boolean - if (typeof enable !== "boolean") {console.log("Use Boolean, default false"); enable = false;} - - // Save - Config.bds.enable_tmp_host = enable - return SaveConfig(); - }, - CloudConfig: {}, - GetCloudConfig: function(cloud = null){ - if (!(cloud) || !(Config.cloud[cloud])) throw new Error("Cloud no exists"); - return Config.cloud[cloud] + return Config.server.versions[platform] + } else throw new Error("Platform invalid") +} + +// Return an Object with all server versions installed +function GetServerVersion(){ + return Config.server.versions +} + +// Catch Players/People from Servers/Telegram to be banned or removed from Server/Minecraft +function GetServerBan(){ + return Config.ban +} + +// Cron for Backup +function GetCronBackup(){ + return Config.server.BackupCron +} + +// Update the entire Bds Manager Core platform +function UpdatePlatform(platform = Config.server.platform){ + platform = platform.toLocaleLowerCase(); + if (/bedrock/.test(platform)) { + Config.server.platform = "bedrock"; + SaveConfig() + } else if (/java/.test(platform)) { + Config.server.platform = "java"; + SaveConfig() + } else if (/pocketmine/.test(platform)) { + Config.server.platform = "pocketmine"; + SaveConfig() + } else if (/jsprismarine/.test(platform)) { + Config.server.platform = "jsprismarine"; + SaveConfig() + } else throw new Error("platform no Exists") + return platform +} + +// Return to platform +function GetPlatform(){ + return Config.server.platform +} + +// Telegram +function UpdateTelegramToken(token = null){ + if (!(token)) throw new Error("Telegram Token invalid") + Config.telegram.token = token + SaveConfig() + return token +} + +function GetTelegramToken(){ + return Config.telegram.token +} + +function GetTelegramAdmins(){ + return Config.telegram.admins +} + +// Get a temporary host to connect to the server. +function GetTempHost(){ + return Config.bds.enable_tmp_host +} + +// Enable and/or disable pick up temporary host. +function UpdateTempHost(enable = false){ + // Check Boolean + if (typeof enable !== "boolean") {console.log("Use Boolean, default false"); enable = false;} + + // Save + Config.bds.enable_tmp_host = enable + return SaveConfig(); +} + +// Get the server settings +function GetCloudConfig(cloud = null){ + if (!(cloud) || !(Config.cloud[cloud])) throw new Error("Cloud no exists"); + return Config.cloud[cloud] +} + +// Settings Cloud +// Azure +function Azure_Settings(account = null, key = null, container = null){ + if (!(account)) throw new Error("Set Azure Blob Account") + if (!(key)) throw new Error("Set Azure Blob Key") + if (!(container)) throw new Error("Set Azure Container") + Config.cloud.Azure.Account = account + Config.cloud.Azure.AccountKey = key + Config.cloud.Azure.Container = container + SaveConfig() + return { + Account: Config.cloud.Azure.Account, + Key: Config.cloud.Azure.AccountKey, + Container: Config.cloud.Azure.Container } } -module.exports.CloudConfig = { - Azure: function(account = null, key = null, container = null){ - if (!(account)) throw new Error("Set Azure Blob Account") - if (!(key)) throw new Error("Set Azure Blob Key") - if (!(container)) throw new Error("Set Azure Container") - Config.cloud.Azure.Account = account - Config.cloud.Azure.AccountKey = key - Config.cloud.Azure.Container = container - SaveConfig() - return { - Account: Config.cloud.Azure.Account, - Key: Config.cloud.Azure.AccountKey, - Container: Config.cloud.Azure.Container - } - }, - Oracle: function(bucket = null){ - if (!(bucket)) throw new Error("Set Oracle Bucket name") - Config.cloud.Oracle.Bucket = bucket - return { - Bucket: bucket - } - }, - Google: function(){throw new Error("doesn't work yet")}, - Driver: function(rootid = null){ - if (!(rootid)) {rootid = null; console.log("No Backup folder id added for Google Driver");} - Config.cloud.Driver.RootID = rootid - SaveConfig() - return { - RootID: rootid - } +// Oracle +function Oracle_Settings(bucket = null){ + if (!(bucket)) throw new Error("Set Oracle Bucket name") + Config.cloud.Oracle.Bucket = bucket + return { + Bucket: bucket } -} \ No newline at end of file +} + +// Google Drive +function Google_Driver_Settings(rootid = null){ + if (!(rootid)) {rootid = null; console.log("No Backup folder id added for Google Driver");} + Config.cloud.Driver.RootID = rootid + SaveConfig() + return { + RootID: rootid + } +} + +module.exports = { + bds_dir: bds_dir, + GetJsonConfig, + GetPaths, + GetServerPaths, + GetServerSettings, + UpdateServerVersion, + GetServerVersion, + GetServerBan, + GetCronBackup, + UpdatePlatform, + GetPlatform, + UpdateTelegramToken, + GetTelegramToken, + GetTelegramAdmins, + GetTempHost, + UpdateTempHost, + GetCloudConfig, + CloudConfig: { + Azure: Azure_Settings, + Oracle: Oracle_Settings, + Driver: Google_Driver_Settings + } +} diff --git a/lib/ServerURL.js b/lib/ServerURL.js index 2df0d72..7599107 100644 --- a/lib/ServerURL.js +++ b/lib/ServerURL.js @@ -1,6 +1,5 @@ const fetchSync = require("@the-bds-maneger/fetchsync"); module.exports = { Servers: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json").json(), - PHPBin: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json(), - GoogleDriver: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Credentials/Google.json").json() + PHPBin: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json() } \ No newline at end of file diff --git a/lib/tempHost.js b/lib/tempHost.js deleted file mode 100644 index 694423c..0000000 --- a/lib/tempHost.js +++ /dev/null @@ -1,37 +0,0 @@ -const fetchSync = require("@the-bds-maneger/fetchsync"); -const { external_ip, Interfaces } = require("../src/external_ip"); -const { GetTempHost } = require("./BdsSettings") - -if (GetTempHost()){ - // Get HOST - const HostResponse = fetchSync("https://bds-core-back-end.vercel.app/Gethost", { - method: "POST", - mode: "cors", - body: JSON.stringify({ - mac: Interfaces[0].MAC, - ip: external_ip.ipv4, - }), - headers: { - "Content-Type": "application/json" - } - }).json(); - global.BdsTempHost = HostResponse.user.host.host - module.exports.host = HostResponse.user.host.host - module.exports.Response = HostResponse - - console.log(`Bds Maneger Core Temp Host ID: ${HostResponse.user.ID}`) - - // Delete Host - process.on("exit", function () { - const deleted_host = fetchSync("https://bds-core-back-end.vercel.app/DeleteHost", { - method: "post", - body: JSON.stringify({ - "ID": HostResponse.user.ID - }), - headers: { - "Content-Type": "application/json" - } - }).json() - if (deleted_host.error) console.log(deleted_host.error) - }) -} else module.exports.host = null \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1ba1363..da05747 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@the-bds-maneger/core", - "version": "1.13.2", + "version": "1.13.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@the-bds-maneger/core", - "version": "1.13.2", + "version": "1.13.4", "license": "AGPL-3.0-or-later", "dependencies": { "@azure/storage-blob": "^12.6.0", @@ -14,7 +14,6 @@ "adm-zip": "^0.5.1", "body-parser": "^1.19.0", "cors": "^2.8.5", - "create-desktop-shortcuts": "^1.4.0", "cron": "^1.8.2", "express": "^4.17.1", "express-fileupload": "^1.2.1", @@ -25,17 +24,19 @@ "minimist": "^1.2.5", "node-cron": "^3.0.0", "node-fetch": "^2.6.1", - "node-localstorage": "^2.1.6", "oci-sdk": "^2.0.0", "open": "^8.0.0", "properties-to-json": "^0.2.1", "request-ip": "^2.1.3", - "telegraf": "^4.0.0" + "telegraf": "^4.0.0", + "uuid": "^8.3.2" }, "bin": { - "bds_maneger": "bin/bds_maneger.js" + "bds_maneger": "bin/bds_maneger.js", + "bds_telegram": "bin/telegram_bot.js" }, "devDependencies": { + "docker-run_build": "github:Sirherobrine23/Docker-Run_Build", "eslint": "^7.19.0", "husky": "^7.0.0", "nexe": "*", @@ -1429,14 +1430,6 @@ "node": ">= 0.10" } }, - "node_modules/create-desktop-shortcuts": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/create-desktop-shortcuts/-/create-desktop-shortcuts-1.5.0.tgz", - "integrity": "sha512-XYRHuBKCfZHbHYHnltfX3HrxIMPWEGNaark+QQmAxeiqAlfMEViTEcJsi+MVMDJy5QXRkXM6bUh9xIWtONoCEw==", - "dependencies": { - "which": "^2.0.2" - } - }, "node_modules/cron": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz", @@ -1801,6 +1794,19 @@ "node": ">=8" } }, + "node_modules/docker-run_build": { + "version": "1.0.0", + "resolved": "git+ssh://git@github.com/Sirherobrine23/Docker-Run_Build.git#dca7037ac2175352485e61e7e565ec1d81caa062", + "dev": true, + "license": "GPL-3.0-or-later", + "dependencies": { + "js-yaml": "^4.1.0", + "minimist": "^1.2.5" + }, + "bin": { + "docker-run_build": "bin/cli.js" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -2993,7 +2999,8 @@ "node_modules/graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", + "dev": true }, "node_modules/gtoken": { "version": "5.3.0", @@ -3217,6 +3224,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true, "engines": { "node": ">=0.8.19" } @@ -3461,7 +3469,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true }, "node_modules/isomorphic-fetch": { "version": "3.0.0", @@ -4177,17 +4186,6 @@ "node": ">= 6.0.0" } }, - "node_modules/node-localstorage": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-2.2.1.tgz", - "integrity": "sha512-vv8fJuOUCCvSPjDjBLlMqYMHob4aGjkmrkaE42/mZr0VT+ZAU10jRF8oTnX9+pgU9/vYJ8P7YT3Vd6ajkmzSCw==", - "dependencies": { - "write-file-atomic": "^1.1.4" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/nodemon": { "version": "2.0.12", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz", @@ -6220,14 +6218,6 @@ "url": "https://github.com/chalk/slice-ansi?sponsor=1" } }, - "node_modules/slide": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", - "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=", - "engines": { - "node": "*" - } - }, "node_modules/sort-keys": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz", @@ -6940,6 +6930,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -6977,16 +6968,6 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, - "node_modules/write-file-atomic": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", - "integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=", - "dependencies": { - "graceful-fs": "^4.1.11", - "imurmurhash": "^0.1.4", - "slide": "^1.1.5" - } - }, "node_modules/xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", @@ -8132,14 +8113,6 @@ "vary": "^1" } }, - "create-desktop-shortcuts": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/create-desktop-shortcuts/-/create-desktop-shortcuts-1.5.0.tgz", - "integrity": "sha512-XYRHuBKCfZHbHYHnltfX3HrxIMPWEGNaark+QQmAxeiqAlfMEViTEcJsi+MVMDJy5QXRkXM6bUh9xIWtONoCEw==", - "requires": { - "which": "^2.0.2" - } - }, "cron": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz", @@ -8422,6 +8395,15 @@ "path-type": "^4.0.0" } }, + "docker-run_build": { + "version": "git+ssh://git@github.com/Sirherobrine23/Docker-Run_Build.git#dca7037ac2175352485e61e7e565ec1d81caa062", + "dev": true, + "from": "docker-run_build@github:Sirherobrine23/Docker-Run_Build", + "requires": { + "js-yaml": "^4.1.0", + "minimist": "^1.2.5" + } + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -9380,7 +9362,8 @@ "graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", + "dev": true }, "gtoken": { "version": "5.3.0", @@ -9532,7 +9515,8 @@ "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=" + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true }, "inflight": { "version": "1.0.6", @@ -9711,7 +9695,8 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true }, "isomorphic-fetch": { "version": "3.0.0", @@ -10281,14 +10266,6 @@ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz", "integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==" }, - "node-localstorage": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-2.2.1.tgz", - "integrity": "sha512-vv8fJuOUCCvSPjDjBLlMqYMHob4aGjkmrkaE42/mZr0VT+ZAU10jRF8oTnX9+pgU9/vYJ8P7YT3Vd6ajkmzSCw==", - "requires": { - "write-file-atomic": "^1.1.4" - } - }, "nodemon": { "version": "2.0.12", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz", @@ -12016,11 +11993,6 @@ "is-fullwidth-code-point": "^3.0.0" } }, - "slide": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", - "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=" - }, "sort-keys": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz", @@ -12575,6 +12547,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "requires": { "isexe": "^2.0.0" } @@ -12600,16 +12573,6 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, - "write-file-atomic": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", - "integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=", - "requires": { - "graceful-fs": "^4.1.11", - "imurmurhash": "^0.1.4", - "slide": "^1.1.5" - } - }, "xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", diff --git a/package.json b/package.json index e15c372..bd9bc42 100644 --- a/package.json +++ b/package.json @@ -3,24 +3,24 @@ "publishConfig": { "access": "public" }, - "version": "1.13.2", + "version": "1.13.4", "description": "Scripts to manage minecraft server's", "private": false, "main": "index.js", "scripts": { "start": "node bin/bds_maneger.js -s", + "start:telegram": "node bin/telegram_bot.js -e js", "stop": "node -p 'console.log(require(\"./\").kill());'", "test": "node .Build/test/ci.js", "ci": "node .Build/test/ci.js", "eslint": "eslint --debug .", - "eslint:debug": "eslint --debug .", - "eslint:fix": "eslint --fix .", + "eslint:fix": "eslint --debug --fix .", "nexe": "node .Build/nexe_build.js", - "Docker": "node .Build/DockerImage.js", - "dev:telegram": "node bin/telegram_bot.js -e js" + "Docker": "node .Build/DockerImage.js" }, "bin": { - "bds_maneger": "./bin/bds_maneger.js" + "bds_maneger": "./bin/bds_maneger.js", + "bds_telegram": "./bin/telegram_bot.js" }, "repository": { "type": "git", @@ -39,18 +39,16 @@ "author": "Sirherobrine23", "license": "AGPL-3.0-or-later", "bugs": { - "url": "https://github.com/The-Bds-Maneger/Bds-Maneger-Core/issues", - "email": "support@the-bds-maneger.org" + "url": "https://github.com/The-Bds-Maneger/Bds-Maneger-Core/issues/new" }, - "homepage": "https://github.com/The-Bds-Maneger/Bds-Maneger-Core/", - "docs_base": "https://docs.the-bds-maneger.org/Bds Maneger core/", + "homepage": "https://docs.bdsmaneger.com/Bds Maneger core", "engines": { "node": ">=14", "npm": ">=7" }, "husky": { "hooks": { - "post-merge": "npm update && npm install" + "post-merge": "npm install --node-save -d" } }, "dependencies": { @@ -59,7 +57,6 @@ "adm-zip": "^0.5.1", "body-parser": "^1.19.0", "cors": "^2.8.5", - "create-desktop-shortcuts": "^1.4.0", "cron": "^1.8.2", "express": "^4.17.1", "express-fileupload": "^1.2.1", @@ -70,14 +67,15 @@ "minimist": "^1.2.5", "node-cron": "^3.0.0", "node-fetch": "^2.6.1", - "node-localstorage": "^2.1.6", "oci-sdk": "^2.0.0", "open": "^8.0.0", "properties-to-json": "^0.2.1", "request-ip": "^2.1.3", - "telegraf": "^4.0.0" + "telegraf": "^4.0.0", + "uuid": "^8.3.2" }, "devDependencies": { + "docker-run_build": "github:Sirherobrine23/Docker-Run_Build", "eslint": "^7.19.0", "husky": "^7.0.0", "nexe": "*", diff --git a/src/backups.js b/src/BdsBackup.js similarity index 96% rename from src/backups.js rename to src/BdsBackup.js index 8467e5e..213d677 100644 --- a/src/backups.js +++ b/src/BdsBackup.js @@ -44,7 +44,7 @@ function Backup() { for (let index of Object.getOwnPropertyNames(GetPaths("all")).filter(path => !/servers|backups/.test(path)).map(name => GetPaths(name))) { if (existsSync(index)) { const _S = statSync(resolve(index)); - if (_S.isFile() || _S.isSymbolicLink()) zip.addLocalFile(index); else zip.addLocalFolder(index) + if (_S.isFile() || _S.isSymbolicLink()) zip.addLocalFile(index, "/BdsManegerCore"); else zip.addLocalFolder(index, join("/BdsManegerCore", index.replace(bds_dir, ""))); } } diff --git a/src/basic_server.js b/src/BdsManegerServer.js similarity index 88% rename from src/basic_server.js rename to src/BdsManegerServer.js index 6f364ff..f627923 100644 --- a/src/basic_server.js +++ b/src/BdsManegerServer.js @@ -2,10 +2,10 @@ const child_process = require("child_process"); const fs = require("fs"); const path = require("path"); const { resolve, join } = require("path"); -const { randomUUID } = require("crypto"); +const randomUUID = require("uuid").v4; const { CronJob } = require("cron"); const { GetCronBackup } = require("../lib/BdsSettings"); -const { Backup } = require("./backups"); +const { Backup } = require("./BdsBackup"); // Bds Maneger Inports const commandExists = require("../lib/commandExist"); @@ -167,6 +167,34 @@ function start() { }); ServerExec.stdout.on("data", data); ServerExec.stderr.on("data", data); + }, + op: function (player = "Steve") { + let command = BdsInfo.Servers[GetPlatform()].op.replace("{{Player}}", player); + ServerExec.stdin.write(command+"\n"); + return command; + }, + deop: function (player = "Steve") { + let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player); + ServerExec.stdin.write(command+"\n"); + return command; + }, + ban: function (player = "Steve") { + let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player); + ServerExec.stdin.write(command+"\n"); + return command; + }, + kick: function (player = "Steve", text = "you got kicked") { + let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text); + ServerExec.stdin.write(command+"\n"); + return command; + }, + tp: function (player = "Steve", cord = {x: 0, y: 128, z: 0}) { + let command = BdsInfo.Servers[GetPlatform()].tp.replace("{{Player}}", player); + if (cord.x) command = command.replace("{{X}}", cord.x); else command = command.replace("{{X}}", 0); + if (cord.y) command = command.replace("{{Y}}", cord.y); else command = command.replace("{{Y}}", 128); + if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0); + ServerExec.stdin.write(command+"\n"); + return command; } } ServerExec.on("exit", ()=>{delete global.BdsExecs[returnFuntion.uuid]}); diff --git a/src/BdsNetwork.js b/src/BdsNetwork.js new file mode 100644 index 0000000..f4aa12e --- /dev/null +++ b/src/BdsNetwork.js @@ -0,0 +1,89 @@ +// External User ip +const fetchSync = require("@the-bds-maneger/fetchsync"); +const os = require("os"); +const { GetTempHost } = require("../lib/BdsSettings"); + +const externalIP = { + ipv4: fetchSync("https://api.ipify.org/").text().replace("\n", ""), + ipv6: fetchSync("https://api64.ipify.org/").text().replace("\n", "") +} + +// Internal ip user +const interfaces = os.networkInterfaces(); +const internal_ip = []; +for (let inter of Object.getOwnPropertyNames(interfaces).map(index => interfaces[index])){ + for (let ind in inter){ + if (inter[ind].address.includes("::")) internal_ip.push(`[${inter[ind].address}]`) + else internal_ip.push(inter[ind].address) + } +} + +// Network Interfaces +const Interfaces = Object.getOwnPropertyNames(interfaces).map(inter => { + inter = interfaces[inter] + if (inter[0].mac !== "00:00:00:00:00:00") { + try { + return { + MAC: inter[0].mac, + Interna_IP: { + ipv4: inter[0].address, + ipv6: inter[1].address, + } + } + } catch (err) { + return { + MAC: inter[0].mac, + Interna_IP: { + ipv4: inter[0].address, + ipv6: null, + } + } + } + } +}).filter(a=>a); + +// Temp Host +var host = null, + HostResponse = null; + +if (GetTempHost()){ + // Get HOST + HostResponse = fetchSync("https://bds-core-back-end.vercel.app/Gethost", { + method: "POST", + mode: "cors", + body: JSON.stringify({ + mac: Interfaces[0].MAC, + ip: external_ip.ipv4, + }), + headers: { + "Content-Type": "application/json" + } + }).json(); + global.BdsTempHost = HostResponse.user.host.host + host = HostResponse.user.host.host + + console.log(`Bds Maneger Core Temp Host ID: ${HostResponse.user.ID}`) + + // Delete Host + process.on("exit", function () { + const deleted_host = fetchSync("https://bds-core-back-end.vercel.app/DeleteHost", { + method: "post", + body: JSON.stringify({ + "ID": HostResponse.user.ID + }), + headers: { + "Content-Type": "application/json" + } + }).json() + if (deleted_host.error) console.log(deleted_host.error) + }) +} else module.exports.host = null + +module.exports = { + externalIP, + ip: externalIP, + internal_ip, + Interfaces, + HostResponse, + host, +} \ No newline at end of file diff --git a/src/download.js b/src/BdsServersDownload.js similarity index 100% rename from src/download.js rename to src/BdsServersDownload.js diff --git a/src/CheckKill.js b/src/CheckKill.js index 953cab4..b7a577b 100644 --- a/src/CheckKill.js +++ b/src/CheckKill.js @@ -1,43 +1,47 @@ const { execSync } = require("child_process"); function getProcess(){ - const MountProcess = []; - var getList = "" + let MountProcess = []; if (process.platform === "win32") { - console.info("Getting the process list in Windows is too slow"); - getList = execSync("tasklist").toString("utf8").split("\r").join("\n").split("\n").filter(d => {return !(d === "" || d.includes("====="))}) - delete getList[0]; - getList = getList.filter(d=>{return (d !== undefined)}) - for (let _line of getList) { - _line = _line.split(/\s+/) - // Get argument: wmic process where "ProcessID=4152" get commandline - const pidNumber = (_line.length - 5) - MountProcess.push({ - command: (function(){ - try { - return execSync(`wmic process where "ProcessID=${_line[pidNumber]}" get commandline`).toString("utf8").split("\r").join("\n").split("\n").filter(d=>{return !(d.trim() === "" || d.trim() === "CommandLine")}).join(" ").trim().split("\"").join("").trim() - } catch (err) { - return null - } - })(), - pid: parseInt(_line[pidNumber]), - cpu: _line[(_line.length - 3)], - mem: (_line[(_line.length - 2)].split(".").join("")), - }) - } + MountProcess = execSync("wmic path win32_process get Processid,Commandline,WorkingSetSize").toString().split(/\n/gi).filter(a => a.trim()).map(Line => { + try { + Line = Line.split(/\r/gi).filter(a => a).join("").trim(); + const line_split = Line.split(/\s+/gi); + + // Ignore empty lines + if (line_split.length <= 2) return false + + let pid = line_split[Math.abs(line_split.length - 2)].toString(); + let mem = line_split[Math.abs(line_split.length - 1)].toString(); + let command = Line.slice(0, - Math.abs(pid.length)).trim().slice(0, - Math.abs(mem.length)).trim(); + pid = parseInt(pid); + mem = parseInt(mem); + if (command && pid && mem) return { + command, + pid, + mem, + }; else return false + } catch (err) { + console.log(err); + return false + } + }).filter(a => a); } else { - getList = execSync("ps -aux").toString("utf8").split("\n").filter(d=>{return !(/USER\s+/.test(d) || d === "")}) - for (let _line of getList) { - _line = _line.split(/\s+/) - MountProcess.push({ - command: (function(){var command = _line[10];const argvLenght = (_line.length - 11);for (let index = 0; index < argvLenght; index++) {command += ` ${_line[11 + index]}`;} return command})(), + MountProcess = execSync("ps -aux").toString("utf8").split("\n").filter(d=>{return !(/USER\s+/.test(d) || d === "")}).map(_line => _line.split(/\s+/)).map(_line =>{ + return { + command: (function(){ + var command = _line[10]; + const argvLenght = (_line.length - 11); + for (let index = 0; index < argvLenght; index++) { + command += ` ${_line[11 + index]}`; + } + return command; + })(), pid: parseInt(_line[1]), - cpu: _line[2], mem: _line[3], - }) - } + } + }) } - return MountProcess; } diff --git a/src/PlayersSave.js b/src/PlayersSave.js index fa62440..b87630e 100644 --- a/src/PlayersSave.js +++ b/src/PlayersSave.js @@ -1,5 +1,5 @@ const bds = require("../index") -const { CheckBan } = require("./check"); +const { CheckBan } = require("./UsersAndtokenChecks"); const { GetPlatform, GetPaths } = require("../lib/BdsSettings"); const fs = require("fs"); diff --git a/src/check.js b/src/UsersAndtokenChecks.js similarity index 76% rename from src/check.js rename to src/UsersAndtokenChecks.js index 8f2b2c1..16204e8 100644 --- a/src/check.js +++ b/src/UsersAndtokenChecks.js @@ -2,21 +2,19 @@ const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = requ const { existsSync, readFileSync } = require("fs") const { join } = require("path") -module.exports.checkUser = function (admin_name){ - var adm = GetTelegramAdmins(); - for(let check_ in adm){ - const admin_check = adm[check_] +function CheckTelegramUser(admin_name){ + for(let admin_check of GetTelegramAdmins()){ if (admin_name === admin_check || admin_check === "all_users") return true; } return false } -module.exports.CheckPlayer = function (player = "null"){ +function CheckPlayer(player = "null"){ const json = require(GetPaths("player"))[GetPlatform()]; if (json[player]) return true; else return false } -module.exports.token_verify = function (token){ +function token_verify(token){ const path_tokens = join(bds_dir, "bds_tokens.json") if (existsSync(path_tokens)) var tokens = JSON.parse(readFileSync(path_tokens, "utf8")); else return false for (let token_verify of tokens) { @@ -26,7 +24,7 @@ module.exports.token_verify = function (token){ return false } -module.exports.CheckBan = function (player){ +function CheckBan(player){ var players = GetServerBan(); for(let check_ in players){ const admin_check = players[check_] @@ -35,4 +33,11 @@ module.exports.CheckBan = function (player){ } } return false +} + +module.exports = { + CheckTelegramUser, + CheckPlayer, + CheckBan, + token_verify } \ No newline at end of file diff --git a/src/clouds/Auth/Google.js b/src/clouds/Auth/Google.js index cc77567..6ae37f2 100644 --- a/src/clouds/Auth/Google.js +++ b/src/clouds/Auth/Google.js @@ -4,7 +4,7 @@ const { randomUUID } = require("crypto"); const express = require("express"); const { google } = require("googleapis"); -const ip_andress = require("../../external_ip"); +const ip_andress = require("../../BdsNetwork"); const { bds_dir } = require("../../../lib/BdsSettings"); const PathToToken = join(bds_dir, "google_user_token.json"); diff --git a/src/external_ip.js b/src/external_ip.js deleted file mode 100644 index 06cf0f7..0000000 --- a/src/external_ip.js +++ /dev/null @@ -1,46 +0,0 @@ -// External User ip -const fetchSync = require("@the-bds-maneger/fetchsync"); -const os = require("os") -const externalIP = { - ipv4: fetchSync("https://api.ipify.org/").text().replace("\n", ""), - ipv6: fetchSync("https://api64.ipify.org/").text().replace("\n", "") -} -module.exports.external_ip = externalIP -module.exports.ip = externalIP - -// Internal ip user -const interfaces = os.networkInterfaces(); -const internal_ip = [] -for (let index of Object.getOwnPropertyNames(require("os").networkInterfaces())){ - const inter = interfaces[index] - for (let ind in inter){ - if (inter[ind].address.includes("::")) internal_ip.push(`[${inter[ind].address}]`) - else internal_ip.push(inter[ind].address) - } -} -module.exports.internal_ip = internal_ip - -// Network Interfaces -const a = os.networkInterfaces(); -module.exports.Interfaces = Object.getOwnPropertyNames(a).map(inter => { - inter = a[inter] - if (inter[0].mac !== "00:00:00:00:00:00") { - try { - return { - MAC: inter[0].mac, - Interna_IP: { - ipv4: inter[0].address, - ipv6: inter[1].address, - } - } - } catch (err) { - return { - MAC: inter[0].mac, - Interna_IP: { - ipv4: inter[0].address, - ipv6: null, - } - } - } - } -}).filter(a=>a) \ No newline at end of file diff --git a/src/rest/api.js b/src/rest/api.js index 23829ee..739ee1f 100644 --- a/src/rest/api.js +++ b/src/rest/api.js @@ -62,7 +62,7 @@ function api(port_api = 1932, callback = function (port){console.log("Bds Manege } module.exports = function (apiConfig = {api_port: 1932}, callback = function (port){console.log("Bds Maneger Core REST API, http port", port)}){ var port_rest = 1932; - if (typeof apiConfig == "object" && apiConfig.api_port !== undefined) port_rest = apiConfig.api_port; + if (typeof apiConfig === "object" && apiConfig.api_port !== undefined) port_rest = apiConfig.api_port; else if (typeof apiConfig === "number") port_rest = apiConfig; return api(port_rest, callback); } diff --git a/src/rest/routes/bds.js b/src/rest/routes/bds.js index edae63e..ad4ff91 100644 --- a/src/rest/routes/bds.js +++ b/src/rest/routes/bds.js @@ -5,7 +5,7 @@ const commandExist = require("../../../lib/commandExist"); const { GetPlatform, GetServerVersion, UpdatePlatform, bds_dir } = require("../../../lib/BdsSettings"); const admzip = require("adm-zip"); const bds = require("../../../index"); -const { token_verify } = require("../../check"); +const { token_verify } = require("../../UsersAndtokenChecks"); // Backup app.get("/backup", (req, res) => { diff --git a/src/rest/routes/players.js b/src/rest/routes/players.js index ba8b72f..45ae281 100644 --- a/src/rest/routes/players.js +++ b/src/rest/routes/players.js @@ -2,7 +2,7 @@ const express = require("express"); const app = express.Router(); const { GetPlatform } = require("../../../lib/BdsSettings") const bds = require("../../../index"); -const { token_verify, CheckPlayer } = require("../../check"); +const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks"); const { readFileSync } = require("fs"); const docs = require("../../../BdsManegerInfo.json").docs;