diff --git a/IncBackups/IncBackups.py b/IncBackups/IncBackups.py new file mode 100644 index 000000000..fe14fb3d2 --- /dev/null +++ b/IncBackups/IncBackups.py @@ -0,0 +1,42 @@ +#!/usr/local/CyberCP/bin/python2 +import os,sys +sys.path.append('/usr/local/CyberCP') +import django +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() +import threading as multi +from plogical.processUtilities import ProcessUtilities +import time +from .models import IncJob, JobSnapshots +from websiteFunctions.models import Websites + +class IncJobs(multi.Thread): + + def __init__(self, function, extraArgs): + multi.Thread.__init__(self) + self.function = function + self.extraArgs = extraArgs + + def run(self): + + if self.function == 'createBackup': + self.createBackup() + + + + def createBackup(self): + tempPath = self.extraArgs['tempPath'] + website = self.extraArgs['website'] + backupDestinations = self.extraArgs['backupDestinations'] + websiteData = self.extraArgs['websiteData'] + websiteEmails = self.extraArgs['websiteEmails'] + websiteSSLs = self.extraArgs['websiteSSLs'] + + website = Websites.objects.get(domain=website) + + newJob = IncJob(website=website) + newJob.save() + + writeToFile = open(tempPath, 'w') + writeToFile.write('Completed') + writeToFile.close() \ No newline at end of file diff --git a/IncBackups/models.py b/IncBackups/models.py index 1dfab7604..0b6c351d5 100644 --- a/IncBackups/models.py +++ b/IncBackups/models.py @@ -1,6 +1,14 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models +from websiteFunctions.models import Websites +from datetime import datetime -# Create your models here. +class IncJob(models.Model): + website = models.ForeignKey(Websites) + date = models.DateTimeField(default=datetime.now, blank=True) + +class JobSnapshots(models.Model): + job = models.ForeignKey(IncJob) + type = models.CharField(max_length=50) + snapshotid = models.CharField(max_length=50) \ No newline at end of file diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index a144ea0dd..2a21a5984 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -6,50 +6,24 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { $scope.backupButton = true; $scope.cyberpanelLoading = true; $scope.runningBackup = true; - $scope.cancelButton = true; - populateCurrentRecords(); - - $scope.cancelBackup = function () { - - var backupCancellationDomain = $scope.websiteToBeBacked; - - url = "/backup/cancelBackupCreation"; - - var data = { - backupCancellationDomain: backupCancellationDomain, - fileName: $scope.fileName, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - }; $scope.fetchDetails = function () { getBackupStatus(); - populateCurrentRecords(); + $scope.populateCurrentRecords(); $scope.destination = false; $scope.runningBackup = true; - }; - function getBackupStatus() { $scope.cyberpanelLoadingBottom = false; - var websiteToBeBacked = $scope.websiteToBeBacked; - - url = "/backup/backupStatus"; + url = "/IncrementalBackups/getBackupStatus"; var data = { - websiteToBeBacked: websiteToBeBacked, + websiteToBeBacked: $scope.websiteToBeBacked, + tempPath: $scope.tempPath }; var config = { @@ -72,18 +46,16 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { $scope.cyberpanelLoadingBottom = true; $scope.destination = false; $scope.runningBackup = false; - $scope.cancelButton = true; $scope.backupButton = false; $scope.cyberpanelLoading = true; $scope.fileName = response.data.fileName; $scope.status = response.data.status; - populateCurrentRecords(); + $scope.populateCurrentRecords(); return; } else { $scope.destination = true; $scope.backupButton = true; $scope.runningBackup = false; - $scope.cancelButton = false; $scope.fileName = response.data.fileName; $scope.status = response.data.status; @@ -94,7 +66,6 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { $timeout.cancel(); $scope.cyberpanelLoadingBottom = true; $scope.cyberpanelLoading = true; - $scope.cancelButton = true; $scope.backupButton = false; } @@ -103,22 +74,18 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { function cantLoadInitialDatas(response) { } - }; - + } $scope.destinationSelection = function () { $scope.backupButton = false; }; + $scope.populateCurrentRecords = function () { - function populateCurrentRecords() { - - var websiteToBeBacked = $scope.websiteToBeBacked; - - url = "/backup/getCurrentBackups"; + url = "/IncrementalBackups/fetchCurrentBackups"; var data = { - websiteToBeBacked: websiteToBeBacked, + websiteToBeBacked: $scope.websiteToBeBacked, }; var config = { @@ -132,31 +99,42 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { function ListInitialDatas(response) { - - - if (response.data.fetchStatus == 1) { + if (response.data.status === 1) { $scope.records = JSON.parse(response.data.data); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); } - } function cantLoadInitialDatas(response) { + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); } }; - $scope.createBackup = function () { - var websiteToBeBacked = $scope.websiteToBeBacked; $scope.cyberpanelLoading = false; - url = "/backup/submitBackupCreation"; + url = "/IncrementalBackups/submitBackupCreation"; var data = { - websiteToBeBacked: websiteToBeBacked, + websiteToBeBacked: $scope.websiteToBeBacked, + backupDestinations: $scope.backupDestinations, + websiteData: $scope.websiteData, + websiteEmails: $scope.websiteEmails, + websiteSSLs: $scope.websiteSSLs + }; var config = { @@ -171,8 +149,8 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { function ListInitialDatas(response) { - - if (response.data.metaStatus === 1) { + if (response.data.status === 1) { + $scope.tempPath = response.data.tempPath; getBackupStatus(); } @@ -183,11 +161,10 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { }; - $scope.deleteBackup = function (id) { - url = "/backup/deleteBackup"; + url = "/IncrementalBackups/deleteBackup"; var data = { backupID: id, @@ -206,20 +183,16 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.deleteStatus == 1) { + if (response.data.status === 1) { - populateCurrentRecords(); + $scope.populateCurrentRecords(); - } else { - } } function cantLoadInitialDatas(response) { - - } @@ -256,9 +229,9 @@ app.controller('incrementalDestinations', function ($scope, $http) { url = "/IncrementalBackups/populateCurrentRecords"; var type = 'SFTP'; - if ($scope.destinationType === 'SFTP'){ + if ($scope.destinationType === 'SFTP') { type = 'SFTP'; - }else{ + } else { type = 'AWS'; } @@ -307,14 +280,14 @@ app.controller('incrementalDestinations', function ($scope, $http) { url = "/IncrementalBackups/addDestination"; - if(type === 'SFTP'){ + if (type === 'SFTP') { var data = { type: type, IPAddress: $scope.IPAddress, password: $scope.password, backupSSHPort: $scope.backupSSHPort }; - }else { + } else { var data = { type: type, AWS_ACCESS_KEY_ID: $scope.AWS_ACCESS_KEY_ID, diff --git a/IncBackups/templates/IncBackups/createBackup.html b/IncBackups/templates/IncBackups/createBackup.html index 23a65a281..6515cffb6 100755 --- a/IncBackups/templates/IncBackups/createBackup.html +++ b/IncBackups/templates/IncBackups/createBackup.html @@ -1,52 +1,58 @@ - {% extends "baseTemplate/index.html" %} {% load i18n %} {% block title %}{% trans "Create Incremental Backup" %}{% endblock %} {% block content %} -{% load static %} + {% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% get_current_language as LANGUAGE_CODE %} + -
-
-

