Telegram bot #150
16
README.md
16
README.md
@ -8,6 +8,10 @@ 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.
|
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, <a href="https://docs.bdsmaneger.com/Bds Maneger core" target="_blank">link here from the main page</a>, <a href="https://github.com/The-Bds-Maneger/Bds-Manager-Project-Documentation" target="_blank">Repository link</a>
|
||||||
|
|
||||||
## Badges
|
## Badges
|
||||||
|
|
||||||
[](https://github.com/The-Bds-Maneger/Bds-Maneger-Core/actions/workflows/codeql%20and%20ossar%20analysis.yml)
|
[](https://github.com/The-Bds-Maneger/Bds-Maneger-Core/actions/workflows/codeql%20and%20ossar%20analysis.yml)
|
||||||
@ -15,9 +19,10 @@ In Version 1.11.0 there was a big change in the way to get the new settings and
|
|||||||
[](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/context:javascript)
|
[](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/context:javascript)
|
||||||
[](https://deepscan.io/dashboard#view=project&tid=13683&pid=16691&bid=363172)
|
[](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:
|
Windows:
|
||||||
|
|
||||||
```cmd
|
```cmd
|
||||||
$ docker run --rm -d --name BdsManegerCore -v BdsCore:/home/bds/bds_core ^
|
$ docker run --rm -d --name BdsManegerCore -v BdsCore:/home/bds/bds_core ^
|
||||||
-p 19132:19132/udp -p 19133:19133/udp -p 1932:1932/tcp ^
|
-p 19132:19132/udp -p 19133:19133/udp -p 1932:1932/tcp ^
|
||||||
@ -34,6 +39,7 @@ bdsmaneger/core:latest
|
|||||||
```
|
```
|
||||||
|
|
||||||
Linux/MacOS:
|
Linux/MacOS:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker run --rm -d --name BdsManegerCore -v BdsCore/:/home/bds/bds_core \
|
$ docker run --rm -d --name BdsManegerCore -v BdsCore/:/home/bds/bds_core \
|
||||||
-p 19132:19132/udp -p 19133:19133/udp -p 1932:1932/tcp \
|
-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
|
## We also have some Implementation Models for Azure
|
||||||
|
|
||||||
#### Microsoft Azure Container
|
### Microsoft Azure Virtual machine
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
[](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
|
|
||||||
|
|
||||||
Here we have a virtual machine totally dedicated to Bds Maneger Core, it still uses Docker to deploy Docker images.
|
Here we have a virtual machine totally dedicated to Bds Maneger Core, it still uses Docker to deploy Docker images.
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#!/usr/bin/env node
|
#!/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;
|
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||||
|
|
||||||
// Inports
|
|
||||||
const readline = require("readline");
|
|
||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const { valid_platform } = require("../lib/BdsSystemInfo");
|
const { valid_platform } = require("../lib/BdsSystemInfo");
|
||||||
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
||||||
const commandExits = require("../lib/commandExist");
|
const commandExits = require("../lib/commandExist");
|
||||||
const download = require("../src/download");
|
const download = require("../src/BdsServersDownload");
|
||||||
|
|
||||||
// Bds Maneger ArgV
|
// Bds Maneger ArgV
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
const argv = require("minimist")(process.argv.slice(2));
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { Telegraf, Markup } = require("telegraf");
|
const { Telegraf, Markup } = require("telegraf");
|
||||||
const bds = require("../index");
|
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 { GetKernel, arch, system } = require("../lib/BdsSystemInfo");
|
||||||
const { Detect } = require("../src/CheckKill");
|
const { Detect } = require("../src/CheckKill");
|
||||||
const { Servers } = require("../lib/ServerURL");
|
const { Servers } = require("../lib/ServerURL");
|
||||||
|
const { CheckTelegramUser } = require("../src/UsersAndtokenChecks")
|
||||||
|
|
||||||
// Bot Start And Help messages
|
// Bot Start And Help messages
|
||||||
const HelpAndStart = [
|
const HelpAndStart = [
|
||||||
@ -24,7 +25,7 @@ const HelpAndStart = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// Set Telegram Bot
|
// Set Telegram Bot
|
||||||
const bot = new Telegraf(bds.telegram_token);
|
const bot = new Telegraf(GetTelegramToken());
|
||||||
|
|
||||||
// Start and Help Command
|
// Start and Help Command
|
||||||
bot.start((ctx)=>ctx.reply(HelpAndStart.join("\n")));
|
bot.start((ctx)=>ctx.reply(HelpAndStart.join("\n")));
|
||||||
@ -32,6 +33,9 @@ bot.help((ctx)=>ctx.reply(HelpAndStart.join("\n")));
|
|||||||
|
|
||||||
// User
|
// User
|
||||||
bot.command("player", ctx => {
|
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 Server = global.ServerExec;
|
||||||
const CtxOption = ctx.message.text.replace("/player", "").trim();
|
const CtxOption = ctx.message.text.replace("/player", "").trim();
|
||||||
const CtxContext = CtxOption.replace(/^kick|^deop|^ban|^op/, "").trim();
|
const CtxContext = CtxOption.replace(/^kick|^deop|^ban|^op/, "").trim();
|
||||||
@ -106,6 +110,9 @@ bot.command("player", ctx => {
|
|||||||
|
|
||||||
// Basic server
|
// Basic server
|
||||||
bot.command("basic", async 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();
|
const text = ctx.message.text.replace("/basic", "").trim();
|
||||||
if (text) {
|
if (text) {
|
||||||
// Start Server
|
// Start Server
|
||||||
@ -161,6 +168,9 @@ bot.command("basic", async ctx => {
|
|||||||
|
|
||||||
// Select Platform
|
// Select Platform
|
||||||
bot.command("platform", async 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();
|
const text = ctx.message.text.replace("/platform", "").trim();
|
||||||
if (text) {
|
if (text) {
|
||||||
try {
|
try {
|
||||||
@ -184,6 +194,9 @@ bot.command("platform", async ctx => {
|
|||||||
|
|
||||||
// Download Server
|
// Download Server
|
||||||
bot.command("download", async ctx => {
|
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();
|
const version = ctx.message.text.replace(/\/download|[a-zA-Z]/gi, "").trim();
|
||||||
if (version) {
|
if (version) {
|
||||||
await bds.download(version, true);
|
await bds.download(version, true);
|
||||||
@ -201,6 +214,9 @@ bot.command("download", async ctx => {
|
|||||||
|
|
||||||
// Command
|
// Command
|
||||||
bot.command("command", async ctx => {
|
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();
|
const text = ctx.message.text.replace("/command", "").trim();
|
||||||
if (!(Detect())) return ctx.reply("Your server is stopped");
|
if (!(Detect())) return ctx.reply("Your server is stopped");
|
||||||
if (text) {
|
if (text) {
|
||||||
@ -238,6 +254,9 @@ bot.command("info", ctx => {
|
|||||||
// Live Log User
|
// Live Log User
|
||||||
global.LiveLog = [];
|
global.LiveLog = [];
|
||||||
bot.command("live_log", async ctx => {
|
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();
|
const option = ctx.message.text.replace("/live_log", "").trim();
|
||||||
if (option) {
|
if (option) {
|
||||||
if (/enable/.test(option)) {
|
if (/enable/.test(option)) {
|
||||||
|
86
index.js
86
index.js
@ -3,6 +3,9 @@ const { resolve } = require("path");
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const randomUUID = require("uuid").v4;
|
const randomUUID = require("uuid").v4;
|
||||||
|
const { bds_dir } = require("./lib/BdsSettings");
|
||||||
|
|
||||||
|
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
||||||
|
|
||||||
function date(format) {
|
function date(format) {
|
||||||
const today = new Date(),
|
const today = new Date(),
|
||||||
@ -26,26 +29,42 @@ module.exports.package_path = bds_core_package
|
|||||||
module.exports.package_json = require("./package.json");
|
module.exports.package_json = require("./package.json");
|
||||||
module.exports.extra_json = require("./BdsManegerInfo.json");
|
module.exports.extra_json = require("./BdsManegerInfo.json");
|
||||||
|
|
||||||
const { bds_dir } = require("./lib/BdsSettings");
|
|
||||||
|
|
||||||
// Inport and Export Arch
|
// Inport and Export Arch
|
||||||
const { arch } = require("./lib/BdsSystemInfo");
|
const { arch } = require("./lib/BdsSystemInfo");
|
||||||
module.exports.arch = arch
|
module.exports.arch = arch
|
||||||
|
|
||||||
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken, GetTelegramToken } = require("./lib/BdsSettings");
|
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken } = require("./lib/BdsSettings");
|
||||||
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
|
||||||
|
|
||||||
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.internal_ip = maneger_ips.internal_ip
|
||||||
module.exports.external_ip = maneger_ips.external_ip
|
module.exports.external_ip = maneger_ips.external_ip
|
||||||
module.exports.save_google_id = require("./lib/BdsSettings").CloudConfig.Driver
|
module.exports.tmphost = {
|
||||||
module.exports.getBdsConfig = GetJsonConfig
|
host: maneger_ips.host,
|
||||||
module.exports.change_platform = module.exports.platform_update = UpdatePlatform
|
Response: maneger_ips.HostResponse
|
||||||
module.exports.telegram_token_save = UpdateTelegramToken
|
}
|
||||||
module.exports.api = require("./src/rest/api");
|
|
||||||
|
|
||||||
// Telegram
|
// Get Old Method Config
|
||||||
module.exports.telegram_token = GetTelegramToken();
|
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() {
|
function token_register() {
|
||||||
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
|
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
|
||||||
@ -67,17 +86,6 @@ function token_register() {
|
|||||||
return bdsuid;
|
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
|
* 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
|
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
|
* Take the current date
|
||||||
*/
|
*/
|
||||||
@ -98,6 +117,7 @@ module.exports.BdsDate = module.exports.date = date
|
|||||||
module.exports.command = BdsCommand
|
module.exports.command = BdsCommand
|
||||||
// New management method
|
// 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
|
* 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)})
|
* server.log(function (log){console.log(log)})
|
||||||
*/
|
*/
|
||||||
module.exports.start = start
|
module.exports.start = start
|
||||||
|
|
||||||
|
// Stop Server
|
||||||
/**
|
/**
|
||||||
* use this command for the server, that's all
|
* use this command for the server, that's all
|
||||||
*/
|
*/
|
||||||
module.exports.stop = stop
|
module.exports.stop = stop
|
||||||
|
|
||||||
|
// Create Backup of Bds Maneger Core and Servers along with your maps and settings
|
||||||
/**
|
/**
|
||||||
* backup your map locally
|
* 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
|
* use download( version, boolean ) // the boolean is for if you want to force the installation of the server
|
||||||
*
|
*
|
||||||
* @example
|
* @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.download = download
|
||||||
module.exports.config_example = config_example
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use this command to modify server settings
|
* use this command to modify server settings
|
||||||
@ -164,19 +187,12 @@ module.exports.config_example = config_example
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
module.exports.set_config = config
|
module.exports.set_config = config
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* takes the server settings in JSON format
|
* takes the server settings in JSON format
|
||||||
*/
|
*/
|
||||||
module.exports.get_config = get_config
|
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
|
* Load Crontab Backup
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
|
@ -9,14 +9,14 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node bin/bds_maneger.js -s",
|
"start": "node bin/bds_maneger.js -s",
|
||||||
|
"start:telegram": "node bin/telegram_bot.js -e js",
|
||||||
"stop": "node -p 'console.log(require(\"./\").kill());'",
|
"stop": "node -p 'console.log(require(\"./\").kill());'",
|
||||||
"test": "node .Build/test/ci.js",
|
"test": "node .Build/test/ci.js",
|
||||||
"ci": "node .Build/test/ci.js",
|
"ci": "node .Build/test/ci.js",
|
||||||
"eslint": "eslint --debug .",
|
"eslint": "eslint --debug .",
|
||||||
"eslint:fix": "eslint --debug --fix .",
|
"eslint:fix": "eslint --debug --fix .",
|
||||||
"nexe": "node .Build/nexe_build.js",
|
"nexe": "node .Build/nexe_build.js",
|
||||||
"Docker": "node .Build/DockerImage.js",
|
"Docker": "node .Build/DockerImage.js"
|
||||||
"dev:telegram": "node bin/telegram_bot.js -e js"
|
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"bds_maneger": "./bin/bds_maneger.js",
|
"bds_maneger": "./bin/bds_maneger.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))) {
|
for (let index of Object.getOwnPropertyNames(GetPaths("all")).filter(path => !/servers|backups/.test(path)).map(name => GetPaths(name))) {
|
||||||
if (existsSync(index)) {
|
if (existsSync(index)) {
|
||||||
const _S = statSync(resolve(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, "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ const { resolve, join } = require("path");
|
|||||||
const randomUUID = require("uuid").v4;
|
const randomUUID = require("uuid").v4;
|
||||||
const { CronJob } = require("cron");
|
const { CronJob } = require("cron");
|
||||||
const { GetCronBackup } = require("../lib/BdsSettings");
|
const { GetCronBackup } = require("../lib/BdsSettings");
|
||||||
const { Backup } = require("./backups");
|
const { Backup } = require("./BdsBackup");
|
||||||
|
|
||||||
// Bds Maneger Inports
|
// Bds Maneger Inports
|
||||||
const commandExists = require("../lib/commandExist");
|
const commandExists = require("../lib/commandExist");
|
89
src/BdsNetwork.js
Normal file
89
src/BdsNetwork.js
Normal file
@ -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,
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
const bds = require("../index")
|
const bds = require("../index")
|
||||||
const { CheckBan } = require("./check");
|
const { CheckBan } = require("./UsersAndtokenChecks");
|
||||||
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
@ -2,21 +2,19 @@ const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = requ
|
|||||||
const { existsSync, readFileSync } = require("fs")
|
const { existsSync, readFileSync } = require("fs")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
|
|
||||||
module.exports.checkUser = function (admin_name){
|
function CheckTelegramUser(admin_name){
|
||||||
var adm = GetTelegramAdmins();
|
for(let admin_check of GetTelegramAdmins()){
|
||||||
for(let check_ in adm){
|
|
||||||
const admin_check = adm[check_]
|
|
||||||
if (admin_name === admin_check || admin_check === "all_users") return true;
|
if (admin_name === admin_check || admin_check === "all_users") return true;
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.CheckPlayer = function (player = "null"){
|
function CheckPlayer(player = "null"){
|
||||||
const json = require(GetPaths("player"))[GetPlatform()];
|
const json = require(GetPaths("player"))[GetPlatform()];
|
||||||
if (json[player]) return true; else return false
|
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")
|
const path_tokens = join(bds_dir, "bds_tokens.json")
|
||||||
if (existsSync(path_tokens)) var tokens = JSON.parse(readFileSync(path_tokens, "utf8")); else return false
|
if (existsSync(path_tokens)) var tokens = JSON.parse(readFileSync(path_tokens, "utf8")); else return false
|
||||||
for (let token_verify of tokens) {
|
for (let token_verify of tokens) {
|
||||||
@ -26,7 +24,7 @@ module.exports.token_verify = function (token){
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.CheckBan = function (player){
|
function CheckBan(player){
|
||||||
var players = GetServerBan();
|
var players = GetServerBan();
|
||||||
for(let check_ in players){
|
for(let check_ in players){
|
||||||
const admin_check = players[check_]
|
const admin_check = players[check_]
|
||||||
@ -36,3 +34,10 @@ module.exports.CheckBan = function (player){
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
CheckTelegramUser,
|
||||||
|
CheckPlayer,
|
||||||
|
CheckBan,
|
||||||
|
token_verify
|
||||||
|
}
|
@ -4,7 +4,7 @@ const { randomUUID } = require("crypto");
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const { google } = require("googleapis");
|
const { google } = require("googleapis");
|
||||||
|
|
||||||
const ip_andress = require("../../external_ip");
|
const ip_andress = require("../../BdsNetwork");
|
||||||
const { bds_dir } = require("../../../lib/BdsSettings");
|
const { bds_dir } = require("../../../lib/BdsSettings");
|
||||||
|
|
||||||
const PathToToken = join(bds_dir, "google_user_token.json");
|
const PathToToken = join(bds_dir, "google_user_token.json");
|
||||||
|
@ -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)
|
|
@ -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)}){
|
module.exports = function (apiConfig = {api_port: 1932}, callback = function (port){console.log("Bds Maneger Core REST API, http port", port)}){
|
||||||
var port_rest = 1932;
|
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;
|
else if (typeof apiConfig === "number") port_rest = apiConfig;
|
||||||
return api(port_rest, callback);
|
return api(port_rest, callback);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ const commandExist = require("../../../lib/commandExist");
|
|||||||
const { GetPlatform, GetServerVersion, UpdatePlatform, bds_dir } = require("../../../lib/BdsSettings");
|
const { GetPlatform, GetServerVersion, UpdatePlatform, bds_dir } = require("../../../lib/BdsSettings");
|
||||||
const admzip = require("adm-zip");
|
const admzip = require("adm-zip");
|
||||||
const bds = require("../../../index");
|
const bds = require("../../../index");
|
||||||
const { token_verify } = require("../../check");
|
const { token_verify } = require("../../UsersAndtokenChecks");
|
||||||
|
|
||||||
// Backup
|
// Backup
|
||||||
app.get("/backup", (req, res) => {
|
app.get("/backup", (req, res) => {
|
||||||
|
@ -2,7 +2,7 @@ const express = require("express");
|
|||||||
const app = express.Router();
|
const app = express.Router();
|
||||||
const { GetPlatform } = require("../../../lib/BdsSettings")
|
const { GetPlatform } = require("../../../lib/BdsSettings")
|
||||||
const bds = require("../../../index");
|
const bds = require("../../../index");
|
||||||
const { token_verify, CheckPlayer } = require("../../check");
|
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
||||||
const { readFileSync } = require("fs");
|
const { readFileSync } = require("fs");
|
||||||
const docs = require("../../../BdsManegerInfo.json").docs;
|
const docs = require("../../../BdsManegerInfo.json").docs;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user