mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 05:45:59 +01:00
bug fix: email reporting
This commit is contained in:
@@ -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,6 +43,8 @@ Subject: %s
|
||||
%s
|
||||
""" % (
|
||||
sender, ", ".join(TO), SUBJECT, '[%s] %s. \n' % (time.strftime("%m.%d.%Y_%H-%M-%S"), message))
|
||||
|
||||
if email == None or email == 1:
|
||||
CyberCPLogFileWriter.SendEmail(sender, TO, message)
|
||||
except BaseException as msg:
|
||||
file = open(CyberCPLogFileWriter.fileName, 'a')
|
||||
@@ -99,5 +90,3 @@ Subject: %s
|
||||
except BaseException as msg:
|
||||
CyberCPLogFileWriter.writeToFile(str(msg) + ' [statusWriter]')
|
||||
#print str(msg)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user