PATH:
usr
/
local
/
jetapps
/
frontend
/
jetbackup
/
app
/
controllers
/* * base/frontend/paper_lantern/jetbackup/controllers/fileManager.js * * JetBackup @ package * Created By Idan Ben-Ezra * * Copyrights @ JetApps * https://www.jetapps.com * **/ /* global define: false, PAGE: false */ define([ "app" ], function (app) { app.controller("fileManager", ["$rootScope", "$scope", "$interval", "$timeout", "jetapi", "$window", "$routeParams", "$location", "consts", "lang", function ($rootScope, $scope, $interval, $timeout, jetapi, $window, $routeParams, $location, consts, lang) { $scope.backupType = consts.BACKUP_TYPE_FILES; $scope.backupId = $routeParams.id; $scope.files = []; $scope.loadingFiles = false; $scope.currentPath = ''; $scope.breadcrumbs = []; $scope.filesIndex = {}; $scope.actionStatus = undefined; $scope.actionModule = undefined; $scope.config = PAGE.config; $scope.restoringBackup = false; $scope.downloadingBackup = false; $scope.downloads = []; $scope.restores = []; $scope.sortedDownloadList = {}; $scope.sortedRestoreList = {}; $scope.showhidden = false; $scope.clearStatus = function () { $scope.actionStatus = undefined; }; $scope.cancelAction = function () { $scope.actionStatus = undefined; $scope.actionModule = undefined; }; $scope.changeView = function (view) { $location.path(view); // path not hash }; $scope.onClickRestore = function () { var selected = getSelected(); if (!selected.length) { $scope.actionStatus = { message: "Please select files to restore", type: "danger", closeable: true, ttl: 10000 }; return; } $scope.actionModule = ($scope.actionModule === 'restore') ? undefined : 'restore'; }; $scope.onClickRestoreConfirm = function () { $scope.restoringBackup = true; $scope.actionStatus = undefined; var selected = JSON.stringify(getSelected()); jetapi.addQueueRestore({_id: $scope.backupId, files: selected}, function (response) { if (response.status) { var text = ''; if (response.data.status === 100) text = lang.t("Restore Completed"); else if (response.data.status > 100) text = lang.t("Restore Failed"); else text = lang.t("Restore in Progress"); var item = { _id: response.data._id, ready: response.data.status >= 100, status: response.data.status, created: response.data.created, text: text }; $scope.restores.push(item); $scope.sortedRestoreList[response.data._id] = item; } $scope.checkStatus(); $scope.actionStatus = { message: response.status ? response.messages[0] : response.errors[0], type: response.status ? "success" : "danger", closeable: true, ttl: 10000 }; $scope.restoringBackup = false; $scope.actionModule = undefined; $scope.uncheckAll(); }); }; $scope.onClickDownload = function () { var selected = getSelected(); if (!selected.length) { $scope.actionStatus = { message: "Please select files to download", type: "danger", closeable: true, ttl: 10000 }; return; } $scope.actionModule = ($scope.actionModule === 'download') ? undefined : 'download'; }; $scope.onClickDownloadConfirm = function () { $scope.downloadingBackup = true; $scope.actionStatus = undefined; var selected = JSON.stringify(getSelected()); jetapi.addQueueDownload({_id: $scope.backupId, files: selected}, function (response) { if (response.status) { var item = { queue_id: response.data._id, ready: response.data.ready, filename: response.data.filename }; $scope.downloads.push(item); $scope.sortedDownloadList[response.data._id] = item; } $scope.getDownloads(); // $scope.checkStatus(); $scope.actionStatus = { message: response.status ? response.messages[0] : response.errors[0], type: response.status ? "success" : "danger", closeable: true, ttl: 10000 }; $scope.downloadingBackup = false; $scope.actionModule = undefined; $scope.uncheckAll(); }); }; $scope.isConditionsAgreed = function () { for (var i in $scope.config.restore_conditions) { if ($scope.config.restore_conditions[i].type !== 0 && $scope.config.restore_conditions[i].type !== $scope.backupType) continue; if (!$scope.config.restore_conditions[i].checked) return true } return false; }; var getSelected = function () { var selected = []; for (var i in $scope.filesIndex) { for (var j in $scope.filesIndex[i].data.files) { if ($scope.filesIndex[i].data.files[j] != null && $scope.filesIndex[i].data.files[j].checked !== undefined && $scope.filesIndex[i].data.files[j].checked) { selected.push($scope.filesIndex[i].data.files[j].path); } } } return selected; }; $scope.canPerformAction = function () { for (var i in $scope.filesIndex) { for (var j in $scope.filesIndex[i].data.files) { if ($scope.filesIndex[i].data.files[j] != null && $scope.filesIndex[i].data.files[j].checked !== undefined && $scope.filesIndex[i].data.files[j].checked) { return false; } } } return true; }; $scope.isDisabled = function () { var file = this.file.parent; while (!file.checked && file.parent) file = file.parent; return file.checked; }; $scope.isChecked = function () { var file = this.file; while (!file.checked && file.parent) file = file.parent; return file.checked; }; $scope.calculateInput = function (value) { if (value === undefined) { var file = this.file; while (!file.checked && file.parent) file = file.parent; return file.checked; } this.file.checked = value; }; var manageBreadcrumbs = function (file) { if (file.path === '/') file.name = '/backup-root'; $scope.breadcrumbs.unshift(file); if (file.parent !== undefined) manageBreadcrumbs(file.parent); }; var handleResponse = function (response, file) { // angular.element("#FilesList").css({ minHeight: "" }); $scope.filesIndex[file.path] = response; $scope.files = response.data.files; $scope.loadingFiles = false; }; $scope.toggleHidden = function () { $scope.showhidden = !$scope.showhidden; }; $scope.fetch = function (file) { if (file.path === undefined) file.path = '/'; $scope.loadingFiles = true; $scope.files = []; $scope.breadcrumbs = []; manageBreadcrumbs(file); // var container = angular.element("#FilesList"); // // if( container && container[0] ) { // container.css({ minHeight: $window.getComputedStyle(container[0]).height }); // } if ($scope.filesIndex[file.path] !== undefined) { handleResponse($scope.filesIndex[file.path], file); return; } apiParams = {}; apiParams['_id'] = $scope.backupId; apiParams['path'] = file.path; jetapi.fileManager(apiParams, function (response) { for (var i = 0; i < response.data.files.length; i++) { response.data.files[i].path = file.path + (file.path === '/' ? '' : '/') + response.data.files[i].name; response.data.files[i].parent = file; response.data.files[i].hidden = response.data.files[i].name.substr(0, 1) === '.'; } handleResponse(response, file); }); }; $scope.uncheckAll = function () { for (var i in $scope.filesIndex) { for (var j in $scope.filesIndex[i].data.files) { if ($scope.filesIndex[i].data.files[j] != null && $scope.filesIndex[i].data.files[j].checked !== undefined && $scope.filesIndex[i].data.files[j].checked) { $scope.filesIndex[i].data.files[j].checked = false; } } } }; $scope.checkAll = function () { $scope.uncheckAll(); var path = $scope.breadcrumbs[$scope.breadcrumbs.length-1].path; for(var i in $scope.filesIndex) { for(var j in $scope.filesIndex[i].data.files) { var file = $scope.filesIndex[i].data.files[j]; if(file && !file.path.indexOf(path) && (file.type == 'File' || file.type == 'Directory')) $scope.filesIndex[i].data.files[j].checked = true; } } }; var getPath = function() { if(!$scope.breadcrumbs) return '/'; var path = ''; for(var i=0; i < $scope.breadcrumbs.length; i++) path += $scope.breadcrumbs[i].path; }; $scope.directDownload = function (filename) { var match = window.location.pathname.match(/^\/cpsess[^\/]+\//); if (match[0] !== undefined) { window.location = match[0] + 'download?file=.jbm/downloads/' + filename; } }; $scope.getDownloads = function () { $scope.loadingDownloads = true; $scope.downloads = []; jetapi.getBackupDownloads({_id: $scope.backupId}, function (response) { if (response.data) $scope.downloads = response.data.downloads; $scope.loadingDownloads = false; $scope.checkStatus(); }); }; $scope.getRestores = function () { $scope.loadingRestores = true; $scope.restores = []; if (!$scope.PERMS.canViewQueues) return; jetapi.listQueueItems({}, function (response) { for (var i in response.data.queue) { var data = response.data.queue[i]; if (data.type !== 1) continue; var text = ''; if (data.status === 100) text = lang.t("Restore Completed"); else if (data.status > 100) text = lang.t("Restore Failed"); else text = lang.t("Restore in Progress"); var item = { _id: data._id, ready: data.status >= 100, status: data.status, created: data.created, text: text }; $scope.restores.push(item); } $scope.loadingRestores = false; $scope.checkStatus(); }); }; var statusInterval = null; $scope.checkStatus = function () { if (statusInterval !== null) return; var runCheckStatus = false; $scope.sortedDownloadList = {}; $scope.sortedRestoreList = {}; for (var i in $scope.downloads) { if (!$scope.downloads[i].ready) { $scope.sortedDownloadList[$scope.downloads[i].queue_id] = $scope.downloads[i]; runCheckStatus = true; } } for (var i in $scope.restores) { if (!$scope.restores[i].ready) { $scope.sortedRestoreList[$scope.restores[i]._id] = $scope.restores[i]; runCheckStatus = true; } } if (!runCheckStatus) return; statusInterval = $interval(function () { jetapi.listQueueItems({}, function (response) { var data = response.data.queue; var queued = 0; for (var i in data) { var _id = data[i]._id; if (data[i].status >= 100) { switch (data[i].type) { // Restore case 1: if ($scope.sortedRestoreList[_id] === undefined) continue; $scope.sortedRestoreList[_id].status = data[i].status; $scope.sortedRestoreList[_id].ready = data[i].status >= 100; var text = ''; if (data[i].status === 100) text = lang.t("Restore Completed"); else if (data[i].status > 100) text = lang.t("Restore Failed"); else text = lang.t("Restore in Progress"); $scope.sortedRestoreList[_id].text = text; break; // Download case 2: if ($scope.sortedDownloadList[_id] === undefined) continue; if (data[i].status === 100) { $scope.sortedDownloadList[_id].filename = data[i].filename; $scope.sortedDownloadList[_id].ready = true; } else { $scope.sortedDownloadList[_id].filename = 'Failed to Download'; $scope.sortedDownloadList[_id].failed = true; } break; } } else { queued++; } } if (!queued) { $interval.cancel(statusInterval); statusInterval = undefined; } } ); }, 5000); }; $scope.minimizeAll = function () { $scope.actionModule = ''; }; $scope.init = function () { $scope.getDownloads(); $scope.getRestores(); $scope.fetch({path: '/'}); }; $timeout($scope.init()); }] ); } );
[-] gdpr.js
[edit]
[+]
..
[-] emailBackups.js
[edit]
[-] cronBackups.js
[edit]
[-] dnsBackups.js
[edit]
[-] settings.js
[edit]
[-] queues.js
[edit]
[-] sslBackups.js
[edit]
[-] backups.js
[edit]
[-] fileBackups.js
[edit]
[-] dbBackups.js
[edit]
[-] fileManager.js
[edit]
[-] fullBackups.js
[edit]
[-] snapshots.js
[edit]