PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9.1
JetBackup – Backup, Restore & Migrate v1.6.9.1
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / public / js / main.js
backup / public / js Last commit date
Chart.bundle.min.js 8 years ago bootstrap-switch.min.js 10 years ago bootstrap.min.js 5 years ago deactivationSurvey.js 5 years ago jquery-ui.js 9 years ago jquery.fileupload.js 8 years ago jquery.iframe-transport.js 8 years ago jquery.rateyo.js 6 years ago jquery.validate.min.js 5 years ago jstree.checkbox.js 8 years ago jstree.min.js 8 years ago jstree.types.js 8 years ago jstree.wholerow.js 8 years ago less.min.js 10 years ago main.js 4 years ago popup.js 5 years ago sgNoticeDismiss.js 6 years ago sgbackup.js 3 years ago sgcloud.js 3 years ago sglicense.js 6 years ago sglogin.js 6 years ago sgrequesthandler.js 10 years ago sgrequesthandler.wordpress.js 10 years ago sgschedule.js 3 years ago sgsettings.js 3 years ago
main.js
647 lines
1 // phpcs:ignoreFile
2 sgBackup = {};
3 sgBackup.isModalOpen = false;
4 SG_CURRENT_ACTIVE_AJAX = '';
5 SG_NOTICE_EXECUTION_TIMEOUT = 'timeout_error';
6 SG_NOTICE_EXECUTION_FREE_TIMEOUT = 'timeout_free_error';
7 SG_NOTICE_MIGRATION_ERROR = 'migration_error';
8 SG_NOTICE_NOT_WRITABLE_ERROR = 'restore_notwritable_error';
9
10 jQuery(window).on(
11 'load', function () {
12 if (jQuery('.sg-active-action-id').length == 0) {
13 sgBackup.showReviewModal();
14 }
15 sgBackup.changeMainUrl();
16 }
17 );
18
19 jQuery(document).ready(
20 function () {
21 jQuery('span[data-toggle=tooltip]').tooltip();
22
23 sgBackup.init();
24
25 jQuery('.sg-badge-warning').on(
26 'click', function () {
27 var url = jQuery(this).attr('target-url');
28 if (url) {
29 window.open(url, '_blank');
30 }
31 }
32 );
33
34 jQuery("#rateYo").rateYo(
35 {
36 rating: 5,
37 fullStar: true,
38 spacing: "3px",
39 starWidth: "16px",
40 starHeight: "16px",
41 rating: 4.5,
42 ratedFill: "#ffffff"
43 }
44 );
45
46 if (typeof SG_AJAX_REQUEST_FREQUENCY === 'undefined') {
47 SG_AJAX_REQUEST_FREQUENCY = 2000;
48 }
49
50 sgBackup.hideAjaxSpinner();
51 var notice = "";
52 jQuery('.notice-dismiss').on(
53 'click', function () {
54 if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_TIMEOUT) {
55 notice = SG_NOTICE_EXECUTION_TIMEOUT;
56 } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_FREE_TIMEOUT) {
57 notice = SG_NOTICE_EXECUTION_TIMEOUT;
58 } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_MIGRATION_ERROR) {
59 notice = SG_NOTICE_MIGRATION_ERROR;
60 } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_NOT_WRITABLE_ERROR) {
61 notice = SG_NOTICE_NOT_WRITABLE_ERROR
62 }
63 var sgNoticeClosedHandler = new sgRequestHandler(
64 'hideNotice', {
65 notice: notice,
66 token: BG_BACKUP_STRINGS.nonce
67 }
68 );
69 sgNoticeClosedHandler.run();
70 }
71 );
72
73 //send awake requests only if there is an active action
74 if (jQuery('.sg-active-action-id').length > 0) {
75 setInterval(sgBackup.awake, SG_AJAX_REQUEST_FREQUENCY);
76 }
77 }
78 );
79
80 sgBackup.awake = function () {
81 var awakeAjaxHandler = new sgRequestHandler('awake', {token: BG_BACKUP_STRINGS.nonce});
82 awakeAjaxHandler.run();
83 }
84
85 //SG init
86 sgBackup.init = function () {
87 sgBackup.initModals();
88 sgBackup.downloadButton();
89 sgBackup.navMenu();
90 sgBackup.sendUsageDataStatus();
91 };
92
93 sgBackup.sendUsageDataStatus = function () {
94 var checkbox = jQuery('.backup-send-usage-data-status');
95
96 if (!checkbox.length) {
97 return false;
98 }
99
100 checkbox.bind(
101 'switchChange.bootstrapSwitch', function () {
102 var currentStatus = jQuery(this).is(':checked');
103 var action = 'send_usage_status';
104 jQuery(this).prop('disabled', true);
105 var ajaxHandler = new sgRequestHandler(action, {currentStatus: currentStatus, token: BG_BACKUP_STRINGS.nonce});
106 ajaxHandler.callback = function (data, error) {
107 jQuery(this).prop('disabled', false);
108 }
109
110 ajaxHandler.run();
111 }
112 );
113 };
114
115 sgBackup.navMenu = function () {
116 var navMenu = jQuery('.sg-backup-sidebar-nav a');
117
118 if (!navMenu.length) {
119 return false;
120 }
121
122 navMenu.unbind('click').bind(
123 'click', function (event) {
124 event.preventDefault();
125 sgBackup.init();
126
127 var currentUrl = jQuery(this).attr('href');
128 var openContent = jQuery(this).data('open-content');
129
130 if (typeof openContent != 'undefined' && openContent == 0) {
131 window.open(currentUrl);
132 return true;
133 }
134 jQuery('.sg-backup-page-content').addClass('sg-visibility-hidden');
135 jQuery('.sg-backup-sidebar-nav li').removeClass('active');
136
137 var currentKey = jQuery(this).data('page-key');
138 var currentPageContent = jQuery('#sg-backup-page-content-' + currentKey);
139
140 if (!currentPageContent.length) {
141 return false;
142 }
143 jQuery(this).parent().addClass('active');
144 currentPageContent.removeClass('sg-visibility-hidden');
145 }
146 );
147 };
148
149 sgBackup.downloadButton = function () {
150 var downloadButtons = jQuery('.sg-bg-download-button');
151
152 if (!downloadButtons.length) {
153 return false;
154 }
155 var isOPen = false;
156 jQuery(window).bind(
157 'click', function () {
158 if (isOPen) {
159 jQuery('.sg-backup-table .dropdown-menu').removeClass('sg-bg-show');
160 isOPen = false;
161 }
162 }
163 );
164
165 downloadButtons.bind(
166 'click', function () {
167 var currentButton = jQuery(this);
168
169 if (!currentButton.length) {
170 return false;
171 }
172 setTimeout(
173 function () {
174 currentButton.next().addClass('sg-bg-show');
175 isOPen = true;
176 }, 0
177 );
178 }
179 );
180 };
181
182 //SG Modal popup logic
183 sgBackup.initModals = function () {
184
185 jQuery('[data-toggle="modal"][href], [data-toggle="modal"][data-remote]').off('click').on(
186 'click', function (e) {
187 var param = '';
188 if (typeof jQuery(this).attr('data-sgbp-params') !== 'undefined') {
189 param = jQuery(this).attr('data-sgbp-params');
190 }
191
192 e.preventDefault();
193 var btn = jQuery(this),
194 url = btn.attr('data-remote'),
195 modalName = btn.attr('data-modal-name'),
196 backupType = btn.attr('sg-data-backup-type'),
197 modal = jQuery('#sg-modal');
198 if (modal.length == 0) {
199 modal = jQuery(
200 '' +
201 '<div class="modal fade" id="sg-modal" tabindex="-1" role="dialog" aria-hidden="true"></div>' +
202 ''
203 );
204 body.append(modal);
205 }
206 sgBackup.showAjaxSpinner('#sg-content-wrapper');
207 if (typeof sgBackup.disableUi == 'function') {
208 sgBackup.disableUi();
209 }
210
211 var ajaxHandler = new sgRequestHandler(
212 url, {
213 param: param,
214 backupType: backupType,
215 token: BG_BACKUP_STRINGS.nonce
216 }
217 );
218
219 if (modalName == 'backup-guard-details') {
220 modal.modal(
221 {
222 backdrop: 'static',
223 keyboard: false
224 }
225 );
226 }
227
228 ajaxHandler.type = 'GET';
229 ajaxHandler.dataType = 'html';
230 ajaxHandler.callback = function (data, error) {
231 sgBackup.hideAjaxSpinner();
232 if (typeof sgBackup.enableUi == 'function') {
233 sgBackup.enableUi();
234 }
235 if (error === false) {
236 jQuery('#sg-modal').append(data);
237 }
238 modal.on(
239 'hide.bs.modal', function () {
240 if (SG_CURRENT_ACTIVE_AJAX != '') {
241 if (!confirm(BG_MAIN_STRINGS.confirmCancel)) {
242 return false;
243 }
244 SG_CURRENT_ACTIVE_AJAX.abort();
245 SG_CURRENT_ACTIVE_AJAX = '';
246 }
247 }
248 );
249 modal.one(
250 'hidden.bs.modal', function () {
251 modal.html('');
252 }
253 ).modal('show');
254 sgBackup.didOpenModal(modalName, param);
255 };
256
257 if (modalName == 'ftp-settings' || modalName == 'amazon-settings') {
258 var storage = 'FTP';
259 if (modalName == 'amazon-settings') {
260 storage = 'AMAZON';
261 }
262 error = false;
263 var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: storage});
264 isFeatureAvailable.callback = function (response) {
265 if (typeof response.error !== 'undefined') {
266 var alert = sgBackup.alertGenerator(response.error, 'alert-warning');
267 jQuery('.sg-cloud-container legend').after(alert);
268 that.bootstrapSwitch('state', false);
269 sgBackup.hideAjaxSpinner();
270 } else {
271 ajaxHandler.run();
272 }
273 }
274
275 isFeatureAvailable.run();
276 } else {
277 ajaxHandler.run();
278 }
279 }
280 );
281 };
282
283 sgBackup.toggleSftpSettings = function () {
284 jQuery('#ftpPort').val('22');
285 jQuery('#sg-sftp-key-file-block').show();
286 jQuery('#sg-browse-key-file-block').hide();
287
288 if (jQuery('#sg-connect-with-key-file').is(':checked') && connectioType == 'sftp') {
289 jQuery('#sg-browse-key-file-block').show();
290 }
291 }
292
293 sgBackup.toggleFtpSettings = function () {
294 jQuery('#ftpPort').val('21');
295 jQuery('#sg-sftp-key-file-block').hide();
296 }
297
298 // Show/hide some fields that are needed/not needed for ftp/sftp
299 sgBackup.toggleNeededFtpFields = function (connectioType) {
300 if (connectioType == 'sftp') {
301 sgBackup.toggleSftpSettings();
302
303 } else if (connectioType == 'ftp') {
304 sgBackup.toggleFtpSettings();
305 }
306 }
307
308 sgBackup.didOpenModal = function (modalName, param) {
309 if (modalName == 'manual-backup' || modalName == 'manual-restore') {
310 sgBackup.initManulBackupRadioInputs();
311 sgBackup.initManualBackupTooltips();
312 jQuery('#fileSystemTreeContainer').jstree(
313 {
314 'core': {
315
316 'data': {
317 'url': function (node) {
318 return getAjaxUrl();
319 },
320 'data': function (node) {
321 var path = node.id;
322 return {
323 action: "backup_guard_getBackupContent",
324 path: path,
325 backupName: param,
326 token: BG_BACKUP_STRINGS.nonce
327 };
328 }
329 }
330 },
331 "plugins": ["wholerow", "checkbox", "types"],
332 "checkbox": {
333 "keep_selected_style": false
334 },
335 "types": {
336 "file": {
337 "icon": "bg-file-icon"
338 },
339 "folder": {
340 "icon": "bg-folder-icon"
341 },
342 "default": {
343 "icon": "bg-no-icon"
344 }
345 }
346 }
347 );
348 } else if (modalName == 'import') {
349 sgBackup.initImportTooltips();
350 jQuery('#modal-import-2').hide();
351 jQuery('#modal-import-3').hide();
352 jQuery('#switch-modal-import-pages-back').hide();
353 jQuery('#uploadSgbpFile').hide();
354 if (jQuery('#modal-import-1').length == 0) {
355 sgBackup.toggleDownloadFromPCPage();
356 }
357 sgBackup.initFileUpload();
358 } else if (modalName == 'ftp-settings') {
359 connectioType = jQuery('#sg-connection-method').val();
360 sgBackup.toggleNeededFtpFields(connectioType);
361
362 jQuery('#sg-connection-method').on(
363 'change', function () {
364 connectioType = jQuery(this).val();
365 sgBackup.toggleNeededFtpFields(connectioType);
366 }
367 );
368
369 jQuery('#sg-connect-with-key-file').on(
370 'click', function () {
371 if (jQuery(this).is(':checked')) {
372 jQuery('#sg-browse-key-file-block').show();
373 } else {
374 jQuery('#sg-browse-key-file-block').hide();
375 }
376 }
377 )
378
379 sgBackup.initSFTPKeyFileSelection();
380
381 jQuery('#sg-modal').on(
382 'hidden.bs.modal', function () {
383 if (sgBackup.isFtpConnected != true) {
384 jQuery('input[data-storage=FTP]').bootstrapSwitch('state', false);
385 }
386 }
387 )
388 } else if (modalName == 'amazon-settings') {
389 jQuery('#sg-modal').on(
390 'hidden.bs.modal', function () {
391 if (sgBackup.isAmazonConnected != true) {
392 jQuery('input[data-storage=AMAZON]').bootstrapSwitch('state', false);
393 }
394 }
395 );
396 jQuery("#bucketType").on(
397 "change", function () {
398 jQuery("#bucketType option").each(
399 function () {
400 var name = jQuery(this).val();
401 jQuery(".form-group-" + name).css("display", "none");
402 // Add $(this).val() to your list
403 }
404 );
405 var selected = jQuery("#bucketType").val();
406 jQuery(".form-group-" + selected).css("display", "block");
407 }
408 )
409 } else if (modalName == 'manual-review') {
410 var action = 'setReviewPopupState';
411 jQuery('#sgLeaveReview').click(
412 function () {
413 var reviewUrl = jQuery(this).attr('data-review-url');
414 //Never show again
415 var reviewState = 2;
416 var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce});
417 ajaxHandler.run();
418 window.open(reviewUrl);
419 }
420 );
421
422 jQuery('#sgDontAskAgain').click(
423 function () {
424 //Never show again
425 var reviewState = 2;
426 var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce});
427 ajaxHandler.run();
428 }
429 );
430
431 jQuery('#sgAskLater').click(
432 function () {
433 var reviewState = 0;
434 var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce});
435 ajaxHandler.run();
436 }
437 );
438 } else if (modalName == 'create-schedule') {
439 sgBackup.initScheduleCreation();
440 }
441 };
442
443 sgBackup.isAnyOpenModal = function () {
444 return jQuery('#sg-modal').length;
445 };
446
447 sgBackup.alertGenerator = function (content, alertClass) {
448 var sgalert = '';
449 sgalert += '<div class="alert alert-dismissible ' + alertClass + '">';
450 sgalert += '<button type="button" class="close" data-dismiss="alert">×</button>';
451 if (jQuery.isArray(content)) {
452 jQuery.each(
453 content, function (index, value) {
454 sgalert += value + '<br/>';
455 }
456 );
457 } else if (content != '') {
458 sgalert += content.replace('[', '').replace(']', '').replace('"', '');
459 }
460 sgalert += '</div>';
461 return sgalert;
462 };
463
464 sgBackup.scrollToElement = function (id) {
465 if (jQuery(id).position()) {
466 if (jQuery(id).position().top < jQuery(window).scrollTop()) {
467 //scroll up
468 jQuery('html,body').animate({scrollTop: jQuery(id).position().top}, 1000);
469 } else if (jQuery(id).position().top + jQuery(id).height() > jQuery(window).scrollTop() + (window.innerHeight || document.documentElement.clientHeight)) {
470 //scroll down
471 jQuery('html,body').animate({scrollTop: jQuery(id).position().top - (window.innerHeight || document.documentElement.clientHeight) + jQuery(id).height() + 15}, 1000);
472 }
473 }
474 };
475
476 sgBackup.showAjaxSpinner = function (appendToElement) {
477 if (typeof appendToElement == 'undefined') {
478 appendToElement = '#sg-wrapper';
479 }
480 jQuery('<div class="sg-spinner"></div>').appendTo(appendToElement);
481 };
482
483 sgBackup.hideAjaxSpinner = function () {
484 jQuery('.sg-spinner').remove();
485 };
486 sgBackup.showReviewModal = function () {
487 if (typeof sgShowReview != 'undefined') {
488 jQuery('#sg-review').trigger("click");
489 }
490 };
491
492 sgBackup.initTablePagination = function (pageName) {
493 var callBack = pageName + '';
494 jQuery.fn.sgTablePagination = function (opts) {
495 var jQuerythis = this,
496 defaults = {
497 perPage: 7,
498 showPrevNext: false,
499 hidePageNumbers: false,
500 pagerSelector: '.' + pageName + ' .pagination'
501 },
502 settings = jQuery.extend(defaults, opts);
503
504 var listElement = jQuerythis.children('tbody');
505 var perPage = settings.perPage;
506 var children = listElement.children();
507 var pager = jQuery('.' + pageName + '.pager');
508
509 if (typeof settings.childSelector != "undefined") {
510 children = listElement.find(settings.childSelector);
511 }
512
513 if (typeof settings.pagerSelector != "undefined") {
514 pager = jQuery(settings.pagerSelector);
515 }
516
517 var numItems = children.length;
518 var numPages = Math.ceil(numItems / perPage);
519
520 pager.data("curr", 0);
521
522 if (settings.showPrevNext) {
523 jQuery('<li><a href="#" class="prev_link">«</a></li>').appendTo(pager);
524 }
525
526 var curr = 0;
527 while (numPages > curr && (settings.hidePageNumbers == false)) {
528 jQuery('<li><a href="#" class="page_link">' + (curr + 1) + '</a></li>').appendTo(pager);
529 curr++;
530 }
531
532 if (curr <= 1) {
533 jQuery(settings.pagerSelector).parent('div').hide();
534 jQuery('.' + pageName + '.page_link').hide();
535 }
536
537 if (settings.showPrevNext) {
538 jQuery('<li><a href="#" class="next_link">»</a></li>').appendTo(pager);
539 }
540
541 pager.find('.page_link:first').addClass('active');
542 pager.find('.prev_link').hide();
543 if (numPages <= 1) {
544 pager.find('.next_link').hide();
545 }
546 pager.children().eq(1).addClass("active");
547
548 children.hide();
549 children.slice(0, perPage).show();
550
551 pager.find('li .page_link').click(
552 function () {
553 var clickedPage = jQuery(this).html().valueOf() - 1;
554 goTo(clickedPage, perPage);
555 return false;
556 }
557 );
558 pager.find('li .prev_link').click(
559 function () {
560 previous();
561 return false;
562 }
563 );
564 pager.find('li .next_link').click(
565 function () {
566 next();
567 return false;
568 }
569 );
570
571 function previous()
572 {
573 var goToPage = parseInt(pager.data("curr")) - 1;
574 goTo(goToPage);
575 }
576
577 function next()
578 {
579 goToPage = parseInt(pager.data("curr")) + 1;
580 goTo(goToPage);
581 }
582
583 function goTo(page)
584 {
585 var startAt = page * perPage,
586 endOn = startAt + perPage;
587
588 children.css('display', 'none').slice(startAt, endOn).show();
589
590 if (page >= 1) {
591 pager.find('.prev_link').show();
592 } else {
593 pager.find('.prev_link').hide();
594 }
595
596 if (page < (numPages - 1)) {
597 pager.find('.next_link').show();
598 } else {
599 pager.find('.next_link').hide();
600 }
601
602 pager.data("curr", page);
603 pager.children().removeClass("active");
604 pager.children().eq(page + 1).addClass("active");
605
606 }
607 };
608 jQuery('table.paginated.' + pageName).sgTablePagination(
609 {
610 pagerSelector: '.' + pageName + ' .pagination',
611 showPrevNext: true,
612 hidePageNumbers: false,
613 perPage: 7
614 }
615 );
616 };
617
618 sgBackup.logout = function () {
619 var ajaxHandler = new sgRequestHandler('logout', {token: BG_BACKUP_STRINGS.nonce});
620 ajaxHandler.callback = function (response) {
621 location.reload();
622 };
623 ajaxHandler.run();
624 };
625
626 sgBackup.changeMainUrl = function () {
627 jQuery('nav#sg-main-sidebar li').click(
628 function () {
629
630 let attr = jQuery(this).children('a').attr('data-page-key');
631
632 if (typeof attr !== typeof undefined && attr !== false) {
633
634 let queryParams = new URLSearchParams(window.location.search);
635
636 queryParams.set('page', 'backup_guard_' + attr);
637
638 history.replaceState(null, null, "?" + queryParams.toString());
639 }
640 }
641 );
642 };
643
644 sgBackup.daysInMonth = function (year, month) {
645 return new Date(year, month, 0).getDate();
646 };
647