From a41e52bef6c4af62f06653ce486b993fc2cae9c4 Mon Sep 17 00:00:00 2001 From: "usman@cyberpersons.com" Date: Fri, 17 Mar 2023 13:58:10 +0500 Subject: [PATCH] some changes --- plogical/Backupsv2.py | 19 +++++++++++++++---- plogical/renew.py | 11 +++++++++-- plogical/sslUtilities.py | 15 +++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/plogical/Backupsv2.py b/plogical/Backupsv2.py index 97ed4bd5a..605f09373 100644 --- a/plogical/Backupsv2.py +++ b/plogical/Backupsv2.py @@ -18,9 +18,9 @@ except: pass from plogical.processUtilities import ProcessUtilities +import threading as multi - -class CPBackupsV2: +class CPBackupsV2(multi.Thread): PENDING_START = 0 RUNNING = 1 COMPLETED = 2 @@ -36,8 +36,11 @@ class CPBackupsV2: command = 'rclone obscure hosting' def __init__(self, data): + multi.Thread.__init__(self) self.data = data + self.function = data['function'] + ### set self.website as it is needed in many functions from websiteFunctions.models import Websites self.website = Websites.objects.get(domain=self.data['domain']) @@ -53,10 +56,18 @@ class CPBackupsV2: self.snapshots = [] + ## self.StatusFile = f'/home/cyberpanel/{self.website.domain}_rustic_backup_log' + def run(self): + try: + if self.function == 'InitiateBackup': + self.InitiateBackup() + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CPBackupsV2.run]') + def FetchSnapShots(self): try: command = f'rustic -r {self.repo} snapshots --password "" --json 2>/dev/null' @@ -145,14 +156,14 @@ token = {token} file = open(self.StatusFile, 'a') file.writelines("[" + time.strftime( - "%m.%d.%Y_%H-%M-%S") + ":FAILED] " + message + "\n") + "%m.%d.%Y_%H-%M-%S") + ":FAILED] " + message + "[404]" +"\n") file.close() elif status == CPBackupsV2.COMPLETED: self.website.BackupLock = 0 self.website.save() file = open(self.StatusFile, 'a') file.writelines("[" + time.strftime( - "%m.%d.%Y_%H-%M-%S") + ":COMPLETED] " + message + "\n") + "%m.%d.%Y_%H-%M-%S") + ":COMPLETED] " + message + "[200]" +"\n") file.close() else: file = open(self.StatusFile, 'a') diff --git a/plogical/renew.py b/plogical/renew.py index 040d081e7..512514e39 100644 --- a/plogical/renew.py +++ b/plogical/renew.py @@ -81,10 +81,14 @@ class Renew: now = datetime.now() diff = finalDate - now - if int(diff.days) >= 15: + SSLProvider = x509.get_issuer().get_components()[1][1] + + print(f"Provider: {x509.get_issuer().get_components()[1][1].decode('utf-8')}, Days : {diff.days}") + + if int(diff.days) >= 15 and SSLProvider != 'Denial': logging.writeToFile( 'SSL exists for %s and is not ready to renew, skipping..' % (website.domain), 0) - elif x509.get_issuer().get_components()[1][1] == 'Denial': + elif SSLProvider == 'Denial': logging.writeToFile( 'SSL exists for %s and ready to renew..' % (website.domain), 0) logging.writeToFile( @@ -92,6 +96,9 @@ class Renew: virtualHostUtilities.issueSSL(website.domain, website.path, website.master.adminEmail) + elif SSLProvider != "Let's Encrypt": + logging.writeToFile( + 'Custom SSL exists for %s and ready to renew..' % (website.domain), 1) else: logging.writeToFile( 'SSL exists for %s and ready to renew..' % (website.domain), 0) diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index 81bfb31c8..eefc2f167 100755 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -392,9 +392,9 @@ class sslUtilities: command = acmePath + " --issue -d " + virtualHostName + " -d www." + virtualHostName \ + ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w /usr/local/lsws/Example/html -k ec-256 --force --server letsencrypt' - ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read() - CurrentMessage = "Trying to obtain SSL for: " + virtualHostName + " and: www." + virtualHostName - if (WWWStatus and NONWWWStatus) or ResultText.find(CurrentMessage) == -1: + #ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read() + #CurrentMessage = "Trying to obtain SSL for: " + virtualHostName + " and: www." + virtualHostName + if (WWWStatus and NONWWWStatus): #logging.CyberCPLogFileWriter.writeToFile(CurrentMessage, 0) @@ -419,17 +419,20 @@ class sslUtilities: + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w /usr/local/lsws/Example/html -k ec-256 --force --server letsencrypt' - ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read() + #ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read() CurrentMessage = '%s\nTrying to obtain SSL for: %s' % (finalText, virtualHostName) - if NONWWWStatus or ResultText.find(CurrentMessage) == -1: + if NONWWWStatus: finalText = '%s\nTrying to obtain SSL for: %s' % (finalText, virtualHostName) logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName, 0) + logging.CyberCPLogFileWriter.writeToFile(command) output = subprocess.check_output(shlex.split(command)).decode("utf-8") - logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName, 0) + logging.CyberCPLogFileWriter.writeToFile( + "Successfully obtained SSL for: " + virtualHostName, 0) finalText = '%s\nSuccessfully obtained SSL for: %s.' % (finalText, virtualHostName) logging.CyberCPLogFileWriter.SendEmail(sender_email, adminEmail, finalText, 'SSL Notification for %s.' % (virtualHostName)) + else: logging.CyberCPLogFileWriter.writeToFile(command, 0) raise subprocess.CalledProcessError(0, '', '')