mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +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 subprocess
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
try:
|
|
||||||
from loginSystem.models import Administrator
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
import os
|
import os
|
||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
@@ -29,7 +17,7 @@ class CyberCPLogFileWriter:
|
|||||||
CyberCPLogFileWriter.writeToFile(str(msg))
|
CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def writeToFile(message):
|
def writeToFile(message, email=None):
|
||||||
try:
|
try:
|
||||||
file = open(CyberCPLogFileWriter.fileName,'a')
|
file = open(CyberCPLogFileWriter.fileName,'a')
|
||||||
file.writelines("[" + time.strftime(
|
file.writelines("[" + time.strftime(
|
||||||
@@ -43,9 +31,10 @@ class CyberCPLogFileWriter:
|
|||||||
try:
|
try:
|
||||||
if os.path.exists(emailPath):
|
if os.path.exists(emailPath):
|
||||||
SUBJECT = "CyberPanel log reporting"
|
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())
|
sender = 'root@%s' % (socket.gethostname())
|
||||||
TO = [admin.email]
|
TO = [adminEmail]
|
||||||
message = """\
|
message = """\
|
||||||
From: %s
|
From: %s
|
||||||
To: %s
|
To: %s
|
||||||
@@ -54,6 +43,8 @@ Subject: %s
|
|||||||
%s
|
%s
|
||||||
""" % (
|
""" % (
|
||||||
sender, ", ".join(TO), SUBJECT, '[%s] %s. \n' % (time.strftime("%m.%d.%Y_%H-%M-%S"), message))
|
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)
|
CyberCPLogFileWriter.SendEmail(sender, TO, message)
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
file = open(CyberCPLogFileWriter.fileName, 'a')
|
file = open(CyberCPLogFileWriter.fileName, 'a')
|
||||||
@@ -99,5 +90,3 @@ Subject: %s
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
CyberCPLogFileWriter.writeToFile(str(msg) + ' [statusWriter]')
|
CyberCPLogFileWriter.writeToFile(str(msg) + ' [statusWriter]')
|
||||||
#print str(msg)
|
#print str(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ class Renew:
|
|||||||
## For websites
|
## For websites
|
||||||
|
|
||||||
for website in Websites.objects.all():
|
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)
|
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain)
|
||||||
|
|
||||||
if path.exists(filePath):
|
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,
|
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
|
||||||
open(filePath, 'r').read())
|
open(filePath, 'r').read())
|
||||||
expireData = x509.get_notAfter().decode('ascii')
|
expireData = x509.get_notAfter().decode('ascii')
|
||||||
@@ -36,37 +36,37 @@ class Renew:
|
|||||||
|
|
||||||
if int(diff.days) >= 15:
|
if int(diff.days) >= 15:
|
||||||
logging.writeToFile(
|
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':
|
elif x509.get_issuer().get_components()[1][1] == 'Denial':
|
||||||
logging.writeToFile(
|
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(
|
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),
|
virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain),
|
||||||
website.adminEmail)
|
website.adminEmail)
|
||||||
else:
|
else:
|
||||||
logging.writeToFile(
|
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(
|
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)
|
virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain), website.adminEmail)
|
||||||
else:
|
else:
|
||||||
logging.writeToFile(
|
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),
|
virtualHostUtilities.issueSSL(website.domain, '/home/%s/public_html' % (website.domain),
|
||||||
website.adminEmail)
|
website.adminEmail)
|
||||||
|
|
||||||
## For child-domains
|
## For child-domains
|
||||||
|
|
||||||
for website in ChildDomains.objects.all():
|
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)
|
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain)
|
||||||
|
|
||||||
if path.exists(filePath):
|
if path.exists(filePath):
|
||||||
logging.writeToFile(
|
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,
|
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
|
||||||
open(filePath, 'r').read())
|
open(filePath, 'r').read())
|
||||||
expireData = x509.get_notAfter().decode('ascii')
|
expireData = x509.get_notAfter().decode('ascii')
|
||||||
@@ -76,26 +76,26 @@ class Renew:
|
|||||||
|
|
||||||
if int(diff.days) >= 15:
|
if int(diff.days) >= 15:
|
||||||
logging.writeToFile(
|
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':
|
elif x509.get_issuer().get_components()[1][1] == 'Denial':
|
||||||
logging.writeToFile(
|
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(
|
logging.writeToFile(
|
||||||
'Renewing SSL for %s..' % (website.domain))
|
'Renewing SSL for %s..' % (website.domain), 0)
|
||||||
|
|
||||||
virtualHostUtilities.issueSSL(website.domain, website.path,
|
virtualHostUtilities.issueSSL(website.domain, website.path,
|
||||||
website.master.adminEmail)
|
website.master.adminEmail)
|
||||||
else:
|
else:
|
||||||
logging.writeToFile(
|
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(
|
logging.writeToFile(
|
||||||
'Renewing SSL for %s..' % (website.domain))
|
'Renewing SSL for %s..' % (website.domain), 0)
|
||||||
|
|
||||||
virtualHostUtilities.issueSSL(website.domain, website.path,
|
virtualHostUtilities.issueSSL(website.domain, website.path,
|
||||||
website.master.adminEmail)
|
website.master.adminEmail)
|
||||||
else:
|
else:
|
||||||
logging.writeToFile(
|
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,
|
virtualHostUtilities.issueSSL(website.domain, website.path,
|
||||||
website.master.adminEmail)
|
website.master.adminEmail)
|
||||||
|
|
||||||
|
|||||||
@@ -358,6 +358,13 @@ def saveModifications(request):
|
|||||||
|
|
||||||
user.save()
|
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'}
|
data_ret = {'status': 1, 'saveStatus': 1, 'error_message': 'None'}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user