2015-12-16 11:01:10 +00:00
#!/usr/bin/env node
'use strict' ;
var cli = require ( 'cli' ) ;
2015-12-16 12:27:23 +00:00
var mkdirp = require ( 'mkdirp' ) ;
2015-12-16 11:01:10 +00:00
cli . parse ( {
2018-05-16 01:29:58 +00:00
'acme-version' :
[ false , " ACME / Let's Encrypt version. v01 or draft-11 (aka v02)" , 'string' , 'draft-11' ]
, 'acme-url' :
[ false , " ACME Directory Resource URL" , 'string' , '' ]
, email :
[ false , " Email used for registration and recovery contact. (default: null)" , 'email' ]
2015-12-16 11:01:10 +00:00
, 'agree-tos' : [ false , " Agree to the Let's Encrypt Subscriber Agreement" , 'boolean' , false ]
2018-05-16 01:29:58 +00:00
, 'community-member' : [ false , " Submit stats to and get updates from Greenlock" , 'boolean' , false ]
, domains :
[ false , " Domain names to apply. For multiple domains you can enter a comma separated list of domains as a parameter. (default: [])" , 'string' ]
2016-10-09 12:54:27 +00:00
, 'renew-within' : [ false , " Renew certificates this many days before expiry" , 'int' , 7 ]
2018-05-16 01:29:58 +00:00
, 'cert-path' :
[ false , " Path to where new cert.pem is saved" , 'string'
, ':configDir/live/:hostname/cert.pem' ]
, 'fullchain-path' :
[ false , " Path to where new fullchain.pem (cert + chain) is saved" , 'string'
, ':configDir/live/:hostname/fullchain.pem' ]
, 'bundle-path' :
[ false , " Path to where new bundle.pem (fullchain + privkey) is saved" , 'string'
, ':configDir/live/:hostname/bundle.pem' ]
, 'chain-path' :
[ false , " Path to where new chain.pem is saved" , 'string'
, ':configDir/live/:hostname/chain.pem' ]
, 'privkey-path' :
[ false , " Path to where privkey.pem is saved" , 'string'
, ':configDir/live/:hostname/privkey.pem' ]
, 'config-dir' :
[ false , " Configuration directory." , 'string'
, '~/letsencrypt/etc/' ]
2016-10-09 12:54:27 +00:00
, 'http-01-port' : [ false , " Use HTTP-01 challenge type with this port (only port 80 is valid with most production servers) (default: 80)" , 'int' ]
, 'dns-01' : [ false , " Use DNS-01 challange type" , 'boolean' , false ]
2015-12-16 12:51:14 +00:00
, standalone : [ false , " Obtain certs using a \"standalone\" webserver." , 'boolean' , false ]
2016-08-10 03:39:07 +00:00
, manual : [ false , " Print the token and key to the screen and wait for you to hit enter, giving you time to copy it somewhere before continuing (default: false)" , 'boolean' , false ]
2016-10-09 12:54:27 +00:00
, debug : [ false , " show traces and logs" , 'boolean' , false ]
2018-05-16 01:29:58 +00:00
, 'root' : [ false , " public_html / webroot path (may use the :hostname template such as /srv/www/:hostname)" , 'string' ]
//
// backwards compat
//
, duplicate :
[ false , " Allow getting a certificate that duplicates an existing one/is an early renewal" , 'boolean' , false ]
, 'rsa-key-size' :
[ false , " Size (in bits) of the RSA key." , 'int' , 2048 ]
, server :
[ false , " alias of acme-url for certbot compatibility" , 'string' , '' ]
, 'domain-key-path' :
[ false , " Path to privkey.pem to use for domain (default: generate new)" , 'string' ]
, 'account-key-path' :
[ false , " Path to privkey.pem to use for account (default: generate new)" , 'string' ]
, webroot : [ false , " for certbot compatibility" , 'boolean' , false ]
, 'webroot-path' : [ false , "alias of '--root' for certbot compatibility" , 'string' ]
//, 'standalone-supported-challenges': [ false, " Supported challenges, order preferences are randomly chosen. (default: http-01,tls-sni-01)", 'string', 'http-01,tls-sni-01']
, 'work-dir' : [ false , "for certbot compatibility (ignored)" , 'string' , '~/letsencrypt/var/lib/' ]
, 'logs-dir' : [ false , "for certbot compatibility (ignored)" , 'string' , '~/letsencrypt/var/log/' ]
2015-12-16 11:01:10 +00:00
} ) ;
2015-12-16 11:43:30 +00:00
// ignore certonly and extraneous arguments
cli . main ( function ( _ , options ) {
2015-12-17 09:16:43 +00:00
console . log ( '' ) ;
2015-12-16 11:43:30 +00:00
var args = { } ;
2018-05-16 01:29:58 +00:00
var homedir = require ( 'os' ) . homedir ( ) ;
2015-12-16 11:43:30 +00:00
Object . keys ( options ) . forEach ( function ( key ) {
var val = options [ key ] ;
if ( 'string' === typeof val ) {
val = val . replace ( /^~/ , homedir ) ;
}
key = key . replace ( /\-([a-z0-9A-Z])/g , function ( c ) { return c [ 1 ] . toUpperCase ( ) ; } ) ;
args [ key ] = val ;
} ) ;
Object . keys ( args ) . forEach ( function ( key ) {
var val = args [ key ] ;
if ( 'string' === typeof val ) {
2016-08-10 02:39:39 +00:00
val = val . replace ( /(\:configDir)|(\:config)/ , args . configDir ) ;
2015-12-16 11:43:30 +00:00
}
args [ key ] = val ;
} ) ;
2015-12-16 12:27:23 +00:00
if ( args . domains ) {
args . domains = args . domains . split ( ',' ) ;
2015-12-16 11:43:30 +00:00
}
2015-12-16 12:27:23 +00:00
2018-05-16 01:29:58 +00:00
if ( ! ( Array . isArray ( args . domains ) && args . domains . length ) || ! args . email || ! args . agreeTos || ! args . acmeVersion || ( ! args . server && ! args . acmeUrl ) ) {
console . error ( "\nUsage:\n\ngreenlock certonly --standalone \\" ) ;
console . error ( "\t--acme-version draft-11 --acme-url https://acme-staging-v02.api.letsencrypt.org/directory \\" ) ;
console . error ( "\t--agree-tos --email user@example.com --domains example.com \\" ) ;
console . error ( "\t--config-dir ~/acme/etc \\" ) ;
2017-01-25 21:42:01 +00:00
console . error ( "\nSee greenlock --help for more details\n" ) ;
2015-12-17 09:14:33 +00:00
return ;
}
2015-12-16 12:27:23 +00:00
if ( args . http01Port ) {
2015-12-28 15:56:46 +00:00
// [@agnat]: Coerce to string. cli returns a number although we request a string.
args . http01Port = "" + args . http01Port ;
2015-12-16 12:27:23 +00:00
args . http01Port = args . http01Port . split ( ',' ) . map ( function ( port ) {
return parseInt ( port , 10 ) ;
} ) ;
2015-12-16 11:43:30 +00:00
}
2015-12-16 12:27:23 +00:00
mkdirp ( args . configDir , function ( err ) {
2015-12-16 11:43:30 +00:00
if ( err ) {
2015-12-16 12:27:23 +00:00
console . error ( "Could not create --config-dir '" + args . configDir + "':" , err . code ) ;
console . error ( "Try setting --config-dir '/tmp'" ) ;
2015-12-16 11:43:30 +00:00
return ;
}
2017-04-16 21:09:23 +00:00
require ( '../' ) . run ( args ) . then ( function ( status ) {
process . exit ( status ) ;
} ) ;
2015-12-16 11:43:30 +00:00
} ) ;
2015-12-16 11:01:10 +00:00
} ) ;