mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-06 01:35: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
|
@ -16,83 +16,83 @@ exports.getAreaAndStorage = getAreaAndStorage;
|
|||
exports.looksLikePattern = looksLikePattern;
|
||||
|
||||
const exitCodes = exports.ExitCodes = {
|
||||
SUCCESS : 0,
|
||||
ERROR : -1,
|
||||
BAD_COMMAND : -2,
|
||||
BAD_ARGS : -3,
|
||||
SUCCESS : 0,
|
||||
ERROR : -1,
|
||||
BAD_COMMAND : -2,
|
||||
BAD_ARGS : -3,
|
||||
};
|
||||
|
||||
const argv = exports.argv = require('minimist')(process.argv.slice(2), {
|
||||
alias : {
|
||||
h : 'help',
|
||||
v : 'version',
|
||||
c : 'config',
|
||||
n : 'no-prompt',
|
||||
}
|
||||
alias : {
|
||||
h : 'help',
|
||||
v : 'version',
|
||||
c : 'config',
|
||||
n : 'no-prompt',
|
||||
}
|
||||
});
|
||||
|
||||
function printUsageAndSetExitCode(errMsg, exitCode) {
|
||||
if(_.isUndefined(exitCode)) {
|
||||
exitCode = exitCodes.ERROR;
|
||||
}
|
||||
if(_.isUndefined(exitCode)) {
|
||||
exitCode = exitCodes.ERROR;
|
||||
}
|
||||
|
||||
process.exitCode = exitCode;
|
||||
process.exitCode = exitCode;
|
||||
|
||||
if(errMsg) {
|
||||
console.error(errMsg);
|
||||
}
|
||||
if(errMsg) {
|
||||
console.error(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaultConfigPath() {
|
||||
return './config/';
|
||||
return './config/';
|
||||
}
|
||||
|
||||
function getConfigPath() {
|
||||
const baseConfigPath = argv.config ? argv.config : config.getDefaultPath();
|
||||
return baseConfigPath + 'config.hjson';
|
||||
const baseConfigPath = argv.config ? argv.config : config.getDefaultPath();
|
||||
return baseConfigPath + 'config.hjson';
|
||||
}
|
||||
|
||||
function initConfig(cb) {
|
||||
const configPath = getConfigPath();
|
||||
const configPath = getConfigPath();
|
||||
|
||||
config.init(configPath, { keepWsc : true, noWatch : true }, cb);
|
||||
config.init(configPath, { keepWsc : true, noWatch : true }, cb);
|
||||
}
|
||||
|
||||
function initConfigAndDatabases(cb) {
|
||||
async.series(
|
||||
[
|
||||
function init(callback) {
|
||||
initConfig(callback);
|
||||
},
|
||||
function initDb(callback) {
|
||||
db.initializeDatabases(callback);
|
||||
},
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
async.series(
|
||||
[
|
||||
function init(callback) {
|
||||
initConfig(callback);
|
||||
},
|
||||
function initDb(callback) {
|
||||
db.initializeDatabases(callback);
|
||||
},
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function getAreaAndStorage(tags) {
|
||||
return tags.map(tag => {
|
||||
const parts = tag.toString().split('@');
|
||||
const entry = {
|
||||
areaTag : parts[0],
|
||||
};
|
||||
entry.pattern = entry.areaTag; // handy
|
||||
if(parts[1]) {
|
||||
entry.storageTag = parts[1];
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
return tags.map(tag => {
|
||||
const parts = tag.toString().split('@');
|
||||
const entry = {
|
||||
areaTag : parts[0],
|
||||
};
|
||||
entry.pattern = entry.areaTag; // handy
|
||||
if(parts[1]) {
|
||||
entry.storageTag = parts[1];
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
|
||||
function looksLikePattern(tag) {
|
||||
// globs can start with @
|
||||
if(tag.indexOf('@') > 0) {
|
||||
return false;
|
||||
}
|
||||
// globs can start with @
|
||||
if(tag.indexOf('@') > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /[*?[\]!()+|^]/.test(tag);
|
||||
return /[*?[\]!()+|^]/.test(tag);
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@ const getDefaultConfigPath = require('./oputil_common.js').getDefaultConfigPat
|
|||
exports.getHelpFor = getHelpFor;
|
||||
|
||||
const usageHelp = exports.USAGE_HELP = {
|
||||
General :
|
||||
General :
|
||||
`usage: optutil.js [--version] [--help]
|
||||
<command> [<args>]
|
||||
|
||||
|
@ -21,7 +21,7 @@ commands:
|
|||
fb file base management
|
||||
mb message base management
|
||||
`,
|
||||
User :
|
||||
User :
|
||||
`usage: optutil.js user <action> [<args>]
|
||||
|
||||
actions:
|
||||
|
@ -33,7 +33,7 @@ actions:
|
|||
group USERNAME [+|-]GROUP adds (+) or removes (-) user from GROUP
|
||||
`,
|
||||
|
||||
Config :
|
||||
Config :
|
||||
`usage: optutil.js config <action> [<args>]
|
||||
|
||||
actions:
|
||||
|
@ -46,7 +46,7 @@ import-areas args:
|
|||
--uplinks UL1,UL2,... specify one or more comma separated uplinks
|
||||
--type TYPE specifies area import type. valid options are "bbs" and "na"
|
||||
`,
|
||||
FileBase :
|
||||
FileBase :
|
||||
`usage: oputil.js fb <action> [<args>]
|
||||
|
||||
actions:
|
||||
|
@ -80,7 +80,7 @@ info args:
|
|||
remove args:
|
||||
--phys-file also remove underlying physical file
|
||||
`,
|
||||
FileOpsInfo :
|
||||
FileOpsInfo :
|
||||
`
|
||||
general information:
|
||||
AREA_TAG[@STORAGE_TAG] can specify an area tag and optionally, a storage specific tag
|
||||
|
@ -90,7 +90,7 @@ general information:
|
|||
SHA full or partial SHA-256
|
||||
FILE_ID a file identifier. see file.sqlite3
|
||||
`,
|
||||
MessageBase :
|
||||
MessageBase :
|
||||
`usage: oputil.js mb <action> [<args>]
|
||||
|
||||
actions:
|
||||
|
@ -101,5 +101,5 @@ general information:
|
|||
};
|
||||
|
||||
function getHelpFor(command) {
|
||||
return usageHelp[command];
|
||||
return usageHelp[command];
|
||||
}
|
||||
|
|
|
@ -14,23 +14,23 @@ const getHelpFor = require('./oputil_help.js').getHelpFor;
|
|||
|
||||
module.exports = function() {
|
||||
|
||||
process.exitCode = ExitCodes.SUCCESS;
|
||||
process.exitCode = ExitCodes.SUCCESS;
|
||||
|
||||
if(true === argv.version) {
|
||||
return console.info(require('../package.json').version);
|
||||
}
|
||||
if(true === argv.version) {
|
||||
return console.info(require('../package.json').version);
|
||||
}
|
||||
|
||||
if(0 === argv._.length ||
|
||||
if(0 === argv._.length ||
|
||||
'help' === argv._[0])
|
||||
{
|
||||
return printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.SUCCESS);
|
||||
}
|
||||
{
|
||||
return printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.SUCCESS);
|
||||
}
|
||||
|
||||
switch(argv._[0]) {
|
||||
case 'user' : return handleUserCommand();
|
||||
case 'config' : return handleConfigCommand();
|
||||
case 'fb' : return handleFileBaseCommand();
|
||||
case 'mb' : return handleMessageBaseCommand();
|
||||
default : return printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.BAD_COMMAND);
|
||||
}
|
||||
switch(argv._[0]) {
|
||||
case 'user' : return handleUserCommand();
|
||||
case 'config' : return handleConfigCommand();
|
||||
case 'fb' : return handleFileBaseCommand();
|
||||
case 'mb' : return handleMessageBaseCommand();
|
||||
default : return printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.BAD_COMMAND);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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)();
|
||||
}
|
|
@ -15,191 +15,191 @@ const _ = require('lodash');
|
|||
exports.handleUserCommand = handleUserCommand;
|
||||
|
||||
function getUser(userName, cb) {
|
||||
const User = require('../../core/user.js');
|
||||
User.getUserIdAndName(userName, (err, userId) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return cb(err);
|
||||
}
|
||||
const u = new User();
|
||||
u.userId = userId;
|
||||
return cb(null, u);
|
||||
});
|
||||
const User = require('../../core/user.js');
|
||||
User.getUserIdAndName(userName, (err, userId) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return cb(err);
|
||||
}
|
||||
const u = new User();
|
||||
u.userId = userId;
|
||||
return cb(null, u);
|
||||
});
|
||||
}
|
||||
|
||||
function initAndGetUser(userName, cb) {
|
||||
async.waterfall(
|
||||
[
|
||||
function init(callback) {
|
||||
initConfigAndDatabases(callback);
|
||||
},
|
||||
function getUserObject(callback) {
|
||||
getUser(userName, (err, user) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, user);
|
||||
});
|
||||
}
|
||||
],
|
||||
(err, user) => {
|
||||
return cb(err, user);
|
||||
}
|
||||
);
|
||||
async.waterfall(
|
||||
[
|
||||
function init(callback) {
|
||||
initConfigAndDatabases(callback);
|
||||
},
|
||||
function getUserObject(callback) {
|
||||
getUser(userName, (err, user) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, user);
|
||||
});
|
||||
}
|
||||
],
|
||||
(err, user) => {
|
||||
return cb(err, user);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function setAccountStatus(user, status) {
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
const statusDesc = _.invert(AccountStatus)[status];
|
||||
user.persistProperty('account_status', status, err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info(`User status set to ${statusDesc}`);
|
||||
}
|
||||
});
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
const statusDesc = _.invert(AccountStatus)[status];
|
||||
user.persistProperty('account_status', status, err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info(`User status set to ${statusDesc}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setUserPassword(user) {
|
||||
if(argv._.length < 4) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
if(argv._.length < 4) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function validate(callback) {
|
||||
// :TODO: prompt if no password provided (more secure, no history, etc.)
|
||||
const password = argv._[argv._.length - 1];
|
||||
if(0 === password.length) {
|
||||
return callback(Errors.Invalid('Invalid password'));
|
||||
}
|
||||
return callback(null, password);
|
||||
},
|
||||
function set(password, callback) {
|
||||
user.setNewAuthCredentials(password, err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info('New password set');
|
||||
}
|
||||
}
|
||||
);
|
||||
async.waterfall(
|
||||
[
|
||||
function validate(callback) {
|
||||
// :TODO: prompt if no password provided (more secure, no history, etc.)
|
||||
const password = argv._[argv._.length - 1];
|
||||
if(0 === password.length) {
|
||||
return callback(Errors.Invalid('Invalid password'));
|
||||
}
|
||||
return callback(null, password);
|
||||
},
|
||||
function set(password, callback) {
|
||||
user.setNewAuthCredentials(password, err => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
}
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info('New password set');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function removeUser(user) {
|
||||
console.error('NOT YET IMPLEMENTED');
|
||||
function removeUser() {
|
||||
console.error('NOT YET IMPLEMENTED');
|
||||
}
|
||||
|
||||
function modUserGroups(user) {
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
if(argv._.length < 3) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
|
||||
let groupName = argv._[argv._.length - 1].toString().replace(/["']/g, ''); // remove any quotes - necessary to allow "-foo"
|
||||
let action = groupName[0]; // + or -
|
||||
let groupName = argv._[argv._.length - 1].toString().replace(/["']/g, ''); // remove any quotes - necessary to allow "-foo"
|
||||
let action = groupName[0]; // + or -
|
||||
|
||||
if('-' === action || '+' === action) {
|
||||
groupName = groupName.substr(1);
|
||||
}
|
||||
if('-' === action || '+' === action) {
|
||||
groupName = groupName.substr(1);
|
||||
}
|
||||
|
||||
action = action || '+';
|
||||
action = action || '+';
|
||||
|
||||
if(0 === groupName.length) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
if(0 === groupName.length) {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// Groups are currently arbritary, so do a slight validation
|
||||
//
|
||||
if(!/[A-Za-z0-9]+/.test(groupName)) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return console.error('Bad group name');
|
||||
}
|
||||
//
|
||||
// Groups are currently arbritary, so do a slight validation
|
||||
//
|
||||
if(!/[A-Za-z0-9]+/.test(groupName)) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
return console.error('Bad group name');
|
||||
}
|
||||
|
||||
function done(err) {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info('User groups modified');
|
||||
}
|
||||
}
|
||||
function done(err) {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.BAD_ARGS;
|
||||
console.error(err.message);
|
||||
} else {
|
||||
console.info('User groups modified');
|
||||
}
|
||||
}
|
||||
|
||||
const UserGroup = require('../../core/user_group.js');
|
||||
if('-' === action) {
|
||||
UserGroup.removeUserFromGroup(user.userId, groupName, done);
|
||||
} else {
|
||||
UserGroup.addUserToGroup(user.userId, groupName, done);
|
||||
}
|
||||
const UserGroup = require('../../core/user_group.js');
|
||||
if('-' === action) {
|
||||
UserGroup.removeUserFromGroup(user.userId, groupName, done);
|
||||
} else {
|
||||
UserGroup.addUserToGroup(user.userId, groupName, done);
|
||||
}
|
||||
}
|
||||
|
||||
function activateUser(user) {
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.active);
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.active);
|
||||
}
|
||||
|
||||
function deactivateUser(user) {
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.inactive);
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.inactive);
|
||||
}
|
||||
|
||||
function disableUser(user) {
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.disabled);
|
||||
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||
return setAccountStatus(user, AccountStatus.disabled);
|
||||
}
|
||||
|
||||
function handleUserCommand() {
|
||||
function errUsage() {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
function errUsage() {
|
||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||
}
|
||||
|
||||
if(true === argv.help) {
|
||||
return errUsage();
|
||||
}
|
||||
if(true === argv.help) {
|
||||
return errUsage();
|
||||
}
|
||||
|
||||
const action = argv._[1];
|
||||
const usernameIdx = [ 'pass', 'passwd', 'password', 'group' ].includes(action) ? argv._.length - 2 : argv._.length - 1;
|
||||
const userName = argv._[usernameIdx];
|
||||
const action = argv._[1];
|
||||
const usernameIdx = [ 'pass', 'passwd', 'password', 'group' ].includes(action) ? argv._.length - 2 : argv._.length - 1;
|
||||
const userName = argv._[usernameIdx];
|
||||
|
||||
if(!userName) {
|
||||
return errUsage();
|
||||
}
|
||||
if(!userName) {
|
||||
return errUsage();
|
||||
}
|
||||
|
||||
initAndGetUser(userName, (err, user) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
return console.error(err.message);
|
||||
}
|
||||
initAndGetUser(userName, (err, user) => {
|
||||
if(err) {
|
||||
process.exitCode = ExitCodes.ERROR;
|
||||
return console.error(err.message);
|
||||
}
|
||||
|
||||
return ({
|
||||
pass : setUserPassword,
|
||||
passwd : setUserPassword,
|
||||
password : setUserPassword,
|
||||
return ({
|
||||
pass : setUserPassword,
|
||||
passwd : setUserPassword,
|
||||
password : setUserPassword,
|
||||
|
||||
rm : removeUser,
|
||||
remove : removeUser,
|
||||
del : removeUser,
|
||||
delete : removeUser,
|
||||
rm : removeUser,
|
||||
remove : removeUser,
|
||||
del : removeUser,
|
||||
delete : removeUser,
|
||||
|
||||
activate : activateUser,
|
||||
deactivate : deactivateUser,
|
||||
disable : disableUser,
|
||||
activate : activateUser,
|
||||
deactivate : deactivateUser,
|
||||
disable : disableUser,
|
||||
|
||||
group : modUserGroups,
|
||||
}[action] || errUsage)(user);
|
||||
});
|
||||
group : modUserGroups,
|
||||
}[action] || errUsage)(user);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue