bootstrap-switch.min.js
3 years ago
bootstrap.bundle.min.js
3 years ago
bootstrap.bundle.min.js.map
3 years ago
chart.umd.min.js
3 years ago
jquery.fileupload.js
3 years ago
jquery.iframe-transport.js
3 years ago
jquery.rateyo.js
3 years ago
jquery.validate.min.js
3 years ago
jstree.checkbox.js
3 years ago
jstree.min.js
3 years ago
jstree.types.js
3 years ago
jstree.wholerow.js
3 years ago
less.min.js
3 years ago
main.js
3 years ago
popup.js
3 years ago
sgbackup.js
3 years ago
sgcloud.js
3 years ago
sglogin.js
3 years ago
sgrequesthandler.js
3 years ago
sgrequesthandler.wordpress.js
3 years ago
sgschedule.js
3 years ago
sgsettings.js
3 years ago
sgbackup.js
952 lines
| 1 | BG_BACKUP_STRINGS_DEACTIVATE = []; |
| 2 | SG_DOWNLOAD_PROGRESS = ''; |
| 3 | SG_ACTIVE_DOWNLOAD_AJAX = ''; |
| 4 | SG_CHECK_ACTION_STATUS_REQUEST_FREQUENCY = 10000; |
| 5 | SG_PING_AWAKE_REQUEST_FREQUENCY = 13000; |
| 6 | |
| 7 | SG_STORAGE_FTP = 1; |
| 8 | SG_STORAGE_DROPBOX = 2; |
| 9 | SG_STORAGE_GOOGLE_DRIVE = 3; |
| 10 | SG_STORAGE_AMAZON = 4; |
| 11 | SG_STORAGE_ONE_DRIVE = 5; |
| 12 | SG_STORAGE_P_CLOUD = 7; |
| 13 | SG_STORAGE_BOX = 8; |
| 14 | |
| 15 | BG_BACKUP_STRINGS_DEACTIVATE.areYouSure = "Are you sure?"; |
| 16 | |
| 17 | |
| 18 | jQuery(document).on( |
| 19 | 'change', |
| 20 | '.btn-file :file', |
| 21 | function () { |
| 22 | var input = jQuery(this); |
| 23 | |
| 24 | if (input.get(0).files) { |
| 25 | var numFile = input.get(0).files.length |
| 26 | } else { |
| 27 | var numFiles = 1; |
| 28 | } |
| 29 | |
| 30 | var label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); |
| 31 | input.trigger('fileselect', [numFiles, label]); |
| 32 | } |
| 33 | ); |
| 34 | |
| 35 | jQuery(document).ready( |
| 36 | function () { |
| 37 | sgBackup.initTablePagination('sg-backups'); |
| 38 | sgBackup.initActiveAction(); |
| 39 | sgBackup.initBackupDeletion(); |
| 40 | sgBackup.toggleMultiDeleteButton(); |
| 41 | sgBackup.closeFreeBanner(); |
| 42 | |
| 43 | jQuery('span[data-toggle=tooltip]').tooltip(); |
| 44 | |
| 45 | jQuery('#sg-checkbox-select-all').on( |
| 46 | 'change', |
| 47 | function () { |
| 48 | var checkAll = jQuery('#sg-checkbox-select-all'); |
| 49 | jQuery('tbody input[type="checkbox"]:not(:disabled):visible').prop('checked', checkAll.prop('checked')); |
| 50 | sgBackup.toggleMultiDeleteButton(); |
| 51 | } |
| 52 | ); |
| 53 | |
| 54 | jQuery('#sg-delete-multi-backups').on( |
| 55 | 'click', |
| 56 | function () { |
| 57 | if (!confirm(BG_BACKUP_STRINGS_DEACTIVATE.areYouSure)) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | var backups = jQuery('tbody input[type="checkbox"]:checked'); |
| 62 | var backupNames = []; |
| 63 | backups.each( |
| 64 | function (i) { |
| 65 | backupNames[i] = jQuery(this).val(); |
| 66 | } |
| 67 | ); |
| 68 | |
| 69 | if (backupNames.length) { |
| 70 | sgBackup.deleteMultiBackups(backupNames); |
| 71 | } |
| 72 | } |
| 73 | ); |
| 74 | |
| 75 | jQuery('tbody input[type="checkbox"]').on( |
| 76 | 'change', |
| 77 | function () { |
| 78 | var numberOfBackups = jQuery('tbody input[type="checkbox"]').length; |
| 79 | var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber(); |
| 80 | var isCheked = jQuery(this).is(':checked'); |
| 81 | sgBackup.toggleMultiDeleteButton(); |
| 82 | |
| 83 | if (!isCheked) { |
| 84 | jQuery('#sg-checkbox-select-all').prop('checked', false); |
| 85 | } else { |
| 86 | if (numberOfBackups === numberOfChoosenBackups) { |
| 87 | jQuery('#sg-checkbox-select-all').prop('checked', true); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | ); |
| 92 | } |
| 93 | ); |
| 94 | |
| 95 | sgBackup.isValidEmailAddress = function (emailAddress) { |
| 96 | var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,10}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i); |
| 97 | return pattern.test(emailAddress); |
| 98 | |
| 99 | }; |
| 100 | |
| 101 | sgBackup.getSelectedBackupsNumber = function () { |
| 102 | return jQuery('tbody input[type="checkbox"]:checked').length |
| 103 | |
| 104 | }; |
| 105 | |
| 106 | sgBackup.toggleMultiDeleteButton = function () { |
| 107 | var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber(); |
| 108 | var target = jQuery('#sg-delete-multi-backups'); |
| 109 | if (numberOfChoosenBackups > 0) { |
| 110 | target.removeAttr('disabled'); |
| 111 | } else { |
| 112 | target.attr('disabled', 'disabled'); |
| 113 | } |
| 114 | |
| 115 | }; |
| 116 | |
| 117 | sgBackup.closeFreeBanner = function () { |
| 118 | jQuery('.sg-close-free-banner').bind( |
| 119 | 'click', |
| 120 | function () { |
| 121 | var ajaxHandler = new sgRequestHandler( |
| 122 | 'closeFreeBanner', |
| 123 | { |
| 124 | token: BG_BACKUP_STRINGS.nonce |
| 125 | } |
| 126 | ); |
| 127 | ajaxHandler.callback = function (response, error) { |
| 128 | jQuery('#sg-banner').remove(); |
| 129 | }; |
| 130 | ajaxHandler.run(); |
| 131 | } |
| 132 | ); |
| 133 | }; |
| 134 | |
| 135 | sgBackup.deleteMultiBackups = function (backupNames) { |
| 136 | var ajaxHandler = new sgRequestHandler('deleteBackup', {backupName: backupNames, token: BG_BACKUP_STRINGS.nonce}); |
| 137 | ajaxHandler.callback = function (response) { |
| 138 | location.reload(); |
| 139 | }; |
| 140 | ajaxHandler.run(); |
| 141 | |
| 142 | }; |
| 143 | |
| 144 | // SGManual Backup AJAX callback. |
| 145 | sgBackup.manualBackup = function (checkedStatus) { |
| 146 | var error = []; |
| 147 | // Validation. |
| 148 | jQuery('.alert').remove(); |
| 149 | if (jQuery('input[type=radio][name=backupType]:checked').val() === 2) { |
| 150 | if (jQuery('.sg-custom-option:checked').length <= 0) { |
| 151 | error.push(BG_BACKUP_STRINGS.invalidBackupOption); |
| 152 | } |
| 153 | |
| 154 | // Check if any file is selected. |
| 155 | if (jQuery('input[type=checkbox][name=backupFiles]:checked').length > 0) { |
| 156 | if (jQuery('.sg-custom-backup-files input:checkbox:checked').length <= 0) { |
| 157 | error.push(BG_BACKUP_STRINGS.invalidDirectorySelected); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Check if any cloud is selected. |
| 163 | if (jQuery('input[type=checkbox][name=backupCloud]:checked').length > 0) { |
| 164 | if (jQuery('.sg-custom-backup-cloud input:checkbox:checked').length <= 0) { |
| 165 | error.push(BG_BACKUP_STRINGS.invalidCloud); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // If any error show it and abort ajax. |
| 170 | if (error.length) { |
| 171 | var sgAlert = sgBackup.alertGenerator(error, 'alert-danger'); |
| 172 | jQuery('#sg-modal .modal-header').prepend(sgAlert); |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | if (!checkedStatus) { |
| 177 | sgBackup.checkBackupCreation(); |
| 178 | } |
| 179 | |
| 180 | // Before all disable buttons. |
| 181 | jQuery('.alert').remove(); |
| 182 | jQuery('.modal-footer .btn-primary').attr('disabled', 'disabled'); |
| 183 | jQuery('.modal-footer .btn-primary').html(BG_BACKUP_STRINGS.backupInProgress); |
| 184 | |
| 185 | // Reset Status! |
| 186 | var backupName = jQuery("#sg-custom-backup-name").val(); |
| 187 | var resetStatusHandler = new sgRequestHandler( |
| 188 | 'resetStatus', |
| 189 | { |
| 190 | backupName: backupName, |
| 191 | token: BG_BACKUP_STRINGS.nonce |
| 192 | } |
| 193 | ); |
| 194 | resetStatusHandler.callback = function (response, error) { |
| 195 | var manualBackupForm = jQuery('#manualBackup'); |
| 196 | var manualBackupHandler = new sgRequestHandler('manualBackup', manualBackupForm.serialize() + '&token=' + BG_BACKUP_STRINGS.nonce); |
| 197 | |
| 198 | manualBackupHandler.dataIsObject = false; |
| 199 | // If error! |
| 200 | if (typeof response.success === 'undefined') { |
| 201 | var sgAlert = sgBackup.alertGenerator(response, 'alert-danger'); |
| 202 | jQuery('#sg-modal .modal-header').prepend(sgAlert); |
| 203 | |
| 204 | if (response === 0 || response === false || response === '0' || response === 'false') { |
| 205 | response = BG_BACKUP_STRINGS.errorMessage; |
| 206 | } |
| 207 | |
| 208 | sgBackup.restManualBackupModal(); |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | if (checkedStatus) { |
| 213 | sgBackup.hideAndReload(); |
| 214 | } |
| 215 | |
| 216 | manualBackupHandler.run(); |
| 217 | }; |
| 218 | resetStatusHandler.run(); |
| 219 | |
| 220 | }; |
| 221 | |
| 222 | sgBackup.hideAndReload = function () { |
| 223 | jQuery('#sg-modal').modal('hide'); |
| 224 | location.reload(); |
| 225 | |
| 226 | }; |
| 227 | |
| 228 | sgBackup.restManualBackupModal = function () { |
| 229 | jQuery('.modal-footer .btn-primary').removeAttr('disabled'); |
| 230 | jQuery('.modal-footer .btn-primary').html('Backup'); |
| 231 | |
| 232 | }; |
| 233 | |
| 234 | sgBackup.cancelDonwload = function (name) { |
| 235 | var cancelDonwloadHandler = new sgRequestHandler('cancelDownload', {name: name, token: BG_BACKUP_STRINGS.nonce}); |
| 236 | cancelDonwloadHandler.callback = function (response) { |
| 237 | sgBackup.hideAjaxSpinner(); |
| 238 | location.reload(); |
| 239 | }; |
| 240 | cancelDonwloadHandler.run(); |
| 241 | |
| 242 | }; |
| 243 | |
| 244 | sgBackup.listStorage = function (importFrom) { |
| 245 | var listStorage = new sgRequestHandler('listStorage', {storage: importFrom, token: BG_BACKUP_STRINGS.nonce}); |
| 246 | sgBackup.showAjaxSpinner('#sg-modal-inport-from'); |
| 247 | jQuery('#sg-archive-list-table tbody').empty(); |
| 248 | |
| 249 | jQuery('#sg-modal').off('hide.bs.modal').on( |
| 250 | 'hide.bs.modal', |
| 251 | function (e) { |
| 252 | if (SG_ACTIVE_DOWNLOAD_AJAX) { |
| 253 | if (!confirm(BG_BACKUP_STRINGS.confirm)) { |
| 254 | e.preventDefault(); |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | var target = jQuery('input[name="select-archive-to-download"]:checked'); |
| 259 | var name = target.attr('file-name'); |
| 260 | |
| 261 | sgBackup.cancelDonwload(name); |
| 262 | } |
| 263 | } |
| 264 | ); |
| 265 | |
| 266 | listStorage.callback = function (response, error) { |
| 267 | var cloudName = ''; |
| 268 | var cloudId = parseInt(importFrom, 10); |
| 269 | |
| 270 | switch (cloudId) { |
| 271 | case SG_STORAGE_AMAZON: |
| 272 | cloudName = "S3"; |
| 273 | break; |
| 274 | |
| 275 | case SG_STORAGE_DROPBOX: |
| 276 | cloudName = "Dropbox"; |
| 277 | break; |
| 278 | |
| 279 | case SG_STORAGE_GOOGLE_DRIVE: |
| 280 | cloudName = "Google Drive"; |
| 281 | break; |
| 282 | |
| 283 | case SG_STORAGE_FTP: |
| 284 | cloudName = "FTP"; |
| 285 | break; |
| 286 | |
| 287 | case SG_STORAGE_ONE_DRIVE: |
| 288 | cloudName = "OneDrive"; |
| 289 | break; |
| 290 | |
| 291 | case SG_STORAGE_P_CLOUD: |
| 292 | cloudName = "pCloud"; |
| 293 | break; |
| 294 | |
| 295 | case SG_STORAGE_BOX: |
| 296 | cloudName = "box.com"; |
| 297 | break; |
| 298 | |
| 299 | default: |
| 300 | cloudName = ''; |
| 301 | break; |
| 302 | }//end switch |
| 303 | |
| 304 | jQuery('.modal-title').html('Import from ' + cloudName); |
| 305 | |
| 306 | sgBackup.hideAjaxSpinner(); |
| 307 | var content = ''; |
| 308 | if ((typeof response.error !== "undefined") || response.length === 0 || response === undefined) { |
| 309 | content = '<tr><td colspan="4">' + BG_BACKUP_STRINGS.noBackupsAvailable + '</td></tr>'; |
| 310 | } else { |
| 311 | jQuery.each( |
| 312 | response, |
| 313 | function (key, value) { |
| 314 | var backupId = 0; |
| 315 | |
| 316 | if (typeof value.id !== 'undefined') { |
| 317 | backupId = value.id; |
| 318 | value.path = value.name; |
| 319 | } |
| 320 | |
| 321 | content += '<tr>'; |
| 322 | content += '<td class="file-select-radio"><input type="radio" file-name="' + value.name + '" name="select-archive-to-download" size="' + value.size + '" backup-id="' + backupId + '" storage="' + importFrom + '" value="' + value.path + '"></td>'; |
| 323 | content += '<td>' + value.name + '</td>'; |
| 324 | content += '<td>' + sgBackup.convertBytesToMegabytes(value.size) + '</td>'; |
| 325 | content += '<td>' + value.date + '</td>'; |
| 326 | content += '</tr>'; |
| 327 | } |
| 328 | ); |
| 329 | }//end if |
| 330 | |
| 331 | jQuery('#sg-archive-list-table tbody').append(content); |
| 332 | sgBackup.toggleDownloadFromCloudPage(); |
| 333 | }; |
| 334 | |
| 335 | listStorage.run(); |
| 336 | |
| 337 | }; |
| 338 | |
| 339 | |
| 340 | sgBackup.convertBytesToMegabytes = function ($bytes) { |
| 341 | return ($bytes / (1024 * 1024)).toFixed(2); |
| 342 | |
| 343 | }; |
| 344 | |
| 345 | // Init file upload! |
| 346 | sgBackup.initFileUpload = function () { |
| 347 | sgBackup.downloadFromPC(); |
| 348 | |
| 349 | jQuery('#uploadSgbpFile').click( |
| 350 | function () { |
| 351 | if (jQuery('#modal-import-3').is(":visible")) { |
| 352 | var target = jQuery('input[name="select-archive-to-download"]:checked'); |
| 353 | var path = target.val(); |
| 354 | var name = target.attr('file-name'); |
| 355 | var storage = target.attr('storage'); |
| 356 | var size = target.attr('size'); |
| 357 | var backupId = target.attr('backup-id'); |
| 358 | sgBackup.downloadFromCloud(path, name, storage, size, backupId); |
| 359 | } |
| 360 | } |
| 361 | ); |
| 362 | |
| 363 | }; |
| 364 | |
| 365 | sgBackup.nextPage = function () { |
| 366 | var importFrom = jQuery('input[name="storage-radio"]:checked').val(); |
| 367 | jQuery('.alert').remove(); |
| 368 | |
| 369 | if (!importFrom) { |
| 370 | var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.invalidImportOption, 'alert-danger'); |
| 371 | jQuery('#sg-modal .modal-header').prepend(alert); |
| 372 | } else { |
| 373 | if (importFrom === 'local-pc') { |
| 374 | sgBackup.toggleDownloadFromPCPage(); |
| 375 | } else { |
| 376 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "DOWNLOAD_FROM_CLOUD"}); |
| 377 | isFeatureAvailable.callback = function (response) { |
| 378 | if (typeof response.success !== 'undefined') { |
| 379 | sgBackup.listStorage(importFrom); |
| 380 | } else { |
| 381 | var alert = sgBackup.alertGenerator(response.error, 'alert-danger'); |
| 382 | jQuery('#sg-modal .modal-header').prepend(alert); |
| 383 | } |
| 384 | }; |
| 385 | |
| 386 | isFeatureAvailable.run(); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | }; |
| 391 | |
| 392 | sgBackup.previousPage = function () { |
| 393 | if (jQuery('#modal-import-2').is(":visible")) { |
| 394 | jQuery('#modal-import-2').hide(); |
| 395 | } else { |
| 396 | jQuery('#modal-import-3').hide(); |
| 397 | } |
| 398 | |
| 399 | sgBackup.toggleNavigationButtons(); |
| 400 | |
| 401 | jQuery('#modal-import-1').show(); |
| 402 | jQuery('#uploadSgbpFile').hide(); |
| 403 | |
| 404 | jQuery('.modal-title').html('Import from'); |
| 405 | |
| 406 | }; |
| 407 | |
| 408 | sgBackup.toggleNavigationButtons = function () { |
| 409 | jQuery('#switch-modal-import-pages-next').toggle(); |
| 410 | jQuery('#switch-modal-import-pages-back').toggle(); |
| 411 | |
| 412 | }; |
| 413 | |
| 414 | sgBackup.toggleDownloadFromPCPage = function () { |
| 415 | sgBackup.toggleNavigationButtons(); |
| 416 | jQuery('#modal-import-1').toggle(); |
| 417 | jQuery('#modal-import-2').toggle(); |
| 418 | jQuery('#uploadSgbpFile').toggle(); |
| 419 | |
| 420 | }; |
| 421 | |
| 422 | sgBackup.toggleDownloadFromCloudPage = function () { |
| 423 | sgBackup.toggleNavigationButtons(); |
| 424 | jQuery('#modal-import-1').toggle(); |
| 425 | jQuery('#modal-import-3').toggle(); |
| 426 | jQuery('#uploadSgbpFile').toggle(); |
| 427 | |
| 428 | }; |
| 429 | |
| 430 | sgBackup.downloadFromCloud = function (path, name, storage, size, backupId) { |
| 431 | sgBackup.showAjaxSpinner('.modal-dialog'); |
| 432 | var error = []; |
| 433 | if (!path) { |
| 434 | error.push(BG_BACKUP_STRINGS.invalidDownloadFile); |
| 435 | } |
| 436 | |
| 437 | jQuery('.alert').remove(); |
| 438 | |
| 439 | if (error.length) { |
| 440 | sgBackup.hideAjaxSpinner(); |
| 441 | var sgAlert = sgBackup.alertGenerator(error, 'alert-danger'); |
| 442 | jQuery('#sg-modal .modal-header').prepend(sgAlert); |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | var downloadFromCloudHandler = new sgRequestHandler( |
| 447 | 'downloadFromCloud', |
| 448 | { |
| 449 | path: path, |
| 450 | storage: storage, |
| 451 | size: size, |
| 452 | backupId: backupId, |
| 453 | token: BG_BACKUP_STRINGS.nonce |
| 454 | } |
| 455 | ); |
| 456 | |
| 457 | jQuery('#switch-modal-import-pages-back').hide(); |
| 458 | jQuery('#uploadSgbpFile').attr('disabled', 'disabled'); |
| 459 | |
| 460 | downloadFromCloudHandler.callback = function (response, error) { |
| 461 | if (typeof response.success !== 'undefined') { |
| 462 | location.reload(); |
| 463 | } else if (typeof response.error !== 'undefined') { |
| 464 | sgBackup.hideAjaxSpinner(); |
| 465 | jQuery('.alert').remove(); |
| 466 | |
| 467 | clearTimeout(SG_DOWNLOAD_PROGRESS); |
| 468 | |
| 469 | jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.import); |
| 470 | |
| 471 | var sgAlert = sgBackup.alertGenerator(response.error, 'alert-danger'); |
| 472 | |
| 473 | jQuery('#uploadSgbpFile').attr('disabled', false); |
| 474 | jQuery('#switch-modal-import-pages-back').toggle(); |
| 475 | jQuery('#sg-modal .modal-header').prepend(sgAlert); |
| 476 | SG_ACTIVE_DOWNLOAD_AJAX = false; |
| 477 | |
| 478 | return false; |
| 479 | } |
| 480 | }; |
| 481 | |
| 482 | SG_ACTIVE_DOWNLOAD_AJAX = true; |
| 483 | downloadFromCloudHandler.run(); |
| 484 | sgBackup.fileDownloadProgress(name, size); |
| 485 | |
| 486 | }; |
| 487 | |
| 488 | sgBackup.downloadFromPC = function () { |
| 489 | var sgData = null; |
| 490 | jQuery('#sg-modal').off('hide.bs.modal').on( |
| 491 | 'hide.bs.modal', |
| 492 | function (e) { |
| 493 | if (SG_ACTIVE_DOWNLOAD_AJAX) { |
| 494 | if (!confirm(BG_BACKUP_STRINGS.confirm)) { |
| 495 | e.preventDefault(); |
| 496 | return false; |
| 497 | } |
| 498 | |
| 499 | sgData.abort(); |
| 500 | sgBackup.cancelDonwload(sgData.files[0].name); |
| 501 | } |
| 502 | } |
| 503 | ); |
| 504 | |
| 505 | jQuery('.sg-backup-upload-input').fileupload( |
| 506 | { |
| 507 | dataType: 'json', |
| 508 | maxChunkSize: 2000000, |
| 509 | add: function (e, data) { |
| 510 | if (data.originalFiles.length) { |
| 511 | var fileName = data.originalFiles[0].name; |
| 512 | jQuery('#sg-import-file-name').val(fileName); |
| 513 | } |
| 514 | |
| 515 | jQuery('#uploadSgbpFile').click( |
| 516 | function () { |
| 517 | if (jQuery('#modal-import-2').is(":visible")) { |
| 518 | sgData = data; |
| 519 | SG_ACTIVE_DOWNLOAD_AJAX = true; |
| 520 | jQuery('#uploadSgbpFile').attr('disabled', 'disabled'); |
| 521 | jQuery('#switch-modal-import-pages-back').hide(); |
| 522 | jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.importInProgress); |
| 523 | data.submit(); |
| 524 | } |
| 525 | } |
| 526 | ); |
| 527 | }, |
| 528 | done: function (e, data) { |
| 529 | location.reload(); |
| 530 | }, |
| 531 | progress: function (e, data) { |
| 532 | var progress = parseInt(((data.loaded / data.total) * 100), 10); |
| 533 | jQuery('#uploadSgbpFile').html('Importing (' + Math.round(progress) + '%)'); |
| 534 | } |
| 535 | } |
| 536 | ).on( |
| 537 | 'fileuploadfail', |
| 538 | function (e, data) { |
| 539 | var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.fileUploadFailed, 'alert-danger'); |
| 540 | jQuery('#sg-modal .modal-header').prepend(alert); |
| 541 | } |
| 542 | ); |
| 543 | |
| 544 | }; |
| 545 | |
| 546 | sgBackup.fileDownloadProgress = function (file, size) { |
| 547 | var getFileDownloadProgress = new sgRequestHandler( |
| 548 | 'getFileDownloadProgress', |
| 549 | { |
| 550 | file: file, |
| 551 | size: size, |
| 552 | token: BG_BACKUP_STRINGS.nonce |
| 553 | } |
| 554 | ); |
| 555 | |
| 556 | getFileDownloadProgress.callback = function (response) { |
| 557 | if (response.progress === 100) { |
| 558 | location.reload(); |
| 559 | } |
| 560 | |
| 561 | if (typeof response.progress !== 'undefined') { |
| 562 | jQuery('#uploadSgbpFile').html('Importing (' + Math.round(response.progress) + '%)'); |
| 563 | SG_DOWNLOAD_PROGRESS = setTimeout( |
| 564 | function () { |
| 565 | getFileDownloadProgress.run(); |
| 566 | }, |
| 567 | SG_AJAX_REQUEST_FREQUENCY |
| 568 | ); |
| 569 | } |
| 570 | }; |
| 571 | |
| 572 | getFileDownloadProgress.run(); |
| 573 | |
| 574 | }; |
| 575 | |
| 576 | sgBackup.fileUploadProgress = function (e) { |
| 577 | if (e.lengthComputable) { |
| 578 | jQuery('#uploadSgbpFile').html('Importing (' + Math.round((e.loaded * 100.0) / e.total) + '%)'); |
| 579 | } |
| 580 | |
| 581 | }; |
| 582 | |
| 583 | sgBackup.checkBackupCreation = function () { |
| 584 | jQuery('#manualBackup .btn-success').attr('disabled', true); |
| 585 | var sgBackupCreationHandler = new sgRequestHandler('checkBackupCreation', {token: BG_BACKUP_STRINGS.nonce}); |
| 586 | sgBackupCreationHandler.dataType = 'html'; |
| 587 | sgBackupCreationHandler.callback = function (response) { |
| 588 | var hideAndReload = function () { |
| 589 | jQuery('#sg-modal').modal('hide'); |
| 590 | location.reload(); |
| 591 | }; |
| 592 | if (response.length) { |
| 593 | var result = jQuery.parseJSON(response); |
| 594 | if (result && result.status === 'cleaned') { |
| 595 | sgBackup.manualBackup('cleaned'); |
| 596 | } else { |
| 597 | hideAndReload(); |
| 598 | } |
| 599 | } else { |
| 600 | hideAndReload(); |
| 601 | } |
| 602 | }; |
| 603 | sgBackupCreationHandler.run(); |
| 604 | |
| 605 | }; |
| 606 | |
| 607 | sgBackup.checkRestoreCreation = function () { |
| 608 | jQuery('#manualBackup .btn-success').attr('disabled', true); |
| 609 | var sgRestoreCreationHandler = new sgRequestHandler('checkRestoreCreation', {token: BG_BACKUP_STRINGS.nonce}); |
| 610 | sgRestoreCreationHandler.callback = function (response) { |
| 611 | if (response.status === 0 && response.external_enabled === 1) { |
| 612 | location.href = response.external_url; |
| 613 | } else if (response.status === 'cleaned') { |
| 614 | jQuery('#manualBackup .btn-success').click(); |
| 615 | } else { |
| 616 | location.reload(); |
| 617 | } |
| 618 | }; |
| 619 | sgRestoreCreationHandler.run(); |
| 620 | |
| 621 | }; |
| 622 | |
| 623 | sgBackup.initManulBackupRadioInputs = function () { |
| 624 | jQuery('input[type=radio][name=backupType]').off('change').on( |
| 625 | 'change', |
| 626 | function () { |
| 627 | jQuery('.sg-custom-backup').fadeToggle(); |
| 628 | } |
| 629 | ); |
| 630 | jQuery('input[type=radio][name=restoreType]').off('change').on( |
| 631 | 'change', |
| 632 | function () { |
| 633 | if (jQuery('input[type=radio][name=restoreType]:checked').val() === "files") { |
| 634 | jQuery('.sg-restore-files-options').fadeIn(); |
| 635 | } else { |
| 636 | jQuery('.sg-restore-files-options').fadeOut(); |
| 637 | } |
| 638 | } |
| 639 | ); |
| 640 | |
| 641 | jQuery('input[type=radio][name=restoreFilesType]').off('change').on( |
| 642 | 'change', |
| 643 | function () { |
| 644 | jQuery('.sg-file-selective-restore').fadeToggle(); |
| 645 | } |
| 646 | ); |
| 647 | |
| 648 | jQuery('input[type=checkbox][name=backupFiles], input[type=checkbox][name=backupDatabase], input[type=checkbox][name=backupCloud]').off('change').on( |
| 649 | 'change', |
| 650 | function () { |
| 651 | var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-checkbox'); |
| 652 | sgCheckBoxWrapper.fadeToggle(); |
| 653 | if (jQuery(this).attr('name') === 'backupFiles') { |
| 654 | sgCheckBoxWrapper.find('input[type=checkbox]').attr('checked', 'checked'); |
| 655 | } |
| 656 | } |
| 657 | ); |
| 658 | jQuery('input[type=radio][name=backupDBType]').off('change').on( |
| 659 | 'change', |
| 660 | function () { |
| 661 | var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-custom-backup-tables'); |
| 662 | if (jQuery('input[type=radio][name=backupDBType]:checked').val() === '2') { |
| 663 | sgCheckBoxWrapper.find('input[type=checkbox]').not("[disabled]").prop('checked', true) |
| 664 | sgCheckBoxWrapper.fadeIn(); |
| 665 | } else { |
| 666 | sgCheckBoxWrapper.fadeOut(); |
| 667 | sgCheckBoxWrapper.find('input[type=checkbox][current="true"]').not("[disabled]").prop('checked', true) |
| 668 | sgCheckBoxWrapper.find('input[type=checkbox][current="false"]').prop('checked', false) |
| 669 | } |
| 670 | } |
| 671 | ) |
| 672 | |
| 673 | }; |
| 674 | |
| 675 | sgBackup.initImportTooltips = function () { |
| 676 | jQuery('a[data-toggle=tooltip]').tooltip(); |
| 677 | |
| 678 | }; |
| 679 | |
| 680 | sgBackup.initManualBackupTooltips = function () { |
| 681 | jQuery('[for=cloud-ftp]').tooltip({ |
| 682 | container: jQuery('[for=cloud-ftp]').parent() |
| 683 | }); |
| 684 | jQuery('[for=cloud-dropbox]').tooltip({ |
| 685 | container: jQuery('[for=cloud-dropbox]').parent() |
| 686 | }); |
| 687 | jQuery('[for=cloud-gdrive]').tooltip({ |
| 688 | container: jQuery('[for=cloud-gdrive]').parent() |
| 689 | }); |
| 690 | jQuery('[for=cloud-one-drive]').tooltip({ |
| 691 | container: jQuery('[for=cloud-one-drive]').parent() |
| 692 | }); |
| 693 | jQuery('[for=cloud-p-cloud]').tooltip({ |
| 694 | container: jQuery('[for=cloud-p-cloud]').parent() |
| 695 | }); |
| 696 | jQuery('[for=cloud-box]').tooltip({ |
| 697 | container: jQuery('[for=cloud-box]').parent() |
| 698 | }); |
| 699 | jQuery('[for=cloud-amazon]').tooltip({ |
| 700 | container: jQuery('[for=cloud-amazon]').parent() |
| 701 | }); |
| 702 | jQuery('[for=cloud-backup-guard]').tooltip({ |
| 703 | container: jQuery('[for=cloud-backup-guard]').parent() |
| 704 | }); |
| 705 | |
| 706 | jQuery('a[data-toggle=tooltip]').tooltip(); |
| 707 | }; |
| 708 | |
| 709 | sgBackup.startRestore = function (bname) { |
| 710 | var checkIsItMigration = new sgRequestHandler('checkFreeMigration', {bname: bname, token: BG_BACKUP_STRINGS.nonce}); |
| 711 | |
| 712 | checkIsItMigration.callback = function (response) { |
| 713 | if (response) { |
| 714 | jQuery('.modal-body.sg-modal-body').html(response); |
| 715 | return false; |
| 716 | } |
| 717 | |
| 718 | sgBackup.startRestoreAction(bname); |
| 719 | }; |
| 720 | checkIsItMigration.dataType = ''; |
| 721 | checkIsItMigration.run(); |
| 722 | |
| 723 | }; |
| 724 | |
| 725 | sgBackup.startRestoreAction = function (bname) { |
| 726 | jQuery('.alert').remove(); |
| 727 | var type = jQuery('input[type=radio][name=restoreType]:checked').val(); |
| 728 | var restoreFilesType = jQuery('input[type=radio][name=restoreFilesType]:checked').val() || "0"; |
| 729 | |
| 730 | if (restoreFilesType === "0") { |
| 731 | var paths = "/"; |
| 732 | } else { |
| 733 | var paths = jQuery("#fileSystemTreeContainer").jstree("get_selected"); |
| 734 | } |
| 735 | |
| 736 | var checkPHPVersionCompatibility = new sgRequestHandler( |
| 737 | 'checkPHPVersionCompatibility', |
| 738 | { |
| 739 | bname: bname, |
| 740 | token: BG_BACKUP_STRINGS.nonce |
| 741 | } |
| 742 | ); |
| 743 | |
| 744 | checkPHPVersionCompatibility.callback = function (response) { |
| 745 | if (typeof response.error !== 'undefined') { |
| 746 | alert(response.error); |
| 747 | return false; |
| 748 | } else if (typeof response.warning !== 'undefined') { |
| 749 | if (!confirm(response.warning)) { |
| 750 | return false; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | sgBackup.showAjaxSpinner('#sg-content-wrapper'); |
| 755 | var resetStatusHandler = new sgRequestHandler('resetStatus', {token: BG_BACKUP_STRINGS.nonce}); |
| 756 | resetStatusHandler.callback = function (response) { |
| 757 | // If error! |
| 758 | if (typeof response.success === 'undefined') { |
| 759 | alert(response); |
| 760 | location.reload(); |
| 761 | return false; |
| 762 | } |
| 763 | |
| 764 | var restoreHandler = new sgRequestHandler('restore', {bname: bname, type: type, paths: paths}); |
| 765 | restoreHandler.run(); |
| 766 | sgBackup.checkRestoreCreation(); |
| 767 | }; |
| 768 | resetStatusHandler.run(); |
| 769 | }; |
| 770 | |
| 771 | if (type === "files" && restoreFilesType === 1) { |
| 772 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "SLECTIVE_RESTORE"}); |
| 773 | isFeatureAvailable.callback = function (response) { |
| 774 | if (typeof response.success !== 'undefined') { |
| 775 | checkPHPVersionCompatibility.run(); |
| 776 | } else { |
| 777 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 778 | jQuery('#sg-modal .modal-header').prepend(alert); |
| 779 | return false; |
| 780 | } |
| 781 | }; |
| 782 | |
| 783 | isFeatureAvailable.run(); |
| 784 | } else { |
| 785 | checkPHPVersionCompatibility.run(); |
| 786 | } |
| 787 | |
| 788 | }; |
| 789 | |
| 790 | sgBackup.initActiveAction = function () { |
| 791 | if (jQuery('.sg-active-action-id').length <= 0) { |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | var activeActionsIds = []; |
| 796 | jQuery('.sg-active-action-id').each( |
| 797 | function () { |
| 798 | activeActionsIds.push(jQuery(this).val()); |
| 799 | } |
| 800 | ); |
| 801 | |
| 802 | // Cancel Button! |
| 803 | jQuery('.sg-cancel-backup').click( |
| 804 | function () { |
| 805 | if (confirm('Are you sure?')) { |
| 806 | var actionId = jQuery(this).attr('sg-data-backup-id'); |
| 807 | var sgCancelHandler = new sgRequestHandler( |
| 808 | 'cancelBackup', |
| 809 | { |
| 810 | actionId: actionId, |
| 811 | token: BG_BACKUP_STRINGS.nonce |
| 812 | } |
| 813 | ); |
| 814 | sgCancelHandler.run(); |
| 815 | } |
| 816 | } |
| 817 | ); |
| 818 | |
| 819 | var activeActionsIdsLength = activeActionsIds.length; |
| 820 | for (var i = 0; i < activeActionsIdsLength; i++) { |
| 821 | // GetProgress! |
| 822 | sgBackup.getActionProgress(activeActionsIds[i]); |
| 823 | sgBackup.pingAwake(); |
| 824 | } |
| 825 | |
| 826 | }; |
| 827 | |
| 828 | sgBackup.getActionProgress = function (actionId) { |
| 829 | var progressBar = jQuery('.sg-progress .progress-bar', '#sg-status-tabe-data-' + actionId); |
| 830 | |
| 831 | var sgActionHandler = new sgRequestHandler('getAction', {actionId: actionId, token: BG_BACKUP_STRINGS.nonce}); |
| 832 | // Init tooltip! |
| 833 | var statusTooltip = jQuery('#sg-status-tabe-data-' + actionId + '[data-toggle=tooltip]').tooltip(); |
| 834 | |
| 835 | sgActionHandler.callback = function (response) { |
| 836 | if (response) { |
| 837 | sgBackup.disableUi(); |
| 838 | var progressInPercents = response.progress + '%'; |
| 839 | progressBar.width(progressInPercents); |
| 840 | sgBackup.statusUpdate(statusTooltip, response, progressInPercents); |
| 841 | setTimeout( |
| 842 | function () { |
| 843 | sgActionHandler.run(); |
| 844 | }, |
| 845 | SG_CHECK_ACTION_STATUS_REQUEST_FREQUENCY |
| 846 | ); |
| 847 | } else { |
| 848 | jQuery('[class*=sg-status]').addClass('active'); |
| 849 | jQuery('.sg-progress').remove(); |
| 850 | jQuery('.sg-active-action-id').remove(); |
| 851 | location.reload(); |
| 852 | } |
| 853 | }; |
| 854 | sgActionHandler.run(); |
| 855 | |
| 856 | }; |
| 857 | |
| 858 | sgBackup.pingAwake = function () { |
| 859 | var sgActionHandler = new sgRequestHandler('awake_frontend', {token: BG_BACKUP_STRINGS.nonce}); |
| 860 | |
| 861 | sgActionHandler.callback = function (response) { |
| 862 | setTimeout( |
| 863 | function () { |
| 864 | sgActionHandler.run(); |
| 865 | }, |
| 866 | SG_PING_AWAKE_REQUEST_FREQUENCY |
| 867 | ); |
| 868 | }; |
| 869 | sgActionHandler.run(); |
| 870 | }; |
| 871 | |
| 872 | sgBackup.statusUpdate = function (tooltip, response, progressInPercents) { |
| 873 | var tooltipText = ''; |
| 874 | if (response.type === '1') { |
| 875 | var currentAction = 'Backup'; |
| 876 | if (response.status === '1') { |
| 877 | tooltipText = currentAction + ' database - ' + progressInPercents; |
| 878 | } else if (response.status === '2') { |
| 879 | tooltipText = currentAction + ' files - ' + progressInPercents; |
| 880 | } |
| 881 | |
| 882 | jQuery('.sg-status-' + response.status).prevAll('[class*=sg-status]').addClass('active'); |
| 883 | } else if (response.type === '2') { |
| 884 | var currentAction = 'Restore'; |
| 885 | if (response.status === '1') { |
| 886 | tooltipText = currentAction + ' database - ' + progressInPercents; |
| 887 | } else if (response.status === '2') { |
| 888 | tooltipText = currentAction + ' files - ' + progressInPercents; |
| 889 | } |
| 890 | |
| 891 | jQuery('.sg-status-' + response.type + response.status).prevAll('[class*=sg-status]').addClass('active'); |
| 892 | } else if (response.type === '3') { |
| 893 | var cloudIcon = jQuery('.sg-status-' + response.type + response.subtype); |
| 894 | if (response.subtype === SG_STORAGE_FTP) { |
| 895 | tooltipText = 'Uploading to FTP - ' + progressInPercents; |
| 896 | } else if (response.subtype === SG_STORAGE_DROPBOX) { |
| 897 | tooltipText = 'Uploading to Dropbox - ' + progressInPercents; |
| 898 | } else if (response.subtype === SG_STORAGE_GOOGLE_DRIVE) { |
| 899 | tooltipText = 'Uploading to Google Drive - ' + progressInPercents; |
| 900 | } else if (response.subtype === SG_STORAGE_AMAZON) { |
| 901 | tooltipText = 'Uploading to Amazon S3 - ' + progressInPercents; |
| 902 | } else if (response.subtype === SG_STORAGE_ONE_DRIVE) { |
| 903 | tooltipText = 'Uploading to OneDrive - ' + progressInPercents; |
| 904 | } else if (response.subtype === SG_STORAGE_P_CLOUD) { |
| 905 | tooltipText = 'Uploading to pCloud - ' + progressInPercents; |
| 906 | } else if (response.subtype === SG_STORAGE_BOX) { |
| 907 | tooltipText = 'Uploading to box.com - ' + progressInPercents; |
| 908 | } |
| 909 | |
| 910 | cloudIcon.prevAll('[class*=sg-status]').addClass('active'); |
| 911 | }//end if |
| 912 | |
| 913 | tooltip.attr('data-bs-original-title', tooltipText); |
| 914 | |
| 915 | }; |
| 916 | |
| 917 | sgBackup.disableUi = function () { |
| 918 | jQuery('#sg-manual-backup').attr('disabled', 'disabled'); |
| 919 | jQuery('#sg-backup-with-migration').attr('disabled', 'disabled'); |
| 920 | jQuery('#sg-import').attr('disabled', 'disabled'); |
| 921 | jQuery('.sg-restore').attr('disabled', 'disabled'); |
| 922 | jQuery('.sg-restore-button').attr('disabled', 'disabled'); |
| 923 | |
| 924 | }; |
| 925 | |
| 926 | sgBackup.enableUi = function () { |
| 927 | jQuery('#sg-manual-backup').removeAttr('disabled'); |
| 928 | jQuery('#sg-backup-with-migration').removeAttr('disabled'); |
| 929 | jQuery('#sg-import').removeAttr('disabled'); |
| 930 | jQuery('.sg-restore').removeAttr('disabled'); |
| 931 | jQuery('.sg-restore-button').removeAttr('disabled'); |
| 932 | |
| 933 | }; |
| 934 | |
| 935 | sgBackup.initBackupDeletion = function () { |
| 936 | jQuery('.sg-remove-backup').click( |
| 937 | function () { |
| 938 | var btn = jQuery(this), |
| 939 | url = btn.attr('data-remote'), |
| 940 | backupName = [btn.attr('data-sgbackup-name')]; |
| 941 | if (confirm('Are you sure?')) { |
| 942 | var ajaxHandler = new sgRequestHandler(url, {backupName: backupName, token: BG_BACKUP_STRINGS.nonce}); |
| 943 | ajaxHandler.callback = function (response) { |
| 944 | location.reload(); |
| 945 | }; |
| 946 | ajaxHandler.run(); |
| 947 | } |
| 948 | } |
| 949 | ); |
| 950 | |
| 951 | }; |
| 952 |