Commit 74921a90 authored by Cédric Moreau's avatar Cédric Moreau

Fix: stuck on "no private key given" on new config

parent 8f8e5cbc
......@@ -6,56 +6,49 @@ var _ = require('underscore');
var inquirer = require('inquirer');
var openpgp = require('openpgp');
module.exports = function (regServer) {
return new Wizard(regServer);
module.exports = function () {
return new Wizard();
}
var IPV4_REGEXP = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
var IPV6_REGEXP = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/;
function Wizard (regServer) {
function Wizard () {
this.configAll = function (conf, done) {
doTasks(['currency', 'openpgp', 'network', 'key', 'autovote'], regServer, conf, done);
doTasks(['currency', 'openpgp', 'network', 'key', 'autovote'], conf, done);
};
this.configCurrency = function (conf, done) {
doTasks(['currency'], regServer, conf, done);
doTasks(['currency'], conf, done);
};
this.configOpenpgp = function (conf, done) {
doTasks(['openpgp'], regServer, conf, done);
doTasks(['openpgp'], conf, done);
};
this.configNetwork = function (conf, done) {
doTasks(['network'], regServer, conf, done);
doTasks(['network'], conf, done);
};
this.configKey = function (conf, done) {
doTasks(['key'], regServer, conf, done);
doTasks(['key'], conf, done);
};
this.configAutovote = function (conf, done) {
doTasks(['autovote'], regServer, conf, done);
doTasks(['autovote'], conf, done);
};
}
function doTasks (todos, server, conf, done) {
function doTasks (todos, conf, done) {
async.forEachSeries(todos, function(task, callback){
async.waterfall([
function (next){
server.initServices(next);
},
function (next){
tasks[task] && tasks[task](server, conf, next);
},
], callback);
tasks[task] && tasks[task](conf, callback);
}, done);
}
var tasks = {
currency: function (server, conf, done) {
currency: function (conf, done) {
inquirer.prompt([{
type: "input",
name: "currency",
......@@ -70,7 +63,7 @@ var tasks = {
});
},
openpgp: function (server, conf, done) {
openpgp: function (conf, done) {
inquirer.prompt([{
type: "list",
name: "openpgp",
......@@ -89,7 +82,7 @@ var tasks = {
});
},
network: function (server, conf, done) {
network: function (conf, done) {
var noInterfaceListened = true;
if (conf.ipv4 || conf.ipv6) {
noInterfaceListened = false;
......@@ -214,8 +207,8 @@ var tasks = {
], done);
},
key: function (regServer, conf, done) {
var fingerprint = regServer.PeeringService.cert.fingerprint;
key: function (conf, done) {
var fingerprint = jpgp().certificate(conf.pgpkey).fingerprint;
var privateKeys = [];
async.waterfall([
function (next){
......@@ -292,7 +285,7 @@ var tasks = {
], done);
},
autovote: function (server, conf, done) {
autovote: function (conf, done) {
choose("Autovoting", conf.sync.AMDaemon ? conf.sync.AMDaemon == "ON" : false,
function enabled () {
conf.sync.AMDaemon = "ON";
......
......@@ -65,7 +65,7 @@ program
type: "console"
}]
});
connect(DO_NOT_LISTEN_HTTP, ucoin.createPeerServer, function (server, conf) {
service(DO_NOT_LISTEN_HTTP, ucoin.createPeerServer, function (server, conf) {
// Only show message "Saved"
require('log4js').configure({
"appenders": [{
......@@ -106,7 +106,7 @@ program
type: "console"
}]
});
connect(DO_NOT_LISTEN_HTTP, ucoin.createRegistryServer, function (step, server, conf) {
connect(function (step, server, conf) {
var wiz = wizard(server);
var task = {
'currency': wiz.configCurrency,
......@@ -127,10 +127,10 @@ program
});
},
function (next) {
server.checkConfig(conf, function (err) {
logger.warn(err);
});
next();
// Check config
service(DO_NOT_LISTEN_HTTP, ucoin.createRegistryServer, function (key, server, conf) {
next();
})(null, null);
}
], function (err, result) {
err && logger.error(err);
......@@ -143,7 +143,7 @@ program
program
.command('sync [host] [port]')
.description('Tries to synchronise data with remote uCoin node')
.action(connect(DO_NOT_LISTEN_HTTP, ucoin.createRegistryServer, function (host, port, server, conf) {
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createRegistryServer, function (host, port, server, conf) {
// Disable daemon
conf.sync.AMDaemon = "OFF";
......@@ -168,7 +168,7 @@ program
program
.command('allow-key [key]')
.description('Add given key to authorized keys of this node')
.action(connect(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
key = key || "";
key = key.toUpperCase();
async.waterfall([
......@@ -198,14 +198,14 @@ program
program
.command('manage-key [key]')
.description('Add given key to stack of managed keys of this node')
.action(connect(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
handleKey(server, key, true, 'Key %s is now managed');
}));
program
.command('forget-key [key]')
.description('Remove given key of the managed keys\' stack of this node')
.action(connect(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createHDCServer, function (key, server, conf) {
handleKey(server, key, false, 'Key %s no more managed from now');
}));
......@@ -234,7 +234,7 @@ function handleKey (server, key, isManaged, message) {
program
.command('check-config')
.description('Checks the node\'s configuration')
.action(connect(function (server, conf) {
.action(service(function (server, conf) {
server.checkConfig(function (err) {
if (err)
logger.warn(err);
......@@ -249,7 +249,7 @@ program
program
.command('config')
.description('Register configuration in database')
.action(connect(false, function (server, conf) {
.action(service(false, function (server, conf) {
conf.save(function (err) {
if(err){
logger.error("Configuration could not be saved: " + err);
......@@ -266,7 +266,7 @@ program
program
.command('reset [config|data]')
.description('Reset configuration or data in database')
.action(connect(function (type, server, conf) {
.action(service(function (type, server, conf) {
if(!~['config', 'data'].indexOf(type)){
logger.error('Bad command: usage `reset config` or `reset data`');
server.disconnect();
......@@ -297,7 +297,7 @@ program
program
.command('start')
.description('Start uCoin server using given --currency')
.action(connect(LISTEN_HTTP, ucoin.createRegistryServer, function (server, conf) {
.action(service(LISTEN_HTTP, ucoin.createRegistryServer, function (server, conf) {
server
.pipe(router(server.PeeringService.cert.fingerprint, server.conn))
......@@ -387,7 +387,32 @@ function overrideConf(conf) {
return conf;
}
function connect(listenHTTP, serverFactory, callback) {
function connect(callback) {
return function () {
var cbArgs = arguments;
var dbName = program.mdb || "ucoin_default";
var server = ucoin.connect({ name: dbName, host: program.mhost, port: program.mport }, overrideConf({}));
// Connecting to DB
server.on('connected', function (err) {
if(err){
logger.warn(err);
server.disconnect();
process.exit(1);
return;
}
cbArgs.length--;
cbArgs[cbArgs.length++] = server;
cbArgs[cbArgs.length++] = server.conf;
callback.apply(this, cbArgs);
});
};
}
function service(listenHTTP, serverFactory, callback) {
if (arguments.length == 1) {
callback = listenHTTP;
listenHTTP = false;
......
var Server = require('./server');
var PKSServer = require('./pksserver');
var HDCServer = require('./hdcserver');
var PeerServer = require('./peerserver');
var RegistryServer = require('./regserver');
module.exports = {
connect: function (dbConf, overConf) {
return new Server(dbConf, overConf);
},
createPKSServer: function (dbConf, overConf) {
return new PKSServer(dbConf, overConf);
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment