mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 00:35:03 +02:00
git push origin masterMerge branch 'w0uld-argparse'
This commit is contained in:
@@ -29,21 +29,36 @@ conf layout.
|
||||
## Command line usage
|
||||
|
||||
```
|
||||
sudo ./letsencrypt.py (default authentication mode using pythondialog) options
|
||||
usage: sudo letsencrypt.py [-h] [-d DOMAIN [DOMAIN ...]] [-s SERVER] [-p PRIVKEY]
|
||||
[-c CSR] [-b ROLLBACK] [-k] [-v] [-r] [-n] [-e] [-t]
|
||||
[--test]
|
||||
|
||||
--text (text mode)
|
||||
--privkey= (specify privatekey file to use to generate the certificate)
|
||||
--csr= (Use a specific CSR. If this is specified, privkey must also be specified
|
||||
with the correct private key for the CSR)
|
||||
--server (list the ACME CA server address)
|
||||
--revoke (revoke a certificate)
|
||||
--view-checkpoints (Used to view available checkpoints and see what configuration
|
||||
changes have been made)
|
||||
--rollback=X (Revert the configuration X number of checkpoints)
|
||||
--redirect (Automatically redirect all HTTP traffic to HTTPS for the newly
|
||||
authenticated vhost)
|
||||
--no-redirect (Skip the HTTPS redirect question, allowing both HTTP and HTTPS)
|
||||
--agree-eula (Skip the end user agreement screen)
|
||||
An ACME client that can update Apache configurations.
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-d DOMAIN [DOMAIN ...], --domains DOMAIN [DOMAIN ...]
|
||||
-s SERVER, --server SERVER
|
||||
The ACME CA server address.
|
||||
-p PRIVKEY, --privkey PRIVKEY
|
||||
Path to the private key file for certificate
|
||||
generation.
|
||||
-c CSR, --csr CSR Path to the certificate signing request file
|
||||
corresponding to the private key file. The private key
|
||||
file argument is required if this argument is
|
||||
specified.
|
||||
-b ROLLBACK, --rollback ROLLBACK
|
||||
Revert configuration <ROLLBACK> number of checkpoints.
|
||||
-k, --revoke Revoke a certificate.
|
||||
-v, --view-checkpoints
|
||||
View checkpoints and associated configuration changes.
|
||||
-r, --redirect Automatically redirect all HTTP traffic to HTTPS for
|
||||
the newly authenticated vhost.
|
||||
-n, --no-redirect Skip the HTTPS redirect question, allowing both HTTP
|
||||
and HTTPS.
|
||||
-e, --agree-eula Skip the end user license agreement screen.
|
||||
-t, --text Use the text output instead of the curses UI.
|
||||
--test Run in test mode.
|
||||
```
|
||||
|
||||
## More Information
|
||||
|
||||
@@ -45,8 +45,8 @@ class Client(object):
|
||||
|
||||
self.server = ca_server
|
||||
|
||||
self.csr_file = cert_signing_request
|
||||
self.key_file = private_key
|
||||
self.csr_file = cert_signing_request.name
|
||||
self.key_file = private_key.name
|
||||
|
||||
# TODO: Figure out all exceptions from this function
|
||||
try:
|
||||
|
||||
+89
-95
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
"""Parse command line and call the appropriate functions."""
|
||||
import getopt
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -10,116 +10,110 @@ from letsencrypt.client import client
|
||||
from letsencrypt.client import display
|
||||
from letsencrypt.client import logger
|
||||
|
||||
logger.setLogger(logger.FileLogger(sys.stdout))
|
||||
logger.setLogLevel(logger.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
# Check to make sure user is root
|
||||
"""Command line argument parsing and main script execution."""
|
||||
if not os.geteuid() == 0:
|
||||
sys.exit("\nOnly root can run letsencrypt.\n")
|
||||
# Parse options
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "", ["text", "test",
|
||||
"view-checkpoints",
|
||||
"privkey=", "csr=",
|
||||
"server=", "rollback=",
|
||||
"revoke", "agree-eula",
|
||||
"redirect",
|
||||
"no-redirect",
|
||||
"help"])
|
||||
except getopt.GetoptError as err:
|
||||
# print help info and exit
|
||||
print str(err)
|
||||
usage()
|
||||
sys.exit(2)
|
||||
sys.exit(
|
||||
"{0}Root is required to run letsencrypt. Please use sudo.{0}"
|
||||
.format(os.linesep))
|
||||
|
||||
server = None
|
||||
csr = None
|
||||
privkey = None
|
||||
curses = True
|
||||
names = args
|
||||
flag_revoke = False
|
||||
redirect = None
|
||||
eula = False
|
||||
parser = argparse.ArgumentParser(
|
||||
description="An ACME client that can update Apache configurations.")
|
||||
|
||||
for o, a in opts:
|
||||
if o == "--text":
|
||||
curses = False
|
||||
elif o == "--csr":
|
||||
csr = a
|
||||
elif o == "--privkey":
|
||||
privkey = a
|
||||
elif o == "--server":
|
||||
server = a
|
||||
elif o == "--rollback":
|
||||
logger.setLogger(logger.FileLogger(sys.stdout))
|
||||
logger.setLogLevel(logger.INFO)
|
||||
config = apache_configurator.ApacheConfigurator()
|
||||
config.rollback_checkpoints(a)
|
||||
config.restart()
|
||||
sys.exit(0)
|
||||
elif o == "--view-checkpoints":
|
||||
logger.setLogger(logger.FileLogger(sys.stdout))
|
||||
logger.setLogLevel(logger.INFO)
|
||||
config = apache_configurator.ApacheConfigurator()
|
||||
config.display_checkpoints()
|
||||
sys.exit(0)
|
||||
elif o == "--revoke":
|
||||
# Do Stuff
|
||||
flag_revoke = True
|
||||
elif o == "--redirect":
|
||||
redirect = True
|
||||
elif o == "--no-redirect":
|
||||
redirect = False
|
||||
elif o == "--agree-eula":
|
||||
eula = True
|
||||
elif o == "--help":
|
||||
print_options()
|
||||
elif o == "--test":
|
||||
# put any temporary tests in here
|
||||
continue
|
||||
parser.add_argument("-d", "--domains", dest="domains", metavar="DOMAIN",
|
||||
nargs="+")
|
||||
parser.add_argument("-s", "--server", dest="server",
|
||||
help="The ACME CA server address.")
|
||||
parser.add_argument("-p", "--privkey", dest="privkey", type=file,
|
||||
help="Path to the private key file for certificate "
|
||||
"generation.")
|
||||
parser.add_argument("-c", "--csr", dest="csr", type=file,
|
||||
help="Path to the certificate signing request file "
|
||||
"corresponding to the private key file. The "
|
||||
"private key file argument is required if this "
|
||||
"argument is specified.")
|
||||
parser.add_argument("-b", "--rollback", dest="rollback", type=int,
|
||||
default=0,
|
||||
help="Revert configuration <ROLLBACK> number of "
|
||||
"checkpoints.")
|
||||
parser.add_argument("-k", "--revoke", dest="revoke", action="store_true",
|
||||
help="Revoke a certificate.")
|
||||
parser.add_argument("-v", "--view-checkpoints", dest="view_checkpoints",
|
||||
action="store_true",
|
||||
help="View checkpoints and associated configuration "
|
||||
"changes.")
|
||||
parser.add_argument("-r", "--redirect", dest="redirect",
|
||||
action="store_const", const=True,
|
||||
help="Automatically redirect all HTTP traffic to HTTPS "
|
||||
"for the newly authenticated vhost.")
|
||||
parser.add_argument("-n", "--no-redirect", dest="redirect",
|
||||
action="store_const", const=False,
|
||||
help="Skip the HTTPS redirect question, allowing both "
|
||||
"HTTP and HTTPS.")
|
||||
parser.add_argument("-e", "--agree-eula", dest="eula", action="store_true",
|
||||
help="Skip the end user license agreement screen.")
|
||||
parser.add_argument("-t", "--text", dest="curses", action="store_false",
|
||||
help="Use the text output instead of the curses UI.")
|
||||
parser.add_argument("--test", dest="test", action="store_true",
|
||||
help="Run in test mode.")
|
||||
|
||||
if curses:
|
||||
args = parser.parse_args()
|
||||
|
||||
# Enforce --privkey is set along with --csr.
|
||||
if args.csr and not args.privkey:
|
||||
parser.print_usage()
|
||||
parser.error("private key file (--privkey) must be specified along{}"
|
||||
"with the certificate signing request file (--csr)"
|
||||
.format(os.linesep))
|
||||
|
||||
if args.curses:
|
||||
display.set_display(display.NcursesDisplay())
|
||||
else:
|
||||
display.set_display(display.FileDisplay(sys.stdout))
|
||||
|
||||
if not server:
|
||||
server = CONFIG.ACME_SERVER
|
||||
if args.rollback > 0:
|
||||
rollback(apache_configurator.ApacheConfigurator(), args.rollback)
|
||||
sys.exit()
|
||||
|
||||
c = client.Client(server, csr, privkey, curses)
|
||||
if flag_revoke:
|
||||
c.list_certs_keys()
|
||||
if args.view_checkpoints:
|
||||
view_checkpoints(apache_configurator.ApacheConfigurator())
|
||||
sys.exit()
|
||||
|
||||
server = args.server is None and CONFIG.ACME_SERVER or args.server
|
||||
|
||||
acme = client.Client(server, args.csr, args.privkey, args.curses)
|
||||
if args.revoke:
|
||||
acme.list_certs_keys()
|
||||
else:
|
||||
c.authenticate(args, redirect, eula)
|
||||
acme.authenticate(args.domains, args.redirect, args.eula)
|
||||
|
||||
|
||||
def usage():
|
||||
s = "Available options: --text, --privkey=, --csr=, --server=, "
|
||||
s += "--rollback=, --view-checkpoints, --revoke, --agree-eula, --redirect,"
|
||||
s += " --no-redirect, --help"
|
||||
print s
|
||||
def rollback(config, checkpoints):
|
||||
"""Revert configuration the specified number of checkpoints.
|
||||
|
||||
:param config: Configurator object
|
||||
:type config: ApacheConfigurator
|
||||
|
||||
:param checkpoints: Number of checkpoints to revert.
|
||||
:type checkpoints: int
|
||||
|
||||
"""
|
||||
config.rollback_checkpoints(checkpoints)
|
||||
config.restart()
|
||||
|
||||
|
||||
def print_options():
|
||||
print ("\nsudo ./letsencrypt.py "
|
||||
"(default authentication mode using pythondialog)")
|
||||
options = ("privkey= (specify key file to use to generate the "
|
||||
"certificate)",
|
||||
"csr= (Use a specific CSR. If this is specified, privkey "
|
||||
"must also be specified with the correct"
|
||||
" private key for the CSR)",
|
||||
"server (list the ACME CA server address)",
|
||||
"revoke (revoke a certificate)",
|
||||
"view-checkpoints (Used to view available checkpoints and "
|
||||
"see what configuration changes have been made)",
|
||||
"rollback=X (Revert the configuration X number of checkpoints)",
|
||||
"redirect (Automatically redirect all HTTP traffic to "
|
||||
"HTTPS for the newly authenticated vhost)",
|
||||
"no-redirect (Skip the HTTPS redirect question, "
|
||||
"allowing both HTTP and HTTPS)",
|
||||
"agree-eula (Skip the end user agreement screen))")
|
||||
for o in options:
|
||||
print " --%s" % o
|
||||
sys.exit(0)
|
||||
def view_checkpoints(config):
|
||||
"""View checkpoints and associated configuration changes.
|
||||
|
||||
:param config: Configurator object
|
||||
:type config: ApacheConfigurator
|
||||
|
||||
"""
|
||||
config.display_checkpoints()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,3 +3,4 @@ python2-pythondialog
|
||||
jsonschema==2.4.0
|
||||
python-augeas==0.5.0
|
||||
requests==2.4.3
|
||||
argparse==1.2.2
|
||||
|
||||
Reference in New Issue
Block a user