From c3076cfdfe0432db26e8de859739aa9d3db8a0f1 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Wed, 14 Oct 2020 15:29:06 +0200 Subject: [PATCH] Fix cert.csv encoding to utf-8 --- install | 2 +- setup.py | 2 +- wo/core/acme.py | 5 ++++- wo/core/fileutils.py | 25 +++++++++++++++++++++++++ wo/core/variables.py | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/install b/install index 4944fd3..6e57049 100755 --- a/install +++ b/install @@ -9,7 +9,7 @@ # ------------------------------------------------------------------------- # wget -qO wo wops.cc && sudo -E bash wo # ------------------------------------------------------------------------- -# Version 3.12.3 - 2020-10-13 +# Version 3.12.4 - 2020-10-14 # ------------------------------------------------------------------------- # CONTENTS diff --git a/setup.py b/setup.py index 090bd92..d60768b 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ if os.geteuid() == 0: os.makedirs('/var/lib/wo/tmp/') setup(name='wordops', - version='3.12.3', + version='3.12.4', description='An essential toolset that eases server administration', long_description=LONG, long_description_content_type='text/markdown', diff --git a/wo/core/acme.py b/wo/core/acme.py index cab1978..86de29e 100644 --- a/wo/core/acme.py +++ b/wo/core/acme.py @@ -206,12 +206,15 @@ class WOAcme: def cert_check(self, wo_domain_name): """Check certificate existance with acme.sh and return Boolean""" WOAcme.export_cert(self) + WOFileUtils.convertFileBestGuess(self, "cert.csv", + "/var/lib/wo/") # set variable acme_cert acme_cert = False # define new csv dialect csv.register_dialect('acmeconf', delimiter='|') # open file - certfile = open('/var/lib/wo/cert.csv', mode='r', encoding='utf-8') + certfile = open('/var/lib/wo/cert.csv', + mode='r', encoding='utf-8') reader = csv.reader(certfile, 'acmeconf') for row in reader: # check if domain exist diff --git a/wo/core/fileutils.py b/wo/core/fileutils.py index be676f0..ec03698 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -3,6 +3,7 @@ import fileinput import os import pwd import shutil +import codecs from wo.core.logging import Log @@ -385,3 +386,27 @@ class WOFileUtils(): return True else: return False + + def writeConversion(self, file): + with codecs.open('tmp' + '/' + file, 'w', 'utf-8') as targetFile: + for line in file: + targetFile.write(line) + + def convertFileBestGuess(self, filename, filepath): + """Convert file to utf-8""" + sourceFormats = ['ascii', 'iso-8859-1'] + for format in sourceFormats: + try: + os.chdir(filepath) + with codecs.open(filename, 'rU', format) as sourceFile: + self.writeConversion(sourceFile) + return + except UnicodeDecodeError: + pass + if os.path.exists("/tmp/{0}".format(filename)): + try: + self.rm(filepath + filename) + self.mvfile("/tmp/{0}".format(filename), filepath + filename) + except Exception as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to change owner : {0} ".format(path)) diff --git a/wo/core/variables.py b/wo/core/variables.py index 5661f29..7b80219 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -14,7 +14,7 @@ class WOVar(): """Intialization of core variables""" # WordOps version - wo_version = "3.12.3" + wo_version = "3.12.4" # WordOps packages versions wo_wp_cli = "2.4.0" wo_adminer = "4.7.5"