Merge pull request #332 from matiu/ref/remove-unused-plugins
rm unused plugins
This commit is contained in:
commit
401003c65c
@ -79,9 +79,6 @@ INSIGHT_PORT # insight api port
|
||||
INSIGHT_DB # Path where to store insight's internal DB. (defaults to $HOME/.insight)
|
||||
INSIGHT_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
|
||||
INSIGHT_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than INSIGHT_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
|
||||
ENABLE_MAILBOX # if "true" will enable mailbox plugin
|
||||
ENABLE_CLEANER # if "true" will enable message db cleaner plugin
|
||||
ENABLE_MONITOR # if "true" will enable message db monitor plugin
|
||||
ENABLE_CURRENCYRATES # if "true" will enable a plugin to obtain historic conversion rates for various currencies
|
||||
ENABLE_RATELIMITER # if "true" will enable the ratelimiter plugin
|
||||
LOGGER_LEVEL # defaults to 'info', can be 'debug','verbose','error', etc.
|
||||
|
||||
@ -80,13 +80,8 @@ var bitcoindConf = {
|
||||
disableAgent: true
|
||||
};
|
||||
|
||||
var enableMonitor = process.env.ENABLE_MONITOR === 'true';
|
||||
var enableCleaner = process.env.ENABLE_CLEANER === 'true';
|
||||
var enableMailbox = process.env.ENABLE_MAILBOX === 'true';
|
||||
var enableRatelimiter = process.env.ENABLE_RATELIMITER === 'true';
|
||||
var enableCredentialstore = process.env.ENABLE_CREDSTORE === 'true';
|
||||
var enableEmailstore = process.env.ENABLE_EMAILSTORE === 'true';
|
||||
var enablePublicInfo = process.env.ENABLE_PUBLICINFO === 'true';
|
||||
var loggerLevel = process.env.LOGGER_LEVEL || 'info';
|
||||
var enableHTTPS = process.env.ENABLE_HTTPS === 'true';
|
||||
var enableCurrencyRates = process.env.ENABLE_CURRENCYRATES === 'true';
|
||||
@ -96,22 +91,12 @@ if (!fs.existsSync(db)) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
enableMonitor: enableMonitor,
|
||||
monitor: require('../plugins/config-monitor.js'),
|
||||
enableCleaner: enableCleaner,
|
||||
cleaner: require('../plugins/config-cleaner.js'),
|
||||
enableMailbox: enableMailbox,
|
||||
mailbox: require('../plugins/config-mailbox.js'),
|
||||
enableRatelimiter: enableRatelimiter,
|
||||
ratelimiter: require('../plugins/config-ratelimiter.js'),
|
||||
enableCredentialstore: enableCredentialstore,
|
||||
credentialstore: require('../plugins/config-credentialstore'),
|
||||
enableEmailstore: enableEmailstore,
|
||||
emailstore: require('../plugins/config-emailstore'),
|
||||
enableCurrencyRates: enableCurrencyRates,
|
||||
currencyrates: require('../plugins/config-currencyrates'),
|
||||
enablePublicInfo: enablePublicInfo,
|
||||
publicInfo: require('../plugins/publicInfo/config'),
|
||||
loggerLevel: loggerLevel,
|
||||
enableHTTPS: enableHTTPS,
|
||||
version: version,
|
||||
|
||||
@ -60,20 +60,8 @@ module.exports = function(app) {
|
||||
// Email store plugin
|
||||
if (config.enableEmailstore) {
|
||||
var emailPlugin = require('../plugins/emailstore');
|
||||
app.post(apiPrefix + '/email/save', emailPlugin.save);
|
||||
app.get(apiPrefix + '/email/retrieve', emailPlugin.retrieve);
|
||||
app.post(apiPrefix + '/email/change_passphrase', emailPlugin.changePassphrase);
|
||||
|
||||
app.post(apiPrefix + '/email/validate', emailPlugin.validate);
|
||||
app.get(apiPrefix + '/email/validate', emailPlugin.validate);
|
||||
|
||||
app.post(apiPrefix + '/email/register', emailPlugin.oldSave);
|
||||
app.get(apiPrefix + '/email/retrieve/:email', emailPlugin.oldRetrieve);
|
||||
|
||||
app.post(apiPrefix + '/email/delete/profile', emailPlugin.eraseProfile);
|
||||
app.get(apiPrefix + '/email/delete/item', emailPlugin.erase);
|
||||
|
||||
app.get(apiPrefix + '/email/resend_email', emailPlugin.resendEmail);
|
||||
}
|
||||
|
||||
// Currency rates plugin
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
var mdb = require('../lib/MessageDb').default();
|
||||
var logger = require('../lib/logger').logger;
|
||||
var preconditions = require('preconditions').singleton();
|
||||
var microtime = require('microtime');
|
||||
var cron = require('cron');
|
||||
var CronJob = cron.CronJob;
|
||||
var Threshold = (process.env.CLEANER_THRESHOLD_DAYS || 30) *24*60*60; // in seconds
|
||||
|
||||
module.exports.init = function(config) {
|
||||
var cronTime = config.cronTime || '0 * * * *';
|
||||
logger.info('Using cleaner plugin with cronTime ' + cronTime + ' and threshold of ' + Threshold + ' seconds');
|
||||
var onTick = function() {
|
||||
var limit = microtime.now() - 1000 * 1000 * Threshold;
|
||||
mdb.removeUpTo(limit, function(err, n) {
|
||||
if (err) logger.error(err);
|
||||
else logger.info('Ran cleaner task, removed ' + n);
|
||||
});
|
||||
};
|
||||
var job = new CronJob({
|
||||
cronTime: cronTime,
|
||||
onTick: onTick
|
||||
});
|
||||
onTick();
|
||||
job.start();
|
||||
};
|
||||
@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
|
||||
cronTime: '0 * * * *', // run each hour
|
||||
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
|
||||
};
|
||||
@ -1,160 +0,0 @@
|
||||
/**
|
||||
* Credentials storage service
|
||||
*
|
||||
* Allows users to store encrypted data on the server, useful to store the user's credentials.
|
||||
*
|
||||
* Steps for the user would be:
|
||||
*
|
||||
* 1. Choose an username
|
||||
* 2. Choose a password
|
||||
* 3. Create a strong key for encryption using PBKDF2 or scrypt with the username and password
|
||||
* 4. Use that key to AES-CRT encrypt the private key
|
||||
* 5. Take the double SHA256 hash of "salt"+"username"+"password" and use that as a secret
|
||||
* 6. Send a POST request to resource /credentials with the params:
|
||||
* username=johndoe
|
||||
* secret=2413fb3709b05939f04cf2e92f7d0897fc2596f9ad0b8a9ea855c7bfebaae892
|
||||
* record=YjU1MTI2YTM5ZjliMTE3MGEzMmU2ZjYxZTRhNjk0YzQ1MjM1ZTVhYzExYzA1ZWNkNmZm
|
||||
* NjM5NWRlNmExMTE4NzIzYzYyYWMwODU1MTdkNWMyNjRiZTVmNmJjYTMxMGQyYmFiNjc4YzdiODV
|
||||
* lZjg5YWIxYzQ4YjJmY2VkYWJjMDQ2NDYzODhkODFiYTU1NjZmMzgwYzhiODdiMzlmYjQ5ZTc1Nz
|
||||
* FjYzQzYjk1YTEyYWU1OGMxYmQ3OGFhOTZmNGMz
|
||||
*
|
||||
* To retrieve data:
|
||||
*
|
||||
* 1. Recover the secret from the double sha256 of the salt, username, and password
|
||||
* 2. Send a GET request to resource /credentials/username?secret=......
|
||||
* 3. Decrypt the data received
|
||||
*/
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
var logger = require('../lib/logger').logger,
|
||||
levelup = require('levelup'),
|
||||
querystring = require('querystring');
|
||||
|
||||
var storePlugin = {};
|
||||
|
||||
/**
|
||||
* Constant enum with the errors that the application may return
|
||||
*/
|
||||
var errors = {
|
||||
MISSING_PARAMETER: {
|
||||
code: 400,
|
||||
message: 'Missing required parameter'
|
||||
},
|
||||
INVALID_REQUEST: {
|
||||
code: 400,
|
||||
message: 'Invalid request parameter'
|
||||
},
|
||||
NOT_FOUND: {
|
||||
code: 404,
|
||||
message: 'Credentials were not found'
|
||||
}
|
||||
};
|
||||
|
||||
var NAMESPACE = 'credentials-store-';
|
||||
var MAX_ALLOWED_STORAGE = 1024 /* no more than 1 kb */;
|
||||
|
||||
/**
|
||||
* Initializes the plugin
|
||||
*
|
||||
* @param {Express} expressApp
|
||||
* @param {Object} config
|
||||
*/
|
||||
storePlugin.init = function(expressApp, config) {
|
||||
var globalConfig = require('../config/config');
|
||||
logger.info('Using credentialstore plugin');
|
||||
|
||||
var path = globalConfig.leveldb + '/credentialstore' + (globalConfig.name ? ('-' + globalConfig.name) : '');
|
||||
storePlugin.db = config.db || globalConfig.db || levelup(path);
|
||||
|
||||
expressApp.post(globalConfig.apiPrefix + '/credentials', storePlugin.post);
|
||||
expressApp.get(globalConfig.apiPrefix + '/credentials/:username', storePlugin.get);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function that ends a requests showing the user an error. The response body will be a JSON
|
||||
* encoded object with only one property with key "error" and value <tt>error.message</tt>, one of
|
||||
* the parameters of the function
|
||||
*
|
||||
* @param {Object} error - The error that caused the request to be terminated
|
||||
* @param {number} error.code - the HTTP code to return
|
||||
* @param {string} error.message - the message to send in the body
|
||||
* @param {Express.Response} response - the express.js response. the methods status, json, and end
|
||||
* will be called, terminating the request.
|
||||
*/
|
||||
var returnError = function(error, response) {
|
||||
response.status(error.code).json({error: error.message}).end();
|
||||
};
|
||||
|
||||
/**
|
||||
* Store a record in the database. The underlying database is merely a levelup instance (a key
|
||||
* value store) that uses the username concatenated with the secret as a key to store the record.
|
||||
* The request is expected to contain the parameters:
|
||||
* * username
|
||||
* * secret
|
||||
* * record
|
||||
*
|
||||
* @param {Express.Request} request
|
||||
* @param {Express.Response} response
|
||||
*/
|
||||
storePlugin.post = function(request, response) {
|
||||
|
||||
var queryData = '';
|
||||
|
||||
request.on('data', function(data) {
|
||||
queryData += data;
|
||||
if (queryData.length > MAX_ALLOWED_STORAGE) {
|
||||
queryData = '';
|
||||
response.writeHead(413, {'Content-Type': 'text/plain'}).end();
|
||||
request.connection.destroy();
|
||||
}
|
||||
}).on('end', function() {
|
||||
var params = querystring.parse(queryData);
|
||||
var username = params.username;
|
||||
var secret = params.secret;
|
||||
var record = params.record;
|
||||
if (!username || !secret || !record) {
|
||||
return returnError(errors.MISSING_PARAMETER, response);
|
||||
}
|
||||
|
||||
storePlugin.db.put(NAMESPACE + username + secret, record, function (err) {
|
||||
if (err) {
|
||||
return returnError({code: 500, message: err}, response);
|
||||
}
|
||||
response.json({success: true}).end();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a record from the database.
|
||||
*
|
||||
* The request is expected to contain the parameters:
|
||||
* * username
|
||||
* * secret
|
||||
*
|
||||
* @param {Express.Request} request
|
||||
* @param {Express.Response} response
|
||||
*/
|
||||
storePlugin.get = function(request, response) {
|
||||
var username = request.param('username');
|
||||
var secret = request.param('secret');
|
||||
if (!username || !secret) {
|
||||
return returnError(errors.MISSING_PARAMETER, response);
|
||||
}
|
||||
|
||||
storePlugin.db.get(NAMESPACE + username + secret, function (err, value) {
|
||||
if (err) {
|
||||
if (err.notFound) {
|
||||
return returnError(errors.NOT_FOUND, response);
|
||||
}
|
||||
return returnError({code: 500, message: err}, response);
|
||||
}
|
||||
response.send(value).end();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = storePlugin;
|
||||
|
||||
})();
|
||||
@ -1,65 +0,0 @@
|
||||
var microtime = require('microtime');
|
||||
var mdb = require('../lib/MessageDb').default();
|
||||
var logger = require('../lib/logger').logger;
|
||||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
var io;
|
||||
module.exports.init = function(ext_io, config) {
|
||||
logger.info('Using mailbox plugin');
|
||||
preconditions.checkArgument(ext_io);
|
||||
io = ext_io;
|
||||
io.sockets.on('connection', function(socket) {
|
||||
// when it requests sync, send him all pending messages
|
||||
socket.on('sync', function(ts) {
|
||||
logger.verbose('Sync requested by ' + socket.id);
|
||||
logger.debug(' from timestamp ' + ts);
|
||||
var rooms = socket.rooms;
|
||||
if (rooms.length !== 2) {
|
||||
socket.emit('insight-error', 'Must subscribe with public key before syncing');
|
||||
return;
|
||||
}
|
||||
var to = rooms[1];
|
||||
var upper_ts = Math.round(microtime.now());
|
||||
logger.debug(' to timestamp ' + upper_ts);
|
||||
mdb.getMessages(to, ts, upper_ts, function(err, messages) {
|
||||
// TODO: return error to the user
|
||||
if (err) {
|
||||
logger.debug('Couldn\'t get messages on sync request: ' + err);
|
||||
}
|
||||
logger.verbose('\tFound ' + messages.length + ' message' + (messages.length !== 1 ? 's' : ''));
|
||||
|
||||
if (messages.length) {
|
||||
for (var i = 0; i < messages.length; i++) {
|
||||
broadcastMessage(messages[i], socket);
|
||||
}
|
||||
} else {
|
||||
socket.emit('no messages');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// when it sends a message, add it to db
|
||||
socket.on('message', function(m) {
|
||||
logger.debug('Message sent from ' + m.pubkey + ' to ' + m.to);
|
||||
mdb.addMessage(m, function(err) {
|
||||
// TODO: return error to the user
|
||||
if (err) {
|
||||
logger.debug('Couldn\'t add message to database: ' + err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
mdb.on('message', broadcastMessage);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
var broadcastMessage = module.exports.broadcastMessage = function(message, socket) {
|
||||
preconditions.checkState(io);
|
||||
var s = socket || io.sockets.in(message.to);
|
||||
logger.debug('sending message to ' + message.to);
|
||||
s.emit('message', message);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user