mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-23 19:20:41 +02:00
* Tons of work with menu/prompts refactoring -- more to come soon
* More work with menu/prompt accets
This commit is contained in:
parent
5faa11664b
commit
bac2f63c1a
21 changed files with 871 additions and 238 deletions
165
core/config.js
165
core/config.js
|
@ -1,68 +1,117 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var paths = require('path');
|
||||
var miscUtil = require('./misc_util.js');
|
||||
var miscUtil = require('./misc_util.js');
|
||||
|
||||
// :TODO: it would be nice to allow for defaults here & .json file only overrides -- e.g. merge the two
|
||||
var fs = require('fs');
|
||||
var paths = require('path');
|
||||
var stripJsonComments = require('strip-json-comments');
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
defaultPath : function() {
|
||||
var base = miscUtil.resolvePath('~/');
|
||||
if(base) {
|
||||
return paths.join(base, '.enigmabbs', 'config.json');
|
||||
}
|
||||
},
|
||||
exports.init = init;
|
||||
exports.getDefaultPath = getDefaultPath;
|
||||
|
||||
initFromFile : function(path, cb) {
|
||||
var data = fs.readFileSync(path, 'utf8');
|
||||
// :TODO: strip comments
|
||||
this.config = JSON.parse(data);
|
||||
},
|
||||
function init(configPath, cb) {
|
||||
|
||||
createDefault : function() {
|
||||
this.config = {
|
||||
bbsName : 'Another Fine ENiGMA½ BBS',
|
||||
|
||||
// :TODO: probably replace this with 'firstMenu' or somthing once that's available
|
||||
entryMod : 'matrix',
|
||||
|
||||
preLoginTheme : '*',
|
||||
|
||||
users : {
|
||||
usernameMin : 2,
|
||||
usernameMax : 22,
|
||||
passwordMin : 6,
|
||||
requireActivation : true, // require SysOp activation?
|
||||
},
|
||||
|
||||
defaults : {
|
||||
theme : 'NU-MAYA',
|
||||
passwordChar : '*',
|
||||
},
|
||||
|
||||
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,
|
||||
},
|
||||
ssh : {
|
||||
port : 8889,
|
||||
enabled : true,
|
||||
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
|
||||
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
|
||||
// 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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function getDefaultPath() {
|
||||
var base = miscUtil.resolvePath('~/');
|
||||
if(base) {
|
||||
return paths.join(base, '.enigmabbs', 'config.json');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getDefaultConfig() {
|
||||
return {
|
||||
general : {
|
||||
boardName : 'Another Fine ENiGMA½ BBS',
|
||||
},
|
||||
|
||||
firstMenu : 'connected',
|
||||
|
||||
preLoginTheme : '*',
|
||||
|
||||
users : {
|
||||
usernameMin : 2,
|
||||
usernameMax : 22,
|
||||
usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+]+$',
|
||||
passwordMin : 6,
|
||||
passwordMax : 256,
|
||||
requireActivation : true, // require SysOp activation?
|
||||
invalidUsernames : [],
|
||||
},
|
||||
|
||||
defaults : {
|
||||
theme : 'NU-MAYA', // :TODO: allow "*" here
|
||||
passwordChar : '*', // TODO: move to user ?
|
||||
},
|
||||
|
||||
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,
|
||||
},
|
||||
ssh : {
|
||||
port : 8889,
|
||||
enabled : true,
|
||||
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
|
||||
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue