2014-10-17 02:21:06 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
var miscUtil = require('./misc_util.js');
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var paths = require('path');
|
|
|
|
var async = require('async');
|
|
|
|
var _ = require('lodash');
|
2015-09-09 04:08:45 +00:00
|
|
|
var hjson = require('hjson');
|
2016-02-03 04:35:59 +00:00
|
|
|
var assert = require('assert');
|
2015-04-17 04:29:53 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
exports.init = init;
|
|
|
|
exports.getDefaultPath = getDefaultPath;
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
function hasMessageConferenceAndArea(config) {
|
2016-09-20 03:28:21 +00:00
|
|
|
assert(_.isObject(config.messageConferences)); // we create one ourself!
|
|
|
|
|
|
|
|
const nonInternalConfs = Object.keys(config.messageConferences).filter(confTag => {
|
|
|
|
return 'system_internal' !== confTag;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(0 === nonInternalConfs.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// :TODO: there is likely a better/cleaner way of doing this
|
|
|
|
|
|
|
|
let result = false;
|
|
|
|
_.forEach(nonInternalConfs, confTag => {
|
|
|
|
if(_.has(config.messageConferences[confTag], 'areas') &&
|
|
|
|
Object.keys(config.messageConferences[confTag].areas) > 0)
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return false; // stop iteration
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
2016-02-03 04:35:59 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
function init(configPath, cb) {
|
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function loadUserConfig(callback) {
|
2015-11-21 06:46:48 +00:00
|
|
|
if(_.isString(configPath)) {
|
|
|
|
fs.readFile(configPath, { encoding : 'utf8' }, function configData(err, data) {
|
|
|
|
if(err) {
|
|
|
|
callback(err);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var configJson = hjson.parse(data);
|
|
|
|
callback(null, configJson);
|
|
|
|
} catch(e) {
|
|
|
|
callback(e);
|
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
2015-11-21 06:46:48 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback(null, { } );
|
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
2015-08-06 04:22:17 +00:00
|
|
|
function mergeWithDefaultConfig(configJson, callback) {
|
2015-08-20 22:35:04 +00:00
|
|
|
var mergedConfig = _.merge(getDefaultConfig(), configJson, function mergeCustomizer(conf1, conf2) {
|
|
|
|
// Arrays should always concat
|
|
|
|
if(_.isArray(conf1)) {
|
|
|
|
// :TODO: look for collisions & override dupes
|
|
|
|
return conf1.concat(conf2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-21 06:46:48 +00:00
|
|
|
callback(null, mergedConfig);
|
|
|
|
},
|
|
|
|
function validate(mergedConfig, callback) {
|
|
|
|
//
|
|
|
|
// Various sections must now exist in config
|
|
|
|
//
|
2016-09-20 03:28:21 +00:00
|
|
|
if(hasMessageConferenceAndArea(mergedConfig)) {
|
|
|
|
var msgAreasErr = new Error('Please create at least one message conference and area!');
|
2015-11-21 06:46:48 +00:00
|
|
|
msgAreasErr.code = 'EBADCONFIG';
|
2016-09-20 03:28:21 +00:00
|
|
|
return callback(msgAreasErr);
|
|
|
|
} else {
|
|
|
|
return callback(null, mergedConfig);
|
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err, mergedConfig) {
|
|
|
|
exports.config = mergedConfig;
|
2016-09-20 03:28:21 +00:00
|
|
|
return cb(err);
|
2014-10-17 02:21:06 +00:00
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
);
|
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
function getDefaultPath() {
|
|
|
|
var base = miscUtil.resolvePath('~/');
|
|
|
|
if(base) {
|
2015-11-12 23:18:28 +00:00
|
|
|
// e.g. /home/users/joeuser/.config/enigma-bbs/config.hjson
|
|
|
|
return paths.join(base, '.config', 'enigma-bbs', 'config.hjson');
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
function getDefaultConfig() {
|
|
|
|
return {
|
|
|
|
general : {
|
2015-08-03 00:27:05 +00:00
|
|
|
boardName : 'Another Fine ENiGMA½ BBS',
|
2015-10-22 04:51:35 +00:00
|
|
|
|
2015-10-28 03:12:55 +00:00
|
|
|
closedSystem : false, // is the system closed to new users?
|
2015-10-22 18:22:03 +00:00
|
|
|
|
2015-10-22 04:51:35 +00:00
|
|
|
loginAttempts : 3,
|
2015-12-11 20:58:58 +00:00
|
|
|
|
|
|
|
menuFile : 'menu.hjson', // Override to use something else, e.g. demo.hjson. Can be a full path (defaults to ./mods)
|
2016-01-15 05:44:33 +00:00
|
|
|
promptFile : 'prompt.hjson', // Override to use soemthing else, e.g. myprompt.hjson. Can be a full path (defaults to ./mods)
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-12-11 20:58:58 +00:00
|
|
|
// :TODO: see notes below about 'theme' section - move this!
|
2015-12-13 23:47:28 +00:00
|
|
|
preLoginTheme : 'luciano_blocktronics',
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
users : {
|
|
|
|
usernameMin : 2,
|
2015-06-25 04:45:21 +00:00
|
|
|
usernameMax : 16, // Note that FidoNet wants 36 max
|
2016-09-02 05:39:49 +00:00
|
|
|
usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+ ]+$',
|
2015-12-24 18:51:49 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
passwordMin : 6,
|
2015-04-27 02:46:16 +00:00
|
|
|
passwordMax : 128,
|
2015-12-24 18:51:49 +00:00
|
|
|
|
|
|
|
realNameMax : 32,
|
|
|
|
locationMax : 32,
|
|
|
|
affilsMax : 32,
|
|
|
|
emailMax : 255,
|
|
|
|
webMax : 255,
|
|
|
|
|
2016-07-15 03:30:02 +00:00
|
|
|
requireActivation : false, // require SysOp activation? false = auto-activate
|
2015-04-19 08:13:13 +00:00
|
|
|
invalidUsernames : [],
|
2015-08-21 04:29:16 +00:00
|
|
|
|
|
|
|
groups : [ 'users', 'sysops' ], // built in groups
|
2015-10-22 17:04:50 +00:00
|
|
|
defaultGroups : [ 'users' ], // default groups new users belong to
|
|
|
|
|
|
|
|
newUserNames : [ 'new', 'apply' ], // Names reserved for applying
|
2015-10-28 03:12:55 +00:00
|
|
|
|
|
|
|
// :TODO: Mystic uses TRASHCAN.DAT for this -- is there a reason to support something like that?
|
2015-11-05 06:04:55 +00:00
|
|
|
badUserNames : [ 'sysop', 'admin', 'administrator', 'root', 'all' ],
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
2015-04-17 04:29:53 +00:00
|
|
|
|
2015-09-09 04:08:45 +00:00
|
|
|
// :TODO: better name for "defaults"... which is redundant here!
|
|
|
|
/*
|
|
|
|
Concept
|
|
|
|
"theme" : {
|
|
|
|
"default" : "defaultThemeName", // or "*"
|
|
|
|
"preLogin" : "*",
|
|
|
|
"passwordChar" : "*",
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2015-04-19 08:13:13 +00:00
|
|
|
defaults : {
|
2015-09-28 04:05:40 +00:00
|
|
|
theme : 'luciano_blocktronics',
|
2015-04-19 08:13:13 +00:00
|
|
|
passwordChar : '*', // TODO: move to user ?
|
2015-07-24 04:23:44 +00:00
|
|
|
dateFormat : {
|
2015-07-23 03:35:35 +00:00
|
|
|
short : 'MM/DD/YYYY',
|
2015-07-24 04:23:44 +00:00
|
|
|
},
|
|
|
|
timeFormat : {
|
2015-07-25 22:10:12 +00:00
|
|
|
short : 'h:mm a',
|
2015-09-02 04:42:54 +00:00
|
|
|
},
|
|
|
|
dateTimeFormat : {
|
|
|
|
short : 'MM/DD/YYYY h:mm a',
|
2015-07-23 03:35:35 +00:00
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
2015-04-15 04:27:07 +00:00
|
|
|
|
2015-09-09 04:08:45 +00:00
|
|
|
menus : {
|
|
|
|
cls : true, // Clear screen before each menu by default?
|
|
|
|
},
|
2015-05-14 04:21:55 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
paths : {
|
|
|
|
mods : paths.join(__dirname, './../mods/'),
|
2016-09-20 03:28:21 +00:00
|
|
|
loginServers : paths.join(__dirname, './servers/login/'),
|
|
|
|
contentServers : paths.join(__dirname, './servers/content/'),
|
2016-02-10 05:30:59 +00:00
|
|
|
|
|
|
|
scannerTossers : paths.join(__dirname, './scanner_tossers/'),
|
|
|
|
mailers : paths.join(__dirname, './mailers/') ,
|
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
art : paths.join(__dirname, './../mods/art/'),
|
2015-05-14 22:49:19 +00:00
|
|
|
themes : paths.join(__dirname, './../mods/themes/'),
|
2015-04-19 08:13:13 +00:00
|
|
|
logs : paths.join(__dirname, './../logs/'), // :TODO: set up based on system, e.g. /var/logs/enigmabbs or such
|
|
|
|
db : paths.join(__dirname, './../db/'),
|
2016-06-26 04:37:02 +00:00
|
|
|
modsDb : paths.join(__dirname, './../db/mods/'),
|
2015-08-03 00:27:05 +00:00
|
|
|
dropFiles : paths.join(__dirname, './../dropfiles/'), // + "/node<x>/
|
2015-11-07 01:30:08 +00:00
|
|
|
misc : paths.join(__dirname, './../misc/'),
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
|
|
|
|
2016-09-20 03:28:21 +00:00
|
|
|
loginServers : {
|
2015-04-19 08:13:13 +00:00
|
|
|
telnet : {
|
|
|
|
port : 8888,
|
|
|
|
enabled : true,
|
2015-10-22 16:36:08 +00:00
|
|
|
firstMenu : 'telnetConnected',
|
2014-10-17 02:21:06 +00:00
|
|
|
},
|
2015-04-19 08:13:13 +00:00
|
|
|
ssh : {
|
2015-10-22 18:22:03 +00:00
|
|
|
port : 8889,
|
2016-03-23 04:29:08 +00:00
|
|
|
enabled : false, // defualt to false as PK/pass in config.hjson are required
|
2015-10-28 02:46:30 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Private key in PEM format
|
|
|
|
//
|
|
|
|
// Generating your PK:
|
|
|
|
// > openssl genrsa -des3 -out ./misc/ssh_private_key.pem 2048
|
|
|
|
//
|
|
|
|
// Then, set servers.ssh.privateKeyPass to the password you use above
|
|
|
|
// in your config.hjson
|
|
|
|
//
|
|
|
|
privateKeyPem : paths.join(__dirname, './../misc/ssh_private_key.pem'),
|
2015-10-22 18:22:03 +00:00
|
|
|
firstMenu : 'sshConnected',
|
|
|
|
firstMenuNewUser : 'sshConnectedNewUser',
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
|
|
|
},
|
2015-07-14 06:13:29 +00:00
|
|
|
|
2016-02-24 04:56:22 +00:00
|
|
|
archivers : {
|
|
|
|
zip : {
|
2016-06-20 03:09:45 +00:00
|
|
|
sig : '504b0304',
|
2016-02-24 04:56:22 +00:00
|
|
|
offset : 0,
|
2016-06-20 03:09:45 +00:00
|
|
|
compressCmd : '7z',
|
|
|
|
compressArgs : [ 'a', '-tzip', '{archivePath}', '{fileList}' ],
|
|
|
|
decompressCmd : '7z',
|
|
|
|
decompressArgs : [ 'e', '-o{extractPath}', '{archivePath}' ]
|
2016-02-24 04:56:22 +00:00
|
|
|
}
|
|
|
|
},
|
2016-06-20 03:09:45 +00:00
|
|
|
|
2016-09-29 03:54:25 +00:00
|
|
|
fileTransferProtocols : {
|
|
|
|
zmodem8kSz : {
|
|
|
|
name : 'ZModem 8k',
|
|
|
|
type : 'external',
|
|
|
|
external : {
|
|
|
|
sendCmd : 'sz', // Avail on Debian/Ubuntu based systems as the package "lrzsz"
|
|
|
|
sendArgs : [
|
|
|
|
'--zmodem', '-y', '--try-8k', '--binary', '--restricted', '{filePath}'
|
|
|
|
],
|
|
|
|
escapeTelnet : true, // set to true to escape Telnet codes such as IAC
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
zmodem8kSexyz : {
|
|
|
|
name : 'ZModem 8k',
|
|
|
|
type : 'external',
|
|
|
|
external : {
|
|
|
|
// :TODO: Look into shipping sexyz binaries or at least hosting them somewhere for common systems
|
|
|
|
sendCmd : 'sexyz',
|
|
|
|
sendArgs : [
|
|
|
|
'-telnet', 'sz', '{filePath}'
|
|
|
|
],
|
|
|
|
escapeTelnet : true, // set to true to escape Telnet codes such as IAC
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2016-06-20 03:09:45 +00:00
|
|
|
|
|
|
|
messageAreaDefaults : {
|
|
|
|
//
|
|
|
|
// The following can be override per-area as well
|
|
|
|
//
|
|
|
|
maxMessages : 1024, // 0 = unlimited
|
|
|
|
maxAgeDays : 0, // 0 = unlimited
|
|
|
|
},
|
2016-02-24 04:56:22 +00:00
|
|
|
|
2016-06-20 03:09:45 +00:00
|
|
|
messageConferences : {
|
2016-02-03 04:35:59 +00:00
|
|
|
system_internal : {
|
|
|
|
name : 'System Internal',
|
|
|
|
desc : 'Built in conference for private messages, bulletins, etc.',
|
|
|
|
|
|
|
|
areas : {
|
|
|
|
private_mail : {
|
|
|
|
name : 'Private Mail',
|
|
|
|
desc : 'Private user to user mail/email',
|
|
|
|
},
|
|
|
|
|
|
|
|
local_bulletin : {
|
|
|
|
name : 'System Bulletins',
|
|
|
|
desc : 'Bulletin messages for all users',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-02-17 05:11:55 +00:00
|
|
|
|
|
|
|
scannerTossers : {
|
|
|
|
ftn_bso : {
|
|
|
|
paths : {
|
2016-02-24 04:56:22 +00:00
|
|
|
outbound : paths.join(__dirname, './../mail/ftn_out/'),
|
|
|
|
inbound : paths.join(__dirname, './../mail/ftn_in/'),
|
|
|
|
secInbound : paths.join(__dirname, './../mail/ftn_secin/'),
|
2016-02-17 05:11:55 +00:00
|
|
|
},
|
|
|
|
|
2016-02-29 05:04:03 +00:00
|
|
|
//
|
|
|
|
// Packet and (ArcMail) bundle target sizes are just that: targets.
|
|
|
|
// Actual sizes may be slightly larger when we must place a full
|
|
|
|
// PKT contents *somewhere*
|
|
|
|
//
|
|
|
|
packetTargetByteSize : 512000, // 512k, before placing messages in a new pkt
|
|
|
|
bundleTargetByteSize : 2048000, // 2M, before creating another archive
|
2016-02-17 05:11:55 +00:00
|
|
|
}
|
|
|
|
},
|
2016-09-20 03:28:21 +00:00
|
|
|
|
|
|
|
fileBase: {
|
|
|
|
// areas with an explicit |storageDir| will be stored relative to |areaStoragePrefix|:
|
|
|
|
areaStoragePrefix : paths.join(__dirname, './../file_base/'),
|
|
|
|
|
|
|
|
fileNamePatterns: {
|
|
|
|
shortDesc : [ '^FILE_ID\.DIZ$', '^DESC\.SDI$' ],
|
|
|
|
longDesc : [ '^.*\.NFO$', '^README\.1ST$', '^README\.TXT$' ],
|
|
|
|
},
|
|
|
|
|
|
|
|
areas: {
|
|
|
|
message_attachment : {
|
|
|
|
name : 'Message attachments',
|
|
|
|
desc : 'File attachments to messages',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-06-20 03:09:45 +00:00
|
|
|
|
|
|
|
eventScheduler : {
|
|
|
|
|
|
|
|
|
|
|
|
events : {
|
|
|
|
trimMessageAreas : {
|
|
|
|
// may optionally use [or ]@watch:/path/to/file
|
2016-06-22 03:37:47 +00:00
|
|
|
schedule : 'every 24 hours',
|
2016-06-20 03:09:45 +00:00
|
|
|
|
|
|
|
// action:
|
|
|
|
// - @method:path/to/module.js:theMethodName
|
|
|
|
// (path is relative to engima base dir)
|
|
|
|
//
|
|
|
|
// - @execute:/path/to/something/executable.sh
|
|
|
|
//
|
2016-06-22 03:37:47 +00:00
|
|
|
action : '@method:core/message_area.js:trimMessageAreasScheduledEvent',
|
2016-06-20 03:09:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-07-21 04:56:48 +00:00
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
misc : {
|
2016-08-22 01:59:21 +00:00
|
|
|
preAuthIdleLogoutSeconds : 60 * 3, // 2m
|
|
|
|
idleLogoutSeconds : 60 * 6, // 6m
|
2015-08-05 04:35:59 +00:00
|
|
|
},
|
|
|
|
|
2015-07-21 04:56:48 +00:00
|
|
|
logging : {
|
2016-09-04 23:46:28 +00:00
|
|
|
level : 'debug',
|
|
|
|
|
|
|
|
rotatingFile : { // set to 'disabled' or false to disable
|
|
|
|
type : 'rotating-file',
|
|
|
|
fileName : 'enigma-bbs.log',
|
|
|
|
period : '1d',
|
|
|
|
count : 3,
|
|
|
|
level : 'debug',
|
|
|
|
}
|
|
|
|
|
|
|
|
// :TODO: syslog - https://github.com/mcavage/node-bunyan-syslog
|
2016-08-22 01:59:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
debug : {
|
|
|
|
assertsEnabled : false,
|
2015-07-21 04:56:48 +00:00
|
|
|
}
|
2015-04-19 08:13:13 +00:00
|
|
|
};
|
|
|
|
}
|