updates, should all work

This commit is contained in:
AJ ONeal 2015-12-16 12:42:04 +00:00
parent f81ab3bd45
commit b83b665a1e
3 changed files with 111 additions and 53 deletions

View File

@ -81,11 +81,11 @@ cli.main(function(_, options) {
var handlers; var handlers;
if (args.standalone) { if (args.standalone) {
handlers = require('../lib/standalone'); handlers = require('../lib/standalone').create();
handlers.startServers(args.http01Ports || [80], args.tlsSni01Port || [443, 5001]); handlers.startServers(args.http01Ports || [80], args.tlsSni01Port || [443, 5001]);
} }
else if (args.webrootPath) { else if (args.webrootPath) {
handlers = require('../lib/webroot'); handlers = require('../lib/webroot').create(args);
} }
LE.create({}, handlers).register(args, function (err, results) { LE.create({}, handlers).register(args, function (err, results) {

View File

@ -1,15 +1,21 @@
'use strict'; 'use strict';
var handlers = module.exports = { var handlers = module.exports.create = function () {
return {
// //
// set,get,remove challenges // set,get,remove challenges
// //
// Note: this is fine for a one-off CLI tool
// but a webserver using node-cluster or multiple
// servers should use a database of some sort
_challenges: {} _challenges: {}
, setChallenge: function (args, key, value, cb) { , setChallenge: function (args, key, value, cb) {
handlers._challenges[key] = value; handlers._challenges[key] = value;
cb(null); cb(null);
} }
, getChallenge: function (args, key, cb) { , getChallenge: function (args, key, cb) {
// TODO keep in mind that, generally get args are just args.domains
// and it is disconnected from the flow of setChallenge and removeChallenge
cb(null, handlers._challenges[key]); cb(null, handlers._challenges[key]);
} }
, removeChallenge: function (args, key, cb) { , removeChallenge: function (args, key, cb) {
@ -60,3 +66,4 @@ var handlers = module.exports = {
handlers._servers = []; handlers._servers = [];
} }
}; };
};

View File

@ -0,0 +1,51 @@
'use strict';
var handlers = module.exports.create = function (defaults) {
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
return {
//
// set,get,remove challenges
//
_challenges: {}
, setChallenge: function (args, key, value, cb) {
mkdirp(defaults.webrootPath, function (err) {
if (err) {
console.error("Could not create --webroot-path '" + defaults.webrootPath + "':", err.code);
console.error("Try checking the permissions, maybe?");
cb(err);
return;
}
var keyfile = path.join(defaults.webrootPath, key);
fs.writeFile(keyfile, value, 'utf8', function (err) {
if (err) {
console.error("Could not write '" + keyfile + "':", err.code);
cb(err);
return;
}
cb(null);
});
});
}
// handled as file read by web server
// , getChallenge: function (args, key, cb) {}
, removeChallenge: function (args, key, cb) {
var keyfile = path.join(defaults.webrootPath, key);
fs.unlink(keyfile, function (err) {
if (err) {
console.error("Could not unlink '" + keyfile + "':", err.code);
cb(err);
return;
}
cb(null);
});
}
};
};