From 5171a7d1e08799b99bbe5c28a6b3c45afdf538c7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 10 May 2018 02:08:20 -0600 Subject: [PATCH] add community member option --- index.js | 2 ++ lib/community.js | 29 +++++++++++++++++++++++++++++ lib/core.js | 9 +++++++++ 3 files changed, 40 insertions(+) create mode 100644 lib/community.js diff --git a/index.js b/index.js index 56dc3ca..15148e4 100644 --- a/index.js +++ b/index.js @@ -103,6 +103,7 @@ LE.create = function (le) { le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize; le.challengeType = le.challengeType || LE.challengeType; le._ipc = ipc; + le._communityPackage = le._communityPackage || 'greenlock'; le.agreeToTerms = le.agreeToTerms || function (args, agreeCb) { agreeCb(new Error("'agreeToTerms' was not supplied to LE and 'agreeTos' was not supplied to LE.register")); }; @@ -259,6 +260,7 @@ LE.create = function (le) { lexOpts.domains = le.approvedDomains.slice(0); lexOpts.email = le.email; lexOpts.agreeTos = le.agreeTos; + lexOpts.communityMember = lexOpts.communityMember; return cb(null, { options: lexOpts, certs: certs }); } log(le.debug, 'unapproved domain', lexOpts.domains, le.approvedDomains); diff --git a/lib/community.js b/lib/community.js new file mode 100644 index 0000000..83ee9e4 --- /dev/null +++ b/lib/community.js @@ -0,0 +1,29 @@ +'use strict'; + +function addCommunityMember(pkg, email, domains) { + setTimeout(function () { + var https = require('https'); + var req = https.request({ + hostname: 'api.ppl.family' + , port: 443 + , path: '/api/ppl.family/public/list' + , method: 'POST' + , headers: { + 'Content-Type': 'application/json' + } + }, function (err, resp) { + if (err) { return; } + resp.on('data', function () {}); + }); + req.write(JSON.stringify({ + address: email + , comment: (pkg || 'community') + ' member w/ ' + (domains||[]).map(function (d) { + return require('crypto').createHash('sha1').update(d).digest('base64') + .replace(/\//g, '_').replace(/\+/g, '-').replace(/=/g, ''); + }).join(',') + })); + req.end(); + }, 50); +} + +module.exports.add = addCommunityMember; diff --git a/lib/core.js b/lib/core.js index 52a6b4f..83b62a2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -384,6 +384,15 @@ module.exports.create = function (le) { var copy = utils.merge(args, le); args = utils.tplCopy(copy); + if (args.communityMember && !args._communityMemberAdded) { + try { + require('./community').add(args._communityPackage, args.email, args.domains); + } catch(e) { + // ignore + } + args._communityMemberAdded = true; + } + return core.certificates.checkAsync(args).then(function (certs) { if (!certs) { // There is no cert available