Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # SergAT (https://serg.at)
- import os, glob, time, random
- from datetime import datetime
- from OpenSSL import crypto as c
- RENEW_AT = 30
- RENEW_NOW = False
- CERT_LOCATION = '/etc/letsencrypt/live/'
- def cert_expiration_days(path):
- certificate = c.load_certificate(c.FILETYPE_PEM, file(path).read())
- cur_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
- exp_date = str(datetime.strptime(certificate.get_notAfter(),"%Y%m%d%H%M%SZ"))
- date_format = "%Y-%m-%d %H:%M:%S"
- a = datetime.strptime(cur_date, date_format)
- b = datetime.strptime(exp_date, date_format)
- delta = b - a
- return delta.days
- if os.path.exists(CERT_LOCATION):
- certs = glob.glob(CERT_LOCATION + '*')
- for cert_path in certs:
- if os.path.isfile(cert_path + '/cert.pem'):
- if RENEW_AT > cert_expiration_days(cert_path + '/cert.pem'):
- RENEW_NOW = True
- break
- if RENEW_NOW:
- time.sleep(random.randint(0,3600))
- os.system('/usr/bin/letsencrypt renew')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement