Files
WPIQ/wo/core/sslutils.py

52 lines
2.0 KiB
Python
Raw Normal View History

2018-11-13 21:55:59 +01:00
import os
2019-09-03 19:02:00 +02:00
2018-11-13 21:55:59 +01:00
from wo.core.logging import Log
2019-09-03 19:02:00 +02:00
from wo.core.shellexec import WOShellExec
2018-11-13 21:55:59 +01:00
class SSL:
2019-03-16 10:30:52 +01:00
def getExpirationDays(self, domain, returnonerror=False):
2018-11-13 21:55:59 +01:00
# check if exist
if not os.path.isfile('/etc/letsencrypt/live/{0}/cert.pem'
2019-03-16 10:30:52 +01:00
.format(domain)):
2019-04-08 13:01:13 +02:00
Log.error(self, 'File Not Found: '
'/etc/letsencrypt/live/{0}/cert.pem'
2019-03-16 10:30:52 +01:00
.format(domain), False)
2018-11-13 21:55:59 +01:00
if returnonerror:
return -1
Log.error(self, "Check the WordOps log for more details "
"`tail /var/log/wo/wordops.log` and please try again...")
current_date = WOShellExec.cmd_exec_stdout(self, "date -d \"now\" +%s")
2019-09-03 19:02:00 +02:00
expiration_date = WOShellExec.cmd_exec_stdout(
self, "date -d \""
"$(openssl x509 -in /etc/letsencrypt/live/"
"{0}/cert.pem -text -noout | grep \"Not After\" "
"| cut -c 25-)\" +%s"
.format(domain))
2018-11-13 21:55:59 +01:00
2019-03-16 10:30:52 +01:00
days_left = int((int(expiration_date) - int(current_date)) / 86400)
2018-11-13 21:55:59 +01:00
if (days_left > 0):
return days_left
else:
# return "Certificate Already Expired ! Please Renew soon."
return -1
2019-03-16 10:30:52 +01:00
def getExpirationDate(self, domain):
2018-11-13 21:55:59 +01:00
# check if exist
if not os.path.isfile('/etc/letsencrypt/live/{0}/cert.pem'
2019-03-16 10:30:52 +01:00
.format(domain)):
2019-04-08 13:01:13 +02:00
Log.error(self, 'File Not Found: /etc/letsencrypt/'
'live/{0}/cert.pem'
2019-03-16 10:30:52 +01:00
.format(domain), False)
2018-11-13 21:55:59 +01:00
Log.error(self, "Check the WordOps log for more details "
"`tail /var/log/wo/wordops.log` and please try again...")
2019-09-03 19:02:00 +02:00
expiration_date = WOShellExec.cmd_exec_stdout(
self, "date -d \"$(/usr/bin/openssl x509 -in "
"/etc/letsencrypt/live/{0}/cert.pem -text -noout | grep "
"\"Not After\" | cut -c 25-)\" "
.format(domain))
2018-11-13 21:55:59 +01:00
return expiration_date