parent
6a3c7619a8
commit
42a2611ac4
|
|
@ -18,6 +18,7 @@ from googleapiclient.discovery import build
|
|||
from googleapiclient.http import MediaFileUpload
|
||||
from plogical.backupSchedule import backupSchedule
|
||||
import requests
|
||||
import socket
|
||||
from websiteFunctions.models import NormalBackupJobs, NormalBackupJobLogs
|
||||
from boto3.s3.transfer import TransferConfig
|
||||
|
||||
|
|
@ -31,6 +32,7 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
|
||||
class IncScheduler():
|
||||
logPath = '/home/cyberpanel/incbackuplogs'
|
||||
gitFolder = '/home/cyberpanel/git'
|
||||
|
|
@ -116,7 +118,7 @@ class IncScheduler():
|
|||
|
||||
message = '[%s Cron] Checking if %s has any pending commits on %s.' % (type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
finalText = '%s\n' % (message)
|
||||
GitLogs(owner=web, type='INFO', message = message).save()
|
||||
GitLogs(owner=web, type='INFO', message=message).save()
|
||||
|
||||
finalPathInside = '%s/%s' % (IncScheduler.gitFolder, website)
|
||||
|
||||
|
|
@ -165,7 +167,6 @@ class IncScheduler():
|
|||
message = 'File: %s, Status: %s' % (file, str(msg))
|
||||
finalText = '%s\n%s' % (finalText, message)
|
||||
|
||||
|
||||
message = '[%s Cron] Finished checking for %s on %s.' % (type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
|
||||
finalText = '%s\n%s' % (finalText, message)
|
||||
logging.SendEmail(web.adminEmail, web.adminEmail, finalText, 'Git report for %s.' % (web.domain))
|
||||
|
|
@ -176,6 +177,7 @@ class IncScheduler():
|
|||
|
||||
@staticmethod
|
||||
def checkDiskUsage():
|
||||
sender_email = 'root@%s' % (socket.gethostname())
|
||||
|
||||
try:
|
||||
|
||||
|
|
@ -188,21 +190,21 @@ class IncScheduler():
|
|||
from plogical.acl import ACLManager
|
||||
message = '%s - Disk Usage Warning - CyberPanel' % (ACLManager.fetchIP())
|
||||
|
||||
if diskUsage >= 50 and diskUsage <= 60 :
|
||||
if diskUsage >= 50 and diskUsage <= 60:
|
||||
|
||||
finalText = 'Current disk usage at "/" is %s percent. No action required.' % (str(diskUsage))
|
||||
logging.SendEmail(admin.email, admin.email, finalText, message)
|
||||
logging.SendEmail(sender_email, admin.email, finalText, message)
|
||||
|
||||
elif diskUsage >= 60 and diskUsage <= 80:
|
||||
|
||||
finalText = 'Current disk usage at "/" is %s percent. We recommend clearing log directory by running \n\n rm -rf /usr/local/lsws/logs/*. \n\n When disk usage go above 80 percent we will automatically run this command.' % (str(diskUsage))
|
||||
logging.SendEmail(admin.email, admin.email, finalText, message)
|
||||
logging.SendEmail(sender_email, admin.email, finalText, message)
|
||||
|
||||
elif diskUsage > 80:
|
||||
|
||||
finalText = 'Current disk usage at "/" is %s percent. We are going to run below command to free up space, If disk usage is still high, manual action is required by the system administrator. \n\n rm -rf /usr/local/lsws/logs/*.' % (
|
||||
str(diskUsage))
|
||||
logging.SendEmail(admin.email, admin.email, finalText, message)
|
||||
logging.SendEmail(sender_email, admin.email, finalText, message)
|
||||
|
||||
command = 'rm -rf /usr/local/lsws/logs/*'
|
||||
import subprocess
|
||||
|
|
@ -225,7 +227,6 @@ class IncScheduler():
|
|||
credentials = google.oauth2.credentials.Credentials(gDriveData['token'], gDriveData['refresh_token'],
|
||||
gDriveData['token_uri'], None, None, gDriveData['scopes'])
|
||||
|
||||
|
||||
drive = build('drive', 'v3', credentials=credentials)
|
||||
drive.files().list(pageSize=10, fields="files(id, name)").execute()
|
||||
except BaseException as msg:
|
||||
|
|
@ -349,7 +350,6 @@ class IncScheduler():
|
|||
GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
|
||||
message='[Site] Site backup failed, Error message: %s.' % (str(msg))).save()
|
||||
|
||||
|
||||
GDriveJobLogs(owner=items, status=backupSchedule.INFO,
|
||||
message='Job Completed').save()
|
||||
except BaseException as msg:
|
||||
|
|
@ -374,7 +374,6 @@ class IncScheduler():
|
|||
## {"frequency": "Daily", "allSites": "Selected Only"}
|
||||
## {"frequency": "Daily"}
|
||||
|
||||
|
||||
for backupjob in NormalBackupJobs.objects.all():
|
||||
|
||||
jobConfig = json.loads(backupjob.config)
|
||||
|
|
@ -436,7 +435,6 @@ class IncScheduler():
|
|||
else:
|
||||
domain = site.domain.domain
|
||||
|
||||
|
||||
## Save currently backing domain in db, so that i can restart from here when prematurely killed
|
||||
|
||||
jobConfig['website'] = domain
|
||||
|
|
@ -634,7 +632,6 @@ Automatic backup failed for %s on %s.
|
|||
def forceRunAWSBackup(planName):
|
||||
try:
|
||||
|
||||
|
||||
plan = BackupPlan.objects.get(name=planName)
|
||||
bucketName = plan.bucket.strip('\n').strip(' ')
|
||||
runTime = time.strftime("%d:%m:%Y")
|
||||
|
|
@ -685,8 +682,8 @@ Automatic backup failed for %s on %s.
|
|||
else:
|
||||
client = boto3.client(
|
||||
's3',
|
||||
aws_access_key_id = aws_access_key_id,
|
||||
aws_secret_access_key = aws_secret_access_key,
|
||||
aws_access_key_id=aws_access_key_id,
|
||||
aws_secret_access_key=aws_secret_access_key,
|
||||
)
|
||||
|
||||
##
|
||||
|
|
@ -740,7 +737,6 @@ Automatic backup failed for %s on %s.
|
|||
BackupLogs(owner=plan, level='INFO', timeStamp=time.strftime("%b %d %Y, %H:%M:%S"),
|
||||
msg='Backup Process Finished.').save()
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
logging.writeToFile(str(msg) + ' [S3Backups.runBackupPlan]')
|
||||
plan = BackupPlan.objects.get(name=planName)
|
||||
|
|
@ -842,4 +838,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
|
||||
class sslUtilities:
|
||||
|
||||
Server_root = "/usr/local/lsws"
|
||||
|
|
@ -22,7 +23,7 @@ class sslUtilities:
|
|||
sslCheck = 0
|
||||
|
||||
for items in data:
|
||||
if items.find("listener") >-1 and items.find("SSL") > -1:
|
||||
if items.find("listener") > - 1 and items.find("SSL") > -1:
|
||||
sslCheck = 1
|
||||
continue
|
||||
if sslCheck == 1:
|
||||
|
|
@ -71,7 +72,6 @@ class sslUtilities:
|
|||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile('%s [installSSLForDomain:72]' % (str(msg)))
|
||||
|
||||
|
||||
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||
confPath = sslUtilities.Server_root + "/conf/vhosts/" + virtualHostName
|
||||
completePathToConfigFile = confPath + "/vhost.conf"
|
||||
|
|
@ -118,7 +118,6 @@ class sslUtilities:
|
|||
writeDataToFile.writelines("\n")
|
||||
writeDataToFile.close()
|
||||
|
||||
|
||||
else:
|
||||
|
||||
if sslUtilities.checkIfSSLMap(virtualHostName) == 0:
|
||||
|
|
@ -273,9 +272,10 @@ class sslUtilities:
|
|||
ProcessUtilities.executioner(command)
|
||||
return 1
|
||||
|
||||
|
||||
@staticmethod
|
||||
def obtainSSLForADomain(virtualHostName,adminEmail,sslpath, aliasDomain = None):
|
||||
def obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain=None):
|
||||
sender_email = 'root@%s' % (socket.gethostname())
|
||||
|
||||
try:
|
||||
acmePath = '/root/.acme.sh/acme.sh'
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ class sslUtilities:
|
|||
# if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
# acmePath = '/home/cyberpanel/.acme.sh/acme.sh'
|
||||
|
||||
if aliasDomain == None:
|
||||
if aliasDomain is None:
|
||||
|
||||
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName
|
||||
if not os.path.exists(existingCertPath):
|
||||
|
|
@ -306,8 +306,7 @@ class sslUtilities:
|
|||
output = subprocess.check_output(shlex.split(command)).decode("utf-8")
|
||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName + " and: www." + virtualHostName, 0)
|
||||
|
||||
logging.CyberCPLogFileWriter.SendEmail(adminEmail, adminEmail, output, 'SSL Notification for %s.' % (virtualHostName))
|
||||
|
||||
logging.CyberCPLogFileWriter.SendEmail(sender_email, adminEmail, output, 'SSL Notification for %s.' % (virtualHostName))
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
|
|
@ -324,11 +323,11 @@ class sslUtilities:
|
|||
output = subprocess.check_output(shlex.split(command)).decode("utf-8")
|
||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName, 0)
|
||||
finalText = '%s\nSuccessfully obtained SSL for: %s.' % (finalText, virtualHostName)
|
||||
logging.CyberCPLogFileWriter.SendEmail(adminEmail, adminEmail, finalText,
|
||||
logging.CyberCPLogFileWriter.SendEmail(sender_email, adminEmail, finalText,
|
||||
'SSL Notification for %s.' % (virtualHostName))
|
||||
except subprocess.CalledProcessError:
|
||||
logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName, 0)
|
||||
logging.CyberCPLogFileWriter.SendEmail(adminEmail, adminEmail, 'Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName,
|
||||
logging.CyberCPLogFileWriter.SendEmail(sender_email, adminEmail, 'Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName,
|
||||
'SSL Notification for %s.' % (virtualHostName))
|
||||
return 0
|
||||
else:
|
||||
|
|
@ -351,7 +350,6 @@ class sslUtilities:
|
|||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
"Successfully obtained SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + "and www." + aliasDomain + ",")
|
||||
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
"Failed to obtain SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + "and www." + aliasDomain + ",")
|
||||
|
|
@ -369,7 +367,7 @@ class sslUtilities:
|
|||
return 0
|
||||
|
||||
|
||||
def issueSSLForDomain(domain, adminEmail, sslpath, aliasDomain = None):
|
||||
def issueSSLForDomain(domain, adminEmail, sslpath, aliasDomain=None):
|
||||
try:
|
||||
if sslUtilities.obtainSSLForADomain(domain, adminEmail, sslpath, aliasDomain) == 1:
|
||||
if sslUtilities.installSSLForDomain(domain, adminEmail) == 1:
|
||||
|
|
@ -392,5 +390,4 @@ def issueSSLForDomain(domain, adminEmail, sslpath, aliasDomain = None):
|
|||
return [0, "210 Failed to install SSL for domain. [issueSSLForDomain]"]
|
||||
|
||||
except BaseException as msg:
|
||||
return [0, "347 "+ str(msg)+ " [issueSSLForDomain]"]
|
||||
|
||||
return [0, "347 " + str(msg) + " [issueSSLForDomain]"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue