mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-23 03:06:04 +02:00
ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
parent
5ddf04c882
commit
e9787cee3e
135 changed files with 27397 additions and 27397 deletions
452
core/bbs.js
452
core/bbs.js
|
@ -41,253 +41,253 @@ valid args:
|
|||
`;
|
||||
|
||||
function printHelpAndExit() {
|
||||
console.info(HELP);
|
||||
process.exit();
|
||||
console.info(HELP);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
function main() {
|
||||
async.waterfall(
|
||||
[
|
||||
function processArgs(callback) {
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
async.waterfall(
|
||||
[
|
||||
function processArgs(callback) {
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
|
||||
if(argv.help) {
|
||||
printHelpAndExit();
|
||||
}
|
||||
if(argv.help) {
|
||||
printHelpAndExit();
|
||||
}
|
||||
|
||||
const configOverridePath = argv.config;
|
||||
const configOverridePath = argv.config;
|
||||
|
||||
return callback(null, configOverridePath || conf.getDefaultPath(), _.isString(configOverridePath));
|
||||
},
|
||||
function initConfig(configPath, configPathSupplied, callback) {
|
||||
const configFile = configPath + 'config.hjson';
|
||||
conf.init(resolvePath(configFile), function configInit(err) {
|
||||
return callback(null, configOverridePath || conf.getDefaultPath(), _.isString(configOverridePath));
|
||||
},
|
||||
function initConfig(configPath, configPathSupplied, callback) {
|
||||
const configFile = configPath + 'config.hjson';
|
||||
conf.init(resolvePath(configFile), function configInit(err) {
|
||||
|
||||
//
|
||||
// If the user supplied a path and we can't read/parse it
|
||||
// then it's a fatal error
|
||||
//
|
||||
if(err) {
|
||||
if('ENOENT' === err.code) {
|
||||
if(configPathSupplied) {
|
||||
console.error('Configuration file does not exist: ' + configFile);
|
||||
} else {
|
||||
configPathSupplied = null; // make non-fatal; we'll go with defaults
|
||||
}
|
||||
} else {
|
||||
console.error(err.toString());
|
||||
}
|
||||
}
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function initSystem(callback) {
|
||||
initialize(function init(err) {
|
||||
if(err) {
|
||||
console.error('Error initializing: ' + util.inspect(err));
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
// note this is escaped:
|
||||
fs.readFile(paths.join(__dirname, '../misc/startup_banner.asc'), 'utf8', (err, banner) => {
|
||||
console.info(FULL_COPYRIGHT);
|
||||
if(!err) {
|
||||
console.info(banner);
|
||||
}
|
||||
console.info('System started!');
|
||||
});
|
||||
//
|
||||
// If the user supplied a path and we can't read/parse it
|
||||
// then it's a fatal error
|
||||
//
|
||||
if(err) {
|
||||
if('ENOENT' === err.code) {
|
||||
if(configPathSupplied) {
|
||||
console.error('Configuration file does not exist: ' + configFile);
|
||||
} else {
|
||||
configPathSupplied = null; // make non-fatal; we'll go with defaults
|
||||
}
|
||||
} else {
|
||||
console.error(err.toString());
|
||||
}
|
||||
}
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function initSystem(callback) {
|
||||
initialize(function init(err) {
|
||||
if(err) {
|
||||
console.error('Error initializing: ' + util.inspect(err));
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
// note this is escaped:
|
||||
fs.readFile(paths.join(__dirname, '../misc/startup_banner.asc'), 'utf8', (err, banner) => {
|
||||
console.info(FULL_COPYRIGHT);
|
||||
if(!err) {
|
||||
console.info(banner);
|
||||
}
|
||||
console.info('System started!');
|
||||
});
|
||||
|
||||
if(err) {
|
||||
console.error('Error initializing: ' + util.inspect(err));
|
||||
}
|
||||
}
|
||||
);
|
||||
if(err) {
|
||||
console.error('Error initializing: ' + util.inspect(err));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function shutdownSystem() {
|
||||
const msg = 'Process interrupted. Shutting down...';
|
||||
console.info(msg);
|
||||
logger.log.info(msg);
|
||||
const msg = 'Process interrupted. Shutting down...';
|
||||
console.info(msg);
|
||||
logger.log.info(msg);
|
||||
|
||||
async.series(
|
||||
[
|
||||
function closeConnections(callback) {
|
||||
const ClientConns = require('./client_connections.js');
|
||||
const activeConnections = ClientConns.getActiveConnections();
|
||||
let i = activeConnections.length;
|
||||
while(i--) {
|
||||
const activeTerm = activeConnections[i].term;
|
||||
if(activeTerm) {
|
||||
activeTerm.write('\n\nServer is shutting down NOW! Disconnecting...\n\n');
|
||||
}
|
||||
ClientConns.removeClient(activeConnections[i]);
|
||||
}
|
||||
callback(null);
|
||||
},
|
||||
function stopListeningServers(callback) {
|
||||
return require('./listening_server.js').shutdown( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
},
|
||||
function stopEventScheduler(callback) {
|
||||
if(initServices.eventScheduler) {
|
||||
return initServices.eventScheduler.shutdown( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
},
|
||||
function stopFileAreaWeb(callback) {
|
||||
require('./file_area_web.js').startup( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
},
|
||||
function stopMsgNetwork(callback) {
|
||||
require('./msg_network.js').shutdown(callback);
|
||||
}
|
||||
],
|
||||
() => {
|
||||
console.info('Goodbye!');
|
||||
return process.exit();
|
||||
}
|
||||
);
|
||||
async.series(
|
||||
[
|
||||
function closeConnections(callback) {
|
||||
const ClientConns = require('./client_connections.js');
|
||||
const activeConnections = ClientConns.getActiveConnections();
|
||||
let i = activeConnections.length;
|
||||
while(i--) {
|
||||
const activeTerm = activeConnections[i].term;
|
||||
if(activeTerm) {
|
||||
activeTerm.write('\n\nServer is shutting down NOW! Disconnecting...\n\n');
|
||||
}
|
||||
ClientConns.removeClient(activeConnections[i]);
|
||||
}
|
||||
callback(null);
|
||||
},
|
||||
function stopListeningServers(callback) {
|
||||
return require('./listening_server.js').shutdown( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
},
|
||||
function stopEventScheduler(callback) {
|
||||
if(initServices.eventScheduler) {
|
||||
return initServices.eventScheduler.shutdown( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
},
|
||||
function stopFileAreaWeb(callback) {
|
||||
require('./file_area_web.js').startup( () => {
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
},
|
||||
function stopMsgNetwork(callback) {
|
||||
require('./msg_network.js').shutdown(callback);
|
||||
}
|
||||
],
|
||||
() => {
|
||||
console.info('Goodbye!');
|
||||
return process.exit();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function initialize(cb) {
|
||||
async.series(
|
||||
[
|
||||
function createMissingDirectories(callback) {
|
||||
async.each(Object.keys(conf.config.paths), function entry(pathKey, next) {
|
||||
mkdirs(conf.config.paths[pathKey], function dirCreated(err) {
|
||||
if(err) {
|
||||
console.error('Could not create path: ' + conf.config.paths[pathKey] + ': ' + err.toString());
|
||||
}
|
||||
return next(err);
|
||||
});
|
||||
}, function dirCreationComplete(err) {
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
function basicInit(callback) {
|
||||
logger.init();
|
||||
logger.log.info(
|
||||
{ version : require('../package.json').version },
|
||||
'**** ENiGMA½ Bulletin Board System Starting Up! ****');
|
||||
async.series(
|
||||
[
|
||||
function createMissingDirectories(callback) {
|
||||
async.each(Object.keys(conf.config.paths), function entry(pathKey, next) {
|
||||
mkdirs(conf.config.paths[pathKey], function dirCreated(err) {
|
||||
if(err) {
|
||||
console.error('Could not create path: ' + conf.config.paths[pathKey] + ': ' + err.toString());
|
||||
}
|
||||
return next(err);
|
||||
});
|
||||
}, function dirCreationComplete(err) {
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
function basicInit(callback) {
|
||||
logger.init();
|
||||
logger.log.info(
|
||||
{ version : require('../package.json').version },
|
||||
'**** ENiGMA½ Bulletin Board System Starting Up! ****');
|
||||
|
||||
process.on('SIGINT', shutdownSystem);
|
||||
process.on('SIGINT', shutdownSystem);
|
||||
|
||||
require('later').date.localTime(); // use local times for later.js/scheduling
|
||||
require('later').date.localTime(); // use local times for later.js/scheduling
|
||||
|
||||
return callback(null);
|
||||
},
|
||||
function initDatabases(callback) {
|
||||
return database.initializeDatabases(callback);
|
||||
},
|
||||
function initMimeTypes(callback) {
|
||||
return require('./mime_util.js').startup(callback);
|
||||
},
|
||||
function initStatLog(callback) {
|
||||
return require('./stat_log.js').init(callback);
|
||||
},
|
||||
function initConfigs(callback) {
|
||||
return require('./config_util.js').init(callback);
|
||||
},
|
||||
function initThemes(callback) {
|
||||
// Have to pull in here so it's after Config init
|
||||
require('./theme.js').initAvailableThemes( (err, themeCount) => {
|
||||
logger.log.info({ themeCount }, 'Themes initialized');
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
function loadSysOpInformation(callback) {
|
||||
//
|
||||
// Copy over some +op information from the user DB -> system propertys.
|
||||
// * Makes this accessible for MCI codes, easy non-blocking access, etc.
|
||||
// * We do this every time as the op is free to change this information just
|
||||
// like any other user
|
||||
//
|
||||
const User = require('./user.js');
|
||||
return callback(null);
|
||||
},
|
||||
function initDatabases(callback) {
|
||||
return database.initializeDatabases(callback);
|
||||
},
|
||||
function initMimeTypes(callback) {
|
||||
return require('./mime_util.js').startup(callback);
|
||||
},
|
||||
function initStatLog(callback) {
|
||||
return require('./stat_log.js').init(callback);
|
||||
},
|
||||
function initConfigs(callback) {
|
||||
return require('./config_util.js').init(callback);
|
||||
},
|
||||
function initThemes(callback) {
|
||||
// Have to pull in here so it's after Config init
|
||||
require('./theme.js').initAvailableThemes( (err, themeCount) => {
|
||||
logger.log.info({ themeCount }, 'Themes initialized');
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
function loadSysOpInformation(callback) {
|
||||
//
|
||||
// Copy over some +op information from the user DB -> system propertys.
|
||||
// * Makes this accessible for MCI codes, easy non-blocking access, etc.
|
||||
// * We do this every time as the op is free to change this information just
|
||||
// like any other user
|
||||
//
|
||||
const User = require('./user.js');
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function getOpUserName(next) {
|
||||
return User.getUserName(1, next);
|
||||
},
|
||||
function getOpProps(opUserName, next) {
|
||||
const propLoadOpts = {
|
||||
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
||||
};
|
||||
User.loadProperties(User.RootUserID, propLoadOpts, (err, opProps) => {
|
||||
return next(err, opUserName, opProps);
|
||||
});
|
||||
}
|
||||
],
|
||||
(err, opUserName, opProps) => {
|
||||
const StatLog = require('./stat_log.js');
|
||||
async.waterfall(
|
||||
[
|
||||
function getOpUserName(next) {
|
||||
return User.getUserName(1, next);
|
||||
},
|
||||
function getOpProps(opUserName, next) {
|
||||
const propLoadOpts = {
|
||||
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
||||
};
|
||||
User.loadProperties(User.RootUserID, propLoadOpts, (err, opProps) => {
|
||||
return next(err, opUserName, opProps);
|
||||
});
|
||||
}
|
||||
],
|
||||
(err, opUserName, opProps) => {
|
||||
const StatLog = require('./stat_log.js');
|
||||
|
||||
if(err) {
|
||||
[ 'username', 'real_name', 'sex', 'email_address', 'location', 'affiliation' ].forEach(v => {
|
||||
StatLog.setNonPeristentSystemStat(`sysop_${v}`, 'N/A');
|
||||
});
|
||||
} else {
|
||||
opProps.username = opUserName;
|
||||
if(err) {
|
||||
[ 'username', 'real_name', 'sex', 'email_address', 'location', 'affiliation' ].forEach(v => {
|
||||
StatLog.setNonPeristentSystemStat(`sysop_${v}`, 'N/A');
|
||||
});
|
||||
} else {
|
||||
opProps.username = opUserName;
|
||||
|
||||
_.each(opProps, (v, k) => {
|
||||
StatLog.setNonPeristentSystemStat(`sysop_${k}`, v);
|
||||
});
|
||||
}
|
||||
_.each(opProps, (v, k) => {
|
||||
StatLog.setNonPeristentSystemStat(`sysop_${k}`, v);
|
||||
});
|
||||
}
|
||||
|
||||
return callback(null);
|
||||
}
|
||||
);
|
||||
},
|
||||
function initFileAreaStats(callback) {
|
||||
const getAreaStats = require('./file_base_area.js').getAreaStats;
|
||||
getAreaStats( (err, stats) => {
|
||||
if(!err) {
|
||||
const StatLog = require('./stat_log.js');
|
||||
StatLog.setNonPeristentSystemStat('file_base_area_stats', stats);
|
||||
}
|
||||
return callback(null);
|
||||
}
|
||||
);
|
||||
},
|
||||
function initFileAreaStats(callback) {
|
||||
const getAreaStats = require('./file_base_area.js').getAreaStats;
|
||||
getAreaStats( (err, stats) => {
|
||||
if(!err) {
|
||||
const StatLog = require('./stat_log.js');
|
||||
StatLog.setNonPeristentSystemStat('file_base_area_stats', stats);
|
||||
}
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
},
|
||||
function initMCI(callback) {
|
||||
return require('./predefined_mci.js').init(callback);
|
||||
},
|
||||
function readyMessageNetworkSupport(callback) {
|
||||
return require('./msg_network.js').startup(callback);
|
||||
},
|
||||
function readyEvents(callback) {
|
||||
return require('./events.js').startup(callback);
|
||||
},
|
||||
function listenConnections(callback) {
|
||||
return require('./listening_server.js').startup(callback);
|
||||
},
|
||||
function readyFileBaseArea(callback) {
|
||||
return require('./file_base_area.js').startup(callback);
|
||||
},
|
||||
function readyFileAreaWeb(callback) {
|
||||
return require('./file_area_web.js').startup(callback);
|
||||
},
|
||||
function readyPasswordReset(callback) {
|
||||
const WebPasswordReset = require('./web_password_reset.js').WebPasswordReset;
|
||||
return WebPasswordReset.startup(callback);
|
||||
},
|
||||
function readyEventScheduler(callback) {
|
||||
const EventSchedulerModule = require('./event_scheduler.js').EventSchedulerModule;
|
||||
EventSchedulerModule.loadAndStart( (err, modInst) => {
|
||||
initServices.eventScheduler = modInst;
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
function onComplete(err) {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
return callback(null);
|
||||
});
|
||||
},
|
||||
function initMCI(callback) {
|
||||
return require('./predefined_mci.js').init(callback);
|
||||
},
|
||||
function readyMessageNetworkSupport(callback) {
|
||||
return require('./msg_network.js').startup(callback);
|
||||
},
|
||||
function readyEvents(callback) {
|
||||
return require('./events.js').startup(callback);
|
||||
},
|
||||
function listenConnections(callback) {
|
||||
return require('./listening_server.js').startup(callback);
|
||||
},
|
||||
function readyFileBaseArea(callback) {
|
||||
return require('./file_base_area.js').startup(callback);
|
||||
},
|
||||
function readyFileAreaWeb(callback) {
|
||||
return require('./file_area_web.js').startup(callback);
|
||||
},
|
||||
function readyPasswordReset(callback) {
|
||||
const WebPasswordReset = require('./web_password_reset.js').WebPasswordReset;
|
||||
return WebPasswordReset.startup(callback);
|
||||
},
|
||||
function readyEventScheduler(callback) {
|
||||
const EventSchedulerModule = require('./event_scheduler.js').EventSchedulerModule;
|
||||
EventSchedulerModule.loadAndStart( (err, modInst) => {
|
||||
initServices.eventScheduler = modInst;
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
function onComplete(err) {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue