PluginProbe
UpdraftCentral Dashboard / 0.8.13
UpdraftCentral Dashboard v0.8.13
0.8.33 0.7.2 0.7.3 0.7.4 0.8.0 0.8.1 0.8.10 0.8.11 0.8.12 0.8.13 0.8.14 0.8.15 0.8.16 0.8.17 0.8.18 0.8.19 0.8.2 0.8.20 0.8.21 0.8.22 0.8.23 0.8.24 0.8.25 0.8.26 0.8.27 All 51 releases
updraftcentral / modules / updraftplus / updraftplus.js

updraftplus.js in UpdraftCentral Dashboard 0.8.13, at modules/updraftplus/updraftplus.js

2,363 lines 101.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 UpdraftCentral_Module_UpdraftPlus = new UpdraftCentral_UpdraftPlus_Module();
3
4 // To allow labelauty remote storage buttons to be used with keyboard
5 jQuery(document).keyup(function(event) {
6 if (event.keyCode === 32 || event.keyCode === 13) {
7 if (jQuery(document.activeElement).is("input.labelauty + label")) {
8 var for_box = jQuery(document.activeElement).attr("for");
9 if (for_box) {
10 jQuery("#"+for_box).change();
11 }
12 }
13 }
14 });
15
16 /*
17 * Handlebars helper function to replace all password chars into asterisk char
18 *
19 * @param {string} password Required. The plain-text password
20 *
21 * @return {string}
22 */
23 Handlebars.registerHelper('maskPassword', function(password) {
24 return password.replace(/./gi,'*');
25 });
26
27 /*
28 * Handlebars helper function that wraps javascript encodeURIComponent so that it could encode the following characters: , / ? : @ & = + $ #
29 *
30 * @param {string} uri Required. The URI to be encoded
31 */
32 Handlebars.registerHelper('encodeURIComponent', function(uri) {
33 return encodeURIComponent(uri);
34 });
35 });
36
37 /**
38 * UpdraftCentral UpdraftPlus Module
39 *
40 * @return {void}
41 */
42 function UpdraftCentral_UpdraftPlus_Module() {
43
44 var $ = jQuery;
45
46 var settings_css_sub_prefix = '.updraftcentral_row_extracontents .updraft_site_settings_output ';
47 var settings_css_prefix = '#updraftcentral_dashboard_existingsites '+settings_css_sub_prefix;
48
49 var backup_listener_ticks = {};
50 var restored_items = new UpdraftCentral_Collection();
51 var selected_items = new UpdraftCentral_Collection();
52 var delete_action = 'single';
53
54 /**
55 * Inserts bulk delete elements (input boxes, bulk delete button) along with the collapsable info
56 * to an existing template pulled from the remote controlled website for the "Existing Backups" section.
57 *
58 * @param {Object} site_row - the jQuery object of the row that the existing backup data was pulled from
59 * @return {void}
60 */
61 function insert_bulk_delete($site_row) {
62
63 var $button = $site_row.find('.updraftcentral_row_extracontents button.updraft_download_button');
64
65 var keys = [];
66 $button.wrapAll(function() {
67 var key = $(this).closest('tr').data('key');
68
69 if (-1 === $.inArray(key, keys)) {
70 keys.push(key);
71 $(this).parent().prepend('<a class="show-backup-data" data-key="'+key+'"><span class="dashicons dashicons-arrow-right"></span> '+udclion.updraftplus.select_backup_data+'</a>');
72 }
73 return '<span class="backup-data-'+key+' hide-backup-data"></span>';
74 });
75
76 UpdraftCentral.register_event_handler('click', 'a.show-backup-data', function() {
77 var key = $(this).data('key');
78
79 $(this).find('span.dashicons').toggleClass('dashicons-arrow-right dashicons-arrow-down');
80 $(this).parent().find('.backup-label-container-'+key).toggleClass('hide-backup-data');
81 $(this).parent().find('.backup-data-'+key).toggleClass('hide-backup-data');
82 });
83
84 var $backup_date_label = $site_row.find('.updraftcentral_row_extracontents div.backup_date_label');
85 if (!$backup_date_label.length) {
86 $site_row.find('.updraftcentral_row_extracontents td.updraft_existingbackup_date').each(function() {
87 var backup_item = $(this);
88 backup_item.wrapInner('<div class="backup_date_label"></div>');
89 });
90
91 $backup_date_label = $site_row.find('.updraftcentral_row_extracontents div.backup_date_label');
92 }
93
94 if ($backup_date_label.length) {
95 $backup_date_label.prepend('<div class="delete-backup-container"><input type="checkbox" class="delete_backup_item" name="delete_backup" value="1" /></div>');
96
97 var $backup_container = $site_row.find('.updraftcentral_row_extracontents div.updraft_existing_backups');
98 $backup_container.append('<button id="btn-backup-bulk-delete" class="btn btn-secondary">'+udclion.updraftplus.delete_selected+'</button>');
99 }
100
101 // Adding new columns for backup label and storage
102 insert_storage_column($site_row);
103 insert_label_column($site_row);
104 }
105
106 /**
107 * Inserts column to the existing backups table
108 *
109 * @param {Object} $site_row The jQuery object of the row that the existing backup data was pulled from
110 * @param {String} column The desired column name
111 * @param {Boolean} [add_class] Optional - A flag whether to add the 'updraft_existingbackup_data' class.
112 * @return {Object} jQuery object representing the backups table
113 */
114 function insert_existingbackup_column($site_row, column, add_class) {
115 var $table = $site_row.find('.updraftcentral_row_extracontents table.existing-backups-table');
116 var $header = $table.find('thead th.backup-date');
117 var $content = $table.find('tbody td.updraft_existingbackup_date');
118 if ('undefined' !== typeof add_class && add_class) $content.next('td').attr('class', 'updraft_existingbackup_data');
119
120 $('<th class="backup-'+column+'">'+udclion.updraftplus.backup+' '+column+'</th>').insertAfter($header);
121 $('<td class="updraft_existingbackup_'+column+'"></td>').insertAfter($content);
122
123 return $table;
124 }
125
126 /**
127 * Inserts the storage column
128 *
129 * @param {Object} $site_row The jQuery object of the row that the existing backup data was pulled from
130 * @return {void}
131 */
132 function insert_storage_column($site_row) {
133 $table = insert_existingbackup_column($site_row, 'storage', true);
134 $table.find('tr.updraft_existing_backups_row').each(function() {
135 var $tr = $(this);
136 $tr.find('.backup_date_label img.stored_icon').each(function() {
137 $(this).appendTo($tr.find('td.updraft_existingbackup_storage'));
138 });
139 });
140 }
141
142 /**
143 * Inserts the label column
144 *
145 * @param {Object} $site_row The jQuery object of the row that the existing backup data was pulled from
146 * @return {void}
147 */
148 function insert_label_column($site_row) {
149 var $table = $site_row.find('.updraftcentral_row_extracontents table.existing-backups-table');
150 $table.find('tr.updraft_existing_backups_row').each(function() {
151 var $tr = $(this);
152 var $show_backup_data = $tr.find('td.updraft_existingbackup_data a.show-backup-data');
153 var class_name = 'backup-label-container-'+$show_backup_data.data('key');
154 $('<div class="'+class_name+' hide-backup-data"></div>').insertAfter($show_backup_data);
155
156 $tr.find('.backup_date_label br').wrap('<span></span>');
157 $tr.find('.backup_date_label .clear-right ~ span').appendTo($tr.find('div.'+class_name));
158 });
159 }
160
161 // Backup now listeners
162
163 /**
164 * Listener function for handling "Backup Now" listeners
165 *
166 * @param {Object} site_listener_row - the jQuery object of the row of the listener
167 * @param {Object} site_row - the jQuery object of the row that the backup is for
168 * @param {number} site_id - the site ID of the site that the backup is for
169 *
170 * @return {void}
171 */
172 function listener_processor_updraftplus_backup(site_listener_row, site_row, site_id) {
173
174 if ($(site_listener_row).find('.updraft_finished').length > 0) {
175 if (UpdraftCentral.get_debug_level() > 1) {
176 console.log("UDCentral: UpdraftPlus backup listener: job finished");
177 }
178 // This means, "finished, and close it after a delay")
179 return 0;
180 }
181
182 var job_id = $(site_listener_row).data('job_id');
183
184 if (!backup_listener_ticks.hasOwnProperty(job_id)) { backup_listener_ticks[job_id] = 0; }
185
186 backup_listener_ticks[job_id]++;
187
188 if (backup_listener_ticks[job_id] < 30 || 0 == backup_listener_ticks[job_id] % 3) {
189 return { call: 'updraftplus.backup_progress', data: { job_id: job_id } };
190 } else {
191 // Means "do nothing, but not because we're finished"
192 return null;
193 }
194 }
195
196 /**
197 * Listener function for handling "Backup Now" listener results
198 *
199 * @param {Object} site_listener_row - the jQuery object of the row of the listener
200 * @param {Object} site_row - the jQuery object of the row that the backup is for
201 * @param {number} site_id - the site ID of the site that the backup is for
202 * @param {*} data - the data returned by the remote call to get the backup progress
203 *
204 * @return {void}
205 */
206 function result_listener_processor_updraftplus_backup_progress(site_listener_row, site_row, site_id, data) {
207 var output = '';
208 if (data.hasOwnProperty('l')) {
209 output += '<strong>'+udclion.updraftplus.lastlogline+':</strong> '+data.l+'<br>';
210 }
211 if (data.hasOwnProperty('j')) {
212 output += data.j;
213 }
214 $(site_listener_row).find('.backup_state:first').html(UpdraftCentral_Library.sanitize_html(output));
215
216 // here we get the attributes that come with the response and make our own progressbar using bootstrap's one.
217 var info = (jQuery.type($(site_listener_row).find('.updraft_percentage').data('info')) === "undefined" ) ? udclion.updraftplus.missing_data_attributes : UpdraftCentral_Library.sanitize_html($(site_listener_row).find('.updraft_percentage').data('info'));
218 var stage = (jQuery.type($(site_listener_row).find('.updraft_percentage').data('progress')) === "undefined" ) ? '0' : UpdraftCentral_Library.quote_attribute($(site_listener_row).find('.updraft_percentage').data('progress'));
219
220 var html_to_show = "<div class='text-center' id='info"+site_id+"'>"+info+"</div>";
221 html_to_show +="<progress class='progress progress-updraftcentral' value='"+stage+"' max='100' ></progress>";
222
223 $(site_listener_row).find('.curstage').html(html_to_show);
224 }
225 UpdraftCentral.register_listener_processor('updraftplus_backup', listener_processor_updraftplus_backup);
226 UpdraftCentral.register_listener_processor('updraftplus.backup_progress', result_listener_processor_updraftplus_backup_progress);
227
228 /**
229 * A listener function for feeding back on what downloads need monitoring
230 *
231 * @param {Object} site_listener_row - jQuery object of the listener row involved
232 * @param {Object} site_row - jQuery object of the site row of the site involved
233 * @param {number} site_id - the site ID (an integer)
234 *
235 * @return {void}
236 */
237 function listener_processor_updraftplus_download(site_listener_row, site_row, site_id) {
238
239 var items = [];
240 var all_finished = null;
241 $(site_listener_row).find('.updraftplus_downloader').each(function(index, item) {
242 if ($(item).data('updraft_finished')) {
243 if (null === all_finished) { all_finished = true; }
244 } else {
245 all_finished = false;
246 }
247 var findex = $(item).data('findex');
248 var what = $(item).data('what');
249 var backup_timestamp = $(item).data('backup_timestamp');
250 // <base(arbitrary - put anything you want returned)>,<timestamp>,<type>(,<findex>)
251 items.push(site_id+','+backup_timestamp+','+what+','+findex);
252 });
253
254 if (all_finished) {
255 console.log("UDCentral: UpdraftPlus download listener: job finished - will not poll any more");
256 // 1 means "don't poll this any more, but don't close it either"
257 return 1;
258 }
259
260 return { call: 'updraftplus.get_download_status', data: items };
261 }
262
263 /**
264 * Update the listener(s) with the returned download info
265 *
266 * @param {Object} status - an object with various properties corresponding to the download state as returned by UD
267 *
268 * @return {number} - whether to not bother with polling again (advisory)
269 */
270 function updraft_downloader_status_update(status) {
271
272 var site_id = status.base;
273 var fullpath = status.f;
274 var findex = status.findex;
275 var message = status.m;
276 var percent = status.hasOwnProperty('p') ? status.p : null;
277 var size_downloaded = status.s;
278 var total_size = status.t;
279 var backup_timestamp = status.timestamp;
280 var what = status.what;
281
282 var stid = site_id+'_'+backup_timestamp+'_'+what+'_'+findex;
283 var stid_selector = '#updraftcentral_notice_container .'+stid;
284
285 var cancel_repeat = 0;
286
287 if (status.hasOwnProperty('failed') && status.failed) {
288 $(stid_selector).data('updraft_finished', true);
289 }
290
291 if (status.hasOwnProperty('e') && status.e) {
292 $(stid_selector+' .raw').html('<strong>'+udclion.error+':</strong> '+status.e);
293 console.log("UDCentral: UpdraftPlus: downloader ("+stid+"): an error was returned (follows)");
294 console.log(status);
295 } else if (status.p !== null) {
296 $(stid_selector+'_st .dlfileprogress').width(status.p+'%');
297 // Is a restart appropriate?
298 // status.a, if set, indicates that a) the download is incomplete and b) the value is the number of seconds since the file was last modified...
299 if (status.a != null && status.a > 0) {
300
301 var time_now = (new Date).getTime();
302
303 var last_time_began = $(stid_selector).data('last_time_began');
304 // Remember that this is in milliseconds
305 var since_last_restart = time_now - last_time_began;
306
307 if (status.a > 90 && since_last_restart > 60000) {
308 console.log("UDCentral: UpdraftPlus: "+stid+": restarting download: file_age="+status.a+", since_last_restart_ms="+since_last_restart);
309
310 var downloader_params = {
311 type: what,
312 timestamp: backup_timestamp,
313 findex: findex
314 };
315
316 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
317
318 // We set this, regardless of success/failure, because we don't want to send the same request multiple times, whether it succeeds or not, until an interval has passed
319 $(stid_selector).data('last_time_began', (new Date).getTime());
320
321 // We don't do anything with a positive result, in terms of creating listeners, etc., because those already exist
322 UpdraftCentral.send_site_rpc('updraftplus.downloader', downloader_params, $site_row, function(response, code, error_code) {
323 if ('ok' != code) {
324 $(stid_selector+' .raw').html(udclion.updraftplus.backup_start_failed);
325 console.log("code="+code+", error_code="+error_code);
326 console.log(response);
327 }
328 });
329
330 }
331 }
332
333 if (status.hasOwnProperty('m') && status.m != null) {
334
335 if (status.p < 100) {
336 $(stid_selector+' .raw').html(status.m);
337 } else {
338
339 msg = template_replace('updraftplus-downloaded', {
340 file_ready: udclion.updraftplus.file_ready,
341 download_to_computer: udclion.updraftplus.download_to_computer,
342 and_then: udclion.updraftplus.and_then,
343 you_should: udclion.updraftplus.you_should,
344 backup_timestamp: backup_timestamp,
345 site_id: site_id,
346 what: what,
347 findex: findex,
348 delete_from_server: udclion.updraftplus.delete_from_server
349 });
350 $(stid_selector).data('updraft_finished', true);
351 $(stid_selector+' .raw').html(msg);
352 }
353 }
354
355 // dlstatus_lastlog = response;
356 } else if (status.m != null) {
357 $(stid_selector+' .raw').html(status.m);
358 } else {
359 $(stid_selector+' .raw').html(udclion.updraftplus.backup_start_failed);
360 cancel_repeat = 1;
361 }
362 return cancel_repeat;
363 }
364
365 /**
366 * Process the results of the request for updates on the download status
367 *
368 * @param {Object} site_listener_row - jQuery object for the listener that made the request (not used)
369 * @param {Object} site_row - jQuery object for the site that the request was to (not used)
370 * @param {number} site_id - the site ID for the site that the request was to (not used)
371 * @param {array} data - the returned download statuses (one array member for each downloader that information was requested on)
372 *
373 * @return {void}
374 */
375 function result_listener_processor_updraftplus_get_download_status(site_listener_row, site_row, site_id, data) {
376 $.each(data, function(index, status) {
377 // Though the site_id is returned by UpdraftCentral's listener handling, it also comes back in the result - so, we don't need to pass anything on
378 if (status.hasOwnProperty('base')) {
379 var cancel_repeat = updraft_downloader_status_update(status);
380 }
381 });
382 }
383 UpdraftCentral.register_listener_processor('updraftplus_download', listener_processor_updraftplus_download);
384 UpdraftCentral.register_listener_processor('updraftplus.get_download_status', result_listener_processor_updraftplus_get_download_status);
385
386 /**
387 * Opens the dialog box for starting a "Backup Now" backup, via fetching the dialog contents (so that we get the relevant options) from the remote site
388 *
389 * @param {boolean} backupnow_nodb - indicate whether to exclude the database from the backup
390 * @param {boolean} backupnow_nofiles - indicate whether to exclude the files from the backup
391 * @param {boolean} backupnow_nocloud - indicate whether to skip sending the backup to any configured remote destination
392 * @param {string} [onlythesefileentities] - a comma-separated list of file entities to back up (only relevant if files are being backed up)
393 * @param {String} [onlythesetableentities] a comma-separated list of table entities to back up (only relevant if databases are being backed up)
394 * @param {*} [extradata] - arbitrary extra data to send with the backup request (though, of course, only relevant data will have any effect)
395 * @param {string} [label] - a label to give to the backup
396 * @param {String} onlythesecloudservices An array of remote sorage locations to be backed up to
397 *
398 * @return {void}
399 */
400 this.backupnow_go = function(backupnow_nodb, backupnow_nofiles, backupnow_nocloud, onlythesefileentities, extradata, label, onlythesetableentities, onlythesecloudservices) {
401
402 var listener_title;
403 if (extradata && extradata.hasOwnProperty('_listener_title')) {
404 listener_title = extradata._listener_title;
405 delete extradata._listener_title;
406 }
407
408 var params = {
409 backupnow_nodb: backupnow_nodb,
410 backupnow_nofiles: backupnow_nofiles,
411 backupnow_nocloud: backupnow_nocloud,
412 backupnow_label: label,
413 extradata: extradata
414 };
415
416 if ('' != onlythesefileentities) {
417 params.onlythisfileentity = onlythesefileentities;
418 }
419
420 if ('' != onlythesetableentities) {
421 params.onlythesetableentities = onlythesetableentities;
422 }
423
424 if ('' != onlythesecloudservices) {
425 params.onlythesecloudservices = onlythesecloudservices;
426 }
427
428 params.always_keep = (typeof extradata.always_keep !== 'undefined') ? extradata.always_keep : 0;
429
430 params.incremental = (typeof extradata.incremental !== 'undefined') ? extradata.incremental : 0;
431
432 UpdraftCentral.send_site_rpc('updraftplus.backupnow', params, UpdraftCentral.$site_row, function(response, code, error_code) {
433 if ('ok' == code && false !== response && response.hasOwnProperty('data')) {
434 if (response.data.hasOwnProperty('nonce')) {
435
436 var listener_message = '<div class="backup_state">'+udclion.updraftplus.backupstarted +'</div>';
437
438 var job_id = response.data.nonce;
439 backup_listener_ticks[job_id] = 0;
440
441 UpdraftCentral.create_dashboard_listener('updraftplus_backup', UpdraftCentral.$site_row, listener_message, { job_id: response.data.nonce }, listener_title);
442
443 } else {
444 UpdraftCentral.add_dashboard_notice('<h2>'+UpdraftCentral.$site_row.data('site_description')+'</h2>'+udclion.updraftplus.backup_start_failed, 'error');
445 }
446 }
447 });
448
449 }
450
451 /**
452 * Create a download listener
453 *
454 * @param {number} site_id - the ID of the site that the downloader is for
455 * @param {number} backup_timestamp - the epoch time of the backup
456 * @param {string} what - the entity name to download (e.g. "plugins")
457 * @param {string} set_contents - comma-separated list of indexes corresponding to files to download
458 * @param {string} pretty_date - the formatted date of the backup
459 * @param {boolean} async - (unused; future possibility) whether to send the request asynchronously, or not
460 * @param {Object} spinner_where - a jQuery object indicating where to place the spinner
461 *
462 * @return {void}
463 */
464 function updraft_downloader(site_id, backup_timestamp, what, set_contents, pretty_date, async, spinner_where) {
465
466 if (typeof set_contents !== "string") set_contents = set_contents.toString();
467 async = async ? true : false;
468
469 set_contents = set_contents.split(',');
470
471 // If there's an existing listener downloading from this site, then add our widget to it instead of creating another.
472 var $listener = $('#updraftcentral_notice_container .updraftcentral_listener_updraftplus_download[data-site_id="'+site_id+'"');
473 if ($listener.length == 0) { $listener = false; }
474
475 for (var i=0; i<set_contents.length; i++) {
476
477 // Create somewhere for the status to be found
478
479 var findex = set_contents[i];
480 var stid = site_id+'_'+backup_timestamp+'_'+what+'_'+findex;
481 var stid_selector = '.'+stid;
482
483 if ($(stid_selector).length) {
484 console.log("UDCentral: There already appears to be an active downloader for this entity (stid: "+stid+")");
485 return;
486 }
487
488 // Now send the actual request to kick it all off
489
490 var downloader_params = {
491 type: what,
492 timestamp: backup_timestamp,
493 findex: findex
494 };
495
496 UpdraftCentral.send_site_rpc('updraftplus.downloader', downloader_params, UpdraftCentral.$site_row, function(response, code, error_code) {
497 if ('ok' == code && false !== response && response.hasOwnProperty('data') && response.data.hasOwnProperty('result')) {
498
499 var result = response.data.result;
500 var request = response.data.request;
501
502 var backup_timestamp = request.timestamp;
503 var what = request.type;
504 var findex = parseInt(request.findex);
505
506 var stid = site_id+'_'+backup_timestamp+'_'+what+'_'+findex;
507 var stid_selector = '.'+stid;
508
509 var msg = '??';
510
511 var last_time_began = (new Date).getTime();
512
513 var show_index = findex+1;
514 var itext = (findex == 0) ? '' : ' ('+show_index+')';
515 var prdate = (pretty_date) ? pretty_date : backup_timestamp;
516
517 // This is the parent object, that contains the results. The updated results go into div.raw within this.
518 widgets_html = template_replace('updraftplus-downloader', {
519 stid: stid,
520 download_verb: udclion.updraftplus.download_verb,
521 what: what,
522 itext: itext,
523 pretty_date: prdate,
524 begun_looking: udclion.updraftplus.begun_looking,
525 site_id: site_id,
526 backup_timestamp: backup_timestamp,
527 findex: findex
528 });
529
530 // deleted|downloaded|needs_download|download_failed
531 if ('downloaded' == result) {
532 msg = template_replace('updraftplus-downloaded', {
533 file_ready: udclion.updraftplus.file_ready,
534 download_to_computer: udclion.updraftplus.download_to_computer,
535 and_then: udclion.updraftplus.and_then,
536 you_should: udclion.updraftplus.you_should,
537 backup_timestamp: backup_timestamp,
538 site_id: site_id,
539 what: what,
540 findex: findex,
541 delete_from_server: udclion.updraftplus.delete_from_server
542 });
543 } else if ('needs_download' == result) {
544 msg = udclion.updraftplus.needs_download;
545 } else if ('download_failed' == result) {
546 msg = udclion.updraftplus.download_failed;
547 }
548
549 if (false === $listener) {
550 $listener = UpdraftCentral.create_dashboard_listener('updraftplus_download', UpdraftCentral.$site_row, widgets_html);
551 } else {
552 // Add a new widget into that listener
553 $listener.append(widgets_html);
554 }
555 // If it was already marked as 'finished', then it won't be polled - we want it to start being polled again
556 $listener.data('finished', false);
557 $listener.find(stid_selector).data('last_time_began', last_time_began);
558 $listener.find(stid_selector+' .raw').html(msg);
559
560
561 } else {
562 UpdraftCentral.add_dashboard_notice('<h2>'+UpdraftCentral.$site_row.data('site_description')+'</h2>'+udclion.updraftplus.download_start_failed, 'error');
563 }
564 });
565
566 }
567 }
568
569 var updraftplus_morefiles_lastind = 0;
570 var updraftplus_version = 0;
571
572 /**
573 * Get the "Settings" panel from the remote UpdraftPlus
574 *
575 * @param {Object} $site_row - jQuery object for the row of the site for which the information is being requested
576 *
577 * @return {void}
578 */
579 function updraft_get_existing_backup_settings($site_row) {
580
581 $site_row.find('.updraftcentral_row_extracontents').css('opacity', '0.3');
582
583 UpdraftCentral.send_site_rpc('updraftplus.get_settings', {
584 include_database_decrypter: 0,
585 include_adverts: 0,
586 include_save_button: 1
587 }, $site_row, function(response, code, error_code) {
588 $site_row.find('.updraftcentral_row_extracontents').css('opacity', '1.0');
589 if ('ok' == code && response) {
590 $site_row.find('.updraftcentral_row_extracontents').html('<div class="updraft_site_settings_output"><button class="btn btn-refresh updraftcentral_site_backup_settings"><span class="dashicons dashicons-image-rotate "></span></button>'+UpdraftCentral_Library.sanitize_html(response.data.settings)+'</div>');
591 if (response.data.hasOwnProperty('remote_storage_templates') && response.data.hasOwnProperty('remote_storage_options')) {
592 var html = '';
593 for (var method in response.data.remote_storage_templates) {
594 if ('undefined' != typeof response.data.remote_storage_options[method]) {
595 var template = Handlebars.compile(response.data.remote_storage_templates[method]);
596 var first_instance = true;
597 for (var instance_id in response.data.remote_storage_options[method]) {
598 if ('default' === instance_id) continue;
599 var context = response.data.remote_storage_options[method][instance_id];
600 context['first_instance'] = first_instance;
601 if ('undefined' == typeof context['instance_enabled']) {
602 context['instance_enabled'] = 1;
603 }
604 html += template(context);
605 first_instance = false;
606 }
607 } else {
608 html += response.data.remote_storage_templates[method];
609 }
610 }
611 $('#remote-storage-holder').append(html);
612 }
613
614 $('.updraftcentral_row_extracontents #remote-storage-holder').on('click', '.updraftplusmethod a.updraft_add_instance', function(e) {
615 e.preventDefault();
616
617 var method = $(this).data('method');
618 add_new_instance(method);
619 });
620
621 $('.updraftcentral_row_extracontents #remote-storage-holder').on('click', '.updraftplusmethod a.updraft_delete_instance', function(e) {
622 e.preventDefault();
623
624 var method = $(this).data('method');
625 var instance_id = $(this).data('instance_id');
626
627 if (1 === $('.' + method + '_updraft_remote_storage_border').length) {
628 add_new_instance(method);
629 }
630
631 $('.' + method + '-' + instance_id).hide('slow', function() {
632 $(this).remove();
633 });
634 });
635
636 /**
637 * This method will get the default options and compile a template with them
638 *
639 * @param {string} method - the remote storage name
640 * @param {boolean} first_instance - indicates if this is the first instance of this type
641 */
642 function add_new_instance(method) {
643 var template = Handlebars.compile(response.data.remote_storage_templates[method]);
644 var context = response.data.remote_storage_options[method]['default'];
645 context['instance_id'] = 's-' + generate_instance_id(32);
646 context['instance_enabled'] = 1;
647 var html = template(context);
648 $(html).hide().insertAfter('.' + method + '_add_instance_container:first').show('slow');
649 }
650
651 /**
652 * This method will return a random instance id string
653 *
654 * @param {integer} length - the length of the string to be generated
655 *
656 * @return string - the instance id
657 */
658 function generate_instance_id(length) {
659 var uuid = '';
660 var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
661
662 for (var i = 0; i < length; i++) {
663 uuid += characters.charAt(Math.floor(Math.random() * characters.length));
664 }
665
666 return uuid;
667 }
668
669 $('.updraftcentral_row_extracontents #remote-storage-holder').on("change", "input[class='updraft_instance_toggle']", function () {
670 if ($(this).is(':checked')) {
671 $(this).siblings('label').html(udclion.updraftplus.instance_enabled);
672 } else {
673 $(this).siblings('label').html(udclion.updraftplus.instance_disabled);
674 }
675 });
676
677 /**
678 * For some reason, the google caja sanitizer is removing the "aria-label" attribute or is currently
679 * not supported. The "aria-label" is intended for accessibility and used by the labelauty to update the label
680 * tag's attribute. Thus, we're rebuilding the aria-label attribute based from the value of the checkbox element
681 * to restore the lost keyboard support (e.g. tab, etc.)
682 */
683 $site_row.find('.updraftcentral_row_extracontents #remote-storage-container > input[type="checkbox"]').each(function() {
684 var input = jQuery(this);
685 input.attr('aria-label', udclion.updraftplus.backup_using + ' ' + input.val() + '?');
686 });
687
688
689 // Set the initial state of the schedule selection text and widgetry
690 updraft_check_same_times();
691
692 updraft_remote_storage_tabs_setup();
693
694 updraft_extra_dbs = 0;
695 updraftplus_morefiles_lastind = 0;
696
697 if (response.data.hasOwnProperty('meta')) {
698
699 var meta = response.data.meta;
700
701 if (meta.hasOwnProperty('retain_rules') && meta.retain_rules.hasOwnProperty('files')) {
702 setup_retain_rules(meta.retain_rules.files, meta.retain_rules.db);
703 }
704
705 if (meta.hasOwnProperty('extra_dbs')) {
706 $.each(meta.extra_dbs, function(i, db) {
707 if (db.hasOwnProperty('host')) {
708 extradbs_add(db.host, db.user, db.name, db.pass, db.prefix);
709 }
710 });
711 }
712 }
713
714 if (response.data.hasOwnProperty('updraftplus_version')) {
715 updraftplus_version = response.data.updraftplus_version;
716 }
717
718 setup_file_entity_exclude_field('uploads');
719 setup_file_entity_exclude_field('others');
720 setup_file_entity_exclude_field('wpcore');
721
722 reportbox_index = $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_report_cell .updraft_reportbox').length + 2;
723
724 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_paths input.updraft_include_more_path').each(function(i, input) {
725 var mp_index = $(input).data(mp_index);
726 if (mp_index > updraftplus_morefiles_lastind) { updraftplus_morefiles_lastind = mp_index; }
727 });
728
729 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output input[type="submit"]').removeClass().addClass('btn btn-primary-outline');
730
731 // Update the WebDAV URL setting as the user edits
732 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output').on("change keyup paste", '.updraft_webdav_settings', function() {
733
734 var updraft_webdav_settings = [];
735 var instance_id = "";
736 $('.updraft_webdav_settings').each(function(index, item) {
737
738 var id = $(item).attr('id');
739
740 // The first part of the "if" is to handle the old options format and can be removed in future
741 if (id && 'updraft_webdav_settings_' == id.substring(0, 24)) {
742 var which_one = id.substring(24);
743 updraft_webdav_settings[which_one] = this.value;
744 } else if (id && 'updraft_webdav_' == id.substring(0, 15)) {
745 var which_one = id.substring(15);
746 id_split = which_one.split('_');
747 which_one = id_split[0];
748 instance_id = id_split[1];
749 if ('undefined' == typeof updraft_webdav_settings[instance_id]) updraft_webdav_settings[instance_id] = [];
750 updraft_webdav_settings[instance_id][which_one] = this.value;
751 }
752
753 });
754
755 var updraft_webdav_url = "";
756 var host = "@";
757 var slash = "/";
758 var colon = ":";
759 var colon_port = ":";
760
761 for (var instance_id in updraft_webdav_settings) {
762
763 if (updraft_webdav_settings[instance_id]['host'].indexOf("@") >= 0 || "" === updraft_webdav_settings[instance_id]['host']) {
764 host = "";
765 }
766
767 if (updraft_webdav_settings[instance_id]['host'].indexOf("/") >= 0 ) {
768 $('#updraft_webdav_host_error').show();
769 } else {
770 $('#updraft_webdav_host_error').hide();
771 }
772
773 if (updraft_webdav_settings[instance_id]['path'].indexOf("/") == 0 || "" === updraft_webdav_settings[instance_id]['path']) {
774 slash = "";
775 }
776
777 if ("" === updraft_webdav_settings[instance_id]['user'] || "" === updraft_webdav_settings[instance_id]['pass']) {
778 colon = "";
779 }
780
781 if ("" === updraft_webdav_settings[instance_id]['host'] || "" === updraft_webdav_settings[instance_id]['port']) {
782 colon_port = "";
783 }
784
785 updraft_webdav_url = updraft_webdav_settings[instance_id]['webdav'] + updraft_webdav_settings[instance_id]['user'] + colon + updraft_webdav_settings[instance_id]['pass'] + host + encodeURIComponent(updraft_webdav_settings[instance_id]['host']) + colon_port + updraft_webdav_settings[instance_id]['port'] + slash + updraft_webdav_settings[instance_id]['path'];
786 masked_webdav_url = updraft_webdav_settings[instance_id]['webdav'] + updraft_webdav_settings[instance_id]['user'] + colon + updraft_webdav_settings[instance_id]['pass'].replace(/./gi, '*') + host + encodeURIComponent(updraft_webdav_settings[instance_id]['host']) + colon_port + updraft_webdav_settings[instance_id]['port'] + slash + updraft_webdav_settings[instance_id]['path'];
787
788 // The first part of the "if" is to handle the old options format and can be removed in future
789 if ("" == instance_id) {
790 $('#updraftcentral_dashboard .updraft_site_settings_output #updraft_webdav_settings_url').val(updraft_webdav_url);
791 } else {
792 $('#updraftcentral_dashboard .updraft_site_settings_output #updraft_webdav_url_' + instance_id).val(updraft_webdav_url);
793 $('#updraftcentral_dashboard .updraft_site_settings_output #updraft_webdav_masked_url_' + instance_id).val(masked_webdav_url);
794 }
795 }
796 });
797
798 }
799 });
800 }
801
802 var updraft_extra_dbs = 0;
803 /**
804 * Add a box for configuring backing of an extra database
805 *
806 * @param {string} host - The hostname of the MySQL database to be backed up
807 * @param {string} user - The MySQL username
808 * @param {string} name - The name of the MySQL database
809 * @param {string} pass - The MySQL password
810 * @param {string} prefix - Only tables prefixed with this string will be backed up. Pass an empty string to back them all up.
811 *
812 * @return {void}
813 */
814 function extradbs_add(host, user, name, pass, prefix) {
815 updraft_extra_dbs++;
816 $(template_replace('updraftplus-settings-extra-db', {
817 updraft_extra_dbs: updraft_extra_dbs,
818 remove: udclion.updraftplus.remove,
819 backup_external_database: udclion.updraftplus.backup_external_database,
820 host: udclion.updraftplus.host,
821 database: udclion.updraftplus.database,
822 username: udclion.updraftplus.username,
823 password: udclion.updraftplus.password,
824 table_prefix: udclion.updraftplus.table_prefix,
825 backup_tables_with_prefixes: udclion.updraftplus.backup_tables_with_prefixes,
826 test_connection: udclion.updraftplus.test_connection
827 }, {
828 host_attr: host,
829 user_attr: user,
830 name_attr: name,
831 pass_attr: pass,
832 prefix_attr: prefix
833 })).appendTo($('#updraft_backupextradbs')).fadeIn();
834 }
835
836 /**
837 * Registers listeners that occur on all tabs.
838 *
839 * @return {void}
840 */
841 function register_global_listeners() {
842 UpdraftCentral.register_row_clicker('.row_backupnow, .updraftcentral_site_backup_now', function($site_row) {
843 backup_now($site_row, 'new');
844 });
845
846 UpdraftCentral.register_row_clicker('.row_backupnow, .updraftcentral_site_backup_now_increment', function ($site_row) {
847 backup_now($site_row, 'incremental');
848 });
849
850 UpdraftCentral.register_modal_listener('#backupnow_includefiles_showmoreoptions', function(e) {
851 e.preventDefault();
852 $('#updraftcentral_modal #backupnow_includefiles_moreoptions').slideToggle();
853 });
854
855 UpdraftCentral.register_modal_listener('#backupnow_database_showmoreoptions', function(e) {
856 e.preventDefault();
857 $('#updraftcentral_modal #backupnow_database_moreoptions').slideToggle();
858 });
859
860 UpdraftCentral.register_modal_listener('#backupnow_includecloud_showmoreoptions', function(e) {
861 e.preventDefault();
862 $('#updraftcentral_modal #backupnow_includecloud_moreoptions').slideToggle();
863 });
864 }
865
866 if ('notices' != UpdraftCentral.get_dashboard_mode()) { register_global_listeners(); }
867
868 // Register the row clickers for all tabs
869 $('#updraftcentral_dashboard_existingsites').on('updraftcentral_dashboard_mode_set', function(event, data) {
870
871 // The 'upgrade' tab has no sites rows visible
872 if (data && data.hasOwnProperty('new_mode') && 'notices' == data.new_mode) { return; }
873
874 register_global_listeners();
875
876 });
877
878 // Register the row clickers for this tab
879 $('#updraftcentral_dashboard_existingsites').on('updraftcentral_dashboard_mode_set_backups', function() {
880
881 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_backupextradb_another', function() {
882 extradbs_add('', '', '', '', '');
883 });
884
885 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_backupextradbs .updraft_backupextradbs_row_delete', function() {
886 $(this).parents('.updraft_backupextradbs_row').fadeOut('medium', function() {
887 $(this).remove();
888 });
889 });
890
891 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_backupextradbs .updraft_backupextradbs_row_testconnection', function() {
892 var $row = $(this).closest('.updraft_backupextradbs_row');
893 $row.find('.updraft_backupextradbs_testresultarea').html('<p><em>'+udclion.updraftplus.testing+'</em></p>');
894
895 var data = {
896 row: $row.attr('id'),
897 host: $row.find('.extradb_host').val(),
898 user: $row.find('.extradb_user').val(),
899 pass: $row.find('.extradb_pass').val(),
900 name: $row.find('.extradb_name').val(),
901 prefix: $row.find('.extradb_prefix').val()
902 };
903
904 UpdraftCentral.send_site_rpc('updraftplus.extradb_testconnection', data, UpdraftCentral.$site_row, function(response, code, error_code) {
905 if ('ok' == code && response) {
906 $row.find('.updraft_backupextradbs_testresultarea').html(UpdraftCentral_Library.sanitize_html(response.data.m));
907 }
908 }, $row);
909 });
910
911 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod button.updraft-test-button', function() {
912
913 var $method_button = $(this);
914 var instance_id = jQuery(this).data('instance_id');
915 var method = $method_button.data('method');
916
917 updraft_remote_storage_test($method_button, function(response, code, error_code, data) {
918
919 if ('sftp' != method) { return false; }
920
921 if ('undefined' !== typeof data && data.hasOwnProperty('scp') && data.scp) {
922 UpdraftCentral_Library.dialog.alert('<h2>'+sprintf(udclion.updraftplus.settings_test_result, 'SCP')+'</h2> '+response.data.output);
923 } else {
924 UpdraftCentral_Library.dialog.alert('<h2>'+sprintf(udclion.updraftplus.settings_test_result, 'SFTP')+'</h2> '+response.data.output);
925 }
926
927 if (response.hasOwnProperty('data') && response.data) {
928 if (response.data.hasOwnProperty('data') && response.data.data) {
929 if ('undefined' !== typeof response.data.data.valid_md5_fingerprint) {
930 $('#updraft_sftp_fingerprint_'+instance_id).val(response.data.data.valid_md5_fingerprint);
931 }
932 }
933 }
934
935 return true;
936
937 });
938 });
939
940 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraftplus-settings-save', function($site_row, site_id) {
941
942 // Gather data
943 var form_data = $(settings_css_prefix+' input, '+settings_css_prefix+' textarea, '+settings_css_prefix+' select').serialize();
944
945 // include unchecked checkboxes. user filter to only include unchecked boxes.
946 $.each($(settings_css_prefix+' input[type=checkbox]')
947 .filter(function(idx) {
948 return $(this).prop('checked') == false
949 }),
950 function(idx, el) {
951 // attach matched element names to the form_data with chosen value.
952 var empty_val = '0';
953 form_data += '&' + $(el).attr('name') + '=' + empty_val;
954 }
955 );
956
957 spin_this = $(this).closest('td');
958
959 form_data += '&updraftplus_version=' + updraftplus_version;
960
961 UpdraftCentral.send_site_rpc('updraftplus.save_settings', form_data, $site_row, function(response, code, error_code) {
962
963 if ('ok' === code) {
964
965 // If backup dir is not writable, change the text, and grey out the 'Backup Now' button
966 var backup_dir_writable = response.data.backup_dir.writable;
967 var backup_dir_message = response.data.backup_dir.message;
968 var backup_button_title = response.data.backup_dir.button_title;
969
970 if (backup_dir_writable == false) {
971 // $('#updraft-backupnow-button').attr('disabled', 'disabled');
972 // $('#updraft-backupnow-button').attr('title', backup_button_title);
973 $(settings_css_prefix+'#updraft_writable_mess').html(backup_dir_message);
974 $(settings_css_prefix+'.backupdirrow').show();
975 } else {
976 // $('#updraft-backupnow-button').removeAttr('disabled');
977 // $('#updraft-backupnow-button').removeAttr('title');
978 $(settings_css_prefix+'.backupdirrow').hide();
979 }
980
981 var site_url = $site_row.data('site_url');
982
983 // Get rid of any existing results-of-saving-settings boxes
984 $('#updraftcentral_notice_container .updraftplus_saved_settings').closest('.updraftcentral_notice').remove();
985
986 var $new_notice = add_dashboard_notice('<h2>'+udclion.updraftplus.settings_saved+' - '+site_url+'</h2><div class="updraftplus_saved_settings" data-site_id="'+site_id+'">'+response.data.messages+'</div>', 'notice', false);
987
988 $('html, body').animate({
989 scrollTop: $new_notice.offset().top
990 }, 1000);
991 }
992
993 }, spin_this);
994
995 });
996
997 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'.backupdirrow a.updraft_backup_dir_reset', function() {
998 $(settings_css_prefix+'#updraft_dir').val('updraft');
999 });
1000
1001 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .enableexpertmode', function() {
1002 $('.updraftcentral_row_extracontents .updraft_site_settings_output .expertmode').fadeIn();
1003 $('.updraftcentral_row_extracontents .updraft_site_settings_output .enableexpertmode').off('click');
1004 });
1005
1006 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+' a.updraft_authlink', function($site_row) {
1007 var href = $(this).attr('href');
1008 if ('undefined' === typeof href) { return; }
1009 var spinner_where = $(this).closest('td');
1010 UpdraftCentral_Library.open_browser_at($site_row, { module: 'direct_url', url: href }, spinner_where);
1011 });
1012
1013 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .updraft_include_entity', function() {
1014 var has_exclude_field = $(this).data('toggle_exclude_field');
1015 if (has_exclude_field) {
1016 setup_file_entity_exclude_field(has_exclude_field, false);
1017 }
1018 }, false, 'change');
1019
1020 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output .updraft_existingbackup_date', function($site_row) {
1021 var data = $(this).data('rawbackup');
1022 if (data != null && data != '') {
1023 UpdraftCentral.open_modal(udclion.updraftplus.raw, data, true, false);
1024 }
1025 }, false, 'dblclick');
1026
1027 register_modal_listener('#always_keep_this_backup', function(e) {
1028 var backup_key = $(this).data('backup_key');
1029 UpdraftCentral.send_site_rpc('updraftplus.always_keep_this_backup', {
1030 backup_key: backup_key,
1031 always_keep: $(this).is(':checked') ? 1 : 0
1032 }, UpdraftCentral.$site_row, function (response, code, error_code) {
1033 if ('ok' == code && false !== response && response.hasOwnProperty('data')) {
1034 if (response.data.hasOwnProperty('rawbackup')) {
1035 UpdraftCentral.close_modal();
1036 $('.updraft_existing_backups_row_'+backup_key+' .updraft_existingbackup_date').data('rawbackup', response.data.rawbackup);
1037 UpdraftCentral.open_modal(udclion.updraftplus.raw, response.data.rawbackup, true, false);
1038 }
1039 }
1040 });
1041 }, 'change');
1042
1043 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output .choose-components-button', function($site_row) {
1044 var this_button = this;
1045 var entities = $(this_button).data('entities');
1046 var spinner_where = $(this_button).closest('td');
1047 if (entities) {
1048
1049 // Alert the user of possible consequences of restoring + other relevant info, before proceeding.
1050 UpdraftCentral_Library.dialog.confirm('<h2>'+udclion.updraftplus.restore_backup+'</h2>'+udclion.updraftplus.pre_restore_message, function(go_ahead) {
1051 if (!go_ahead) { return; }
1052 UpdraftCentral_Library.open_browser_at($site_row, { module: 'updraftplus', action: 'initiate_restore', data: {
1053 entities: entities,
1054 backup_timestamp: $(this_button).data('backup_timestamp'),
1055 showdata: $(this_button).data('showdata')
1056 } }, spinner_where);
1057
1058 restored_items.add($(this_button).data('backup_timestamp'), $(this_button).closest('tr.updraft_existing_backups_row').data('nonce'));
1059 });
1060
1061 }
1062 });
1063
1064 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output .updraft_download_button', function($site_row) {
1065
1066 var site_id = $site_row.data('site_id');
1067 var backup_timestamp = $(this).data('backup_timestamp');
1068 var what = $(this).data('what');
1069 var set_contents = $(this).data('set_contents');
1070 var pretty_date = $(this).data('prettydate');
1071 var async = true;
1072
1073 var spinner_where = $(this).closest('td');
1074
1075 updraft_downloader(site_id, backup_timestamp, what, set_contents, pretty_date, async, spinner_where);
1076
1077 });
1078
1079 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output button.updraft-upload-link', function ($site_row) {
1080 $(this).hide();
1081 var nonce = $(this).data('nonce').toString();
1082 var key = $(this).data('key').toString();
1083 if (nonce) {
1084 UpdraftCentral.send_site_rpc('updraftplus.upload_local_backup', {
1085 use_nonce: nonce,
1086 use_timestamp: key
1087 }, UpdraftCentral.$site_row, function (response, code, error_code) {
1088 if ('ok' == code && false !== response && response.hasOwnProperty('data')) {
1089 if (response.data.hasOwnProperty('nonce')) {
1090
1091 var listener_message = '<div class="backup_state">' + udclion.updraftplus.backupstarted + '</div>';
1092
1093 UpdraftCentral.create_dashboard_listener('updraftplus_backup', UpdraftCentral.$site_row, listener_message, { job_id: response.data.nonce }, udclion.updraftplus.upload_backup);
1094
1095 } else {
1096 UpdraftCentral.add_dashboard_notice('<h2>' + UpdraftCentral.$site_row.data('site_description') + '</h2>' + udclion.updraftplus.backup_start_failed, 'error');
1097 }
1098 }
1099 });
1100 } else {
1101 console.log("UDCentral: UpdraftPlus: A upload link was clicked, but the backup ID could not be found");
1102 }
1103 });
1104
1105 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output .updraft-delete-link', function($site_row) {
1106 var hasremote = $(this).data('hasremote').toString();
1107 hasremote = (hasremote === '0') ? false : true;
1108 var nonce = $(this).data('nonce').toString();
1109 var key = $(this).data('key').toString();
1110
1111 delete_action = 'single';
1112 if (nonce) {
1113 if (restored_items.exists(key)) {
1114 updraft_get_existing_backups_panel($site_row);
1115 } else {
1116 updraft_delete(key, nonce, hasremote);
1117 }
1118 } else {
1119 console.log("UDCentral: UpdraftPlus: A delete link was clicked, but the backup ID could not be found");
1120 }
1121 });
1122
1123 UpdraftCentral.register_event_handler('click', '.delete-backup-container input.delete_backup_item', function($site_row) {
1124 var checked = $('.delete-backup-container input.delete_backup_item:checked').length;
1125
1126 if (0 < checked) {
1127 $('button#btn-backup-bulk-delete').removeClass('btn-secondary').addClass('btn-primary');
1128 } else {
1129 $('button#btn-backup-bulk-delete').removeClass('btn-primary').addClass('btn-secondary');
1130 }
1131 });
1132
1133 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output button#btn-backup-bulk-delete', function($site_row) {
1134 var keys = [],
1135 hasremote = false,
1136 nonce,
1137 hasrestored = false;
1138
1139 selected_items.clear();
1140 $('.delete-backup-container input.delete_backup_item:checked').each(function() {
1141 var delete_link = $(this).closest('tr.updraft_existing_backups_row').find('a.updraft-delete-link');
1142 var key = delete_link.data('key');
1143
1144 if ('undefined' !== typeof key && key) {
1145 keys.push(key.toString());
1146 nonce = delete_link.data('nonce');
1147
1148 if (!hasremote) {
1149 hasremote = ('undefined' === typeof delete_link.data('hasremote') || delete_link.data('hasremote') === '0') ? false : true;
1150 }
1151
1152 if (restored_items.exists(key)) hasrestored = true;
1153 selected_items.add(key, $(this).closest('tr.updraft_existing_backups_row').data('nonce'));
1154 }
1155 });
1156
1157 delete_action = 'multiple';
1158 if (keys.length) {
1159 if (hasrestored) {
1160 updraft_get_existing_backups_panel($site_row);
1161 } else {
1162 updraft_delete(keys.join(), nonce, hasremote);
1163 }
1164 } else {
1165 console.log("UDCentral: UpdraftPlus: The bulk delete button was clicked, but none of the backup IDs could be found");
1166 }
1167 });
1168
1169 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output a.updraft_diskspaceused_update', function($site_row) {
1170 var spin_this = this.closest('ul');
1171 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', { fragment: 'disk_usage', data: 'updraft' } , $site_row, function(response, code, error_code) {
1172 if ('ok' == code && response) {
1173 $site_row.find('.updraft_diskspaceused').html(UpdraftCentral_Library.sanitize_html(response.data.output));
1174 }
1175 }, spin_this);
1176 });
1177
1178 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output a.updraft_rescan_local', function($site_row) {
1179 var spin_this = this.closest('ul');
1180 $site_row.find('.updraft_existing_backups').html('<div class="rescanning">'+udclion.updraftplus.rescanning+'</div>');
1181 UpdraftCentral.send_site_rpc('updraftplus.rescan', 'rescan' , $site_row, function(response, code, error_code) {
1182 if ('ok' == code && response) {
1183 $site_row.find('.updraft_existing_backups').html(response.data.t);
1184 $site_row.find('.updraft_existing_backups_output h2').html(response.data.n);
1185
1186 insert_bulk_delete($site_row);
1187 }
1188 }, spin_this);
1189 });
1190
1191 UpdraftCentral.register_row_clicker('.updraft_existing_backups_output a.updraft_rescan_remote', function($site_row) {
1192 var spin_this = this.closest('ul');
1193 $site_row.find('.updraft_existing_backups').html('<div class="rescanning">'+udclion.updraftplus.rescanningremote+'</div>');
1194 UpdraftCentral.send_site_rpc('updraftplus.rescan', 'remotescan' , $site_row, function(response, code, error_code) {
1195 if ('ok' == code && response) {
1196 $site_row.find('.updraft_existing_backups').html(response.data.t);
1197 $site_row.find('.updraft_existing_backups_output h2').html(response.data.n);
1198
1199 insert_bulk_delete($site_row);
1200 }
1201 }, spin_this, 90);
1202 });
1203
1204 UpdraftCentral.register_row_clicker('.updraftcentral_site_backups_manage', function($site_row) {
1205 updraft_get_existing_backups_panel($site_row);
1206 }, true);
1207
1208 UpdraftCentral.register_row_clicker('.updraftcentral_site_backup_settings', function($site_row) {
1209 updraft_get_existing_backup_settings($site_row);
1210 }, true);
1211
1212 UpdraftCentral.register_row_clicker('.updraft_site_settings_output select.updraft_interval, .updraft_site_settings_output select.updraft_interval_database', function() {
1213 updraft_check_same_times();
1214 }, false, 'change');
1215
1216 // Remote method authentication click
1217 UpdraftCentral.register_row_clicker('.updraft_authlink', function($site_row) {
1218 var spin_this = this.closest('ul');
1219 var data = {
1220 remote_method: $(this).data('remote_method'),
1221 instance_id: $(this).data('instance_id')
1222 }
1223
1224 UpdraftCentral.send_site_rpc('updraftplus.auth_remote_method', data, $site_row, function(response, code, error_code) {
1225 if ('ok' == code && false !== response) {
1226 var resp = response.data;
1227 if ('error' == resp.result) {
1228 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.error+'</h2>'+resp.message);
1229 } else if ('success' == resp.result) {
1230 updraft_get_existing_backup_settings($site_row);
1231 }
1232 }
1233 }, spin_this);
1234
1235 }, true);
1236
1237 // Remote method deauthentication click
1238 UpdraftCentral.register_row_clicker('.updraft_deauthlink', function($site_row) {
1239 var spin_this = this.closest('ul');
1240 var data = {
1241 remote_method: $(this).data('remote_method'),
1242 instance_id: $(this).data('instance_id')
1243 }
1244
1245 UpdraftCentral.send_site_rpc('updraftplus.deauth_remote_method', data, $site_row, function(response, code, error_code) {
1246 if ('ok' == code && false !== response) {
1247 var resp = response.data;
1248 if ('error' == resp.result) {
1249 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.error+'</h2>'+resp.message);
1250 } else if ('success' == resp.result) {
1251 updraft_get_existing_backup_settings($site_row);
1252 }
1253 }
1254 }, spin_this);
1255
1256 }, true);
1257
1258 UpdraftCentral.register_row_clicker('.updraft_site_settings_output #updraft_retain_db_addnew', function() {
1259 add_rule('db', 12, 604800, 1, 604800);
1260 });
1261
1262 UpdraftCentral.register_row_clicker('.updraft_site_settings_output #updraft_retain_files_addnew', function() {
1263 add_rule('files', 12, 604800, 1, 604800);
1264 });
1265
1266 UpdraftCentral.register_row_clicker('.updraft_site_settings_output .updraft_retain_rules_delete, .updraft_site_settings_output .updraft_retain_rules_delete', function() {
1267 $(this).parent('.updraft_retain_rules').slideUp(function() {
1268 $(this).remove();
1269 });
1270 });
1271
1272 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_report_cell .updraft_reportbox .updraft_reportbox_delete', function() {
1273 $(this).closest('.updraft_reportbox').fadeOut('medium', function() {
1274 $(this).remove();
1275 });
1276 });
1277
1278 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_report_cell .updraft_report_another', function() {
1279
1280 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_report_cell .updraft_report_another_p').before(template_replace('updraftplus-settings-report-email', {
1281 index: reportbox_index,
1282 send_only_on_warnings: udclion.updraftplus.send_only_on_warnings,
1283 whole_backup: udclion.updraftplus.whole_backup,
1284 email_size_limits: udclion.updraftplus.email_size_limits,
1285 db_backup: udclion.updraftplus.db_backup
1286 }));
1287 $('#updraft_reportbox_'+reportbox_index).fadeIn();
1288 reportbox_index++;
1289
1290 });
1291
1292 UpdraftCentral.register_event_handler('change', '.updraft_report_wholebackup .updraft_report_checkbox', function() {
1293 var reportbox = $(this).closest('.updraft_reportbox').find('.updraft_report_dbbackup');
1294 if ($(this).is(':checked')) {
1295 reportbox.removeClass('updraft_report_disabled').find('.updraft_report_checkbox').removeProp('disabled');
1296 } else {
1297 reportbox.find('.updraft_report_checkbox').prop('checked', false);
1298 reportbox.addClass('updraft_report_disabled').find('.updraft_report_checkbox').prop('disabled', true);
1299 }
1300 });
1301
1302 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more', function() {
1303 if ($('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more').is(':checked')) {
1304 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_options').slideDown();
1305 } else {
1306 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_options').slideUp();
1307 }
1308 }, false, 'change');
1309
1310 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_paths_another', function() {
1311 updraftplus_morefiles_lastind++;
1312 $(template_replace('updraftplus-settings-more-paths', {
1313 index: updraftplus_morefiles_lastind,
1314 enter_the_directory: udclion.updraftplus.enter_the_directory,
1315 remove: udclion.updraftplus.remove
1316 })).appendTo($('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_paths')).slideDown();
1317 });
1318
1319 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_more_options .updraftplus-morefiles-row-delete', function() {
1320 var prow = $(this).closest('.updraftplus-morefiles-row');
1321 $(prow).slideUp('medium', function() {
1322 $(this).remove();
1323 });
1324 });
1325
1326 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .updraft_servicecheckbox', function() {
1327 var sclass = $(this).attr('id');
1328 if ('updraft_servicecheckbox_' == sclass.substring(0,24)) {
1329 var serv = sclass.substring(24);
1330 if (null != serv && '' != serv) {
1331 if ($(this).is(':checked')) {
1332 remote_storage_tabs_any_checked++;
1333 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab-'+serv).fadeIn();
1334 updraft_remote_storage_tab_activation(serv);
1335 } else {
1336 remote_storage_tabs_any_checked--;
1337 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab-'+serv).hide();
1338 // Check if this was the active tab, if yes, switch to another
1339 if ($('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab-'+serv).data('active') == true) {
1340 updraft_remote_storage_tab_activation($('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab:visible').last().attr('name'));
1341 }
1342 }
1343 }
1344 }
1345
1346 if (remote_storage_tabs_any_checked <= 0) {
1347 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.none').fadeIn();
1348 } else {
1349 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.none').hide();
1350 }
1351 }, false, 'change');
1352
1353 // Changing tabs for the remote storage methods
1354 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab', function() {
1355 var the_method = $(this).attr('name');
1356 updraft_remote_storage_tab_activation(the_method);
1357 });
1358
1359 // For the free version, where only one remote storage choice can be made at a time
1360 UpdraftCentral.register_row_clicker('.updraftcentral_row_extracontents .updraft_site_settings_output .updraft_servicecheckbox:not(.multi)', function() {
1361 var svalue = $(this).attr('value');
1362
1363 if ($(this).is(':not(:checked)')) {
1364 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.'+svalue).hide();
1365 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.none').fadeIn();
1366 } else {
1367 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraft_servicecheckbox').not(this).prop('checked', false);
1368 }
1369 }, false, 'change');
1370
1371 // UpdraftVault settings handling
1372 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_settings_cell .updraftvault_backtostart', function() {
1373 $(settings_css_prefix+'#updraftvault_settings_showoptions').slideUp();
1374 $(settings_css_prefix+'#updraftvault_settings_connect').slideUp();
1375 $(settings_css_prefix+'#updraftvault_settings_connected').slideUp();
1376 $(settings_css_prefix+'#updraftvault_settings_default').slideDown();
1377 });
1378
1379 // Prevent default event when pressing return in the form
1380 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_settings_connect input', function($site_row, site_id, event) {
1381 if (event.which == 13) {
1382 $(settings_css_prefix+'#updraftvault_connect_go').click();
1383 event.preventDefault();
1384 }
1385 }, false, 'keypress');
1386
1387 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_settings_cell #updraftvault_recountquota', function() {
1388 $(settings_css_prefix+'#updraftvault_recountquota').html(udclion.updraftplus.counting);
1389 UpdraftCentral.send_site_rpc('updraftplus.vault_recountquota', { instance_id: $('#updraftvault_settings_connect').data('instance_id') }, UpdraftCentral.$site_row, function(response, code, error_code) {
1390 $(settings_css_prefix+'#updraftvault_recountquota').html(udclion.updraftplus.update_quota_count);
1391 if ('ok' == code && response) {
1392 if (response.hasOwnProperty('data') && response.data.hasOwnProperty('html')) {
1393 $(settings_css_prefix+'#updraftvault_settings_connected').html(response.data.html);
1394 if (response.data.hasOwnProperty('connected')) {
1395 if (response.data.connected) {
1396 $(settings_css_prefix+'#updraftvault_settings_default').hide();
1397 $(settings_css_prefix+'#updraftvault_settings_connected').show();
1398 } else {
1399 $(settings_css_prefix+'#updraftvault_settings_connected').hide();
1400 $(settings_css_prefix+'#updraftvault_settings_default').show();
1401 }
1402 }
1403 }
1404 }
1405 });
1406 });
1407
1408 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_settings_cell #updraftvault_disconnect', function() {
1409 $(settings_css_prefix+'#updraftvault_disconnect').html(udclion.updraftplus.disconnecting);
1410 UpdraftCentral.send_site_rpc('updraftplus.vault_disconnect', { instance_id: $('#updraftvault_settings_connect').data('instance_id') }, UpdraftCentral.$site_row, function(response, code, error_code) {
1411 $(settings_css_prefix+'#updraftvault_disconnect').html(udclion.updraftplus.disconnect);
1412
1413 if ('ok' == code && response.hasOwnProperty('data')) {
1414
1415 $(settings_css_prefix+'#updraftvault_disconnect').html(udclion.updraftplus.disconnect);
1416
1417 if (response.data.hasOwnProperty('html')) {
1418 $(settings_css_prefix+'#updraftvault_settings_connected').html(response.data.html).slideUp();
1419 $(settings_css_prefix+'#updraftvault_settings_default').slideDown();
1420 }
1421 }
1422 });
1423 });
1424
1425 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_connect', function() {
1426 $(settings_css_prefix+'#updraftvault_settings_default').slideUp();
1427 $(settings_css_prefix+'#updraftvault_settings_connect').slideDown();
1428 });
1429
1430 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_showoptions', function() {
1431 $(settings_css_prefix+'#updraftvault_settings_default').slideUp();
1432 $(settings_css_prefix+'#updraftvault_settings_showoptions').slideDown();
1433 });
1434
1435 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraft_s3_newapiuser', function($site_row) {
1436 var spin_this = this.closest('td');
1437 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', { fragment: 's3_new_api_user_form', data: null } , $site_row, function(response, code, error_code) {
1438 if ('ok' == code && response) {
1439 UpdraftCentral.open_modal(udclion.updraftplus.create_new_iam_user_and_bucket, response.data.output, function() {
1440
1441 // $('#updraftcentral_modal #updraft-s3newapiuser-results').html('<p style="color:green">'+udclion.updraftplus.trying+'</p>');
1442 $('#updraftcentral_modal #updraft-s3newapiuser-results').empty();
1443
1444 var data = {
1445 adminaccesskey: $('#updraftcentral_modal #updraft_s3newapiuser_adminaccesskey').val(),
1446 adminsecret: $('#updraftcentral_modal #updraft_s3newapiuser_adminsecret').val(),
1447 newuser: $('#updraftcentral_modal #updraft_s3newapiuser_newuser').val(),
1448 bucket: $('#updraftcentral_modal #updraft_s3newapiuser_bucket').val(),
1449 region: $('#updraftcentral_modal #updraft_s3newapiuser_region').val(),
1450 useservercerts: $('#updraftcentral_modal #updraft_ssl_useservercerts').val(),
1451 disableverify: $('#updraftcentral_modal #updraft_ssl_disableverify').val(),
1452 nossl: $('#updraftcentral_modal #updraft_ssl_nossl').val(),
1453 allowdelete: $('#updraftcentral_modal #updraft_s3newapiuser_allowdelete').is(':checked') ? 1 : 0,
1454 allowdownload: $('#updraftcentral_modal #updraft_s3newapiuser_allowdownload').is(':checked') ? 1 : 0
1455 };
1456
1457 var spin_this = $('#updraftcentral_modal');
1458
1459 UpdraftCentral.send_site_rpc('updraftplus.s3_newuser', data , $site_row, function(response, code, error_code) {
1460
1461 if ('ok' == code && response) {
1462 if (response.data.e == 1) {
1463 $('#updraftcentral_modal #updraft-s3newapiuser-results').html('<p style="color:red;">'+UpdraftCentral_Library.sanitize_html(response.data.m)+'</p>');
1464 } else if (response.data.e == 0) {
1465 $('#updraftcentral_modal #updraft-s3newapiuser-results').html('<p style="color:green;">'+UpdraftCentral_Library.sanitize_html(response.data.m)+'</p>');
1466 $(settings_css_prefix+'#updraft_s3_apikey').val(response.data.k);
1467 $(settings_css_prefix+'#updraft_s3_apisecret').val(response.data.s);
1468 $(settings_css_prefix+'#updraft_s3_rrs').prop(':checked', response.data.r);
1469 $(settings_css_prefix+'#updraft_s3_path').val(response.data.c);
1470
1471 // Change link to open dialog to reflect that using IAM user
1472 $(settings_css_prefix+'#updraft_s3_newapiuser').html(udclion.updraftplus.now_using_iam);
1473
1474 UpdraftCentral.close_modal();
1475 }
1476 }
1477
1478 }, spin_this);
1479
1480 }, udclion.updraftplus.create);
1481 }
1482 }, spin_this);
1483 });
1484
1485 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraft_cloudfiles_newapiuser', function($site_row) {
1486 var spin_this = this.closest('td');
1487
1488 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', { fragment: 'cloudfiles_new_api_user_form', data: null }, $site_row, function(response, code, error_code) {
1489 if ('ok' == code) {
1490 var html = UpdraftCentral.template_replace('updraftplus-cloudfiles_new_api_user', response.data.output);
1491
1492 UpdraftCentral.open_modal(udclion.updraftplus.new_api_user, UpdraftCentral_Library.sanitize_html(html), function() {
1493 var $form = $(this).closest('.modal-dialog').find('.form-table'),
1494 new_user = {
1495 'adminuser': $form.find('.adminuser').val(),
1496 'adminapikey': $form.find('.adminapikey').val(),
1497 'newuser': $form.find('.newuser').val(),
1498 'container': $form.find('.container').val(),
1499 'newemail': $form.find('.newemail').val(),
1500 'location': $form.find('.location').val(),
1501 'region': $form.find('.region').val()
1502 };
1503
1504 var spin_this = $('.modal-dialog');
1505
1506 UpdraftCentral.send_site_rpc('updraftplus.cloudfiles_newuser', new_user, $site_row, function(response, code, error_code) {
1507 if ('ok' == code) {
1508 UpdraftCentral.close_modal();
1509
1510 var user = response.data.u;
1511 var key = response.data.k;
1512 var container = response.data.c;
1513
1514 $site_row.find('#updraft_cloudfiles_user').val(user);
1515 $site_row.find('#updraft_cloudfiles_apikey').val(key);
1516 $site_row.find('#updraft_cloudfiles_path').val(container);
1517 } else if (error_code === "error") {
1518 UpdraftCentral_Library.dialog.alert('<h3>'+udclion.error+'</h3>' + response.m);
1519 return true;
1520 }
1521 }, spin_this)
1522 }, udclion.updraftplus.create);
1523 }
1524 }, spin_this)
1525 });
1526
1527 UpdraftCentral.register_row_clicker(settings_css_sub_prefix+'#updraftvault_connect_go', function() {
1528 $(settings_css_prefix+'#updraftvault_connect_go').html(udclion.updraftplus.connecting);
1529
1530 var data = {
1531 email: $(settings_css_prefix+'#updraftvault_email').val(),
1532 pass: $(settings_css_prefix+'#updraftvault_pass').val(),
1533 instance_id: $(settings_css_prefix+'#updraftvault_settings_connect').data('instance_id')
1534 }
1535
1536 UpdraftCentral.send_site_rpc('updraftplus.vault_connect', data, UpdraftCentral.$site_row, function(response, code, error_code) {
1537
1538 $(settings_css_prefix+'#updraftvault_connect_go').html(udclion.updraftplus.connect);
1539
1540 if ('ok' == code && response.hasOwnProperty('data')) {
1541 if (response.data.hasOwnProperty('e')) {
1542 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.error+'</h2><p>'+response.data.e+'</p>');
1543 if (response.data.hasOwnProperty('code') && response.data.code == 'no_quota') {
1544 $(settings_css_prefix+'#updraftvault_settings_connect').slideUp();
1545 $(settings_css_prefix+'#updraftvault_settings_default').slideDown();
1546 }
1547 } else if (response.data.hasOwnProperty('connected') && response.data.connected && response.data.hasOwnProperty('html')) {
1548 $(settings_css_prefix+'#updraftvault_settings_connect').slideUp();
1549 $(settings_css_prefix+'#updraftvault_settings_connected').html(response.data.html).slideDown();
1550 } else {
1551 console.log(response);
1552 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.error+'</h2><p>'+udclion.js_exception_occurred+'</p>');
1553 }
1554 }
1555
1556 });
1557 });
1558
1559 });
1560
1561 /**
1562 * Remote test call back
1563 *
1564 * @callable RemoteTestCallback
1565 * @param {Object} response - the data returned by the RPC call
1566 * @param {string} code - the code returned by the RPC call
1567 * @param {string|null} error_code - the error code returned by the RPC call (if any)
1568 * @param {Object} data - the data that was sent to the remote side (the settings to be tested)
1569 */
1570
1571 /**
1572 * Do a remote storage test based on the indicated button having been pressed, and report the results in a dialog
1573 *
1574 * @param {Object} $method_button - jQuery object for the relevant button
1575 * @param {RemoteTestCallback|false} [result_callback] - optional callable to be invoked with the result
1576 *
1577 * @return {void}
1578 */
1579 function updraft_remote_storage_test($method_button, result_callback) {
1580
1581 var $site_row = $method_button.closest('.updraftcentral_site_row');
1582
1583 var method = $method_button.data('method');
1584 var method_label = $method_button.data('method_label');
1585 var instance_id = $method_button.data('instance_id');
1586 var settings_selector;
1587
1588 if (instance_id) {
1589 settings_selector = '.updraftplusmethod.'+method+'-'+instance_id;
1590 } else {
1591 settings_selector = '.updraftplusmethod.'+method;
1592 }
1593
1594 $method_button.html(sprintf(udclion.updraftplus.testing_settings, method_label));
1595
1596 var data = {
1597 method: method
1598 };
1599
1600 // Add the other items to the data object. The expert mode settings are for the generic SSL options.
1601 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output '+settings_selector+' input[data-updraft_settings_test], #updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .expertmode input[data-updraft_settings_test]').each(function(index, item) {
1602 var item_key = $(item).data('updraft_settings_test');
1603 var input_type = $(item).attr('type');
1604 if (!item_key) { return; }
1605 if (!input_type) {
1606 console.log("UpdraftCentral: UpdraftPlus: settings test input item with no type found");
1607 console.log(item);
1608 // A default
1609 input_type = 'text';
1610 }
1611 var value = null;
1612 if ('checkbox' == input_type) {
1613 value = $(item).is(':checked') ? 1 : 0;
1614 } else if ('text' == input_type || 'password' == input_type) {
1615 value = $(item).val();
1616 } else {
1617 console.log("UpdraftCentral: UpdraftPlus: settings test input item with unrecognised type ("+input_type+") found");
1618 console.log(item);
1619 }
1620 data[item_key] = value;
1621 });
1622 // Data from any text areas or select drop-downs
1623 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output '+settings_selector+' textarea[data-updraft_settings_test], #updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output '+settings_selector+' select[data-updraft_settings_test]').each(function(index, item) {
1624 var item_key = $(item).data('updraft_settings_test');
1625 data[item_key] = $(item).val();
1626 });
1627
1628 UpdraftCentral.send_site_rpc('updraftplus.test_storage_settings', data, $site_row, function(response, code, error_code) {
1629
1630 if ('ok' == code && response) {
1631 $method_button.html(sprintf(udclion.updraftplus.test_settings, method_label));
1632 if ('undefined' !== typeof result_callback && false != result_callback) {
1633 result_callback = result_callback.call(this, response, code, error_code, data);
1634 }
1635 if ('undefined' !== typeof result_callback && false === result_callback) {
1636 UpdraftCentral_Library.dialog.alert('<h2>'+sprintf(udclion.updraftplus.settings_test_result, method_label)+'</h2> '+response.data.output);
1637 }
1638 }
1639
1640 }, $method_button.closest('td'));
1641
1642
1643 }
1644
1645 $('#updraftcentral_notice_container').on('click', '.updraftplus_saved_settings a.updraft_authlink', function(e) {
1646
1647 var href = $(this).attr('href');
1648 if ('undefined' === typeof href) { return; }
1649 var site_id = $(this).closest('.updraftplus_saved_settings').data('site_id');
1650 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
1651
1652 if ($site_row.length < 1) {
1653 console.log("UpdraftCentral: UpdraftPlus: site row not found for the link clicked (site_id="+site_id+")");
1654 return;
1655 }
1656
1657 e.preventDefault();
1658
1659 var spinner_where = $(this).closest('.updraftplus_saved_settings');
1660
1661 UpdraftCentral_Library.open_browser_at($site_row, { module: 'direct_url', url: href }, spinner_where);
1662
1663 });
1664
1665 /**
1666 * Get the "Existing Backups" panel from the remote UpdraftPlus
1667 *
1668 * @param {Object} $site_row - jQuery object for the row of the site for which the information is being requested
1669 *
1670 * @return {void}
1671 */
1672 function updraft_get_existing_backups_panel($site_row) {
1673
1674 $site_row.find('.updraftcentral_row_extracontents').css('opacity', '0.3');
1675
1676 // This just causes an extra informational message to be shown, if set (telling the user to turn off 'Turbo' mode prior to downloading). It does not affect any functionality.
1677 var is_opera = (navigator.userAgent.match(/Opera|OPR\//) ? 1 : 0);
1678 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', {
1679 fragment: 'panel_download_and_restore',
1680 data: {
1681 include_opera_warning: is_opera,
1682 include_uploader: 0,
1683 will_immediately_calculate_disk_space: 0,
1684 include_header: 1
1685 }
1686 }, $site_row, function(response, code, error_code) {
1687 $site_row.find('.updraftcentral_row_extracontents').css('opacity', '1.0');
1688 if ('ok' == code && response) {
1689 $site_row.find('.updraftcentral_row_extracontents').html('<div class="updraft_existing_backups_output"><button class="btn btn-refresh updraftcentral_site_backups_manage"><span class="dashicons dashicons-image-rotate" ></span></button>'+UpdraftCentral_Library.sanitize_html(response.data.output)+'</div>');
1690 insert_bulk_delete($site_row);
1691
1692 if (restored_items.count()) {
1693 var backups_table, backups_checker;
1694 backups_checker = setInterval(function() {
1695 backups_table = $('table.existing-backups-table');
1696 if (backups_table.length) {
1697 clearInterval(backups_checker);
1698
1699 switch (delete_action) {
1700 case 'single':
1701 var items = restored_items.get_items();
1702 restored_items.clear();
1703
1704 if (items.length) {
1705 $('tr.updraft_existing_backups_row[data-nonce="'+items[0]+'"]').find('a.updraft-delete-link').trigger('click');
1706 }
1707 break;
1708 case 'multiple':
1709 var items = selected_items.get_items();
1710 selected_items.clear();
1711 restored_items.clear();
1712
1713 if (items.length) {
1714 for (var i=0; i<items.length; i++) {
1715 $('tr.updraft_existing_backups_row[data-nonce="'+items[i]+'"]').find('input.delete_backup_item').prop('checked', true);
1716 }
1717
1718 $('button#btn-backup-bulk-delete').trigger('click');
1719 }
1720 break;
1721 default:
1722 break;
1723 }
1724 }
1725 }, 1000);
1726 }
1727 }
1728 });
1729 }
1730
1731 /**
1732 * Start a "Backup Now" operation on the specified site
1733 *
1734 * @param {Object} $site_row - the jQuery object for the row of the site to start the backup on
1735 * @param {String} $type - the type of backup e.g new or increment
1736 *
1737 * @return {void}
1738 */
1739 function backup_now($site_row, type) {
1740 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', 'backupnow_modal_contents', $site_row, function(response, code, error_code) {
1741 if ('ok' == code && response) {
1742
1743 var was_error = response.data.output.hasOwnProperty('error') && response.data.output.error;
1744
1745 var action_button = (was_error) ? false : udclion.updraftplus.backupnow;
1746
1747 var impossible_increment_entities;
1748 var incremental_installed = false
1749
1750 if (response.data.output.hasOwnProperty('backupnow_file_entities')) {
1751 impossible_increment_entities = response.data.output.backupnow_file_entities;
1752 }
1753
1754 if (response.data.output.hasOwnProperty('incremental_installed')) {
1755 incremental_installed = response.data.output.incremental_installed;
1756 }
1757
1758 UpdraftCentral.open_modal(udclion.updraftplus.backupnow, response.data.output.html, function() {
1759 var backupnow_nodb = $('#updraftcentral_modal #backupnow_includedb').is(':checked') ? 0 : 1;
1760 var backupnow_nofiles = $('#updraftcentral_modal #backupnow_includefiles').is(':checked') ? 0 : 1;
1761 var backupnow_nocloud = $('#updraftcentral_modal #backupnow_includecloud').is(':checked') ? 0 : 1;
1762 var incremental = ('incremental' == type) ? 1 : 0;
1763
1764 var onlythesefileentities = '';
1765 $('#updraftcentral_modal #backupnow_includefiles_moreoptions input[type="checkbox"]').each(function(index) {
1766 if (!$(this).is(':checked')) { return; }
1767 var name = $(this).attr('name');
1768 if (name.substring(0, 16) != 'updraft_include_') { return; }
1769 var entity = name.substring(16);
1770 if (onlythesefileentities != '') { onlythesefileentities += ','; }
1771 onlythesefileentities += entity;
1772 });
1773
1774 var onlythesetableentities = '';
1775 var send_list = false;
1776 $('#backupnow_database_moreoptions input[type="checkbox"]').each(function(index) {
1777 if (!$(this).is(':checked')) { send_list = true; return; }
1778 });
1779
1780 if (send_list) {
1781 onlythesetableentities = jQuery("input[name^='updraft_include_tables_']").serializeArray();
1782 } else {
1783 onlythesetableentities = true;
1784 }
1785
1786 var send_list_cloud = false;
1787 var onlythesecloudservices = '';
1788 jQuery('#backupnow_includecloud_moreoptions input[type="checkbox"]').each(function(index) {
1789 if (!jQuery(this).is(':checked')) { send_list_cloud = true; return; }
1790 });
1791
1792 if (send_list_cloud) {
1793 onlythesecloudservices = jQuery("input[name^='updraft_include_remote_service_']").serializeArray();
1794 } else {
1795 onlythesecloudservices = true;
1796 }
1797
1798 var always_keep = $('#always_keep').is(':checked') ? 1 : 0;
1799
1800 if ('' == onlythesefileentities && 0 == backupnow_nofiles) {
1801 UpdraftCentral_Library.dialog.alert(udclion.updraftplus.nofileschosen);
1802 return;
1803 }
1804
1805 if ('' == onlythesetableentities && 0 == backupnow_nodb) {
1806 UpdraftCentral_Library.dialog.alert(udclion.updraftplus.notableschosen);
1807 return;
1808 }
1809
1810 if ('' == onlythesecloudservices && 0 == backupnow_nocloud) {
1811 alert(udclion.updraftplus.nocloudserviceschosen);
1812 jQuery('#backupnow_includecloud_moreoptions').show();
1813 return;
1814 }
1815
1816 if (!send_list) {
1817 onlythesetableentities = null;
1818 }
1819
1820 if (!send_list_cloud) {
1821 onlythesecloudservices = null;
1822 }
1823
1824 if (backupnow_nodb && backupnow_nofiles) {
1825 UpdraftCentral_Library.dialog.alert(udclion.updraftplus.excludedeverything);
1826 return;
1827 }
1828
1829 UpdraftCentral.close_modal();
1830
1831 UpdraftCentral_Module_UpdraftPlus.backupnow_go(backupnow_nodb, backupnow_nofiles, backupnow_nocloud, onlythesefileentities, { always_keep: always_keep, incremental: incremental}, $('#updraftcentral_modal #backupnow_label').val(), onlythesetableentities, onlythesecloudservices);
1832 }, action_button, function() {
1833 if (!incremental_installed && 'incremental' == type) {
1834 jQuery('#updraftcentral_modal .incremental-free-only').show();
1835 type = 'new';
1836 } else {
1837 jQuery('#updraftcentral_modal .incremental-backups-only').hide();
1838 }
1839 $('#updraftcentral_modal #backupnow_label').val('');
1840 if ('incremental' == type) {
1841 update_file_entities_checkboxes(true, impossible_increment_entities);
1842 $('#updraftcentral_modal #backupnow_includedb').prop('checked', false);
1843 $('#updraftcentral_modal #backupnow_includefiles').prop('checked', true);
1844 $('#updraftcentral_modal #backupnow_includefiles_label').text(udclion.updraftplus.files_incremental_backup);
1845 $('#updraftcentral_modal .new-backups-only').hide();
1846 $('#updraftcentral_modal .incremental-backups-only').show();
1847 } else {
1848 update_file_entities_checkboxes(false, impossible_increment_entities);
1849 $('#updraftcentral_modal #backupnow_includedb').prop('checked', true);
1850 $('#updraftcentral_modal #backupnow_includefiles_label').text(udclion.updraftplus.files_new_backup);
1851 $('#updraftcentral_modal .new-backups-only').show();
1852 $('#updraftcentral_modal .incremental-backups-only').hide();
1853 }
1854 $('#updraftcentral_modal #backupnow_includefiles_moreoptions').hide();
1855 // Remove the <a> link tab wrapping it, as that goes to the site's WP dashboard
1856 $('#updraftcentral_modal #updraft_backupnow_gotosettings').contents().unwrap();
1857 }, true, 'backup-now');
1858 }
1859 });
1860 }
1861
1862 /**
1863 * This function will enable and disable the file entity options depending on what entities increments can be added to and if this is a new backup or not.
1864 *
1865 * @param {boolean} incremental - a boolean to indicate if this is an incremental backup or not
1866 * @param {array} entities - an array of entities to disable
1867 */
1868 function update_file_entities_checkboxes(incremental, entities) {
1869 if (incremental) {
1870 jQuery(entities).each(function (index, entity) {
1871 jQuery('#updraftcentral_modal #backupnow_files_updraft_include_' + entity).prop('checked', false);
1872 jQuery('#updraftcentral_modal #backupnow_files_updraft_include_' + entity).prop('disabled', true);
1873 });
1874 } else {
1875 jQuery('#updraftcentral_modal #backupnow_includefiles_moreoptions input[type="checkbox"]').each(function (index) {
1876 var name = jQuery(this).attr('name');
1877 if (name.substring(0, 16) != 'updraft_include_') { return; }
1878 var entity = name.substring(16);
1879 jQuery('#updraftcentral_modal #backupnow_files_updraft_include_' + entity).prop('disabled', false);
1880 if (jQuery(this).is(':checked')) {
1881 jQuery('#updraftcentral_modal #backupnow_files_updraft_include_' + entity).prop('checked', true);
1882 }
1883 });
1884 }
1885 }
1886
1887 /**
1888 * Open a modal showing the indicated log file for the indicated site
1889 *
1890 * @param {string} job_id - The UpdraftPlus job identifier string
1891 * @param {Object} $site_row - The jQuery object for the site row that the request is for
1892 *
1893 * @return {void}
1894 */
1895 function updraft_popuplog(job_id, $site_row) {
1896 UpdraftCentral.send_site_rpc('updraftplus.get_log', job_id, $site_row, function(response, code, error_code) {
1897 if ('ok' == code && response) {
1898 UpdraftCentral.open_modal(udclion.updraftplus.logfile, '<pre id="updraft_poppedlog">'+UpdraftCentral_Library.sanitize_html(response.data.log)+'</pre>', function() {
1899 UpdraftCentral_Library.download_inner_html('log.'+job_id+'.txt', 'updraft_poppedlog');
1900 }, udclion.updraftplus.downloadlog, function() {
1901 // Function that gets called after population of modal, before opening
1902 }, null, true, 'modal-lg');
1903 }
1904 });
1905 }
1906
1907 /**
1908 * Open the modal to confirm, and then carry out, deletion of the indicate backup
1909 *
1910 * @param {string} key - A comma-separated list of timestamps of the backups to delete
1911 * @param {string} nonce - the UpdraftPlus job identifier string
1912 * @param {boolean} showremote - whether or not to show the option to also remove the backup from remote storage (if any)
1913 *
1914 * @return {void}
1915 */
1916 function updraft_delete(key, nonce, showremote) {
1917 var delete_question = udclion.updraftplus.delete_areyousure_singular;
1918 if (key.indexOf(',') > -1) {
1919 delete_question = udclion.updraftplus.delete_areyousure_plural;
1920 }
1921
1922 // title, body, action_button_callback, action_button_text, pre_open_callback, sanitize_body
1923 UpdraftCentral.open_modal(
1924 udclion.updraftplus.deletebackupset,
1925 UpdraftCentral.template_replace('updraftplus-deletebackup', {
1926 nonce: nonce,
1927 timestamp: key,
1928 delete_question: delete_question,
1929 also_delete_from_remote: udclion.updraftplus.also_delete_from_remote,
1930 deleting_please_allow_time: udclion.updraftplus.deleting_please_allow_time
1931 }),
1932 function() {
1933 var nonce = $('#updraft_delete_modal_contents').data('nonce').toString();
1934 var timestamps = $('#updraft_delete_modal_contents').data('timestamp').toString();
1935 var delete_remote = 0;
1936 if ($('#updraft_delete_modal_contents #updraft_delete_remote').is(':checked')) {
1937 delete_remote = 1;
1938 }
1939
1940 $('#updraftcentral_modal #updraft-delete-waitwarning').slideDown();
1941
1942 var is_opera = (navigator.userAgent.match(/Opera|OPR\//) ? true : false);
1943
1944 UpdraftCentral.send_site_rpc('updraftplus.deleteset', {
1945 backup_nonce: nonce,
1946 backup_timestamp: timestamps,
1947 delete_remote: delete_remote,
1948 get_history_opts: {
1949 include_opera_warning: is_opera,
1950 include_uploader: false,
1951 will_immediately_calculate_disk_space: false,
1952 include_header: true
1953 }
1954 }, UpdraftCentral.$site_row, function(response, code, error_code) {
1955
1956 $('#updraftcentral_modal #updraft-delete-waitwarning').slideUp();
1957 if ('ok' == code && response) {
1958 var resp = response.data;
1959 if (resp.result != null) {
1960 if (resp.result == 'error') {
1961 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.error+'</h2>'+resp.message);
1962 } else if (resp.result == 'success') {
1963 updraft_get_existing_backups_panel(UpdraftCentral.$site_row);
1964 UpdraftCentral.close_modal();
1965
1966 var message = resp.message;
1967 if ('undefined' === typeof message) {
1968 message = resp.local_message+' '+resp.backup_local;
1969 message += ', '+resp.remote_message+' '+resp.backup_remote;
1970 message += ', '+resp.set_message+' '+resp.backup_sets;
1971 }
1972
1973 UpdraftCentral_Library.dialog.alert('<h2>'+udclion.updraftplus.deleted+'</h2>'+message);
1974 }
1975 }
1976 }
1977
1978 });
1979
1980 },
1981 udclion.updraftplus.delete,
1982 function() {
1983 if (!showremote) {
1984 $('#updraft-delete-remote-section').remove();
1985 } else {
1986 $('#updraft-delete-remote-section, #updraft_delete_remote').removeAttr('disabled').show();
1987 }
1988
1989 }
1990 );
1991
1992 }
1993
1994 /**
1995 * Send a command to abort an active backup job_id
1996 *
1997 * @param {string} job_id - the job identifier for the job to be aborted
1998 * @param {Object} $site_row - the jQuery object for the row for the site to send the command to
1999 * @param {Object} site_listener_row - the jQuery object for the listener row associated with the request
2000 *
2001 * @return {void}
2002 */
2003 function updraft_activejobs_delete(job_id, $site_row, site_listener_row) {
2004
2005 UpdraftCentral.send_site_rpc('updraftplus.activejobs_delete', job_id, $site_row, function(response, code, error_code) {
2006 if ('ok' == code && response) {
2007 var msg = '';
2008 if (response.hasOwnProperty('data') && response.data.hasOwnProperty('c')) {
2009 if ('deleted' == response.data.c) {
2010 msg = udclion.updraftplus.delete_deleted;
2011 } else if ('not_found' == response.data.c) {
2012 msg = udclion.updraftplus.delete_not_found;
2013 } else {
2014 console.log("UDCentral: UpdraftPlus: abort job: unknown response");
2015 console.log(response.data);
2016 msg = UpdraftCentral_Library.sanitize_html(response.data.m);
2017 }
2018 } else {
2019 console.log("UDCentral: UpdraftPlus: abort job: unknown response");
2020 console.log(response.data);
2021 msg = udclion.js_exception_occurred;
2022 }
2023 $(site_listener_row).find('.backup_state:first').html(msg);
2024 }
2025 });
2026 }
2027
2028 $('#updraftcentral_notice_container').on('click', '.updraftcentral_listener .updraftplus_downloader_closebutton', function(e) {
2029 e.preventDefault();
2030 var $listener = $(this).closest('.updraftcentral_listener');
2031 $(this).closest('.updraftplus_downloader').fadeOut().remove();
2032 var how_many_downloaders = $listener.find('.updraftplus_downloader').length;
2033 if (how_many_downloaders < 1) {
2034 console.log($listener);
2035 $listener.clearQueue().slideUp('slow', function() {
2036 $(this).remove();
2037 });
2038 }
2039 });
2040
2041 $('#updraftcentral_notice_container').on('click', '.updraftcentral_listener .updraft_downloaded', function(e) {
2042 var site_id = $(this).data('site_id');
2043 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
2044 if ($site_row.length < 1) { return; }
2045 var backup_timestamp = $(this).data('backup_timestamp');
2046 var what = $(this).data('what');
2047 var findex = $(this).data('findex');
2048 UpdraftCentral_Library.open_browser_at($site_row, { module: 'updraftplus', action: 'download_file', data: {
2049 backup_timestamp: backup_timestamp,
2050 what: what,
2051 findex: findex
2052 } }, null);
2053 });
2054
2055 $('#updraftcentral_notice_container').on('click', '.updraftcentral_listener .updraft_delete_downloaded_backup', function(e) {
2056 e.preventDefault();
2057 var delete_button = this;
2058 var site_id = $(this).data('site_id');
2059 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
2060 var findex = $(this).data('findex');
2061 var what = $(this).data('what');
2062 var backup_timestamp = $(this).data('backup_timestamp');
2063 UpdraftCentral.send_site_rpc('updraftplus.delete_downloaded', {
2064 timestamp: backup_timestamp,
2065 site_id: site_id,
2066 type: what,
2067 findex: findex
2068 }, $site_row, function(response, code, error_code) {
2069 if ('ok' == code && false !== response && response.hasOwnProperty('data')) {
2070 $(delete_button).closest('.raw').html(udclion.updraftplus.entity_deleted);
2071 }
2072 });
2073 });
2074
2075 $('#updraftcentral_notice_container, #updraftcentral_dashboard_existingsites').on('click', '.updraftcentral_listener .updraft-log-link, .updraft_existing_backups_output .updraft-log-link', function(e) {
2076 e.preventDefault();
2077 var job_id = $(this).data('jobid');
2078 if (job_id) {
2079 var $site_listener = $(this).closest('.updraftcentral_listener, .updraftcentral_site_row');
2080 var site_id = $site_listener.data('site_id');
2081 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
2082 updraft_popuplog(job_id, $site_row);
2083 } else {
2084 console.log(this);
2085 console.log("UpdraftPlus: A log link was clicked, but the Job ID could not be found");
2086 }
2087 });
2088
2089 $('#updraftcentral_notice_container').on('click', '.updraftcentral_listener .updraft_jobinfo_delete', function(e) {
2090 e.preventDefault();
2091 var job_id = $(this).data('jobid');
2092 if (job_id) {
2093 var $site_listener = $(this).closest('.updraftcentral_listener');
2094 var site_id = $site_listener.data('site_id');
2095 var $site_row = $('#updraftcentral_dashboard_existingsites .updraftcentral_site_row[data-site_id="'+site_id+'"');
2096 updraft_activejobs_delete(job_id, $site_row, $site_listener);
2097 } else {
2098 console.log("UpdraftPlus: A stop job link was clicked, but the Job ID could not be found");
2099 console.log(this);
2100 }
2101 });
2102
2103 /**
2104 * Updates the various bits of widgetry and text associated with the scheduling settings. Suitable for calling when a chosen schedule value (daily/monthly/etc.) changes.
2105 *
2106 * @return {void}
2107 */
2108 function updraft_check_same_times() {
2109 var dbmanual = 0;
2110 var file_interval = $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_interval').val();
2111 if (file_interval == 'manual') {
2112 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_files_timings').hide();
2113 } else {
2114 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_files_timings').show();
2115 }
2116
2117 if ('weekly' == file_interval || 'fortnightly' == file_interval || 'monthly' == file_interval) {
2118 updraft_intervals_monthly_or_not('updraft_startday_files', file_interval);
2119 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output #updraft_startday_files').show();
2120 } else {
2121 $('#updraftcentral_dashboard_existingsites .updraft_monthly_extra_words_updraft_startday_files').remove();
2122 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output #updraft_startday_files').hide();
2123 }
2124
2125 var db_interval = $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_interval_database').val();
2126 if (db_interval == 'manual') {
2127 dbmanual = 1;
2128 // $('#updraft_db_timings').css('opacity', '0.25');
2129 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_db_timings').hide();
2130 }
2131
2132 if ('weekly' == db_interval || 'fortnightly' == db_interval || 'monthly' == db_interval) {
2133 updraft_intervals_monthly_or_not('updraft_startday_db', db_interval);
2134 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output #updraft_startday_db').show();
2135 } else {
2136 $('#updraftcentral_dashboard_existingsites .updraft_monthly_extra_words_updraft_startday_db').remove();
2137 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output #updraft_startday_db').hide();
2138 }
2139
2140 if (db_interval == file_interval) {
2141 // $('#updraft_db_timings').css('opacity','0.25');
2142 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_db_timings').hide();
2143 // $('#updraft_same_schedules_message').show();
2144 if (0 == dbmanual) {
2145 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_same_schedules_message').show();
2146 } else {
2147 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_same_schedules_message').hide();
2148 }
2149 } else {
2150 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_same_schedules_message').hide();
2151 if (0 == dbmanual) {
2152 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_db_timings').show();
2153 }
2154 }
2155 }
2156
2157 var updraft_interval_week_val = false;
2158 var updraft_interval_month_val = false;
2159
2160 /**
2161 * This function displays the month-day selector, and adjusts the wording, of the backup scheduling portion of the settings
2162 *
2163 * @param {string} selector_id - the CSS ID to use for finding the element to adjust (according to whether adjusting the files or DB schedule)
2164 * @param {string} now_showing - the currently chosen interval
2165 *
2166 * @return {void}
2167 */
2168 function updraft_intervals_monthly_or_not(selector_id, now_showing) {
2169 var selector = '#updraftcentral_dashboard_existingsites .updraft_site_settings_output #'+selector_id;
2170 var current_length = $(selector+' option').length;
2171 var is_monthly = ('monthly' == now_showing) ? true : false;
2172 var existing_is_monthly = false;
2173 if (current_length > 10) { existing_is_monthly = true; }
2174 if (!is_monthly && !existing_is_monthly) {
2175 return;
2176 }
2177 if (is_monthly && existing_is_monthly) {
2178 if ('monthly' == now_showing) {
2179 // existing_is_monthly does not mean the same as now_showing=='monthly'. existing_is_monthly refers to the drop-down, not whether the drop-down is being displayed. We may need to add these words back.
2180 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_monthly_extra_words_'+selector_id).remove();
2181 $(selector).before('<span class="updraft_monthly_extra_words_'+selector_id+'">'+udclion.updraftplus.day+' </span>').after('<span class="updraft_monthly_extra_words_'+selector_id+'"> '+udclion.updraftplus.in_the_month+' </span>');
2182 }
2183 return;
2184 }
2185 $('#updraftcentral_dashboard_existingsites .updraft_site_settings_output .updraft_monthly_extra_words_'+selector_id).remove();
2186 if (is_monthly) {
2187 // Save the old value
2188 updraft_interval_week_val = $(selector+' option:selected').val();
2189 $(selector).html(udclion.updraftplus.mday_selector).before('<span class="updraft_monthly_extra_words_'+selector_id+'">'+udclion.updraftplus.day+' </span>').after('<span class="updraft_monthly_extra_words_'+selector_id+'"> '+udclion.updraftplus.in_the_month+' </span>');
2190 var select_mday = (updraft_interval_month_val === false) ? 1 : updraft_interval_month_val;
2191 // Convert from day of the month (ordinal) to option index (starts at 0)
2192 select_mday = select_mday - 1;
2193 $(selector+" option:eq("+select_mday+")").prop('selected', true);
2194 } else {
2195 // Save the old value
2196 updraft_interval_month_val = $(selector+' option:selected').val();
2197 $(selector).html(udclion.updraftplus.day_selector);
2198 var select_day = (updraft_interval_week_val === false) ? 1 : updraft_interval_week_val;
2199 $(selector+" option:eq("+select_day+")").prop('selected', true);
2200 }
2201 }
2202
2203 var db_index;
2204 var files_index;
2205 /**
2206 * Set up the HTML for the retain rules. This should be called after receiving the settings and rules from the remote end.
2207 *
2208 * @param {array} retain_rules_files - array of retain rules for the files backup
2209 * @param {array} retain_rules_db - array of retain rules for the database backup
2210 *
2211 * @return {void}
2212 */
2213 function setup_retain_rules(retain_rules_files, retain_rules_db) {
2214 // Code for handling the advanced retain rules
2215 db_index = 0;
2216 files_index = 0;
2217 $.each(retain_rules_files, function(index, rule) {
2218 add_rule('files', rule.after_howmany, rule.after_period, rule.every_howmany, rule.every_period);
2219 });
2220
2221 $.each(retain_rules_db, function(index, rule) {
2222 add_rule('db', rule.after_howmany, rule.after_period, rule.every_howmany, rule.every_period);
2223 });
2224 }
2225
2226 /**
2227 * Adds a new advanced retain rule to the relevant section of the settings
2228 *
2229 * @param {string} type - either 'files' or 'db'
2230 * @param {number} howmany_after - how many periods the rule applies after
2231 * @param {number} period_after - the length (in seconds) of the period that the rule applies after
2232 * @param {number} howmany_every - how many periods 1 backup is to be kept for
2233 * @param {number} period_every - the length (in seconds) of the period that 1 backup is to be kept for
2234 *
2235 * @return {void}
2236 */
2237 function add_rule(type, howmany_after, period_after, howmany_every, period_every) {
2238 var selector = 'updraft_retain_'+type+'_rules';
2239 var index;
2240 if ('db' == type) {
2241 db_index++;
2242 index = db_index;
2243 } else {
2244 files_index++;
2245 index = files_index;
2246 }
2247 $('#'+selector).append(
2248 '<div style="float:left; clear:left;" class="updraft_retain_rules '+selector+'_entry">'+
2249 udclion.updraftplus.for_backups_older_than+' '+rule_period_selector(type, index, 'after', howmany_after, period_after)+' keep no more than 1 backup every '+rule_period_selector(type, index, 'every', howmany_every, period_every)+
2250 ' <span title="'+udclion.updraftplus.delete+'" class="updraft_retain_rules_delete"><span class="dashicons dashicons-no"></span></span></div>'
2251 )
2252 }
2253
2254 /**
2255 * Returns the HTML for creating a dropdown <select> widget
2256 *
2257 * @param {string} type - either 'files' or 'db'
2258 * @param {number} index - the rule number, used for constructing the name attribute
2259 * @param {string} which - drop-down type - either 'every' or 'after'
2260 * @param {number} howmany_value - the number of periods of time
2261 * @param {number} period - the length (in seconds) of each period of time
2262 *
2263 * @return {void}
2264 */
2265 function rule_period_selector(type, index, which, howmany_value, period) {
2266 var nameprefix = "updraft_retain_extrarules["+type+"]["+index+"]["+which+"-";
2267 var ret = '<input type="number" min="1" step="1" class="additional-rule-width" name="'+nameprefix+'howmany]" value="'+howmany_value+'"> \
2268 <select name="'+nameprefix+'period]">\
2269 <option value="3600"';
2270 if (period == 3600) { ret += ' selected="selected"'; }
2271 ret += '>'+udclion.updraftplus.hours+'</option>\
2272 <option value="86400"';
2273 if (period == 86400) { ret += ' selected="selected"'; }
2274 ret += '>'+udclion.updraftplus.days+'</option>\
2275 <option value="604800"';
2276 if (period == 604800) { ret += ' selected="selected"'; }
2277 ret += '>'+udclion.updraftplus.weeks+'</option>\
2278 </select>';
2279 return ret;
2280 }
2281
2282 /**
2283 * Set up the status of the 'exclude' field (relevant to backing up uploads, others, WordPress Core)
2284 *
2285 * @param {string} field - the entity type ('uploads', 'others', 'wpcore')
2286 * @param {boolean} instant - whether to simply show/hide, or whether to apply an effect
2287 *
2288 * @return {void}
2289 */
2290 function setup_file_entity_exclude_field(field, instant) {
2291 if ($('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_'+field).is(':checked')) {
2292 if (instant) {
2293 $('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_'+field+'_exclude').show();
2294 } else {
2295 $('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_'+field+'_exclude').slideDown();
2296 }
2297 } else {
2298 if (instant) {
2299 $('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_'+field+'_exclude').hide();
2300 } else {
2301 $('.updraftcentral_row_extracontents .updraft_site_settings_output #updraft_include_'+field+'_exclude').slideUp();
2302 }
2303 }
2304 }
2305
2306 var reportbox_index = 1;
2307
2308 /**
2309 * Activate the specified tab within the remote storage section
2310 *
2311 * @param {string} the_method - the remote storage method whose tab is to be activated. Corresponds to UD's internal method string identifiers (e.g. s3, dropbox, etc.)
2312 *
2313 * @return {void}
2314 */
2315 function updraft_remote_storage_tab_activation(the_method) {
2316 var prefix = '#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output';
2317 $(prefix+' .updraftplusmethod').hide();
2318 $(prefix+' .remote-tab').data('active', false);
2319 $(prefix+' .remote-tab').removeClass('nav-tab-active');
2320 $(prefix+' .updraftplusmethod.'+the_method).show();
2321 $(prefix+' .remote-tab-'+the_method).data('active', true);
2322 $(prefix+' .remote-tab-'+the_method).addClass('nav-tab-active');
2323 }
2324
2325 var remote_storage_tabs_any_checked = 0;
2326
2327 /**
2328 * Set the initial state of the remote storage options, depending on the currently selected option(s). Includes labelauty setup.
2329 *
2330 * @return {void}
2331 */
2332 function updraft_remote_storage_tabs_setup() {
2333
2334 remote_storage_tabs_any_checked = 0;
2335 var set = $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraft_servicecheckbox:checked');
2336
2337 $(set).each(function(ind, obj) {
2338 var ser = $(obj).val();
2339
2340 if ($(obj).attr('id') != 'updraft_servicecheckbox_none') {
2341 remote_storage_tabs_any_checked++;
2342 }
2343
2344 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .remote-tab-'+ser).show();
2345 if (ind == $(set).length-1) {
2346 updraft_remote_storage_tab_activation(ser);
2347 }
2348 });
2349
2350 if (remote_storage_tabs_any_checked > 0) {
2351 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.none').hide();
2352 } else {
2353 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod:not(.none)').hide();
2354 $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraftplusmethod.none').show();
2355 }
2356
2357 var servicecheckbox = $('#updraftcentral_dashboard_existingsites .updraftcentral_row_extracontents .updraft_site_settings_output .updraft_servicecheckbox');
2358 if (typeof servicecheckbox.labelauty === 'function') { servicecheckbox.labelauty(); }
2359
2360 }
2361
2362 }
2363