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 stripJsonComments = require('strip-json-comments');
|
|
|
|
var async = require('async');
|
|
|
|
var _ = require('lodash');
|
2015-04-17 04:29:53 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
exports.init = init;
|
|
|
|
exports.getDefaultPath = getDefaultPath;
|
|
|
|
|
|
|
|
function init(configPath, cb) {
|
|
|
|
|
|
|
|
// Probably many better ways of doing this:
|
|
|
|
// :TODO: See http://jsfiddle.net/jlowery2663/z8at6knn/4/
|
|
|
|
var recursiveMerge = function(target, source) {
|
|
|
|
for(var p in source) {
|
|
|
|
try {
|
|
|
|
if(_.isObject(source)) {
|
|
|
|
target[p] = recursiveMerge(target[p], source[p]);
|
|
|
|
} else {
|
|
|
|
target[p] = source[p];
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
target[p] = source[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function loadUserConfig(callback) {
|
|
|
|
|
|
|
|
fs.readFile(configPath, { encoding : 'utf8' }, function configData(err, data) {
|
|
|
|
if(err) {
|
|
|
|
callback(null, { } );
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var configJson = JSON.parse(stripJsonComments(data));
|
|
|
|
callback(null, configJson);
|
|
|
|
} catch(e) {
|
|
|
|
callback(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function mergeWithDefaultConfig(menuConfig, callback) {
|
|
|
|
var mergedConfig = recursiveMerge(menuConfig, getDefaultConfig());
|
|
|
|
callback(null, mergedConfig);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err, mergedConfig) {
|
|
|
|
exports.config = mergedConfig;
|
|
|
|
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-05-04 03:36:53 +00:00
|
|
|
return paths.join(base, '.enigma-bbs', 'config.json');
|
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 : {
|
|
|
|
boardName : 'Another Fine ENiGMA½ BBS',
|
|
|
|
},
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
firstMenu : 'connected',
|
|
|
|
|
|
|
|
preLoginTheme : '*',
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
users : {
|
|
|
|
usernameMin : 2,
|
|
|
|
usernameMax : 22,
|
|
|
|
usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+]+$',
|
|
|
|
passwordMin : 6,
|
2015-04-27 02:46:16 +00:00
|
|
|
passwordMax : 128,
|
2015-04-19 08:13:13 +00:00
|
|
|
requireActivation : true, // require SysOp activation?
|
|
|
|
invalidUsernames : [],
|
2015-05-11 22:39:28 +00:00
|
|
|
defaultGroups : [ 'users' ]
|
2015-04-19 08:13:13 +00:00
|
|
|
},
|
2015-04-17 04:29:53 +00:00
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
defaults : {
|
|
|
|
theme : 'NU-MAYA', // :TODO: allow "*" here
|
|
|
|
passwordChar : '*', // TODO: move to user ?
|
|
|
|
},
|
2015-04-15 04:27:07 +00:00
|
|
|
|
2015-05-14 04:21:55 +00:00
|
|
|
/*
|
|
|
|
Concept
|
|
|
|
"theme" : {
|
|
|
|
"default" : "defaultThemeName", // or "*"
|
|
|
|
"passwordChar" : "*",
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-04-19 08:13:13 +00:00
|
|
|
paths : {
|
|
|
|
mods : paths.join(__dirname, './../mods/'),
|
|
|
|
servers : paths.join(__dirname, './servers/'),
|
|
|
|
art : paths.join(__dirname, './../mods/art/'),
|
|
|
|
themes : paths.join(__dirname, './../mods/art/themes/'),
|
|
|
|
logs : paths.join(__dirname, './../logs/'), // :TODO: set up based on system, e.g. /var/logs/enigmabbs or such
|
|
|
|
db : paths.join(__dirname, './../db/'),
|
|
|
|
},
|
|
|
|
|
|
|
|
servers : {
|
|
|
|
telnet : {
|
|
|
|
port : 8888,
|
|
|
|
enabled : true,
|
2014-10-17 02:21:06 +00:00
|
|
|
},
|
2015-04-19 08:13:13 +00:00
|
|
|
ssh : {
|
|
|
|
port : 8889,
|
|
|
|
enabled : true,
|
|
|
|
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
|
|
|
|
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|