From 1b1bea9e47818018f957c99f8bba13746bea5229 Mon Sep 17 00:00:00 2001 From: tabarra Date: Tue, 16 May 2023 10:50:34 -0300 Subject: [PATCH] feat(core): improve zap/ptero detection --- core/components/PlayerDatabase/idGenerator.ts | 1 + core/components/StatsCollector/runtime.ts | 2 +- core/components/WebServer/ctxUtils.js | 11 ++++++++--- core/globalData.ts | 17 +++++++++++++---- docs/dev_notes.md | 9 +++++---- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core/components/PlayerDatabase/idGenerator.ts b/core/components/PlayerDatabase/idGenerator.ts index 9b96d64e0..901c4831b 100644 --- a/core/components/PlayerDatabase/idGenerator.ts +++ b/core/components/PlayerDatabase/idGenerator.ts @@ -53,6 +53,7 @@ const printDiagnostics = async () => { console.error(`txAdmin: ${txEnv.txAdminVersion}`); console.error(`FXServer: ${txEnv.fxServerVersion}`); console.error(`ZAP: ${convars.isZapHosting}`); + console.error(`Pterodactyl: ${convars.isPterodactyl}`); console.error(`Unique Test: secure ${secureStorage.size}/100, non-secure ${nonsecureStorage.size}/100`); }; diff --git a/core/components/StatsCollector/runtime.ts b/core/components/StatsCollector/runtime.ts index 9aec74082..25f38eb6a 100644 --- a/core/components/StatsCollector/runtime.ts +++ b/core/components/StatsCollector/runtime.ts @@ -23,7 +23,7 @@ type RuntimeDataType = { //static txAdminPort: number; isZapHosting: boolean; - isPterodactyl: boolean; //check if proc.env.TXADMIN_ENABLE exists + isPterodactyl: boolean; osDistro: string; hostCpuModel: string; hostTotalMemory: string; diff --git a/core/components/WebServer/ctxUtils.js b/core/components/WebServer/ctxUtils.js index ca957c3ff..9a0899ffa 100644 --- a/core/components/WebServer/ctxUtils.js +++ b/core/components/WebServer/ctxUtils.js @@ -43,6 +43,9 @@ const RESOURCE_PATH = 'nui://monitor/web/public/'; const THEME_DARK = 'theme--dark'; const DEFAULT_AVATAR = 'img/default_avatar.png'; +const displayFxserverVersionPrefix = convars.isZapHosting && '/ZAP' || convars.isPterodactyl && '/Ptero' || ''; +const displayFxserverVersion = `${txEnv.fxServerVersion}${displayFxserverVersionPrefix}`; + function getEjsOptions(filePath) { const webTemplateRoot = path.resolve(txEnv.txAdminResourcePath, 'web'); const webCacheDir = path.resolve(txEnv.txAdminResourcePath, 'web-cache', filePath); @@ -257,19 +260,21 @@ export default async function WebCtxUtils(ctx, next) { // Setting up default render data: const baseViewData = { - isWebInterface: isWebInterface, + isWebInterface, basePath: (isWebInterface) ? '/' : WEBPIPE_PATH, resourcePath: (isWebInterface) ? '' : RESOURCE_PATH, serverProfile: globals.info.serverProfile, serverName: globals.config.serverName || globals.info.serverProfile, uiTheme: (ctx.cookies.get('txAdmin-darkMode') === 'true' || !isWebInterface) ? THEME_DARK : '', - fxServerVersion: (convars.isZapHosting) ? `${txEnv.fxServerVersion}/ZAP` : txEnv.fxServerVersion, + fxServerVersion: displayFxserverVersion, txAdminVersion: txEnv.txAdminVersion, txaOutdated: globals.databus.updateChecker?.txadmin, fxsOutdated: globals.databus.updateChecker?.fxserver, jsInjection: getJavascriptConsts({ + isZapHosting: convars.isZapHosting, //not in use + isPterodactyl: convars.isPterodactyl, //not in use + isWebInterface, csrfToken: (ctx.session?.auth?.csrfToken) ? ctx.session.auth.csrfToken : 'not_set', - isWebInterface: isWebInterface, TX_BASE_PATH: (isWebInterface) ? '' : WEBPIPE_PATH, PAGE_TITLE: data?.headerTitle ?? 'txAdmin', }), diff --git a/core/globalData.ts b/core/globalData.ts index db3bbb81c..baa814e0a 100644 --- a/core/globalData.ts +++ b/core/globalData.ts @@ -134,17 +134,25 @@ const debugExternalSource = getConvarString('txDebugExternalSource'); /** - * Convars - ZAP dependant + * Host type check */ //Checking for ZAP Configuration file const zapCfgFile = path.join(dataPath, 'txAdminZapConfig.json'); -let zapCfgData, isZapHosting, forceInterface, forceFXServerPort, txAdminPort, loginPageLogo, defaultMasterAccount, deployerDefaults; +let isZapHosting: boolean; +let forceInterface; +let forceFXServerPort; +let txAdminPort; +let loginPageLogo; +let defaultMasterAccount; +let deployerDefaults; const loopbackInterfaces = ['::1', '127.0.0.1', '127.0.1.1']; +const isPterodactyl = process.env?.TXADMIN_ENABLE === '1'; if (fs.existsSync(zapCfgFile)) { console.log('Loading ZAP-Hosting configuration file.'); + let zapCfgData; try { zapCfgData = JSON.parse(fs.readFileSync(zapCfgFile, 'utf8')); - isZapHosting = true; + isZapHosting = !isPterodactyl; forceInterface = zapCfgData.interface; forceFXServerPort = zapCfgData.fxServerPort; txAdminPort = zapCfgData.txAdminPort; @@ -197,7 +205,7 @@ if (fs.existsSync(zapCfgFile)) { } } if (verboseConvar) { - console.dir({ isZapHosting, forceInterface, forceFXServerPort, txAdminPort, loginPageLogo, deployerDefaults }); + console.dir({ isPterodactyl, isZapHosting, forceInterface, forceFXServerPort, txAdminPort, loginPageLogo, deployerDefaults }); } //Setting the variables in console without it having to importing from here (cyclical dependency) @@ -227,6 +235,7 @@ export const convars = Object.freeze({ debugPlayerlistGenerator, debugExternalSource, //Convars - zap dependant + isPterodactyl, isZapHosting, forceInterface, forceFXServerPort, diff --git a/docs/dev_notes.md b/docs/dev_notes.md index 1dbe66ec3..24008e348 100644 --- a/docs/dev_notes.md +++ b/docs/dev_notes.md @@ -94,9 +94,9 @@ - set steam_webApiKey "{{steam_webApiKey}}" - clean the lines at the end of server.cfg - server.cfg fix exec line 40 [vorp_official_plugins] - - [x] find out where that .replxx_history is comming from - + - [x] find out where that .replxx_history is coming from > beta1 release + - [x] fix system log page font fallback - [x] remove debug noclip command - [x] fix playerBanned and actionRevoked events playerIds and add playerHwids @@ -104,10 +104,11 @@ - [x] fix adminvault behavior on empty `admins.json` file - [x] change `cl_main.lua` RedM detection - [x] check/merge redm vehicle boost - > beta2 release + - [x] bot should check if it has any dangerous permission -- [ ] inject consts isZapHosting and isPterodactyl in ctxUtil +- [x] improve zap/ptero detection +- [ ] flexibilized ad options - [ ] stats: - [ ] adapt the new runtime specs, separate temp stats from classic stats - [ ] add bot enabled / whitelist back into stats