2018-10-31 19:17:23 +02:00
|
|
|
#!/usr/bin/python3
|
2017-09-24 17:50:10 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
command = [
|
|
|
|
"certbot",
|
|
|
|
"-n", "--agree-tos", # non-interactive
|
|
|
|
"-d", os.environ["HOSTNAMES"],
|
|
|
|
"-m", "{}@{}".format(os.environ["POSTMASTER"], os.environ["DOMAIN"]),
|
|
|
|
"certonly", "--standalone",
|
|
|
|
"--cert-name", "mailu",
|
2017-11-01 16:24:22 +02:00
|
|
|
"--preferred-challenges", "http", "--http-01-port", "8008",
|
2017-09-24 17:50:10 +02:00
|
|
|
"--keep-until-expiring",
|
2021-08-09 21:06:15 +02:00
|
|
|
"--config-dir", "/certs/letsencrypt",
|
|
|
|
"--post-hook", "/config.py"
|
|
|
|
]
|
|
|
|
command2 = [
|
|
|
|
"certbot",
|
|
|
|
"-n", "--agree-tos", # non-interactive
|
|
|
|
"-d", os.environ["HOSTNAMES"],
|
|
|
|
"-m", "{}@{}".format(os.environ["POSTMASTER"], os.environ["DOMAIN"]),
|
|
|
|
"certonly", "--standalone",
|
|
|
|
"--cert-name", "mailu-ecdsa",
|
|
|
|
"--preferred-challenges", "http", "--http-01-port", "8008",
|
|
|
|
"--keep-until-expiring",
|
|
|
|
"--key-type", "ecdsa",
|
2017-09-24 17:50:10 +02:00
|
|
|
"--config-dir", "/certs/letsencrypt",
|
|
|
|
"--post-hook", "/config.py"
|
|
|
|
]
|
|
|
|
|
2021-08-09 22:51:23 +02:00
|
|
|
def format_for_nginx(fullchain, output):
|
2021-08-10 12:19:51 +02:00
|
|
|
""" We may want to strip ISRG Root X1 out
|
2021-08-09 22:51:23 +02:00
|
|
|
"""
|
|
|
|
certs = []
|
|
|
|
with open(fullchain, 'r') as pem:
|
|
|
|
cert = ''
|
|
|
|
for line in pem:
|
|
|
|
cert += line
|
|
|
|
if '-----END CERTIFICATE-----' in line:
|
|
|
|
certs += [cert]
|
|
|
|
cert = ''
|
|
|
|
with open(output, 'w') as pem:
|
2021-08-10 12:19:51 +02:00
|
|
|
for cert in certs[:-1] if len(certs)>2 and os.getenv('LETSENCRYPT_SHORTCHAIN', default="False") else certs:
|
2021-08-09 22:51:23 +02:00
|
|
|
pem.write(cert)
|
|
|
|
|
2017-09-24 17:50:10 +02:00
|
|
|
# Wait for nginx to start
|
|
|
|
time.sleep(5)
|
|
|
|
|
2021-08-14 15:04:02 +02:00
|
|
|
# Run certbot every day
|
2017-09-24 17:50:10 +02:00
|
|
|
while True:
|
|
|
|
subprocess.call(command)
|
2021-08-09 22:51:23 +02:00
|
|
|
format_for_nginx('/certs/letsencrypt/live/mailu/fullchain.pem', '/certs/letsencrypt/live/mailu/nginx-chain.pem')
|
2021-08-09 21:06:15 +02:00
|
|
|
subprocess.call(command2)
|
2021-08-09 22:51:23 +02:00
|
|
|
format_for_nginx('/certs/letsencrypt/live/mailu-ecdsa/fullchain.pem', '/certs/letsencrypt/live/mailu-ecdsa/nginx-chain.pem')
|
2017-09-24 17:50:10 +02:00
|
|
|
time.sleep(3600)
|
|
|
|
|