diff --git a/plogical/CyberCPLogFileWriter.py b/plogical/CyberCPLogFileWriter.py index 4bfe86a46..c0616ad94 100755 --- a/plogical/CyberCPLogFileWriter.py +++ b/plogical/CyberCPLogFileWriter.py @@ -1,18 +1,6 @@ -import os,sys -sys.path.append('/usr/local/CyberCP') -import django -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") -try: - django.setup() -except: - pass import subprocess import time import socket -try: - from loginSystem.models import Administrator -except: - pass import os import smtplib @@ -29,7 +17,7 @@ class CyberCPLogFileWriter: CyberCPLogFileWriter.writeToFile(str(msg)) @staticmethod - def writeToFile(message): + def writeToFile(message, email=None): try: file = open(CyberCPLogFileWriter.fileName,'a') file.writelines("[" + time.strftime( @@ -43,9 +31,10 @@ class CyberCPLogFileWriter: try: if os.path.exists(emailPath): SUBJECT = "CyberPanel log reporting" - admin = Administrator.objects.get(userName='admin') + adminEmailPath = '/home/cyberpanel/adminEmail' + adminEmail = open(adminEmailPath, 'r').read().rstrip('\n') sender = 'root@%s' % (socket.gethostname()) - TO = [admin.email] + TO = [adminEmail] message = """\ From: %s To: %s @@ -54,7 +43,9 @@ Subject: %s %s """ % ( sender, ", ".join(TO), SUBJECT, '[%s] %s. \n' % (time.strftime("%m.%d.%Y_%H-%M-%S"), message)) - CyberCPLogFileWriter.SendEmail(sender, TO, message) + + if email == None or email == 1: + CyberCPLogFileWriter.SendEmail(sender, TO, message) except BaseException as msg: file = open(CyberCPLogFileWriter.fileName, 'a') file.writelines("[" + time.strftime( @@ -98,6 +89,4 @@ Subject: %s print((mesg + '\n')) except BaseException as msg: CyberCPLogFileWriter.writeToFile(str(msg) + ' [statusWriter]') - #print str(msg) - - + #print str(msg) \ No newline at end of file diff --git a/plogical/renew.py b/plogical/renew.py index 70d43bd29..ec1c8535f 100644 --- a/plogical/renew.py +++ b/plogical/renew.py @@ -22,11 +22,11 @@ class Renew: ## For websites for website in Websites.objects.all(): - logging.writeToFile('Checking SSL for %s.' % (website.domain)) + logging.writeToFile('Checking SSL for %s.' % (website.domain), 0) filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain) if path.exists(filePath): - logging.writeToFile('SSL exists for %s. Checking if SSL will expire in 15 days..' % (website.domain)) + logging.writeToFile('SSL exists for %s. Checking if SSL will expire in 15 days..' % (website.domain), 0) x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(filePath, 'r').read()) expireData = x509.get_notAfter().decode('ascii') @@ -36,37 +36,37 @@ class Renew: if int(diff.days) >= 15: logging.writeToFile( - 'SSL exists for %s and is not ready to renew, skipping..' % (website.domain)) + 'SSL exists for %s and is not ready to renew, skipping..' % (website.domain), 0) elif x509.get_issuer().get_components()[1][1] == 'Denial': logging.writeToFile( - 'SSL exists for %s and ready to renew..' % (website.domain)) + 'SSL exists for %s and ready to renew..' % (website.domain), 0) logging.writeToFile( - 'Renewing SSL for %s..' % (website.domain)) + 'Renewing SSL for %s..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain), website.adminEmail) else: logging.writeToFile( - 'SSL exists for %s and ready to renew..' % (website.domain)) + 'SSL exists for %s and ready to renew..' % (website.domain), 0) logging.writeToFile( - 'Renewing SSL for %s..' % (website.domain)) + 'Renewing SSL for %s..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain), website.adminEmail) else: logging.writeToFile( - 'SSL does not exist for %s. Obtaining now..' % (website.domain)) + 'SSL does not exist for %s. Obtaining now..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain), website.adminEmail) ## For child-domains for website in ChildDomains.objects.all(): - logging.writeToFile('Checking SSL for %s.' % (website.domain)) + logging.writeToFile('Checking SSL for %s.' % (website.domain), 0) filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain) if path.exists(filePath): logging.writeToFile( - 'SSL exists for %s. Checking if SSL will expire in 15 days..' % (website.domain)) + 'SSL exists for %s. Checking if SSL will expire in 15 days..' % (website.domain), 0) x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(filePath, 'r').read()) expireData = x509.get_notAfter().decode('ascii') @@ -76,26 +76,26 @@ class Renew: if int(diff.days) >= 15: logging.writeToFile( - 'SSL exists for %s and is not ready to renew, skipping..' % (website.domain)) + 'SSL exists for %s and is not ready to renew, skipping..' % (website.domain), 0) elif x509.get_issuer().get_components()[1][1] == 'Denial': logging.writeToFile( - 'SSL exists for %s and ready to renew..' % (website.domain)) + 'SSL exists for %s and ready to renew..' % (website.domain), 0) logging.writeToFile( - 'Renewing SSL for %s..' % (website.domain)) + 'Renewing SSL for %s..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, website.path, website.master.adminEmail) else: logging.writeToFile( - 'SSL exists for %s and ready to renew..' % (website.domain)) + 'SSL exists for %s and ready to renew..' % (website.domain), 0) logging.writeToFile( - 'Renewing SSL for %s..' % (website.domain)) + 'Renewing SSL for %s..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, website.path, website.master.adminEmail) else: logging.writeToFile( - 'SSL does not exist for %s. Obtaining now..' % (website.domain)) + 'SSL does not exist for %s. Obtaining now..' % (website.domain), 0) virtualHostUtilities.issueSSL(website.domain, website.path, website.master.adminEmail) diff --git a/userManagment/views.py b/userManagment/views.py index 09aa15877..9511a7c2c 100755 --- a/userManagment/views.py +++ b/userManagment/views.py @@ -358,6 +358,13 @@ def saveModifications(request): user.save() + adminEmailPath = '/home/cyberpanel/adminEmail' + + if accountUsername == 'admin': + writeToFile = open(adminEmailPath, 'w') + writeToFile.write(email) + writeToFile.close() + data_ret = {'status': 1, 'saveStatus': 1, 'error_message': 'None'} json_data = json.dumps(data_ret) return HttpResponse(json_data)