diff --git a/backup/backupManager.py b/backup/backupManager.py index 6e298d26b..eb9f4fe73 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -9,7 +9,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging -from websiteFunctions.models import Websites, Backups, dest, backupSchedules +from websiteFunctions.models import Websites, Backups, dest, backupSchedules, BackupJob, BackupJobLogs from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex @@ -1186,3 +1186,96 @@ class BackupManager: data = {'cancelStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data) return HttpResponse(json_data) + + def backupLogs(self, request = None, userID = None, data = None): + try: + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + all_files = [] + + logFiles = BackupJob.objects.all().order_by('-id') + + for logFile in logFiles: + all_files.append(logFile.logFile) + + return render(request, 'backup/backupLogs.html', {'backups': all_files}) + + except BaseException as msg: + return HttpResponse(str(msg)) + + def fetchLogs(self, userID = None, data = None): + try: + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + page = int(str(data['page']).rstrip('\n')) + recordsToShow = int(data['recordsToShow']) + logFile = data['logFile'] + + logJob = BackupJob.objects.get(logFile=logFile) + + logs = logJob.backupjoblogs_set.all() + + from s3Backups.s3Backups import S3Backups + from plogical.backupSchedule import backupSchedule + + pagination = S3Backups.getPagination(len(logs), recordsToShow) + endPageNumber, finalPageNumber = S3Backups.recordsPointer(page, recordsToShow) + finalLogs = logs[finalPageNumber:endPageNumber] + + json_data = "[" + checker = 0 + counter = 0 + + for log in finalLogs: + + if log.status == backupSchedule.INFO: + status = 'INFO' + else: + status = 'ERROR' + + dic = { + 'LEVEL': status, "Message": log.message + } + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + counter = counter + 1 + + json_data = json_data + ']' + + if logJob.location == backupSchedule.LOCAL: + location = 'local' + else: + location = 'remote' + + + data = { + 'status': 1, + 'error_message': 'None', + 'logs': json_data, + 'pagination': pagination, + 'jobSuccessSites': logJob.jobSuccessSites, + 'jobFailedSites': logJob.jobFailedSites, + 'location': location + } + + + json_data = json.dumps(data) + return HttpResponse(json_data) + + except BaseException as msg: + data = {'remoteRestoreStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data) + return HttpResponse(json_data) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index cbe74d8ef..59c654f87 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -1541,4 +1541,68 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { }); -///** Backup site ends **/// \ No newline at end of file +///** Backup site ends **/// + + +//*** Remote Backup site ****// +app.controller('backupLogsScheduled', function ($scope, $http, $timeout) { + + $scope.cyberpanelLoading = true; + $scope.logDetails = true; + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.fetchLogs = function () { + + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + logFile: $scope.logFile, + recordsToShow: $scope.recordsToShow, + page: $scope.currentPage + }; + + dataurl = "/backup/fetchLogs"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.logDetails = false; + $scope.logs = JSON.parse(response.data.logs); + $scope.pagination = response.data.pagination; + $scope.jobSuccessSites = response.data.jobSuccessSites; + $scope.jobFailedSites = response.data.jobFailedSites; + $scope.location = response.data.location; + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + +}); + +///** Backup site ends **/// diff --git a/backup/templates/backup/backupLogs.html b/backup/templates/backup/backupLogs.html new file mode 100755 index 000000000..0c7dadf49 --- /dev/null +++ b/backup/templates/backup/backupLogs.html @@ -0,0 +1,125 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Backup Logs - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + + {% get_current_language as LANGUAGE_CODE %} + + + +
{% trans "On this page you can view detailed logs of your local and remote scheduled backups." %}
+
+ | {% trans "Successful Sites" %} | +{% trans "Failed Sites" %} | +{% trans "Location" %} | +
|---|---|---|
| {$ jobSuccessSites $} | +{$ jobFailedSites $} | +{$ location $} | +
| {% trans "LEVEL" %} | +{% trans "Message" %} | +
|---|---|
| + | + |
{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}
@@ -20,8 +20,11 @@
+ {% trans "Schedule Back up" %} -
{% trans "Backup Logs" %}