mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-27 01:39:03 +01:00
some changes
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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, '', '')
|
||||
|
||||
Reference in New Issue
Block a user