Parse acme.sh csv cert list to detect if a wildcard is available

This commit is contained in:
VirtuBox
2019-08-30 04:27:54 +02:00
parent 743aec2caa
commit 51b698988e
3 changed files with 43 additions and 2 deletions

View File

@@ -8,6 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### v3.9.x - [Unreleased] ### v3.9.x - [Unreleased]
#### Changed
- Date format in backup name : /backup/30Aug2019035932 -> /backup/30Aug2019-03-59-32
#### Fixed
- cache-enabler plugin not installed and configured with `wo site update site.tld --wpce`
### v3.9.8.5 - 2019-08-30 ### v3.9.8.5 - 2019-08-30
#### Changed #### Changed

View File

@@ -1539,7 +1539,7 @@ class WOSiteUpdateController(CementBaseController):
"enable_purge": 1, "enable_purge": 1,
"enable_map": "0", "enable_map": "0",
"enable_log": 0, "enable_log": 0,
"enable_stamp": 0, "enable_stamp": 1,
"purge_homepage_on_new": 1, "purge_homepage_on_new": 1,
"purge_homepage_on_edit": 1, "purge_homepage_on_edit": 1,
"purge_homepage_on_del": 1, "purge_homepage_on_del": 1,
@@ -1580,7 +1580,7 @@ class WOSiteUpdateController(CementBaseController):
"enable_purge": 1, "enable_purge": 1,
"enable_map": "0", "enable_map": "0",
"enable_log": 0, "enable_log": 0,
"enable_stamp": 0, "enable_stamp": 1,
"purge_homepage_on_new": 1, "purge_homepage_on_new": 1,
"purge_homepage_on_edit": 1, "purge_homepage_on_edit": 1,
"purge_homepage_on_del": 1, "purge_homepage_on_del": 1,

View File

@@ -6,6 +6,7 @@ import json
import re import re
import string import string
import subprocess import subprocess
import csv
from subprocess import CalledProcessError from subprocess import CalledProcessError
from wo.cli.plugins.sitedb import getSiteInfo from wo.cli.plugins.sitedb import getSiteInfo
@@ -1455,6 +1456,38 @@ def setupLetsEncrypt(self, wo_domain_name, subdomain=False, wildcard=False,
"you are running Let\'s Encrypt Client " "you are running Let\'s Encrypt Client "
"\n to allow it to verify the site automatically.") "\n to allow it to verify the site automatically.")
# check if a wildcard exist to secure a new subdomain
def checkWildcardExist(self, wo_domain_name):
wo_acme_exec = ("/etc/letsencrypt/acme.sh --config-home "
"'/etc/letsencrypt/config'")
try:
# export certificates list from acme.sh
WOShellExec.cmd_exec(self, "{0} ".format(wo_acme_exec) +
"--list --list-raw > /var/lib/wo/cert.csv")
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Failed to export cert list")
# define new csv dialect
csv.register_dialect('acmeconf', delimiter='|')
# open file
with open('/var/lib/wo/cert.csv', 'rt') as wo_cert:
reader = csv.reader(wo_cert, 'acmeconf')
wo_wildcard = "*.{0}".format(wo_domain_name)
try:
for row in reader:
if wo_wildcard in row[2]:
break
return True
else:
return False
except csv.Error as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Failed to read cert list")
# letsencrypt cert renewal # letsencrypt cert renewal