greenlock.js-ARCHIVED/examples/commandline.js

91 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-12-12 13:11:05 +00:00
'use strict';
var conf = {
domains: process.argv[2]
, email: process.argv[3]
, agree: process.argv[4]
};
2015-12-12 15:05:45 +00:00
var port = 80;
var tlsPort = 5001;
if (!conf.domains || !conf.email || !conf.agree) {
console.error("Usage: letsencrypt <domain1,domain2> <email> agree");
console.error("Example: letsencrypt example.com,www.example.com user@example.com agree");
return;
}
2015-12-12 13:11:05 +00:00
2015-12-13 05:03:48 +00:00
var LE = require('../');
var path = require('path');
// backend-specific defaults will be passed through
// Note: Since agreeTos is a legal agreement, I would suggest not accepting it by default
2015-12-12 13:11:05 +00:00
var bkDefaults = {
2015-12-13 05:03:48 +00:00
webrootPath: path.join(__dirname, '..', 'tests', 'acme-challenge')
2015-12-12 13:11:05 +00:00
, fullchainTpl: '/live/:hostname/fullchain.pem'
2015-12-12 15:19:11 +00:00
, privkeyTpl: '/live/:hostname/privkey.pem'
2015-12-12 15:05:45 +00:00
, configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config')
, logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs')
, workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work')
2015-12-13 05:03:48 +00:00
, server: LE.stagingServer
2015-12-12 13:11:05 +00:00
, text: true
};
2015-12-13 05:03:48 +00:00
var leBinPath = require('homedir')() + '/.local/share/letsencrypt/bin/letsencrypt';
var LEB = require('../backends-python');
var backend = LEB.create(leBinPath, bkDefaults, { debug: true });
var le = LE.create(backend, bkDefaults, {
2015-12-13 01:04:12 +00:00
/*
2015-12-13 05:03:48 +00:00
setChallenge: function (hostnames, key, value, cb) {
2015-12-13 01:04:12 +00:00
// the python backend needs fs.watch implemented
// before this would work (and even then it would be difficult)
2015-12-13 05:03:48 +00:00
}
, getChallenge: function (hostnames, key, cb) {
2015-12-13 01:04:12 +00:00
//
}
2015-12-13 05:03:48 +00:00
, sniRegisterCallback: function (args, certInfo, cb) {
2015-12-13 01:04:12 +00:00
}
2015-12-13 05:03:48 +00:00
, registrationFailureCallback: function (args, certInfo, cb) {
what do to when a backgrounded registration fails
2015-12-13 01:04:12 +00:00
}
*/
});
2015-12-12 13:11:05 +00:00
var localCerts = require('localhost.daplie.com-certificates');
var express = require('express');
var app = express();
2015-12-12 15:05:45 +00:00
app.use('/', le.middleware());
2015-12-12 13:11:05 +00:00
var server = require('http').createServer();
server.on('request', app);
2015-12-12 15:05:45 +00:00
server.listen(port, function () {
2015-12-12 13:11:05 +00:00
console.log('Listening http', server.address());
});
var tlsServer = require('https').createServer({
key: localCerts.key
, cert: localCerts.cert
2015-12-12 14:20:12 +00:00
, SNICallback: le.sniCallback
2015-12-12 13:11:05 +00:00
});
tlsServer.on('request', app);
2015-12-12 15:05:45 +00:00
tlsServer.listen(tlsPort, function () {
2015-12-12 13:11:05 +00:00
console.log('Listening http', tlsServer.address());
});
2015-12-12 14:20:12 +00:00
le.register({
2015-12-12 13:11:05 +00:00
agreeTos: 'agree' === conf.agree
, domains: conf.domains.split(',')
, email: conf.email
}, function (err) {
2015-12-13 01:04:12 +00:00
if (err) {
console.error('[Error]: node-letsencrypt/examples/standalone');
console.error(err.stack);
} else {
console.log('success');
}
2015-12-12 13:11:05 +00:00
server.close();
tlsServer.close();
});