Skip to content

Commit

Permalink
feat(core): improve zap/ptero detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed May 16, 2023
1 parent da3aefa commit 1b1bea9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/components/PlayerDatabase/idGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
};

Expand Down
2 changes: 1 addition & 1 deletion core/components/StatsCollector/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions core/components/WebServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
}),
Expand Down
17 changes: 13 additions & 4 deletions core/globalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -227,6 +235,7 @@ export const convars = Object.freeze({
debugPlayerlistGenerator,
debugExternalSource,
//Convars - zap dependant
isPterodactyl,
isZapHosting,
forceInterface,
forceFXServerPort,
Expand Down
9 changes: 5 additions & 4 deletions docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,21 @@
- 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
- [x] updated some packages
- [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
Expand Down

0 comments on commit 1b1bea9

Please sign in to comment.