Skip to content

Commit

Permalink
wip zap: increased update time + minor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Mar 31, 2021
1 parent b6c7601 commit 6df97d4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
- [x] zap: Add txData path warnings;
- [x] zap: Add `sv_maxClients` enforcement;
- [x] zap: One-click-login button via JWT/JWT (and documment it);
- [ ] zap: increase `txAdminVersionBestBy` by 7d when running in zap;
- [x] zap: increase `txAdminVersionBestBy` by 10d when running in zap;
- [x] zap: Ad placement on login page, main interface (desk/mobile), and home-hosting warning (CLI);
- [x] make chart available without auth (since its public info anyways) and add thread filter
- [ ] allow 3 chars admin names NOTE: `\webroutes\adminManager\actions.js` `nameRegex`
- [ ] disable server auto-start when no admins configured
- [ ] login page indicate if the `admins.json` file is not found
Expand Down
6 changes: 3 additions & 3 deletions src/components/webServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sqrl.filters.define("base64", (x)=>{
return Buffer.from(x).toString('base64');
});
sqrl.filters.define("ternary", (x)=>{
return (x[0])? x[2] : x[1];
return (x[0])? x[1] : x[2];
});

//================================================================
Expand All @@ -71,7 +71,7 @@ async function renderMasterView(view, reqSess, data, txVars){
data.serverProfile = globals.info.serverProfile;
data.txAdminVersion = GlobalData.txAdminVersion;
data.txAdminOutdated = (now() > GlobalData.txAdminVersionBestBy);
data.fxServerVersion = GlobalData.fxServerVersion;
data.fxServerVersion = (GlobalData.isZapHosting)? `${GlobalData.fxServerVersion}/ZAP` : GlobalData.fxServerVersion;
data.adminIsMaster = (reqSess && reqSess.auth && reqSess.auth.username && reqSess.auth.master === true);
data.adminUsername = (reqSess && reqSess.auth && reqSess.auth.username)? reqSess.auth.username : 'unknown user';
data.profilePicture = (reqSess && reqSess.auth && reqSess.auth.picture)? reqSess.auth.picture : 'img/default_avatar.png';
Expand Down Expand Up @@ -120,7 +120,7 @@ async function renderLoginView(data, txVars){
data.template = data.template || 'normal';
data.serverProfile = globals.info.serverProfile;
data.txAdminVersion = GlobalData.txAdminVersion;
data.fxServerVersion = GlobalData.fxServerVersion;
data.fxServerVersion = (GlobalData.isZapHosting)? `${GlobalData.fxServerVersion}/ZAP` : GlobalData.fxServerVersion;
data.serverName = globals.config.serverName || globals.info.serverProfile;

let out;
Expand Down
2 changes: 1 addition & 1 deletion src/components/webServer/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = router = (config) =>{
router.get('/txAdminLog', requestAuth('web'), webRoutes.txAdminLog);
router.get('/serverLog', requestAuth('web'), webRoutes.serverLog);
router.get('/status', requestAuth('api'), webRoutes.status);
router.get('/chartData', requestAuth('api'), webRoutes.chartData);
router.get('/chartData', webRoutes.chartData);

//Player routes
router.get('/player/list', requestAuth('web'), webRoutes.player.list);
Expand Down
29 changes: 18 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ if(typeof txAdminVersion !== 'string' || txAdminVersion == 'null'){
logDie(`txAdmin version not set or in the wrong format`);
}

//Check if this version of txAdmin is too outdated to be considered safe to use in prod
//NOTE: Only valid if its being very actively maintained.
// Use 30d for patch 0, or 45~60d otherwise
const txAdminVersionBestBy = 1615200000 + (28 * 86400);
// dir(new Date(txAdminVersionBestBy*1000).toLocaleString()) // 05/04/2021 07:40:00 BRT
// dir(require('humanize-duration')(((now() - txAdminVersionBestBy)*1000)))
if(now() > txAdminVersionBestBy){
logError(`This version of txAdmin is outdated.`);
logError(`Please update as soon as possible.`);
}

//Get txAdmin Resource Path
let txAdminResourcePath;
const txAdminResourcePathConvar = GetResourcePath(resourceName);
Expand Down Expand Up @@ -203,6 +192,24 @@ if(fs.existsSync(zapCfgFile)){
if(verbose) dir({isZapHosting, forceInterface, forceFXServerPort, txAdminPort, loginPageLogo, runtimeSecret, deployerDefaults});


//Check if this version of txAdmin is too outdated to be considered safe to use in prod
//NOTE: Only valid if its being very actively maintained.
// Use 30d for patch 0, or 45~60d otherwise
const txVerBBLastUpdate = 1615200000;
const txVerBBDelta = 28 + ((isZapHosting)? 10 : 0);
const txAdminVersionBestBy = txVerBBLastUpdate + (txVerBBDelta * 86400);
dir({
lastUpdate: new Date(txVerBBLastUpdate*1000).toLocaleString(),
nextUpdate: new Date(txAdminVersionBestBy*1000).toLocaleString(),
timeUntil: require('humanize-duration')(((now() - txAdminVersionBestBy)*1000)),
delta: txVerBBDelta
})
if(now() > txAdminVersionBestBy){
logError(`This version of txAdmin is outdated.`);
logError(`Please update as soon as possible.`);
}


//Get profile name
const serverProfile = GetConvar('serverProfile', 'default').replace(/[^a-z0-9._-]/gi, "").trim();
if(serverProfile.endsWith('.base')){
Expand Down
9 changes: 3 additions & 6 deletions src/webroutes/chartData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//Requires
const modulename = 'WebServer:ChartData';
const dateFormat = require('dateformat');
const xss = require('../extras/xss')();
const { dir, log, logOk, logWarn, logError, getLog } = require('../extras/console')(modulename);


Expand All @@ -16,11 +14,10 @@ module.exports = async function chartData(ctx) {
if(globals.statsCollector.perfSeries.length < 12){
return ctx.send({failReason: 'not_enough_data'});
}

//Process data & filter thread
// const threadName = 'svNetwork';
// const threadName = 'svSync';
const threadName = 'svMain';
const availableThreads = ['svNetwork', 'svSync', 'svMain'];
const threadName = (availableThreads.includes(ctx.query.thread))? ctx.query.thread : 'svMain';
// const maxDeltaTime = 288; //5*288 = 1440 = 1 day
const maxDeltaTime = 360; //5*360 = 30 hours
let outData;
Expand Down

0 comments on commit 6df97d4

Please sign in to comment.