Merge branch 'master' of ssh://numinibsd/git/base/enigma-bbs
This commit is contained in:
commit
b427e79876
|
@ -196,19 +196,18 @@ function initialize(cb) {
|
||||||
// * We do this every time as the op is free to change this information just
|
// * We do this every time as the op is free to change this information just
|
||||||
// like any other user
|
// like any other user
|
||||||
//
|
//
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
function getOpUserName(next) {
|
function getOpUserName(next) {
|
||||||
return user.getUserName(1, next);
|
return User.getUserName(1, next);
|
||||||
},
|
},
|
||||||
function getOpProps(opUserName, next) {
|
function getOpProps(opUserName, next) {
|
||||||
const propLoadOpts = {
|
const propLoadOpts = {
|
||||||
userId : 1,
|
|
||||||
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
||||||
};
|
};
|
||||||
user.loadProperties(propLoadOpts, (err, opProps) => {
|
User.loadProperties(User.RootUserID, propLoadOpts, (err, opProps) => {
|
||||||
return next(err, opUserName, opProps);
|
return next(err, opUserName, opProps);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const term = require('./client_term.js');
|
const term = require('./client_term.js');
|
||||||
const ansi = require('./ansi_term.js');
|
const ansi = require('./ansi_term.js');
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
const Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
const MenuStack = require('./menu_stack.js');
|
const MenuStack = require('./menu_stack.js');
|
||||||
const ACS = require('./acs.js');
|
const ACS = require('./acs.js');
|
||||||
|
@ -77,7 +77,7 @@ function Client(input, output) {
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.user = new user.User();
|
this.user = new User();
|
||||||
this.currentTheme = { info : { name : 'N/A', description : 'None' } };
|
this.currentTheme = { info : { name : 'N/A', description : 'None' } };
|
||||||
this.lastKeyPressMs = Date.now();
|
this.lastKeyPressMs = Date.now();
|
||||||
this.menuStack = new MenuStack(this);
|
this.menuStack = new MenuStack(this);
|
||||||
|
@ -457,10 +457,6 @@ Client.prototype.waitForKeyPress = function(cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.address = function() {
|
|
||||||
return this.input.address();
|
|
||||||
};
|
|
||||||
|
|
||||||
Client.prototype.isLocal = function() {
|
Client.prototype.isLocal = function() {
|
||||||
// :TODO: return rather client is a local connection or not
|
// :TODO: return rather client is a local connection or not
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -57,13 +57,14 @@ function getActiveNodeList(authUsersOnly) {
|
||||||
|
|
||||||
function addNewClient(client, clientSock) {
|
function addNewClient(client, clientSock) {
|
||||||
const id = client.session.id = clientConnections.push(client) - 1;
|
const id = client.session.id = clientConnections.push(client) - 1;
|
||||||
|
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
||||||
|
|
||||||
// Create a client specific logger
|
// Create a client specific logger
|
||||||
// Note that this will be updated @ login with additional information
|
// Note that this will be updated @ login with additional information
|
||||||
client.log = logger.log.child( { clientId : id } );
|
client.log = logger.log.child( { clientId : id } );
|
||||||
|
|
||||||
const connInfo = {
|
const connInfo = {
|
||||||
ip : clientSock.remoteAddress,
|
remoteAddress : remoteAddress,
|
||||||
serverName : client.session.serverName,
|
serverName : client.session.serverName,
|
||||||
isSecure : client.session.isSecure,
|
isSecure : client.session.isSecure,
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,4 +37,5 @@ exports.ErrorReasons = {
|
||||||
InvalidNextMenu : 'BADNEXT',
|
InvalidNextMenu : 'BADNEXT',
|
||||||
NoPreviousMenu : 'NOPREV',
|
NoPreviousMenu : 'NOPREV',
|
||||||
NoConditionMatch : 'NOCONDMATCH',
|
NoConditionMatch : 'NOCONDMATCH',
|
||||||
|
NotEnabled : 'NOTENABLED',
|
||||||
};
|
};
|
|
@ -8,6 +8,11 @@ const getISOTimestampString = require('./database.js').getISOTimestampString;
|
||||||
const FileEntry = require('./file_entry.js');
|
const FileEntry = require('./file_entry.js');
|
||||||
const getServer = require('./listening_server.js').getServer;
|
const getServer = require('./listening_server.js').getServer;
|
||||||
const Errors = require('./enig_error.js').Errors;
|
const Errors = require('./enig_error.js').Errors;
|
||||||
|
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||||
|
const StatLog = require('./stat_log.js');
|
||||||
|
const User = require('./user.js');
|
||||||
|
const Log = require('./logger.js').log;
|
||||||
|
const getConnectionByUserId = require('./client_connections.js').getConnectionByUserId;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const hashids = require('hashids');
|
const hashids = require('hashids');
|
||||||
|
@ -27,6 +32,10 @@ const WEB_SERVER_PACKAGE_NAME = 'codes.l33t.enigma.web.server';
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function notEnabledError() {
|
||||||
|
return Errors.General('Web server is not enabled', ErrNotEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
class FileAreaWebAccess {
|
class FileAreaWebAccess {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.hashids = new hashids(Config.general.boardName);
|
this.hashids = new hashids(Config.general.boardName);
|
||||||
|
@ -47,13 +56,16 @@ class FileAreaWebAccess {
|
||||||
return callback(Errors.DoesNotExist(`Server with package name "${WEB_SERVER_PACKAGE_NAME}" does not exist`));
|
return callback(Errors.DoesNotExist(`Server with package name "${WEB_SERVER_PACKAGE_NAME}" does not exist`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(self.isEnabled()) {
|
||||||
const routeAdded = self.webServer.instance.addRoute({
|
const routeAdded = self.webServer.instance.addRoute({
|
||||||
method : 'GET',
|
method : 'GET',
|
||||||
path : Config.fileBase.web.routePath,
|
path : Config.fileBase.web.routePath,
|
||||||
handler : self.routeWebRequestForFile.bind(self),
|
handler : self.routeWebRequestForFile.bind(self),
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
||||||
|
} else {
|
||||||
|
return callback(null); // not enabled, but no error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
err => {
|
err => {
|
||||||
|
@ -66,6 +78,10 @@ class FileAreaWebAccess {
|
||||||
return cb(null);
|
return cb(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return this.webServer.instance.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
load(cb) {
|
load(cb) {
|
||||||
//
|
//
|
||||||
// Load entries, register expiration timers
|
// Load entries, register expiration timers
|
||||||
|
@ -187,6 +203,10 @@ class FileAreaWebAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
||||||
|
if(!this.isEnabled()) {
|
||||||
|
return cb(notEnabledError());
|
||||||
|
}
|
||||||
|
|
||||||
const hashId = this.getHashId(client, fileEntry);
|
const hashId = this.getHashId(client, fileEntry);
|
||||||
this.loadServedHashId(hashId, (err, servedItem) => {
|
this.loadServedHashId(hashId, (err, servedItem) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
@ -200,6 +220,10 @@ class FileAreaWebAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
createAndServeTempDownload(client, fileEntry, options, cb) {
|
createAndServeTempDownload(client, fileEntry, options, cb) {
|
||||||
|
if(!this.isEnabled()) {
|
||||||
|
return cb(notEnabledError());
|
||||||
|
}
|
||||||
|
|
||||||
const hashId = this.getHashId(client, fileEntry);
|
const hashId = this.getHashId(client, fileEntry);
|
||||||
const url = this.buildTempDownloadLink(client, fileEntry, hashId);
|
const url = this.buildTempDownloadLink(client, fileEntry, hashId);
|
||||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||||
|
@ -257,7 +281,7 @@ class FileAreaWebAccess {
|
||||||
|
|
||||||
resp.on('finish', () => {
|
resp.on('finish', () => {
|
||||||
// transfer completed fully
|
// transfer completed fully
|
||||||
// :TODO: we need to update the users stats - bytes xferred, credit stuff, etc.
|
this.updateDownloadStatsForUserId(servedItem.userId, stats.size);
|
||||||
});
|
});
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
@ -273,6 +297,37 @@ class FileAreaWebAccess {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDownloadStatsForUserId(userId, dlBytes, cb) {
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function fetchActiveUser(callback) {
|
||||||
|
const clientForUserId = getConnectionByUserId(userId);
|
||||||
|
if(clientForUserId) {
|
||||||
|
return callback(null, clientForUserId.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// not online now - look 'em up
|
||||||
|
User.getUser(userId, (err, assocUser) => {
|
||||||
|
return callback(err, assocUser);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function updateStats(user, callback) {
|
||||||
|
StatLog.incrementUserStat(user, 'dl_total_count', 1);
|
||||||
|
StatLog.incrementUserStat(user, 'dl_total_bytes', dlBytes);
|
||||||
|
StatLog.incrementSystemStat('dl_total_count', 1);
|
||||||
|
StatLog.incrementSystemStat('dl_total_bytes', dlBytes);
|
||||||
|
|
||||||
|
return callback(null);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if(cb) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new FileAreaWebAccess();
|
module.exports = new FileAreaWebAccess();
|
|
@ -23,6 +23,7 @@ const iconv = require('iconv-lite');
|
||||||
exports.isInternalArea = isInternalArea;
|
exports.isInternalArea = isInternalArea;
|
||||||
exports.getAvailableFileAreas = getAvailableFileAreas;
|
exports.getAvailableFileAreas = getAvailableFileAreas;
|
||||||
exports.getSortedAvailableFileAreas = getSortedAvailableFileAreas;
|
exports.getSortedAvailableFileAreas = getSortedAvailableFileAreas;
|
||||||
|
exports.getAreaStorageDirectoryByTag = getAreaStorageDirectoryByTag;
|
||||||
exports.getAreaDefaultStorageDirectory = getAreaDefaultStorageDirectory;
|
exports.getAreaDefaultStorageDirectory = getAreaDefaultStorageDirectory;
|
||||||
exports.getAreaStorageLocations = getAreaStorageLocations;
|
exports.getAreaStorageLocations = getAreaStorageLocations;
|
||||||
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
|
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
|
||||||
|
|
|
@ -289,8 +289,37 @@ module.exports = class FileEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// :TODO: Use static get accessor:
|
||||||
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
|
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
|
||||||
|
|
||||||
|
static findFileBySha(sha, cb) {
|
||||||
|
// full or partial SHA-256
|
||||||
|
fileDb.all(
|
||||||
|
`SELECT file_id
|
||||||
|
FROM file
|
||||||
|
WHERE file_sha256 LIKE "${sha}%"
|
||||||
|
LIMIT 2;`, // limit 2 such that we can find if there are dupes
|
||||||
|
(err, fileIdRows) => {
|
||||||
|
if(err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!fileIdRows || 0 === fileIdRows.length) {
|
||||||
|
return cb(Errors.DoesNotExist('No matches'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fileIdRows.length > 1) {
|
||||||
|
return cb(Errors.Invalid('SHA is ambiguous'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileEntry = new FileEntry();
|
||||||
|
return fileEntry.load(fileIdRows[0].file_id, err => {
|
||||||
|
return cb(err, fileEntry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static findFiles(filter, cb) {
|
static findFiles(filter, cb) {
|
||||||
filter = filter || {};
|
filter = filter || {};
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ const theme = require('./theme.js');
|
||||||
const Message = require('./message.js');
|
const Message = require('./message.js');
|
||||||
const updateMessageAreaLastReadId = require('./message_area.js').updateMessageAreaLastReadId;
|
const updateMessageAreaLastReadId = require('./message_area.js').updateMessageAreaLastReadId;
|
||||||
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
||||||
const getUserIdAndName = require('./user.js').getUserIdAndName;
|
const User = require('./user.js');
|
||||||
const cleanControlCodes = require('./string_util.js').cleanControlCodes;
|
const cleanControlCodes = require('./string_util.js').cleanControlCodes;
|
||||||
const StatLog = require('./stat_log.js');
|
const StatLog = require('./stat_log.js');
|
||||||
const stringFormat = require('./string_format.js');
|
const stringFormat = require('./string_format.js');
|
||||||
|
@ -373,7 +373,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
||||||
callback(null);
|
callback(null);
|
||||||
} else {
|
} else {
|
||||||
// we need to look it up
|
// we need to look it up
|
||||||
getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) {
|
User.getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) {
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -64,7 +64,7 @@ function initConfigAndDatabases(cb) {
|
||||||
|
|
||||||
function getAreaAndStorage(tags) {
|
function getAreaAndStorage(tags) {
|
||||||
return tags.map(tag => {
|
return tags.map(tag => {
|
||||||
const parts = tag.split('@');
|
const parts = tag.toString().split('@');
|
||||||
const entry = {
|
const entry = {
|
||||||
areaTag : parts[0],
|
areaTag : parts[0],
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,11 +8,13 @@ const argv = require('./oputil_common.js').argv;
|
||||||
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
||||||
const getHelpFor = require('./oputil_help.js').getHelpFor;
|
const getHelpFor = require('./oputil_help.js').getHelpFor;
|
||||||
const getAreaAndStorage = require('./oputil_common.js').getAreaAndStorage;
|
const getAreaAndStorage = require('./oputil_common.js').getAreaAndStorage;
|
||||||
|
const Errors = require('../../core/enig_error.js').Errors;
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
exports.handleFileBaseCommand = handleFileBaseCommand;
|
exports.handleFileBaseCommand = handleFileBaseCommand;
|
||||||
|
|
||||||
|
@ -119,6 +121,140 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dumpAreaInfo(areaInfo, areaAndStorageInfo, cb) {
|
||||||
|
console.info(`areaTag: ${areaInfo.areaTag}`);
|
||||||
|
console.info(`name: ${areaInfo.name}`);
|
||||||
|
console.info(`desc: ${areaInfo.desc}`);
|
||||||
|
|
||||||
|
areaInfo.storage.forEach(si => {
|
||||||
|
console.info(`storageTag: ${si.storageTag} => ${si.dir}`);
|
||||||
|
});
|
||||||
|
console.info('');
|
||||||
|
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dumpFileInfo(shaOrFileId, cb) {
|
||||||
|
const FileEntry = require('../../core/file_entry.js');
|
||||||
|
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function getBySha(callback) {
|
||||||
|
FileEntry.findFileBySha(shaOrFileId, (err, fileEntry) => {
|
||||||
|
return callback(null, fileEntry);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function getByFileId(fileEntry, callback) {
|
||||||
|
if(fileEntry) {
|
||||||
|
return callback(null, fileEntry); // already got it by sha
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileId = parseInt(shaOrFileId);
|
||||||
|
if(isNaN(fileId)) {
|
||||||
|
return callback(Errors.DoesNotExist('Not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
fileEntry = new FileEntry();
|
||||||
|
fileEntry.load(shaOrFileId, err => {
|
||||||
|
return callback(err, fileEntry);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function dumpInfo(fileEntry, callback) {
|
||||||
|
const fullPath = paths.join(fileArea.getAreaStorageDirectoryByTag(fileEntry.storageTag), fileEntry.fileName);
|
||||||
|
|
||||||
|
console.info(`file_id: ${fileEntry.fileId}`);
|
||||||
|
console.info(`sha_256: ${fileEntry.fileSha256}`);
|
||||||
|
console.info(`area_tag: ${fileEntry.areaTag}`);
|
||||||
|
console.info(`path: ${fullPath}`);
|
||||||
|
console.info(`hashTags: ${Array.from(fileEntry.hashTags).join(', ')}`);
|
||||||
|
console.info(`uploaded: ${moment(fileEntry.uploadTimestamp).format()}`);
|
||||||
|
|
||||||
|
_.each(fileEntry.meta, (metaValue, metaName) => {
|
||||||
|
console.info(`${metaName}: ${metaValue}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(argv['show-desc']) {
|
||||||
|
console.info(`${fileEntry.desc}`);
|
||||||
|
}
|
||||||
|
console.info('');
|
||||||
|
|
||||||
|
return callback(null);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
/*
|
||||||
|
FileEntry.findFileBySha(sha, (err, fileEntry) => {
|
||||||
|
if(err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullPath = paths.join(fileArea.getAreaStorageDirectoryByTag(fileEntry.storageTag), fileEntry.fileName);
|
||||||
|
|
||||||
|
console.info(`file_id: ${fileEntry.fileId}`);
|
||||||
|
console.info(`sha_256: ${fileEntry.fileSha256}`);
|
||||||
|
console.info(`area_tag: ${fileEntry.areaTag}`);
|
||||||
|
console.info(`path: ${fullPath}`);
|
||||||
|
console.info(`hashTags: ${Array.from(fileEntry.hashTags).join(', ')}`);
|
||||||
|
console.info(`uploaded: ${moment(fileEntry.uploadTimestamp).format()}`);
|
||||||
|
|
||||||
|
_.each(fileEntry.meta, (metaValue, metaName) => {
|
||||||
|
console.info(`${metaName}: ${metaValue}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(argv['show-desc']) {
|
||||||
|
console.info(`${fileEntry.desc}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayFileAreaInfo() {
|
||||||
|
// AREA_TAG[@STORAGE_TAG]
|
||||||
|
// SHA256|PARTIAL
|
||||||
|
// if sha: dump file info
|
||||||
|
// if area/stoarge dump area(s) +
|
||||||
|
|
||||||
|
async.series(
|
||||||
|
[
|
||||||
|
function init(callback) {
|
||||||
|
return initConfigAndDatabases(callback);
|
||||||
|
},
|
||||||
|
function dumpInfo(callback) {
|
||||||
|
const Config = require('../../core/config.js').config;
|
||||||
|
let suppliedAreas = argv._.slice(2);
|
||||||
|
if(!suppliedAreas || 0 === suppliedAreas.length) {
|
||||||
|
suppliedAreas = _.map(Config.fileBase.areas, (areaInfo, areaTag) => areaTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
const areaAndStorageInfo = getAreaAndStorage(suppliedAreas);
|
||||||
|
|
||||||
|
fileArea = require('../../core/file_base_area.js');
|
||||||
|
|
||||||
|
async.eachSeries(areaAndStorageInfo, (areaAndStorage, nextArea) => {
|
||||||
|
const areaInfo = fileArea.getFileAreaByTag(areaAndStorage.areaTag);
|
||||||
|
if(areaInfo) {
|
||||||
|
return dumpAreaInfo(areaInfo, areaAndStorageInfo, nextArea);
|
||||||
|
} else {
|
||||||
|
return dumpFileInfo(areaAndStorage.areaTag, nextArea);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
return callback(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if(err) {
|
||||||
|
process.exitCode = ExitCodes.ERROR;
|
||||||
|
console.error(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function scanFileAreas() {
|
function scanFileAreas() {
|
||||||
const options = {};
|
const options = {};
|
||||||
|
|
||||||
|
@ -170,6 +306,7 @@ function handleFileBaseCommand() {
|
||||||
const action = argv._[1];
|
const action = argv._[1];
|
||||||
|
|
||||||
switch(action) {
|
switch(action) {
|
||||||
|
case 'info' : return displayFileAreaInfo();
|
||||||
case 'scan' : return scanFileAreas();
|
case 'scan' : return scanFileAreas();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,6 @@ global args:
|
||||||
where <command> is one of:
|
where <command> is one of:
|
||||||
user : user utilities
|
user : user utilities
|
||||||
config : config file management
|
config : config file management
|
||||||
file-base
|
|
||||||
fb : file base management
|
fb : file base management
|
||||||
|
|
||||||
`,
|
`,
|
||||||
|
@ -39,14 +38,22 @@ valid args:
|
||||||
--new : generate a new/initial configuration
|
--new : generate a new/initial configuration
|
||||||
`,
|
`,
|
||||||
FileBase :
|
FileBase :
|
||||||
`usage: oputil.js file-base <action> [<args>] [<action_specific>]
|
`usage: oputil.js fb <action> [<args>] <AREA_TAG|SHA|FILE_ID[@STORAGE_TAG] ...> [<args>]
|
||||||
|
|
||||||
where <action> is one of:
|
where <action> is one of:
|
||||||
scan <args> AREA_TAG : (re)scan area specified by AREA_TAG for new files
|
scan AREA_TAG|SHA|FILE_ID : scan specified areas
|
||||||
multiple area tags can be specified in form of AREA_TAG1 AREA_TAG2 ...
|
AREA_TAG may be suffixed with @STORAGE_TAG; for example: retro@bbs
|
||||||
|
|
||||||
|
info AREA_TAG|FILE_ID|SHA : display information about areas and/or files
|
||||||
|
SHA may be a full or partial SHA-256
|
||||||
|
|
||||||
valid scan <args>:
|
valid scan <args>:
|
||||||
--tags TAG1,TAG2,... : specify tag(s) to assign to discovered entries
|
--tags TAG1,TAG2,... : specify tag(s) to assign to discovered entries
|
||||||
|
|
||||||
|
valid info <args>:
|
||||||
|
--show-desc : display short description, if any
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ module.exports = function() {
|
||||||
handleConfigCommand();
|
handleConfigCommand();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'file-base' :
|
|
||||||
case 'fb' :
|
case 'fb' :
|
||||||
handleFileBaseCommand();
|
handleFileBaseCommand();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,8 +7,8 @@ const ExitCodes = require('./oputil_common.js').ExitCodes;
|
||||||
const argv = require('./oputil_common.js').argv;
|
const argv = require('./oputil_common.js').argv;
|
||||||
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
||||||
|
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
exports.handleUserCommand = handleUserCommand;
|
exports.handleUserCommand = handleUserCommand;
|
||||||
|
|
||||||
|
@ -55,13 +55,13 @@ function handleUserCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUser(userName, cb) {
|
function getUser(userName, cb) {
|
||||||
const user = require('./core/user.js');
|
const User = require('../../core/user.js');
|
||||||
user.getUserIdAndName(argv.user, function userNameAndId(err, userId) {
|
User.getUserIdAndName(argv.user, function userNameAndId(err, userId) {
|
||||||
if(err) {
|
if(err) {
|
||||||
process.exitCode = ExitCodes.BAD_ARGS;
|
process.exitCode = ExitCodes.BAD_ARGS;
|
||||||
return cb(new Error('Failed to retrieve user'));
|
return cb(new Error('Failed to retrieve user'));
|
||||||
} else {
|
} else {
|
||||||
let u = new user.User();
|
let u = new User();
|
||||||
u.userId = userId;
|
u.userId = userId;
|
||||||
return cb(null, u);
|
return cb(null, u);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ function setAccountStatus(userName, active) {
|
||||||
initAndGetUser(argv.user, callback);
|
initAndGetUser(argv.user, callback);
|
||||||
},
|
},
|
||||||
function activateUser(user, callback) {
|
function activateUser(user, callback) {
|
||||||
const AccountStatus = require('./core/user.js').User.AccountStatus;
|
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||||
user.persistProperty('account_status', active ? AccountStatus.active : AccountStatus.inactive, callback);
|
user.persistProperty('account_status', active ? AccountStatus.active : AccountStatus.inactive, callback);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -91,7 +91,7 @@ function getPredefinedMCIValue(client, code) {
|
||||||
UT : function themeId() { return userStatAsString(client, 'theme_id', ''); },
|
UT : function themeId() { return userStatAsString(client, 'theme_id', ''); },
|
||||||
UC : function loginCount() { return userStatAsString(client, 'login_count', 0); },
|
UC : function loginCount() { return userStatAsString(client, 'login_count', 0); },
|
||||||
ND : function connectedNode() { return client.node.toString(); },
|
ND : function connectedNode() { return client.node.toString(); },
|
||||||
IP : function clientIpAddress() { return client.address().address; },
|
IP : function clientIpAddress() { return client.remoteAddress; },
|
||||||
ST : function serverName() { return client.session.serverName; },
|
ST : function serverName() { return client.session.serverName; },
|
||||||
FN : function activeFileBaseFilterName() {
|
FN : function activeFileBaseFilterName() {
|
||||||
const activeFilter = FileBaseFilters.getActiveFilter(client);
|
const activeFilter = FileBaseFilters.getActiveFilter(client);
|
||||||
|
|
|
@ -53,12 +53,12 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.enableHttp = Config.contentServers.web.http.enabled || true;
|
this.enableHttp = Config.contentServers.web.http.enabled || false;
|
||||||
this.enableHttps = Config.contentServers.web.https.enabled || false;
|
this.enableHttps = Config.contentServers.web.https.enabled || false;
|
||||||
|
|
||||||
this.routes = {};
|
this.routes = {};
|
||||||
|
|
||||||
if(Config.contentServers.web.staticRoot) {
|
if(this.isEnabled() && Config.contentServers.web.staticRoot) {
|
||||||
this.addRoute({
|
this.addRoute({
|
||||||
method : 'GET',
|
method : 'GET',
|
||||||
path : '/static/.*$',
|
path : '/static/.*$',
|
||||||
|
@ -67,6 +67,10 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return this.enableHttp || this.enableHttps;
|
||||||
|
}
|
||||||
|
|
||||||
createServer() {
|
createServer() {
|
||||||
if(this.enableHttp) {
|
if(this.enableHttp) {
|
||||||
this.httpServer = http.createServer( (req, resp) => this.routeRequest(req, resp) );
|
this.httpServer = http.createServer( (req, resp) => this.routeRequest(req, resp) );
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
const Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
|
|
||||||
exports.validateNonEmpty = validateNonEmpty;
|
exports.validateNonEmpty = validateNonEmpty;
|
||||||
|
@ -38,7 +38,7 @@ function validateUserNameAvail(data, cb) {
|
||||||
} else if(/^[0-9]+$/.test(data)) {
|
} else if(/^[0-9]+$/.test(data)) {
|
||||||
return cb(new Error('Username cannot be a number'));
|
return cb(new Error('Username cannot be a number'));
|
||||||
} else {
|
} else {
|
||||||
user.getUserIdAndName(data, function userIdAndName(err) {
|
User.getUserIdAndName(data, function userIdAndName(err) {
|
||||||
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
||||||
return cb(new Error('Username unavailable'));
|
return cb(new Error('Username unavailable'));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ function validateUserNameExists(data, cb) {
|
||||||
return cb(invalidUserNameError);
|
return cb(invalidUserNameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserIdAndName(data, (err) => {
|
User.getUserIdAndName(data, (err) => {
|
||||||
return cb(err ? invalidUserNameError : null);
|
return cb(err ? invalidUserNameError : null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ function validateEmailAvail(data, cb) {
|
||||||
return cb(new Error('Invalid email address'));
|
return cb(new Error('Invalid email address'));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
User.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return cb(new Error('Internal system error'));
|
return cb(new Error('Internal system error'));
|
||||||
} else if(uids.length > 0) {
|
} else if(uids.length > 0) {
|
||||||
|
|
615
core/user.js
615
core/user.js
|
@ -1,171 +1,169 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var userDb = require('./database.js').dbs.user;
|
const userDb = require('./database.js').dbs.user;
|
||||||
var Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
var userGroup = require('./user_group.js');
|
const userGroup = require('./user_group.js');
|
||||||
|
const Errors = require('./enig_error.js').Errors;
|
||||||
|
|
||||||
var crypto = require('crypto');
|
// deps
|
||||||
var assert = require('assert');
|
const crypto = require('crypto');
|
||||||
var async = require('async');
|
const assert = require('assert');
|
||||||
var _ = require('lodash');
|
const async = require('async');
|
||||||
var moment = require('moment');
|
const _ = require('lodash');
|
||||||
|
const moment = require('moment');
|
||||||
exports.User = User;
|
|
||||||
exports.getUserIdAndName = getUserIdAndName;
|
|
||||||
exports.getUserName = getUserName;
|
|
||||||
exports.loadProperties = loadProperties;
|
|
||||||
exports.getUserIdsWithProperty = getUserIdsWithProperty;
|
|
||||||
exports.getUserList = getUserList;
|
|
||||||
|
|
||||||
exports.isRootUserId = function(id) { return 1 === id; };
|
exports.isRootUserId = function(id) { return 1 === id; };
|
||||||
|
|
||||||
function User() {
|
module.exports = class User {
|
||||||
var self = this;
|
constructor() {
|
||||||
|
|
||||||
this.userId = 0;
|
this.userId = 0;
|
||||||
this.username = '';
|
this.username = '';
|
||||||
this.properties = {}; // name:value
|
this.properties = {}; // name:value
|
||||||
this.groups = []; // group membership(s)
|
this.groups = []; // group membership(s)
|
||||||
|
|
||||||
this.isAuthenticated = function() {
|
|
||||||
return true === self.authenticated;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.isValid = function() {
|
|
||||||
if(self.userId <= 0 || self.username.length < Config.users.usernameMin) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.hasValidPassword();
|
// static property accessors
|
||||||
};
|
static get RootUserID() {
|
||||||
|
return 1;
|
||||||
this.hasValidPassword = function() {
|
|
||||||
if(!this.properties || !this.properties.pw_pbkdf2_salt || !this.properties.pw_pbkdf2_dk) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.properties.pw_pbkdf2_salt.length === User.PBKDF2.saltLen * 2 &&
|
static get PBKDF2() {
|
||||||
this.prop_name.pw_pbkdf2_dk.length === User.PBKDF2.keyLen * 2;
|
return {
|
||||||
};
|
|
||||||
|
|
||||||
this.isRoot = function() {
|
|
||||||
return 1 === this.userId;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.isSysOp = this.isRoot; // alias
|
|
||||||
|
|
||||||
this.isGroupMember = function(groupNames) {
|
|
||||||
if(_.isString(groupNames)) {
|
|
||||||
groupNames = [ groupNames ];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isMember = groupNames.some(gn => (-1 !== self.groups.indexOf(gn)));
|
|
||||||
return isMember;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getLegacySecurityLevel = function() {
|
|
||||||
if(self.isRoot() || self.isGroupMember('sysops')) {
|
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self.isGroupMember('users')) {
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 10; // :TODO: Is this what we want?
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
User.PBKDF2 = {
|
|
||||||
iterations : 1000,
|
iterations : 1000,
|
||||||
keyLen : 128,
|
keyLen : 128,
|
||||||
saltLen : 32,
|
saltLen : 32,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
User.StandardPropertyGroups = {
|
static get StandardPropertyGroups() {
|
||||||
|
return {
|
||||||
password : [ 'pw_pbkdf2_salt', 'pw_pbkdf2_dk' ],
|
password : [ 'pw_pbkdf2_salt', 'pw_pbkdf2_dk' ],
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
User.AccountStatus = {
|
static get AccountStatus() {
|
||||||
|
return {
|
||||||
disabled : 0,
|
disabled : 0,
|
||||||
inactive : 1,
|
inactive : 1,
|
||||||
active : 2,
|
active : 2,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
User.prototype.load = function(userId, cb) {
|
isAuthenticated() {
|
||||||
|
return true === this.authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
isValid() {
|
||||||
|
if(this.userId <= 0 || this.username.length < Config.users.usernameMin) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
User.prototype.authenticate = function(username, password, cb) {
|
return this.hasValidPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
hasValidPassword() {
|
||||||
|
if(!this.properties || !this.properties.pw_pbkdf2_salt || !this.properties.pw_pbkdf2_dk) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.properties.pw_pbkdf2_salt.length === User.PBKDF2.saltLen * 2 && this.prop_name.pw_pbkdf2_dk.length === User.PBKDF2.keyLen * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
isRoot() {
|
||||||
|
return User.isRootUserId(this.userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
isSysOp() { // alias to isRoot()
|
||||||
|
return this.isRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
isGroupMember(groupNames) {
|
||||||
|
if(_.isString(groupNames)) {
|
||||||
|
groupNames = [ groupNames ];
|
||||||
|
}
|
||||||
|
|
||||||
|
const isMember = groupNames.some(gn => (-1 !== this.groups.indexOf(gn)));
|
||||||
|
return isMember;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLegacySecurityLevel() {
|
||||||
|
if(this.isRoot() || this.isGroupMember('sysops')) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.isGroupMember('users')) {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 10; // :TODO: Is this what we want?
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate(username, password, cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
const cachedInfo = {};
|
const cachedInfo = {};
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
function fetchUserId(callback) {
|
function fetchUserId(callback) {
|
||||||
// get user ID
|
// get user ID
|
||||||
getUserIdAndName(username, function onUserId(err, uid, un) {
|
User.getUserIdAndName(username, (err, uid, un) => {
|
||||||
cachedInfo.userId = uid;
|
cachedInfo.userId = uid;
|
||||||
cachedInfo.username = un;
|
cachedInfo.username = un;
|
||||||
|
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
function getRequiredAuthProperties(callback) {
|
function getRequiredAuthProperties(callback) {
|
||||||
// fetch properties required for authentication
|
// fetch properties required for authentication
|
||||||
loadProperties( { userId : cachedInfo.userId, names : User.StandardPropertyGroups.password }, function onProps(err, props) {
|
User.loadProperties(cachedInfo.userId, { names : User.StandardPropertyGroups.password }, (err, props) => {
|
||||||
callback(err, props);
|
return callback(err, props);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function getDkWithSalt(props, callback) {
|
function getDkWithSalt(props, callback) {
|
||||||
// get DK from stored salt and password provided
|
// get DK from stored salt and password provided
|
||||||
generatePasswordDerivedKey(password, props.pw_pbkdf2_salt, function onDk(err, dk) {
|
User.generatePasswordDerivedKey(password, props.pw_pbkdf2_salt, (err, dk) => {
|
||||||
callback(err, dk, props.pw_pbkdf2_dk);
|
return callback(err, dk, props.pw_pbkdf2_dk);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function validateAuth(passDk, propsDk, callback) {
|
function validateAuth(passDk, propsDk, callback) {
|
||||||
//
|
//
|
||||||
// Use constant time comparison here for security feel-goods
|
// Use constant time comparison here for security feel-goods
|
||||||
//
|
//
|
||||||
var passDkBuf = new Buffer(passDk, 'hex');
|
const passDkBuf = new Buffer(passDk, 'hex');
|
||||||
var propsDkBuf = new Buffer(propsDk, 'hex');
|
const propsDkBuf = new Buffer(propsDk, 'hex');
|
||||||
|
|
||||||
if(passDkBuf.length !== propsDkBuf.length) {
|
if(passDkBuf.length !== propsDkBuf.length) {
|
||||||
callback(new Error('Invalid password'));
|
return callback(Errors.AccessDenied('Invalid password'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = 0;
|
let c = 0;
|
||||||
for(var i = 0; i < passDkBuf.length; i++) {
|
for(let i = 0; i < passDkBuf.length; i++) {
|
||||||
c |= passDkBuf[i] ^ propsDkBuf[i];
|
c |= passDkBuf[i] ^ propsDkBuf[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(0 === c ? null : new Error('Invalid password'));
|
return callback(0 === c ? null : Errors.AccessDenied('Invalid password'));
|
||||||
},
|
},
|
||||||
function initProps(callback) {
|
function initProps(callback) {
|
||||||
loadProperties( { userId : cachedInfo.userId }, function onProps(err, allProps) {
|
User.loadProperties(cachedInfo.userId, (err, allProps) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
cachedInfo.properties = allProps;
|
cachedInfo.properties = allProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function initGroups(callback) {
|
function initGroups(callback) {
|
||||||
userGroup.getGroupsForUser(cachedInfo.userId, function groupsLoaded(err, groups) {
|
userGroup.getGroupsForUser(cachedInfo.userId, (err, groups) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
cachedInfo.groups = groups;
|
cachedInfo.groups = groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
err => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
self.userId = cachedInfo.userId;
|
self.userId = cachedInfo.userId;
|
||||||
self.username = cachedInfo.username;
|
self.username = cachedInfo.username;
|
||||||
|
@ -177,15 +175,16 @@ User.prototype.authenticate = function(username, password, cb) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
User.prototype.create = function(options, cb) {
|
create(password, cb) {
|
||||||
assert(0 === this.userId);
|
assert(0 === this.userId);
|
||||||
assert(this.username.length > 0); // :TODO: Min username length? Max?
|
|
||||||
assert(_.isObject(options));
|
|
||||||
assert(_.isString(options.password));
|
|
||||||
|
|
||||||
var self = this;
|
if(this.username.length < Config.users.usernameMin || this.username.length > Config.users.usernameMax) {
|
||||||
|
return cb(Errors.Invalid('Invalid username length'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
// :TODO: set various defaults, e.g. default activation status, etc.
|
// :TODO: set various defaults, e.g. default activation status, etc.
|
||||||
self.properties.account_status = Config.users.requireActivation ? User.AccountStatus.inactive : User.AccountStatus.active;
|
self.properties.account_status = Config.users.requireActivation ? User.AccountStatus.inactive : User.AccountStatus.active;
|
||||||
|
@ -193,139 +192,139 @@ User.prototype.create = function(options, cb) {
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
function beginTransaction(callback) {
|
function beginTransaction(callback) {
|
||||||
userDb.run('BEGIN;', function transBegin(err) {
|
userDb.run('BEGIN;', err => {
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function createUserRec(callback) {
|
function createUserRec(callback) {
|
||||||
userDb.run(
|
userDb.run(
|
||||||
'INSERT INTO user (user_name) ' +
|
`INSERT INTO user (user_name)
|
||||||
'VALUES (?);',
|
VALUES (?);`,
|
||||||
[ self.username ],
|
[ self.username ],
|
||||||
function userInsert(err) {
|
function inserted(err) { // use classic function for |this|
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
return callback(err);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
self.userId = this.lastID;
|
self.userId = this.lastID;
|
||||||
|
|
||||||
// Do not require activation for userId 1 (root/admin)
|
// Do not require activation for userId 1 (root/admin)
|
||||||
if(1 === self.userId) {
|
if(User.RootUserID === self.userId) {
|
||||||
self.properties.account_status = User.AccountStatus.active;
|
self.properties.account_status = User.AccountStatus.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null);
|
return callback(null);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
function genAuthCredentials(callback) {
|
function genAuthCredentials(callback) {
|
||||||
generatePasswordDerivedKeyAndSalt(options.password, function dkAndSalt(err, info) {
|
User.generatePasswordDerivedKeyAndSalt(password, (err, info) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
return callback(err);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
self.properties.pw_pbkdf2_salt = info.salt;
|
self.properties.pw_pbkdf2_salt = info.salt;
|
||||||
self.properties.pw_pbkdf2_dk = info.dk;
|
self.properties.pw_pbkdf2_dk = info.dk;
|
||||||
callback(null);
|
return callback(null);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function setInitialGroupMembership(callback) {
|
function setInitialGroupMembership(callback) {
|
||||||
self.groups = Config.users.defaultGroups;
|
self.groups = Config.users.defaultGroups;
|
||||||
|
|
||||||
if(1 === self.userId) { // root/SysOp?
|
if(User.RootUserID === self.userId) { // root/SysOp?
|
||||||
self.groups.push('sysops');
|
self.groups.push('sysops');
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null);
|
return callback(null);
|
||||||
},
|
},
|
||||||
function saveAll(callback) {
|
function saveAll(callback) {
|
||||||
self.persist(false, function persisted(err) {
|
self.persist(false, err => {
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
var originalError = err;
|
const originalError = err;
|
||||||
userDb.run('ROLLBACK;', function rollback(err) {
|
userDb.run('ROLLBACK;', err => {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
cb(originalError);
|
return cb(originalError);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
userDb.run('COMMIT;', function commited(err) {
|
userDb.run('COMMIT;', err => {
|
||||||
cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
User.prototype.persist = function(useTransaction, cb) {
|
persist(useTransaction, cb) {
|
||||||
assert(this.userId > 0);
|
assert(this.userId > 0);
|
||||||
|
|
||||||
var self = this;
|
const self = this;
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
function beginTransaction(callback) {
|
function beginTransaction(callback) {
|
||||||
if(useTransaction) {
|
if(useTransaction) {
|
||||||
userDb.run('BEGIN;', function transBegin(err) {
|
userDb.run('BEGIN;', err => {
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
return callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function saveProps(callback) {
|
function saveProps(callback) {
|
||||||
self.persistAllProperties(function persisted(err) {
|
self.persistProperties(self.properties, err => {
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function saveGroups(callback) {
|
function saveGroups(callback) {
|
||||||
userGroup.addUserToGroups(self.userId, self.groups, function groupsSaved(err) {
|
userGroup.addUserToGroups(self.userId, self.groups, err => {
|
||||||
callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(useTransaction) {
|
if(useTransaction) {
|
||||||
userDb.run('ROLLBACK;', function rollback(err) {
|
userDb.run('ROLLBACK;', err => {
|
||||||
cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(useTransaction) {
|
if(useTransaction) {
|
||||||
userDb.run('COMMIT;', function commited(err) {
|
userDb.run('COMMIT;', err => {
|
||||||
cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cb(null);
|
return cb(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
User.prototype.persistProperty = function(propName, propValue, cb) {
|
persistProperty(propName, propValue, cb) {
|
||||||
// update live props
|
// update live props
|
||||||
this.properties[propName] = propValue;
|
this.properties[propName] = propValue;
|
||||||
|
|
||||||
userDb.run(
|
userDb.run(
|
||||||
'REPLACE INTO user_property (user_id, prop_name, prop_value) ' +
|
`REPLACE INTO user_property (user_id, prop_name, prop_value)
|
||||||
'VALUES (?, ?, ?);',
|
VALUES (?, ?, ?);`,
|
||||||
[ this.userId, propName, propValue ],
|
[ this.userId, propName, propValue ],
|
||||||
function ran(err) {
|
err => {
|
||||||
if(cb) {
|
if(cb) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
User.prototype.removeProperty = function(propName, cb) {
|
removeProperty(propName, cb) {
|
||||||
// update live
|
// update live
|
||||||
delete this.properties[propName];
|
delete this.properties[propName];
|
||||||
|
|
||||||
|
@ -339,231 +338,261 @@ User.prototype.removeProperty = function(propName, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
User.prototype.persistProperties = function(properties, cb) {
|
persistProperties(properties, cb) {
|
||||||
var self = this;
|
const self = this;
|
||||||
|
|
||||||
// update live props
|
// update live props
|
||||||
_.merge(this.properties, properties);
|
_.merge(this.properties, properties);
|
||||||
|
|
||||||
var stmt = userDb.prepare(
|
const stmt = userDb.prepare(
|
||||||
'REPLACE INTO user_property (user_id, prop_name, prop_value) ' +
|
`REPLACE INTO user_property (user_id, prop_name, prop_value)
|
||||||
'VALUES (?, ?, ?);');
|
VALUES (?, ?, ?);`
|
||||||
|
);
|
||||||
|
|
||||||
async.each(Object.keys(properties), function property(propName, callback) {
|
async.each(Object.keys(properties), (propName, nextProp) => {
|
||||||
stmt.run(self.userId, propName, properties[propName], function onRun(err) {
|
stmt.run(self.userId, propName, properties[propName], err => {
|
||||||
callback(err);
|
return nextProp(err);
|
||||||
});
|
});
|
||||||
}, function complete(err) {
|
},
|
||||||
|
err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
} else {
|
}
|
||||||
stmt.finalize(function finalized() {
|
|
||||||
cb(null);
|
stmt.finalize( () => {
|
||||||
|
return cb(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
User.prototype.persistAllProperties = function(cb) {
|
setNewAuthCredentials(password, cb) {
|
||||||
assert(this.userId > 0);
|
User.generatePasswordDerivedKeyAndSalt(password, (err, info) => {
|
||||||
|
|
||||||
this.persistProperties(this.properties, cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
User.prototype.setNewAuthCredentials = function(password, cb) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
generatePasswordDerivedKeyAndSalt(password, function dkAndSalt(err, info) {
|
|
||||||
if(err) {
|
if(err) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
} else {
|
}
|
||||||
var newProperties = {
|
|
||||||
|
const newProperties = {
|
||||||
pw_pbkdf2_salt : info.salt,
|
pw_pbkdf2_salt : info.salt,
|
||||||
pw_pbkdf2_dk : info.dk,
|
pw_pbkdf2_dk : info.dk,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.persistProperties(newProperties, function persisted(err) {
|
this.persistProperties(newProperties, err => {
|
||||||
cb(err);
|
return cb(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
User.prototype.getAge = function() {
|
getAge() {
|
||||||
if(_.has(this.properties, 'birthdate')) {
|
if(_.has(this.properties, 'birthdate')) {
|
||||||
return moment().diff(this.properties.birthdate, 'years');
|
return moment().diff(this.properties.birthdate, 'years');
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Exported methods
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
function getUserIdAndName(username, cb) {
|
|
||||||
userDb.get(
|
|
||||||
'SELECT id, user_name ' +
|
|
||||||
'FROM user ' +
|
|
||||||
'WHERE user_name LIKE ?;',
|
|
||||||
[ username ],
|
|
||||||
function onResults(err, row) {
|
|
||||||
if(err) {
|
|
||||||
cb(err);
|
|
||||||
} else {
|
|
||||||
if(row) {
|
|
||||||
cb(null, row.id, row.user_name);
|
|
||||||
} else {
|
|
||||||
cb(new Error('No matching username'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserName(userId, cb) {
|
static getUser(userId, cb) {
|
||||||
userDb.get(
|
|
||||||
'SELECT user_name ' +
|
|
||||||
'FROM user ' +
|
|
||||||
'WHERE id=?;', [ userId ],
|
|
||||||
function got(err, row) {
|
|
||||||
if(err) {
|
|
||||||
cb(err);
|
|
||||||
} else {
|
|
||||||
if(row) {
|
|
||||||
cb(null, row.user_name);
|
|
||||||
} else {
|
|
||||||
cb(new Error('No matching user ID'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Internal utility methods
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
function generatePasswordDerivedKeyAndSalt(password, cb) {
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
function getSalt(callback) {
|
function fetchUserId(callback) {
|
||||||
generatePasswordDerivedKeySalt(function onSalt(err, salt) {
|
User.getUserName(userId, (err, userName) => {
|
||||||
callback(err, salt);
|
return callback(null, userName);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function getDk(salt, callback) {
|
function initProps(userName, callback) {
|
||||||
generatePasswordDerivedKey(password, salt, function onDk(err, dk) {
|
User.loadProperties(userId, (err, properties) => {
|
||||||
callback(err, salt, dk);
|
return callback(err, userName, properties);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function initGroups(userName, properties, callback) {
|
||||||
|
userGroup.getGroupsForUser(userId, (err, groups) => {
|
||||||
|
return callback(null, userName, properties, groups);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function onComplete(err, salt, dk) {
|
(err, userName, properties, groups) => {
|
||||||
cb(err, { salt : salt, dk : dk });
|
const user = new User();
|
||||||
|
user.userId = userId;
|
||||||
|
user.username = userName;
|
||||||
|
user.properties = properties;
|
||||||
|
user.groups = groups;
|
||||||
|
user.authenticated = false; // this is NOT an authenticated user!
|
||||||
|
|
||||||
|
return cb(err, user);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePasswordDerivedKeySalt(cb) {
|
static isRootUserId(userId) {
|
||||||
crypto.randomBytes(User.PBKDF2.saltLen, function onRandSalt(err, salt) {
|
return (User.RootUserID === userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getUserIdAndName(username, cb) {
|
||||||
|
userDb.get(
|
||||||
|
`SELECT id, user_name
|
||||||
|
FROM user
|
||||||
|
WHERE user_name LIKE ?;`,
|
||||||
|
[ username ],
|
||||||
|
(err, row) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
} else {
|
|
||||||
cb(null, salt.toString('hex'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePasswordDerivedKey(password, salt, cb) {
|
if(row) {
|
||||||
password = new Buffer(password).toString('hex');
|
return cb(null, row.id, row.user_name);
|
||||||
crypto.pbkdf2(password, salt, User.PBKDF2.iterations, User.PBKDF2.keyLen, 'sha1', function onDerivedKey(err, dk) {
|
}
|
||||||
|
|
||||||
|
return cb(Errors.DoesNotExist('No matching username'));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getUserName(userId, cb) {
|
||||||
|
userDb.get(
|
||||||
|
`SELECT user_name
|
||||||
|
FROM user
|
||||||
|
WHERE id = ?;`,
|
||||||
|
[ userId ],
|
||||||
|
(err, row) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
} else {
|
|
||||||
cb(null, dk.toString('hex'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadProperties(options, cb) {
|
if(row) {
|
||||||
assert(options.userId);
|
return cb(null, row.user_name);
|
||||||
|
}
|
||||||
|
|
||||||
var sql =
|
return cb(Errors.DoesNotExist('No matching user ID'));
|
||||||
'SELECT prop_name, prop_value ' +
|
}
|
||||||
'FROM user_property ' +
|
);
|
||||||
'WHERE user_id = ?';
|
}
|
||||||
|
|
||||||
|
static loadProperties(userId, options, cb) {
|
||||||
|
if(!cb && _.isFunction(options)) {
|
||||||
|
cb = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
let sql =
|
||||||
|
`SELECT prop_name, prop_value
|
||||||
|
FROM user_property
|
||||||
|
WHERE user_id = ?`;
|
||||||
|
|
||||||
if(options.names) {
|
if(options.names) {
|
||||||
sql +=' AND prop_name IN("' + options.names.join('","') + '");';
|
sql += ` AND prop_name IN("${options.names.join('","')}");`;
|
||||||
} else {
|
} else {
|
||||||
sql += ';';
|
sql += ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = {};
|
let properties = {};
|
||||||
|
userDb.each(sql, [ userId ], (err, row) => {
|
||||||
userDb.each(sql, [ options.userId ], function onRow(err, row) {
|
|
||||||
if(err) {
|
if(err) {
|
||||||
cb(err);
|
return cb(err);
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
properties[row.prop_name] = row.prop_value;
|
|
||||||
}
|
}
|
||||||
}, function complete() {
|
properties[row.prop_name] = row.prop_value;
|
||||||
cb(null, properties);
|
}, () => {
|
||||||
|
return cb(null, properties);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: make this much more flexible - propValue should allow for case-insensitive compare, etc.
|
// :TODO: make this much more flexible - propValue should allow for case-insensitive compare, etc.
|
||||||
function getUserIdsWithProperty(propName, propValue, cb) {
|
static getUserIdsWithProperty(propName, propValue, cb) {
|
||||||
var userIds = [];
|
let userIds = [];
|
||||||
|
|
||||||
userDb.each(
|
userDb.each(
|
||||||
'SELECT user_id ' +
|
`SELECT user_id
|
||||||
'FROM user_property ' +
|
FROM user_property
|
||||||
'WHERE prop_name = ? AND prop_value = ?;',
|
WHERE prop_name = ? AND prop_value = ?;`,
|
||||||
[ propName, propValue ],
|
[ propName, propValue ],
|
||||||
function rowEntry(err, row) {
|
(err, row) => {
|
||||||
if(!err) {
|
if(row) {
|
||||||
userIds.push(row.user_id);
|
userIds.push(row.user_id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function complete() {
|
() => {
|
||||||
cb(null, userIds);
|
return cb(null, userIds);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserList(options, cb) {
|
static getUserList(options, cb) {
|
||||||
var userList = [];
|
let userList = [];
|
||||||
|
let orderClause = 'ORDER BY ' + (options.order || 'user_name');
|
||||||
var orderClause = 'ORDER BY ' + (options.order || 'user_name');
|
|
||||||
|
|
||||||
userDb.each(
|
userDb.each(
|
||||||
'SELECT id, user_name ' +
|
`SELECT id, user_name
|
||||||
'FROM user ' +
|
FROM user
|
||||||
orderClause + ';',
|
${orderClause};`,
|
||||||
function userRow(err, row) {
|
(err, row) => {
|
||||||
|
if(row) {
|
||||||
userList.push({
|
userList.push({
|
||||||
userId : row.id,
|
userId : row.id,
|
||||||
userName : row.user_name,
|
userName : row.user_name,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function usersComplete(err) {
|
() => {
|
||||||
options.properties = options.properties || [];
|
options.properties = options.properties || [];
|
||||||
async.map(userList, function iter(user, callback) {
|
async.map(userList, (user, nextUser) => {
|
||||||
userDb.each(
|
userDb.each(
|
||||||
'SELECT prop_name, prop_value ' +
|
`SELECT prop_name, prop_value
|
||||||
'FROM user_property ' +
|
FROM user_property
|
||||||
'WHERE user_id=? AND prop_name IN ("' + options.properties.join('","') + '");',
|
WHERE user_id = ? AND prop_name IN ("${options.properties.join('","')}");`,
|
||||||
[ user.userId ],
|
[ user.userId ],
|
||||||
function propRow(err, row) {
|
(err, row) => {
|
||||||
|
if(row) {
|
||||||
user[row.prop_name] = row.prop_value;
|
user[row.prop_name] = row.prop_value;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function complete(err) {
|
err => {
|
||||||
callback(err, user);
|
return nextUser(err, user);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, function propsComplete(err, transformed) {
|
},
|
||||||
cb(err, transformed);
|
(err, transformed) => {
|
||||||
|
return cb(err, transformed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static generatePasswordDerivedKeyAndSalt(password, cb) {
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function getSalt(callback) {
|
||||||
|
User.generatePasswordDerivedKeySalt( (err, salt) => {
|
||||||
|
return callback(err, salt);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function getDk(salt, callback) {
|
||||||
|
User.generatePasswordDerivedKey(password, salt, (err, dk) => {
|
||||||
|
return callback(err, salt, dk);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
],
|
||||||
|
(err, salt, dk) => {
|
||||||
|
return cb(err, { salt : salt, dk : dk } );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static generatePasswordDerivedKeySalt(cb) {
|
||||||
|
crypto.randomBytes(User.PBKDF2.saltLen, (err, salt) => {
|
||||||
|
if(err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
return cb(null, salt.toString('hex'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static generatePasswordDerivedKey(password, salt, cb) {
|
||||||
|
password = new Buffer(password).toString('hex');
|
||||||
|
|
||||||
|
crypto.pbkdf2(password, salt, User.PBKDF2.iterations, User.PBKDF2.keyLen, 'sha1', (err, dk) => {
|
||||||
|
if(err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb(null, dk.toString('hex'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -22,6 +22,11 @@ The following archivers are pre-configured in ENiGMA½ as of this writing. Remem
|
||||||
* Key: `Arj`
|
* Key: `Arj`
|
||||||
* Homepage/package: `arj` on most *nix environments.
|
* Homepage/package: `arj` on most *nix environments.
|
||||||
|
|
||||||
|
#### Rar
|
||||||
|
* Formats: .Rar
|
||||||
|
* Key: `Rar`
|
||||||
|
* Homepage/package: `unrar` on most *nix environments. See also https://blog.hostonnet.com/unrar
|
||||||
|
|
||||||
### Archiver Configuration
|
### Archiver Configuration
|
||||||
Archiver entries in `config.hjson` are mostly self explanatory with the exception of `list` commands that require some additional information. The `args` member for an entry is an array of arguments to pass to `cmd`. Some variables are available to `args` that will be expanded by the system:
|
Archiver entries in `config.hjson` are mostly self explanatory with the exception of `list` commands that require some additional information. The `args` member for an entry is an array of arguments to pass to `cmd`. Some variables are available to `args` that will be expanded by the system:
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ const getModDatabasePath = require('../core/database.js').getModDatabasePath;
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const ansi = require('../core/ansi_term.js');
|
const ansi = require('../core/ansi_term.js');
|
||||||
const theme = require('../core/theme.js');
|
const theme = require('../core/theme.js');
|
||||||
const getUserName = require('../core/user.js').getUserName;
|
const User = require('../core/user.js');
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
|
@ -284,7 +284,7 @@ exports.getModule = class BBSListModule extends MenuModule {
|
||||||
},
|
},
|
||||||
function getUserNames(entriesView, callback) {
|
function getUserNames(entriesView, callback) {
|
||||||
async.each(self.entries, (entry, next) => {
|
async.each(self.entries, (entry, next) => {
|
||||||
getUserName(entry.submitterUserId, (err, username) => {
|
User.getUserName(entry.submitterUserId, (err, username) => {
|
||||||
if(username) {
|
if(username) {
|
||||||
entry.submitter = username;
|
entry.submitter = username;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,6 +11,7 @@ const stringFormat = require('../core/string_format.js');
|
||||||
const createCleanAnsi = require('../core/string_util.js').createCleanAnsi;
|
const createCleanAnsi = require('../core/string_util.js').createCleanAnsi;
|
||||||
const FileArea = require('../core/file_base_area.js');
|
const FileArea = require('../core/file_base_area.js');
|
||||||
const Errors = require('../core/enig_error.js').Errors;
|
const Errors = require('../core/enig_error.js').Errors;
|
||||||
|
const ErrNotEnabled = require('../core/enig_error.js').ErrorReasons.NotEnabled;
|
||||||
const ArchiveUtil = require('../core/archive_util.js');
|
const ArchiveUtil = require('../core/archive_util.js');
|
||||||
const Config = require('../core/config.js').config;
|
const Config = require('../core/config.js').config;
|
||||||
const DownloadQueue = require('../core/download_queue.js');
|
const DownloadQueue = require('../core/download_queue.js');
|
||||||
|
@ -256,8 +257,12 @@ exports.getModule = class FileAreaList extends MenuModule {
|
||||||
|
|
||||||
FileAreaWeb.getExistingTempDownloadServeItem(this.client, this.currentFileEntry, (err, serveItem) => {
|
FileAreaWeb.getExistingTempDownloadServeItem(this.client, this.currentFileEntry, (err, serveItem) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
|
||||||
entryInfo.webDlExpire = '';
|
entryInfo.webDlExpire = '';
|
||||||
|
if(ErrNotEnabled === err.reasonCode) {
|
||||||
|
entryInfo.webDlExpire = config.webDlLinkNoWebserver || 'Web server is not enabled';
|
||||||
|
} else {
|
||||||
|
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const StatLog = require('../core/stat_log.js');
|
const StatLog = require('../core/stat_log.js');
|
||||||
const getUserName = require('../core/user.js').getUserName;
|
const User = require('../core/user.js');
|
||||||
const loadProperties = require('../core/user.js').loadProperties;
|
|
||||||
const isRootUserId = require('../core/user.js').isRootUserId;
|
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
|
@ -73,7 +71,7 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
||||||
|
|
||||||
if(self.menuConfig.config.hideSysOpLogin) {
|
if(self.menuConfig.config.hideSysOpLogin) {
|
||||||
const noOpLoginHistory = loginHistory.filter(lh => {
|
const noOpLoginHistory = loginHistory.filter(lh => {
|
||||||
return false === isRootUserId(parseInt(lh.log_value)); // log_value=userId
|
return false === User.isRootUserId(parseInt(lh.log_value)); // log_value=userId
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -106,11 +104,10 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
||||||
item.userId = parseInt(item.log_value);
|
item.userId = parseInt(item.log_value);
|
||||||
item.ts = moment(item.timestamp).format(dateTimeFormat);
|
item.ts = moment(item.timestamp).format(dateTimeFormat);
|
||||||
|
|
||||||
getUserName(item.userId, (err, userName) => {
|
User.getUserName(item.userId, (err, userName) => {
|
||||||
item.userName = userName;
|
item.userName = userName;
|
||||||
getPropOpts.userId = item.userId;
|
|
||||||
|
|
||||||
loadProperties(getPropOpts, (err, props) => {
|
User.loadProperties(item.userId, getPropOpts, (err, props) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
item.location = props.location;
|
item.location = props.location;
|
||||||
item.affiliation = item.affils = props.affiliation;
|
item.affiliation = item.affils = props.affiliation;
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
||||||
var Message = require('../core/message.js');
|
|
||||||
var messageArea = require('../core/message_area.js');
|
|
||||||
var user = require('../core/user.js');
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
|
||||||
var async = require('async');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
exports.getModule = AreaReplyFSEModule;
|
exports.getModule = AreaReplyFSEModule;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const user = require('../core/user.js');
|
const User = require('../core/user.js');
|
||||||
const theme = require('../core/theme.js');
|
const theme = require('../core/theme.js');
|
||||||
const login = require('../core/system_menu_method.js').login;
|
const login = require('../core/system_menu_method.js').login;
|
||||||
const Config = require('../core/config.js').config;
|
const Config = require('../core/config.js').config;
|
||||||
|
@ -61,7 +61,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
// Submit handlers
|
// Submit handlers
|
||||||
//
|
//
|
||||||
submitApplication : function(formData, extraArgs, cb) {
|
submitApplication : function(formData, extraArgs, cb) {
|
||||||
const newUser = new user.User();
|
const newUser = new User();
|
||||||
|
|
||||||
newUser.username = formData.value.username;
|
newUser.username = formData.value.username;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: User.create() should validate email uniqueness!
|
// :TODO: User.create() should validate email uniqueness!
|
||||||
newUser.create( { password : formData.value.password }, err => {
|
newUser.create(formData.value.password, err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
self.client.log.info( { error : err, username : formData.value.username }, 'New user creation failed');
|
self.client.log.info( { error : err, username : formData.value.username }, 'New user creation failed');
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.User.AccountStatus.inactive === self.client.user.properties.account_status) {
|
if(User.AccountStatus.inactive === self.client.user.properties.account_status) {
|
||||||
return self.gotoMenu(extraArgs.inactive, cb);
|
return self.gotoMenu(extraArgs.inactive, cb);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const getUserList = require('../core/user.js').getUserList;
|
const User = require('../core/user.js');
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ exports.getModule = class UserListModule extends MenuModule {
|
||||||
},
|
},
|
||||||
function fetchUserList(callback) {
|
function fetchUserList(callback) {
|
||||||
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
||||||
getUserList(USER_LIST_OPTS, function got(err, ul) {
|
User.getUserList(USER_LIST_OPTS, function got(err, ul) {
|
||||||
userList = ul;
|
userList = ul;
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue