mirror of
				https://github.com/therootcompany/greenlock.js.git
				synced 2025-10-31 03:52:46 +00:00 
			
		
		
		
	Handle asynchronous exceptions, e.g. 'socket hang up'
This commit is contained in:
		
							parent
							
								
									fb69d25250
								
							
						
					
					
						commit
						4513a6d49c
					
				| @ -2,47 +2,58 @@ | |||||||
| 
 | 
 | ||||||
| function addCommunityMember(opts) { | function addCommunityMember(opts) { | ||||||
|   // { name, version, email, domains, action, communityMember, telemetry }
 |   // { name, version, email, domains, action, communityMember, telemetry }
 | ||||||
|   setTimeout(function () { |   var https = require('https'); | ||||||
|     var https = require('https'); |   var req = https.request({ | ||||||
|     var req = https.request({ |     hostname: 'api.ppl.family' | ||||||
|       hostname: 'api.ppl.family' |   , port: 443 | ||||||
|     , port: 443 |   , path: '/api/ppl.family/public/list' | ||||||
|     , path: '/api/ppl.family/public/list' |   , method: 'POST' | ||||||
|     , method: 'POST' |   , headers: { | ||||||
|     , headers: { |       'Content-Type': 'application/json' | ||||||
|         'Content-Type': 'application/json' |  | ||||||
|       } |  | ||||||
|     }, function (err, resp) { |  | ||||||
|       if (err) { return; } |  | ||||||
|       resp.on('data', function () {}); |  | ||||||
|     }); |  | ||||||
|     var os = require('os'); |  | ||||||
|     var data = { |  | ||||||
|       address: opts.email |  | ||||||
|       // greenlock-security is transactional and security only
 |  | ||||||
|     , list: opts.communityMember ? (opts.name + '@ppl.family') : 'greenlock-security@ppl.family' |  | ||||||
|     , action: opts.action // reg | renew
 |  | ||||||
|     , package: opts.name |  | ||||||
|       // hashed for privacy, but so we can still get some telemetry and inform users
 |  | ||||||
|       // if abnormal things are happening (like several registrations for the same domain each day)
 |  | ||||||
|     , domain: (opts.domains||[]).map(function (d) { |  | ||||||
|         return require('crypto').createHash('sha1').update(d).digest('base64') |  | ||||||
|           .replace(/\//g, '_').replace(/\+/g, '-').replace(/=/g, ''); |  | ||||||
|       }).join(',') |  | ||||||
|     }; |  | ||||||
|     if (false !== opts.telemetry) { |  | ||||||
|       data.arch = process.arch || os.arch(); |  | ||||||
|       data.platform = process.platform || os.platform(); |  | ||||||
|       data.release = os.release(); |  | ||||||
|       data.version = opts.version; |  | ||||||
|       data.node = process.version; |  | ||||||
|     } |     } | ||||||
|     req.write(JSON.stringify(data, 2, null)); |   }, function (err, resp) { | ||||||
|     req.end(); |     if (err) { return; } | ||||||
|   }, 50); |     resp.on('data', function () {}); | ||||||
|  |   }); | ||||||
|  |   var os = require('os'); | ||||||
|  |   var data = { | ||||||
|  |     address: opts.email | ||||||
|  |     // greenlock-security is transactional and security only
 | ||||||
|  |   , list: opts.communityMember ? (opts.name + '@ppl.family') : 'greenlock-security@ppl.family' | ||||||
|  |   , action: opts.action // reg | renew
 | ||||||
|  |   , package: opts.name | ||||||
|  |     // hashed for privacy, but so we can still get some telemetry and inform users
 | ||||||
|  |     // if abnormal things are happening (like several registrations for the same domain each day)
 | ||||||
|  |   , domain: (opts.domains||[]).map(function (d) { | ||||||
|  |       return require('crypto').createHash('sha1').update(d).digest('base64') | ||||||
|  |         .replace(/\//g, '_').replace(/\+/g, '-').replace(/=/g, ''); | ||||||
|  |     }).join(',') | ||||||
|  |   }; | ||||||
|  |   if (false !== opts.telemetry) { | ||||||
|  |     data.arch = process.arch || os.arch(); | ||||||
|  |     data.platform = process.platform || os.platform(); | ||||||
|  |     data.release = os.release(); | ||||||
|  |     data.version = opts.version; | ||||||
|  |     data.node = process.version; | ||||||
|  |   } | ||||||
|  |   req.write(JSON.stringify(data, 2, null)); | ||||||
|  |   req.end(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| module.exports.add = addCommunityMember; | function delay(ms) { | ||||||
|  |   return new Promise(function (resolve) { | ||||||
|  |     return setTimeout(resolve, ms); | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | module.exports.add = function (opts) { | ||||||
|  |   return delay(50).then(() => { | ||||||
|  |     return addCommunityMember(opts); | ||||||
|  |   }) | ||||||
|  |   .catch(function (ex) { | ||||||
|  |     /* ignore */ | ||||||
|  |   }) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| if (require.main === module) { | if (require.main === module) { | ||||||
|   //addCommunityMember('greenlock-express.js', 'reg', 'coolaj86+test42@gmail.com', ['coolaj86.com'], true);
 |   //addCommunityMember('greenlock-express.js', 'reg', 'coolaj86+test42@gmail.com', ['coolaj86.com'], true);
 | ||||||
|  | |||||||
							
								
								
									
										52
									
								
								lib/core.js
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								lib/core.js
									
									
									
									
									
								
							| @ -558,20 +558,18 @@ module.exports.create = function (gl) { | |||||||
|           if (!certs || !utils.certHasDomain(certs, args.domain)) { |           if (!certs || !utils.certHasDomain(certs, args.domain)) { | ||||||
|             // There is no cert available
 |             // There is no cert available
 | ||||||
|             if (false !== args.securityUpdates && !args._communityMemberAdded) { |             if (false !== args.securityUpdates && !args._communityMemberAdded) { | ||||||
|               try { |               // We will notify all greenlock users of mandatory and security updates
 | ||||||
|                 // We will notify all greenlock users of mandatory and security updates
 |               // We'll keep track of versions and os so we can make sure things work well
 | ||||||
|                 // We'll keep track of versions and os so we can make sure things work well
 |               // { name, version, email, domains, action, communityMember, telemetry }
 | ||||||
|                 // { name, version, email, domains, action, communityMember, telemetry }
 |               require('./community').add({ | ||||||
|                 require('./community').add({ |                 name: args._communityPackage | ||||||
|                   name: args._communityPackage |               , version: args._communityPackageVersion | ||||||
|                 , version: args._communityPackageVersion |               , email: args.email | ||||||
|                 , email: args.email |               , domains: args.domains || args.servernames | ||||||
|                 , domains: args.domains || args.servernames |               , action: 'reg' | ||||||
|                 , action: 'reg' |               , communityMember: args.communityMember | ||||||
|                 , communityMember: args.communityMember |               , telemetry: args.telemetry | ||||||
|                 , telemetry: args.telemetry |               }); | ||||||
|                 }); |  | ||||||
|               } catch(e) { /* ignore */ } |  | ||||||
|               args._communityMemberAdded = true; |               args._communityMemberAdded = true; | ||||||
|             } |             } | ||||||
|             return core.certificates.registerAsync(args); |             return core.certificates.registerAsync(args); | ||||||
| @ -580,20 +578,18 @@ module.exports.create = function (gl) { | |||||||
|           if (core.certificates._isRenewable(args, certs)) { |           if (core.certificates._isRenewable(args, certs)) { | ||||||
|             // it's time to renew the available cert
 |             // it's time to renew the available cert
 | ||||||
|             if (false !== args.securityUpdates && !args._communityMemberAdded) { |             if (false !== args.securityUpdates && !args._communityMemberAdded) { | ||||||
|               try { |               // We will notify all greenlock users of mandatory and security updates
 | ||||||
|                 // We will notify all greenlock users of mandatory and security updates
 |               // We'll keep track of versions and os so we can make sure things work well
 | ||||||
|                 // We'll keep track of versions and os so we can make sure things work well
 |               // { name, version, email, domains, action, communityMember, telemetry }
 | ||||||
|                 // { name, version, email, domains, action, communityMember, telemetry }
 |               require('./community').add({ | ||||||
|                 require('./community').add({ |                 name: args._communityPackage | ||||||
|                   name: args._communityPackage |               , version: args._communityPackageVersion | ||||||
|                 , version: args._communityPackageVersion |               , email: args.email | ||||||
|                 , email: args.email |               , domains: args.domains || args.servernames | ||||||
|                 , domains: args.domains || args.servernames |               , action: 'renew' | ||||||
|                 , action: 'renew' |               , communityMember: args.communityMember | ||||||
|                 , communityMember: args.communityMember |               , telemetry: args.telemetry | ||||||
|                 , telemetry: args.telemetry |               }); | ||||||
|                 }); |  | ||||||
|               } catch(e) { /* ignore */ } |  | ||||||
|               args._communityMemberAdded = true; |               args._communityMemberAdded = true; | ||||||
|             } |             } | ||||||
|             certs.renewing = core.certificates.renewAsync(args, certs); |             certs.renewing = core.certificates.renewAsync(args, certs); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user