{% trans "Back up Website" %} - {% trans "Backup Docs" %}

-

{% trans "This page can be used to create incremental backups for your websites." %}

-
+
+
+

{% trans "Back up Website" %} - {% trans "Backup Docs" %} +

+

{% trans "This page can be used to create incremental backups for your websites." %}

+
-
-
-

- {% trans "Back up Website" %} -

-
+
+
+

+ {% trans "Back up Website" %} +

+
-
+ -
- -
- -
-
+
+ +
+ +
+
-
- -
- -
-
+
+ +
+ +
+
-
+
@@ -77,110 +83,70 @@
- + -
- -
- - - - - - - - - - - - - - - - -
{% trans "File Name" %}{% trans "Status" %}
{% trans "Running" %}{$ fileName $}{$ status $}
-
-
- - - - -
- -
- -
-
- -
- -
- -
-
- - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - -
{% trans "ID" %}{% trans "File" %}{% trans "Date" %}{% trans "Size" %}{% trans "Status" %}{% trans "Delete" %}
-
-
- - - - -
- -
-
-

{% trans "Cannot delete website, Error message: " %}{$ errorMessage $}

+
+
+
+ +
+
-
-

Website {$ deletedWebsite $} {% trans "Successfully Deleted" %}

+ + + +
+ +
+
-
+
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
{% trans "ID" %}{% trans "Date" %}{% trans "Includes" %}{% trans "Delete" %}
+
+
+ + + + + +
- - - - - - +
+ +
-
- - -
{% endblock %} \ No newline at end of file diff --git a/IncBackups/urls.py b/IncBackups/urls.py index e1fab2ab1..34a275eb5 100644 --- a/IncBackups/urls.py +++ b/IncBackups/urls.py @@ -7,5 +7,8 @@ urlpatterns = [ url(r'^addDestination$', views.addDestination, name='addDestinationInc'), url(r'^populateCurrentRecords$', views.populateCurrentRecords, name='populateCurrentRecordsInc'), url(r'^removeDestination$', views.removeDestination, name='removeDestinationInc'), - + url(r'^fetchCurrentBackups$', views.fetchCurrentBackups, name='fetchCurrentBackupsInc'), + url(r'^submitBackupCreation$', views.submitBackupCreation, name='submitBackupCreationInc'), + url(r'^getBackupStatus$', views.getBackupStatus, name='getBackupStatusInc'), + url(r'^deleteBackup$', views.deleteBackup, name='deleteBackupInc'), ] \ No newline at end of file diff --git a/IncBackups/views.py b/IncBackups/views.py index 37a429bc4..683a73c29 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -8,6 +8,13 @@ from plogical.processUtilities import ProcessUtilities from plogical.virtualHostUtilities import virtualHostUtilities import json import os +from loginSystem.models import Administrator +from websiteFunctions.models import Websites +from .models import IncJob, JobSnapshots +from .IncBackups import IncJobs +from random import randint +import time +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging # Create your views here. @@ -23,7 +30,19 @@ def createBackup(request): return ACLManager.loadError() websitesName = ACLManager.findAllSites(currentACL, userID) - return defRenderer(request, 'IncBackups/createBackup.html', {'websiteList': websitesName}) + + destinations = [] + destinations.append('local') + + path = '/home/cyberpanel/sftp' + + for items in os.listdir(path): + destinations.append('sftp:%s' % (items)) + + for items in os.listdir(path): + destinations.append('s3:s3.amazonaws.com/%s' % (items)) + + return defRenderer(request, 'IncBackups/createBackup.html', {'websiteList': websitesName, 'destinations': destinations}) except BaseException, msg: return HttpResponse(str(msg)) @@ -239,6 +258,194 @@ def removeDestination(request): final_json = json.dumps(final_dic) return HttpResponse(final_json) + except BaseException, msg: + final_dic = {'destStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def fetchCurrentBackups(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + data = json.loads(request.body) + backupDomain = data['websiteToBeBacked'] + + if ACLManager.checkOwnership(backupDomain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('fetchStatus', 0) + + if ACLManager.checkOwnership(backupDomain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson() + + website = Websites.objects.get(domain=backupDomain) + + backups = website.incjob_set.all() + + json_data = "[" + checker = 0 + + for items in backups: + + includes = "" + + jobs = items.jobsnapshots_set.all() + + for job in jobs: + includes = '%s,%s:%s' % (includes, job.type, job.snapshotid) + + dic = {'id': items.id, + 'date': str(items.date), + 'includes': includes + } + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + + json_data = json_data + ']' + final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data}) + return HttpResponse(final_json) + except BaseException, msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def submitBackupCreation(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + data = json.loads(request.body) + backupDomain = data['websiteToBeBacked'] + backupDestinations = data['backupDestinations'] + + if ACLManager.checkOwnership(backupDomain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('metaStatus', 0) + + tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + + try: + websiteData = data['websiteData'] + except: + websiteData = False + + try: + websiteEmails = data['websiteEmails'] + except: + websiteEmails = False + + try: + websiteSSLs = data['websiteSSLs'] + except: + websiteSSLs = False + + extraArgs = {} + extraArgs['website'] = backupDomain + extraArgs['tempPath'] = tempPath + extraArgs['backupDestinations'] = backupDestinations + extraArgs['websiteData'] = websiteData + extraArgs['websiteEmails'] = websiteEmails + extraArgs['websiteSSLs'] = websiteSSLs + + startJob = IncJobs('createBackup', extraArgs) + startJob.start() + + + time.sleep(2) + + final_json = json.dumps({'status': 1, 'error_message': "None", 'tempPath': tempPath}) + return HttpResponse(final_json) + + except BaseException, msg: + logging.writeToFile(str(msg)) + final_dic = {'status': 0, 'metaStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def getBackupStatus(request): + try: + userID = request.session['userID'] + data = json.loads(request.body) + + status = data['tempPath'] + backupDomain = data['websiteToBeBacked'] + + domain = Websites.objects.get(domain=backupDomain) + + ## file name read ends + + if os.path.exists(status): + command = "sudo cat " + status + status = ProcessUtilities.outputExecutioner(command, 'cyberpanel') + + if status.find("Completed") > -1: + + ### Removing Files + + command = 'sudo rm -f ' + status + ProcessUtilities.executioner(command, 'cyberpanel') + + final_json = json.dumps( + {'backupStatus': 1, 'error_message': "None", "status": status, "abort": 1}) + return HttpResponse(final_json) + + elif status.find("[5009]") > -1: + ## removing status file, so that backup can re-run + try: + command = 'sudo rm -f ' + status + ProcessUtilities.executioner(command, 'cyberpanel') + + except: + pass + + final_json = json.dumps( + {'backupStatus': 1, 'error_message': "None", "status": status, + "abort": 1}) + return HttpResponse(final_json) + else: + final_json = json.dumps( + {'backupStatus': 1, 'error_message': "None", "status": status, + "abort": 0}) + return HttpResponse(final_json) + else: + final_json = json.dumps({'backupStatus': 1, 'error_message': "None", "status": 1, "abort": 0}) + return HttpResponse(final_json) + + except BaseException, msg: + final_dic = {'backupStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + logging.writeToFile(str(msg) + " [backupStatus]") + return HttpResponse(final_json) + + +def deleteBackup(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if ACLManager.currentContextPermission(currentACL, 'addDeleteDestinations') == 0: + return ACLManager.loadErrorJson('destStatus', 0) + + data = json.loads(request.body) + + id = data['backupID'] + + IncJob.objects.get(id=id).delete() + + final_dic = {'status': 1, 'error_message': 'None'} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except BaseException, msg: final_dic = {'destStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) diff --git a/managePHP/ubuntuphp70.xml b/managePHP/ubuntuphp70.xml index eff67d913..4e56290b2 100755 --- a/managePHP/ubuntuphp70.xml +++ b/managePHP/ubuntuphp70.xml @@ -117,7 +117,7 @@ - lsphp70-pecl-imagick + lsphp70-imagick Extension to create and modify images using ImageMagick 0 diff --git a/managePHP/ubuntuphp71.xml b/managePHP/ubuntuphp71.xml index f994a8562..a56a980d0 100755 --- a/managePHP/ubuntuphp71.xml +++ b/managePHP/ubuntuphp71.xml @@ -117,7 +117,7 @@ - lsphp71-pecl-imagick + lsphp71-imagick Extension to create and modify images using ImageMagick 0 diff --git a/managePHP/ubuntuphp72.xml b/managePHP/ubuntuphp72.xml index d0e01cd10..9914be67a 100755 --- a/managePHP/ubuntuphp72.xml +++ b/managePHP/ubuntuphp72.xml @@ -117,7 +117,7 @@ - lsphp72-pecl-imagick + lsphp72-imagick Extension to create and modify images using ImageMagick 0 diff --git a/managePHP/ubuntuphp73.xml b/managePHP/ubuntuphp73.xml index 895006c82..175b09399 100755 --- a/managePHP/ubuntuphp73.xml +++ b/managePHP/ubuntuphp73.xml @@ -117,7 +117,7 @@ - lsphp73-pecl-imagick + lsphp73-imagick Extension to create and modify images using ImageMagick 0