From 8652b35b46873ff12081f84eec15f4933d02c1d3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 9 Dec 2018 01:01:55 -0700 Subject: [PATCH] Code cleanup & resolve some minor TODO's in dropfile gen --- core/door.js | 3 +-- core/dropfile.js | 33 ++++++++++++++++++--------------- core/user.js | 16 +++++++++++----- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/core/door.js b/core/door.js index 120bd6f3..b07c89bc 100644 --- a/core/door.js +++ b/core/door.js @@ -9,7 +9,6 @@ const pty = require('node-pty'); const decode = require('iconv-lite').decode; const createServer = require('net').createServer; const paths = require('path'); -const sanatizeFilename = require('sanitize-filename'); module.exports = class Door { constructor(client) { @@ -64,7 +63,7 @@ module.exports = class Door { node : exeInfo.node.toString(), srvPort : this.sockServer ? this.sockServer.address().port.toString() : '-1', userId : this.client.user.userId.toString(), - userName : sanatizeFilename(this.client.user.username) || `user${this.client.user.userId.toString()}`, + userName : this.client.user.getSanitizedName(), userNameRaw : this.client.user.username, cwd : cwd, }; diff --git a/core/dropfile.js b/core/dropfile.js index eb3d9136..0c66d38a 100644 --- a/core/dropfile.js +++ b/core/dropfile.js @@ -5,6 +5,7 @@ const Config = require('./config.js').get; const StatLog = require('./stat_log.js'); const UserProps = require('./user_property.js'); +const SysProps = require('./system_property.js'); // deps const fs = require('graceful-fs'); @@ -86,9 +87,14 @@ module.exports = class DropFile { const prop = this.client.user.properties; const now = moment(); const secLevel = this.client.user.getLegacySecurityLevel().toString(); - const fullName = prop[UserProps.RealName] || this.client.user.username; + const fullName = this.client.user.getSanitizedName('real'); const bd = moment(prop[UserProps.Birthdate]).format('MM/DD/YY'); + const upK = Math.floor((parseInt(prop[UserProps.FileUlTotalBytes]) || 0) / 1024); + const downK = Math.floor((parseInt(prop[UserProps.FileDlTotalBytes]) || 0) / 1024); + + const timeOfCall = moment(prop[UserProps.LastLoginTs] || moment()).format('hh:mm'); + // :TODO: fix time remaining // :TODO: fix default protocol -- user prop: transfer_protocol return iconv.encode( [ @@ -127,8 +133,8 @@ module.exports = class DropFile { bd, // "Caller's Birthdate" 'X:\\MAIN\\', // "Path to the MAIN directory (where User File is)" 'X:\\GEN\\', // "Path to the GEN directory" - StatLog.getSystemStat('sysop_username'), // "Sysop's Name (name BBS refers to Sysop as)" - this.client.user.username, // "Alias name" + StatLog.getSystemStat(SysProps.SysOpUsername), // "Sysop's Name (name BBS refers to Sysop as)" + this.client.user.getSanitizedName(), // "Alias name" '00:05', // "Event time (hh:mm)" (note: wat?) 'Y', // "If its an error correcting connection (Y/N)" 'Y', // "ANSI supported & caller using NG mode (Y/N)" @@ -137,18 +143,15 @@ module.exports = class DropFile { // :TODO: fix minutes here also: '256', // "Time Credits In Minutes (positive/negative)" '07/07/90', // "Last New Files Scan Date (mm/dd/yy)" - // :TODO: fix last vs now times: - now.format('hh:mm'), // "Time of This Call" - now.format('hh:mm'), // "Time of Last Call (hh:mm)" + timeOfCall, // "Time of This Call" + timeOfCall, // "Time of Last Call (hh:mm)" '9999', // "Maximum daily files available" - // :TODO: fix these stats: - '0', // "Files d/led so far today" - '0', // "Total "K" Bytes Uploaded" - '0', // "Total "K" Bytes Downloaded" + '0', // "Files d/led so far today" + upK.toString(), // "Total "K" Bytes Uploaded" + downK.toString(), // "Total "K" Bytes Downloaded" prop[UserProps.UserComment] || 'None', // "User Comment" '0', // "Total Doors Opened" '0', // "Total Messages Left" - ].join('\r\n') + '\r\n', 'cp437'); } @@ -173,8 +176,8 @@ module.exports = class DropFile { '115200', Config().general.boardName, this.client.user.userId.toString(), - this.client.user.properties[UserProps.RealName] || this.client.user.username, - this.client.user.username, + this.client.user.getSanitizedName('real'), + this.client.user.getSanitizedName(), this.client.user.getLegacySecurityLevel().toString(), '546', // :TODO: Minutes left! '1', // ANSI @@ -191,8 +194,8 @@ module.exports = class DropFile { // // Note that usernames are just used for first/last names here // - const opUserName = /[^\s]*/.exec(StatLog.getSystemStat('sysop_username'))[0]; - const userName = /[^\s]*/.exec(this.client.user.username)[0]; + const opUserName = /[^\s]*/.exec(StatLog.getSystemStat(SysProps.SysOpUsername))[0]; + const userName = /[^\s]*/.exec(this.client.user.getSanitizedName())[0]; const secLevel = this.client.user.getLegacySecurityLevel().toString(); const location = this.client.user.properties[UserProps.Location]; diff --git a/core/user.js b/core/user.js index 0121133a..ba89b387 100644 --- a/core/user.js +++ b/core/user.js @@ -15,11 +15,12 @@ const Log = require('./logger.js').log; const StatLog = require('./stat_log.js'); // deps -const crypto = require('crypto'); -const assert = require('assert'); -const async = require('async'); -const _ = require('lodash'); -const moment = require('moment'); +const crypto = require('crypto'); +const assert = require('assert'); +const async = require('async'); +const _ = require('lodash'); +const moment = require('moment'); +const sanatizeFilename = require('sanitize-filename'); exports.isRootUserId = function(id) { return 1 === id; }; @@ -114,6 +115,11 @@ module.exports = class User { return isMember; } + getSanitizedName(type='username') { + const name = 'real' === type ? this.getProperty(UserProps.RealName) : this.username; + return sanatizeFilename(name) || `user${this.userId.toString()}`; + } + getLegacySecurityLevel() { if(this.isRoot() || this.isGroupMember('sysops')) { return 100;