mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-11 23:24:43 +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
|
@ -16,127 +16,127 @@ const async = require('async');
|
|||
exports.handleMessageBaseCommand = handleMessageBaseCommand;
|
||||
|
||||
function areaFix() {
|
||||
//
|
||||
// oputil mb areafix CMD1 CMD2 ... ADDR [--password PASS]
|
||||
//
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(
|
||||
getHelpFor('MessageBase'),
|
||||
ExitCodes.ERROR
|
||||
);
|
||||
}
|
||||
//
|
||||
// oputil mb areafix CMD1 CMD2 ... ADDR [--password PASS]
|
||||
//
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(
|
||||
getHelpFor('MessageBase'),
|
||||
ExitCodes.ERROR
|
||||
);
|
||||
}
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function init(callback) {
|
||||
return initConfigAndDatabases(callback);
|
||||
},
|
||||
function validateAddress(callback) {
|
||||
const addrArg = argv._.slice(-1)[0];
|
||||
const ftnAddr = Address.fromString(addrArg);
|
||||
async.waterfall(
|
||||
[
|
||||
function init(callback) {
|
||||
return initConfigAndDatabases(callback);
|
||||
},
|
||||
function validateAddress(callback) {
|
||||
const addrArg = argv._.slice(-1)[0];
|
||||
const ftnAddr = Address.fromString(addrArg);
|
||||
|
||||
if(!ftnAddr) {
|
||||
return callback(Errors.Invalid(`"${addrArg}" is not a valid FTN address`));
|
||||
}
|
||||
if(!ftnAddr) {
|
||||
return callback(Errors.Invalid(`"${addrArg}" is not a valid FTN address`));
|
||||
}
|
||||
|
||||
//
|
||||
// We need to validate the address targets a system we know unless
|
||||
// the --force option is used
|
||||
//
|
||||
// :TODO:
|
||||
return callback(null, ftnAddr);
|
||||
},
|
||||
function fetchFromUser(ftnAddr, callback) {
|
||||
//
|
||||
// --from USER || +op from system
|
||||
//
|
||||
// If possible, we want the user ID of the supplied user as well
|
||||
//
|
||||
const User = require('../user.js');
|
||||
//
|
||||
// We need to validate the address targets a system we know unless
|
||||
// the --force option is used
|
||||
//
|
||||
// :TODO:
|
||||
return callback(null, ftnAddr);
|
||||
},
|
||||
function fetchFromUser(ftnAddr, callback) {
|
||||
//
|
||||
// --from USER || +op from system
|
||||
//
|
||||
// If possible, we want the user ID of the supplied user as well
|
||||
//
|
||||
const User = require('../user.js');
|
||||
|
||||
if(argv.from) {
|
||||
User.getUserIdAndNameByLookup(argv.from, (err, userId, fromName) => {
|
||||
if(err) {
|
||||
return callback(null, ftnAddr, argv.from, 0);
|
||||
}
|
||||
if(argv.from) {
|
||||
User.getUserIdAndNameByLookup(argv.from, (err, userId, fromName) => {
|
||||
if(err) {
|
||||
return callback(null, ftnAddr, argv.from, 0);
|
||||
}
|
||||
|
||||
// fromName is the same as argv.from, but case may be differnet (yet correct)
|
||||
return callback(null, ftnAddr, fromName, userId);
|
||||
});
|
||||
} else {
|
||||
User.getUserName(User.RootUserID, (err, fromName) => {
|
||||
return callback(null, ftnAddr, fromName || 'SysOp', err ? 0 : User.RootUserID);
|
||||
});
|
||||
}
|
||||
},
|
||||
function createMessage(ftnAddr, fromName, fromUserId, callback) {
|
||||
//
|
||||
// Build message as commands separated by line feed
|
||||
//
|
||||
// We need to remove quotes from arguments. These are required
|
||||
// in the case of e.g. removing an area: "-SOME_AREA" would end
|
||||
// up confusing minimist, therefor they must be quoted: "'-SOME_AREA'"
|
||||
//
|
||||
const messageBody = argv._.slice(2, -1).map(arg => {
|
||||
return arg.replace(/["']/g, '');
|
||||
}).join('\r\n') + '\n';
|
||||
// fromName is the same as argv.from, but case may be differnet (yet correct)
|
||||
return callback(null, ftnAddr, fromName, userId);
|
||||
});
|
||||
} else {
|
||||
User.getUserName(User.RootUserID, (err, fromName) => {
|
||||
return callback(null, ftnAddr, fromName || 'SysOp', err ? 0 : User.RootUserID);
|
||||
});
|
||||
}
|
||||
},
|
||||
function createMessage(ftnAddr, fromName, fromUserId, callback) {
|
||||
//
|
||||
// Build message as commands separated by line feed
|
||||
//
|
||||
// We need to remove quotes from arguments. These are required
|
||||
// in the case of e.g. removing an area: "-SOME_AREA" would end
|
||||
// up confusing minimist, therefor they must be quoted: "'-SOME_AREA'"
|
||||
//
|
||||
const messageBody = argv._.slice(2, -1).map(arg => {
|
||||
return arg.replace(/["']/g, '');
|
||||
}).join('\r\n') + '\n';
|
||||
|
||||
const Message = require('../message.js');
|
||||
const Message = require('../message.js');
|
||||
|
||||
const message = new Message({
|
||||
toUserName : argv.to || 'AreaFix',
|
||||
fromUserName : fromName,
|
||||
subject : argv.password || '',
|
||||
message : messageBody,
|
||||
areaTag : Message.WellKnownAreaTags.Private, // mark private
|
||||
meta : {
|
||||
System : {
|
||||
[ Message.SystemMetaNames.RemoteToUser ] : ftnAddr.toString(), // where to send it
|
||||
[ Message.SystemMetaNames.ExternalFlavor ] : Message.AddressFlavor.FTN, // on FTN-style network
|
||||
}
|
||||
}
|
||||
});
|
||||
const message = new Message({
|
||||
toUserName : argv.to || 'AreaFix',
|
||||
fromUserName : fromName,
|
||||
subject : argv.password || '',
|
||||
message : messageBody,
|
||||
areaTag : Message.WellKnownAreaTags.Private, // mark private
|
||||
meta : {
|
||||
System : {
|
||||
[ Message.SystemMetaNames.RemoteToUser ] : ftnAddr.toString(), // where to send it
|
||||
[ Message.SystemMetaNames.ExternalFlavor ] : Message.AddressFlavor.FTN, // on FTN-style network
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(0 !== fromUserId) {
|
||||
message.setLocalFromUserId(fromUserId);
|
||||
}
|
||||
if(0 !== fromUserId) {
|
||||
message.setLocalFromUserId(fromUserId);
|
||||
}
|
||||
|
||||
return callback(null, message);
|
||||
},
|
||||
function persistMessage(message, callback) {
|
||||
message.persist(err => {
|
||||
if(!err) {
|
||||
console.log('AreaFix message persisted and will be exported at next scheduled scan');
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
console.error(`${err.message}${err.reason ? ': ' + err.reason : ''}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
return callback(null, message);
|
||||
},
|
||||
function persistMessage(message, callback) {
|
||||
message.persist(err => {
|
||||
if(!err) {
|
||||
console.log('AreaFix message persisted and will be exported at next scheduled scan');
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
console.error(`${err.message}${err.reason ? ': ' + err.reason : ''}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function handleMessageBaseCommand() {
|
||||
|
||||
function errUsage() {
|
||||
return printUsageAndSetExitCode(
|
||||
getHelpFor('MessageBase'),
|
||||
ExitCodes.ERROR
|
||||
);
|
||||
}
|
||||
function errUsage() {
|
||||
return printUsageAndSetExitCode(
|
||||
getHelpFor('MessageBase'),
|
||||
ExitCodes.ERROR
|
||||
);
|
||||
}
|
||||
|
||||
if(true === argv.help) {
|
||||
return errUsage();
|
||||
}
|
||||
if(true === argv.help) {
|
||||
return errUsage();
|
||||
}
|
||||
|
||||
const action = argv._[1];
|
||||
const action = argv._[1];
|
||||
|
||||
return({
|
||||
areafix : areaFix,
|
||||
}[action] || errUsage)();
|
||||
return({
|
||||
areafix : areaFix,
|
||||
}[action] || errUsage)();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue