Merge branch 'master' of ssh://numinibsd/git/base/enigma-bbs

This commit is contained in:
Bryan Ashby 2016-04-12 22:42:17 -06:00
commit 9cc1ea917f
9 changed files with 374 additions and 145 deletions

View File

@ -176,7 +176,7 @@ function ANSIEscapeParser(options) {
id : id ? parseInt(id, 10) : null, id : id ? parseInt(id, 10) : null,
args : args, args : args,
SGR : ansi.getSGRFromGraphicRendition(self.graphicRendition, true) SGR : ansi.getSGRFromGraphicRendition(self.graphicRendition, true)
}); });
if(self.mciReplaceChar.length > 0) { if(self.mciReplaceChar.length > 0) {
self.emit('chunk', ansi.getSGRFromGraphicRendition(self.graphicRenditionForErase)); self.emit('chunk', ansi.getSGRFromGraphicRendition(self.graphicRenditionForErase));

View File

@ -665,13 +665,12 @@ function FullScreenEditorModule(options) {
// We want to prefix the subject with "RE: " only if it's not already // We want to prefix the subject with "RE: " only if it's not already
// that way -- avoid RE: RE: RE: RE: ... // that way -- avoid RE: RE: RE: RE: ...
// //
var newSubj = self.replyToMessage.subject; let newSubj = self.replyToMessage.subject;
if(!_.startsWith(self.replyToMessage.subject, 'RE:')) { if(false === /^RE:\s+/i.test(newSubj)) {
newSubj = 'RE: ' + newSubj; newSubj = `RE: ${newSubj}`;
} }
self.setHeaderText(MCICodeIds.ReplyEditModeHeader.Subject, newSubj); self.setHeaderText(MCICodeIds.ReplyEditModeHeader.Subject, newSubj);
}; };
this.initFooterViewMode = function() { this.initFooterViewMode = function() {

View File

@ -473,6 +473,7 @@ function Packet(options) {
try { try {
decoded = iconv.decode(messageBodyBuffer, encoding); decoded = iconv.decode(messageBodyBuffer, encoding);
} catch(e) { } catch(e) {
// :TODO: add log warning here including failure reason
decoded = iconv.decode(messageBodyBuffer, 'ascii'); decoded = iconv.decode(messageBodyBuffer, 'ascii');
} }
//const messageLines = iconv.decode(messageBodyBuffer, encoding).replace(/\xec/g, '').split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g); //const messageLines = iconv.decode(messageBodyBuffer, encoding).replace(/\xec/g, '').split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
@ -603,7 +604,15 @@ function Packet(options) {
if(self.options.keepTearAndOrigin) { if(self.options.keepTearAndOrigin) {
msg.message += `${messageBodyData.originLine}\r\n`; msg.message += `${messageBodyData.originLine}\r\n`;
} }
} }
//
// If we have a UTC offset kludge (e.g. TZUTC) then update
// modDateTime with it
//
if(_.isString(msg.meta.FtnKludge.TZUTC) && msg.meta.FtnKludge.TZUTC.length > 0) {
msg.modDateTime = msg.modTimestamp.utcOffset(msg.meta.FtnKludge.TZUTC);
}
const nextBuf = packetBuffer.slice(read); const nextBuf = packetBuffer.slice(read);
if(nextBuf.length > 0) { if(nextBuf.length > 0) {

View File

@ -97,7 +97,7 @@ function loadMenu(options, cb) {
menuName : options.name, menuName : options.name,
menuConfig : modData.config, menuConfig : modData.config,
extraArgs : options.extraArgs, extraArgs : options.extraArgs,
client : options.client, client : options.client,
}); });
callback(null, moduleInstance); callback(null, moduleInstance);
} catch(e) { } catch(e) {

View File

@ -68,13 +68,6 @@ Message.WellKnownAreaTags = {
Bulletin : 'local_bulletin', Bulletin : 'local_bulletin',
}; };
// :TODO: FTN stuff really doesn't belong here - move it elsewhere and/or just use the names directly when needed
Message.MetaCategories = {
System : 1, // ENiGMA1/2 stuff
FtnProperty : 2, // Various FTN network properties, ftn_cost, ftn_origin, ...
FtnKludge : 3, // FTN kludges -- PATH, MSGID, ...
};
Message.SystemMetaNames = { Message.SystemMetaNames = {
LocalToUserID : 'local_to_user_id', LocalToUserID : 'local_to_user_id',
LocalFromUserID : 'local_from_user_id', LocalFromUserID : 'local_from_user_id',

View File

@ -32,23 +32,23 @@ const CONF_AREA_RW_ACS_DEFAULT = 'GM[users]';
const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]'; const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]';
const AREA_ACS_DEFAULT = { const AREA_ACS_DEFAULT = {
read : CONF_AREA_RW_ACS_DEFAULT, read : CONF_AREA_RW_ACS_DEFAULT,
write : CONF_AREA_RW_ACS_DEFAULT, write : CONF_AREA_RW_ACS_DEFAULT,
manage : AREA_MANAGE_ACS_DEFAULT, manage : AREA_MANAGE_ACS_DEFAULT,
}; };
function getAvailableMessageConferences(client, options) { function getAvailableMessageConferences(client, options) {
options = options || { includeSystemInternal : false }; options = options || { includeSystemInternal : false };
// perform ACS check per conf & omit system_internal if desired // perform ACS check per conf & omit system_internal if desired
return _.omit(Config.messageConferences, (v, k) => { return _.omit(Config.messageConferences, (v, k) => {
if(!options.includeSystemInternal && 'system_internal' === k) { if(!options.includeSystemInternal && 'system_internal' === k) {
return true; return true;
} }
const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT; const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT;
return !checkAcs(client, readAcs); return !checkAcs(client, readAcs);
}); });
} }
function getSortedAvailMessageConferences(client, options) { function getSortedAvailMessageConferences(client, options) {
@ -75,19 +75,19 @@ function getAvailableMessageAreasByConfTag(confTag, options) {
// :TODO: confTag === "" then find default // :TODO: confTag === "" then find default
if(_.has(Config.messageConferences, [ confTag, 'areas' ])) { if(_.has(Config.messageConferences, [ confTag, 'areas' ])) {
const areas = Config.messageConferences[confTag].areas; const areas = Config.messageConferences[confTag].areas;
if(!options.client || true === options.noAcsCheck) { if(!options.client || true === options.noAcsCheck) {
// everything - no ACS checks // everything - no ACS checks
return areas; return areas;
} else { } else {
// perform ACS check per area // perform ACS check per area
return _.omit(areas, (v, k) => { return _.omit(areas, v => {
const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT; const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT;
return !checkAcs(options.client, readAcs); return !checkAcs(options.client, readAcs);
}); });
} }
} }
} }
function getSortedAvailMessageAreasByConfTag(confTag, options) { function getSortedAvailMessageAreasByConfTag(confTag, options) {
@ -95,7 +95,7 @@ function getSortedAvailMessageAreasByConfTag(confTag, options) {
return { return {
areaTag : k, areaTag : k,
area : v, area : v,
} };
}); });
areas.sort((a, b) => { areas.sort((a, b) => {
@ -322,16 +322,16 @@ function getNewMessagesInAreaForUser(userId, areaTag, cb) {
}); });
}, },
function getMessages(lastMessageId, callback) { function getMessages(lastMessageId, callback) {
var sql = let sql =
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count ' + `SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count
'FROM message ' + FROM message
'WHERE area_tag ="' + areaTag + '" AND message_id > ' + lastMessageId; WHERE area_tag = "${areaTag}" AND message_id > ${lastMessageId}`;
if(Message.WellKnownAreaTags.Private === areaTag) { if(Message.WellKnownAreaTags.Private === areaTag) {
sql += sql +=
' AND message_id in (' + ` AND message_id in (
'SELECT message_id from message_meta where meta_category=' + Message.MetaCategories.System + SELECT message_id from message_meta where meta_category ="System"
' AND meta_name="' + Message.SystemMetaNames.LocalToUserID + '" and meta_value=' + userId + ')'; AND meta_name ="${Message.SystemMetaNames.LocalToUserID}" AND meta_value =${userId})`;
} }
sql += ' ORDER BY message_id;'; sql += ' ORDER BY message_id;';

View File

@ -2,15 +2,14 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
let Config = require('./config.js').config; const Config = require('./config.js').config;
let miscUtil = require('./misc_util.js');
// standard/deps // deps
let fs = require('fs'); const fs = require('fs');
let paths = require('path'); const paths = require('path');
let _ = require('lodash'); const _ = require('lodash');
let assert = require('assert'); const assert = require('assert');
let async = require('async'); const async = require('async');
// exports // exports
exports.loadModuleEx = loadModuleEx; exports.loadModuleEx = loadModuleEx;
@ -25,25 +24,22 @@ function loadModuleEx(options, cb) {
const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null; const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
if(_.isObject(modConfig) && false === modConfig.enabled) { if(_.isObject(modConfig) && false === modConfig.enabled) {
cb(new Error('Module "' + options.name + '" is disabled')); return cb(new Error('Module "' + options.name + '" is disabled'));
return;
} }
var mod; let mod;
try { try {
mod = require(paths.join(options.path, options.name + '.js')); mod = require(paths.join(options.path, options.name + '.js'));
} catch(e) { } catch(e) {
cb(e); return cb(e);
} }
if(!_.isObject(mod.moduleInfo)) { if(!_.isObject(mod.moduleInfo)) {
cb(new Error('Module is missing "moduleInfo" section')); return cb(new Error('Module is missing "moduleInfo" section'));
return;
} }
if(!_.isFunction(mod.getModule)) { if(!_.isFunction(mod.getModule)) {
cb(new Error('Invalid or missing "getModule" method for module!')); return cb(new Error('Invalid or missing "getModule" method for module!'));
return;
} }
// Ref configuration, if any, for convience to the module // Ref configuration, if any, for convience to the module
@ -53,11 +49,10 @@ function loadModuleEx(options, cb) {
} }
function loadModule(name, category, cb) { function loadModule(name, category, cb) {
var path = Config.paths[category]; const path = Config.paths[category];
if(!_.isString(path)) { if(!_.isString(path)) {
cb(new Error('Not sure where to look for "' + name + '" of category "' + category + '"')); return cb(new Error(`Not sure where to look for "${name}" of category "${category}"`));
return;
} }
loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) { loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) {

View File

@ -2,13 +2,13 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
var msgArea = require('./message_area.js'); const msgArea = require('./message_area.js');
var Message = require('./message.js'); const MenuModule = require('./menu_module.js').MenuModule;
var MenuModule = require('./menu_module.js').MenuModule; const ViewController = require('../core/view_controller.js').ViewController;
var ViewController = require('../core/view_controller.js').ViewController;
var _ = require('lodash'); // deps
var async = require('async'); const _ = require('lodash');
const async = require('async');
exports.moduleInfo = { exports.moduleInfo = {
name : 'New Scan', name : 'New Scan',
@ -60,65 +60,74 @@ function NewScanModule(options) {
} }
}; };
this.newScanMessageConference = function(cb) { this.newScanMessageConference = function(cb) {
// lazy init // lazy init
if(!self.sortedMessageConfs) { if(!self.sortedMessageConfs) {
const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc. const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc.
self.sortedMessageConfs = _.map(msgArea.getAvailableMessageConferences(self.client, getAvailOpts), (v, k) => { self.sortedMessageConfs = _.map(msgArea.getAvailableMessageConferences(self.client, getAvailOpts), (v, k) => {
return { return {
confTag : k, confTag : k,
conf : v, conf : v,
}; };
}); });
// //
// Sort conferences by name, other than 'system_internal' which should // Sort conferences by name, other than 'system_internal' which should
// always come first such that we display private mails/etc. before // always come first such that we display private mails/etc. before
// other conferences & areas // other conferences & areas
// //
self.sortedMessageConfs.sort((a, b) => { self.sortedMessageConfs.sort((a, b) => {
if('system_internal' === a.confTag) { if('system_internal' === a.confTag) {
return -1; return -1;
} else { } else {
return a.conf.name.localeCompare(b.conf.name); return a.conf.name.localeCompare(b.conf.name);
} }
}); });
self.currentScanAux.conf = self.currentScanAux.conf || 0; self.currentScanAux.conf = self.currentScanAux.conf || 0;
self.currentScanAux.area = self.currentScanAux.area || 0; self.currentScanAux.area = self.currentScanAux.area || 0;
} }
const currentConf = self.sortedMessageConfs[self.currentScanAux.conf]; const currentConf = self.sortedMessageConfs[self.currentScanAux.conf];
async.series( async.series(
[ [
function scanArea(callback) { function scanArea(callback) {
//self.currentScanAux.area = self.currentScanAux.area || 0; //self.currentScanAux.area = self.currentScanAux.area || 0;
self.newScanMessageArea(currentConf, function areaScanComplete(err) { self.newScanMessageArea(currentConf, () => {
if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) { if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) {
self.currentScanAux.conf += 1; self.currentScanAux.conf += 1;
self.currentScanAux.area = 0; self.currentScanAux.area = 0;
self.newScanMessageConference(cb); // recursive to next conf self.newScanMessageConference(cb); // recursive to next conf
//callback(null); //callback(null);
} else { } else {
self.updateScanStatus(self.scanCompleteMsg); self.updateScanStatus(self.scanCompleteMsg);
callback(new Error('No more conferences')); callback(new Error('No more conferences'));
} }
}); });
} }
], ],
cb cb
); );
}; };
this.newScanMessageArea = function(conf, cb) { this.newScanMessageArea = function(conf, cb) {
// :TODO: it would be nice to cache this - must be done by conf! // :TODO: it would be nice to cache this - must be done by conf!
const sortedAreas = msgArea.getSortedAvailMessageAreasByConfTag(conf.confTag, { client : self.client } ); const sortedAreas = msgArea.getSortedAvailMessageAreasByConfTag(conf.confTag, { client : self.client } );
const currentArea = sortedAreas[self.currentScanAux.area]; const currentArea = sortedAreas[self.currentScanAux.area];
function getFormatObj() {
return {
confName : conf.conf.name,
confDesc : conf.conf.desc,
areaName : currentArea.area.name,
areaDesc : currentArea.area.desc
};
}
// //
// Scan and update index until we find something. If results are found, // Scan and update index until we find something. If results are found,
// we'll goto the list module & show them. // we'll goto the list module & show them.
@ -136,12 +145,7 @@ function NewScanModule(options) {
} }
}, },
function updateStatusScanStarted(callback) { function updateStatusScanStarted(callback) {
self.updateScanStatus(self.scanStartFmt.format({ self.updateScanStatus(self.scanStartFmt.format(getFormatObj()));
confName : conf.conf.name,
confDesc : conf.conf.desc,
areaName : currentArea.area.name,
areaDesc : currentArea.area.desc,
}));
callback(null); callback(null);
}, },
function newScanAreaAndGetMessages(callback) { function newScanAreaAndGetMessages(callback) {
@ -149,26 +153,17 @@ function NewScanModule(options) {
self.client.user.userId, currentArea.areaTag, function msgs(err, msgList) { self.client.user.userId, currentArea.areaTag, function msgs(err, msgList) {
if(!err) { if(!err) {
if(0 === msgList.length) { if(0 === msgList.length) {
self.updateScanStatus(self.scanFinishNoneFmt.format({ self.updateScanStatus(self.scanFinishNoneFmt.format(getFormatObj()));
confName : conf.conf.name,
confDesc : conf.conf.desc,
areaName : currentArea.area.name,
areaDesc : currentArea.area.desc,
}));
} else { } else {
self.updateScanStatus(self.scanFinishNewFmt.format({ const formatObj = Object.assign(getFormatObj(), { count : msgList.length } );
confName : conf.conf.name, self.updateScanStatus(self.scanFinishNewFmt.format(formatObj));
confDesc : conf.conf.desc,
areaName : currentArea.area.name,
count : msgList.length,
}));
} }
} }
callback(err, msgList); callback(err, msgList);
} }
); );
}, },
function displayMessageList(msgList, callback) { function displayMessageList(msgList) {
if(msgList && msgList.length > 0) { if(msgList && msgList.length > 0) {
var nextModuleOpts = { var nextModuleOpts = {
extraArgs: { extraArgs: {
@ -183,7 +178,7 @@ function NewScanModule(options) {
} }
} }
], ],
cb cb // no more areas
); );
}; };
@ -216,7 +211,7 @@ NewScanModule.prototype.mciReady = function(mciData, cb) {
NewScanModule.super_.prototype.mciReady.call(self, mciData, callback); NewScanModule.super_.prototype.mciReady.call(self, mciData, callback);
}, },
function loadFromConfig(callback) { function loadFromConfig(callback) {
var loadOpts = { const loadOpts = {
callingMenu : self, callingMenu : self,
mciMap : mciData.menu, mciMap : mciData.menu,
noInput : true, noInput : true,
@ -227,13 +222,12 @@ NewScanModule.prototype.mciReady = function(mciData, cb) {
function performCurrentStepScan(callback) { function performCurrentStepScan(callback) {
switch(self.currentStep) { switch(self.currentStep) {
case 'messageConferences' : case 'messageConferences' :
self.newScanMessageConference(function scanComplete(err) { self.newScanMessageConference( () => {
callback(null); // finished callback(null); // finished
}); });
break; break;
default : default : return callback(null);
callback(null);
} }
} }
], ],

249
oputil.js
View File

@ -4,12 +4,19 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
var config = require('./core/config.js'); const config = require('./core/config.js');
var db = require('./core/database.js'); const db = require('./core/database.js');
const resolvePath = require('./core/misc_util.js').resolvePath;
var _ = require('lodash'); // deps
var async = require('async'); const _ = require('lodash');
var assert = require('assert'); const async = require('async');
const assert = require('assert');
const inq = require('inquirer');
const mkdirsSync = require('fs-extra').mkdirsSync;
const fs = require('fs');
const hjson = require('hjson');
const paths = require('path');
var argv = require('minimist')(process.argv.slice(2)); var argv = require('minimist')(process.argv.slice(2));
@ -116,6 +123,234 @@ function handleUserCommand() {
} }
} }
function getAnswers(questions, cb) {
inq.prompt(questions, cb);
}
function getDefaultConfigPath() {
return resolvePath('~/.config/enigma-bbs/config.hjson');
}
const QUESTIONS = {
Intro : [
{
name : 'createNewConfig',
message : 'Create a new configuration?',
type : 'confirm',
default : false,
},
{
name : 'configPath',
message : 'Configuration path:',
default : getDefaultConfigPath(),
when : answers => answers.createNewConfig
},
],
OverwriteConfig : [
{
name : 'overwriteConfig',
message : 'Config file exists. Overwrite?',
type : 'confirm',
default : false,
}
],
Basic : [
{
name : 'boardName',
message : 'BBS name:',
default : 'New ENiGMA½ BBS',
},
],
Misc : [
{
name : 'loggingLevel',
message : 'Logging level:',
type : 'list',
choices : [ 'Error', 'Warn', 'Info', 'Debug', 'Trace' ],
default : 2,
filter : s => s.toLowerCase(),
},
{
name : 'sevenZipExe',
message : '7-Zip executable:',
type : 'list',
choices : [ '7z', '7za', 'None' ]
}
],
MessageConfAndArea : [
{
name : 'msgConfName',
message : 'First message conference:',
default : 'Local',
},
{
name : 'msgConfDesc',
message : 'Conference description:',
default : 'Local Areas',
},
{
name : 'msgAreaName',
message : 'First area in message conference:',
default : 'General',
},
{
name : 'msgAreaDesc',
message : 'Area description:',
default : 'General chit-chat',
}
]
};
function makeMsgConfAreaName(s) {
return s.toLowerCase().replace(/\s+/g, '_');
}
function askQuestions(cb) {
const ui = new inq.ui.BottomBar();
let configPath;
let config;
async.waterfall(
[
function intro(callback) {
getAnswers(QUESTIONS.Intro, answers => {
if(!answers.createNewConfig) {
return callback('exit');
}
// adjust for ~ and the like
configPath = resolvePath(answers.configPath);
const configDir = paths.dirname(configPath);
mkdirsSync(configDir);
//
// Check if the file exists and can be written to
//
fs.access(configPath, fs.F_OK | fs.W_OK, err => {
if(err) {
if('EACCES' === err.code) {
ui.log.write(`${configPath} cannot be written to`);
callback('exit');
} else if('ENOENT' === err.code) {
callback(null, false);
}
} else {
callback(null, true); // exists + writable
}
});
});
},
function promptOverwrite(needPrompt, callback) {
if(needPrompt) {
getAnswers(QUESTIONS.OverwriteConfig, answers => {
callback(answers.overwriteConfig ? null : 'exit');
});
} else {
callback(null);
}
},
function basic(callback) {
getAnswers(QUESTIONS.Basic, answers => {
config = {
general : {
boardName : answers.boardName,
},
};
callback(null);
});
},
function msgConfAndArea(callback) {
getAnswers(QUESTIONS.MessageConfAndArea, answers => {
config.messageConferences = {};
const confName = makeMsgConfAreaName(answers.msgConfName);
const areaName = makeMsgConfAreaName(answers.msgAreaName);
config.messageConferences[confName] = {
name : answers.msgConfName,
desc : answers.msgConfDesc,
sort : 1,
default : true,
};
config.messageConferences.another_sample_conf = {
name : 'Another Sample Conference',
desc : 'Another conference example. Change me!',
sort : 2,
};
config.messageConferences[confName].areas = {};
config.messageConferences[confName].areas[areaName] = {
name : answers.msgAreaName,
desc : answers.msgAreaDesc,
sort : 1,
default : true,
};
config.messageConferences.another_sample_conf = {
areas : {
another_sample_area : {
name : 'Another Sample Area',
desc : 'Another area example. Change me!',
sort : 2
}
}
};
callback(null);
});
},
function misc(callback) {
getAnswers(QUESTIONS.Misc, answers => {
if('None' !== answers.sevenZipExe) {
config.archivers = {
zip : {
compressCmd : answers.sevenZipExe,
decompressCmd : answers.sevenZipExe,
}
};
}
config.logging = {
level : answers.loggingLevel,
};
callback(null);
});
}
],
err => {
cb(err, configPath, config);
}
);
}
function handleConfigCommand() {
askQuestions( (err, configPath, config) => {
if(err) {
return;
}
config = hjson.stringify(config, { bracesSameLine : true, spaces : '\t' } );
try {
fs.writeFileSync(configPath, config, 'utf8');
console.info('Configuration generated');
} catch(e) {
console.error('Exception attempting to create config: ' + e.toString());
}
});
}
function main() { function main() {
process.exitCode = ExitCodes.SUCCESS; process.exitCode = ExitCodes.SUCCESS;
@ -135,6 +370,10 @@ function main() {
case 'user' : case 'user' :
handleUserCommand(); handleUserCommand();
break; break;
case 'config' :
handleConfigCommand();
break;
default: default:
printUsage(''); printUsage('');