PluginProbe ʕ •ᴥ•ʔ
UpdraftPlus: WP Backup & Migration Plugin / 1.26.4
UpdraftPlus: WP Backup & Migration Plugin v1.26.4
1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 1.9.64 1.11.12 1.4.8 1.11.15 1.4.9 1.11.17 1.5.16 1.11.18 1.5.20 1.11.2 1.5.21 1.11.20 1.5.22 1.11.23 1.5.5 1.11.24 1.5.6 1.11.25 1.5.7 1.11.26 1.5.8 1.11.27 1.5.9 1.11.28 1.6.1 1.11.3 1.6.17 1.11.4 1.6.2 1.11.5 1.6.46 1.11.8 1.7.0 1.11.9 1.7.1 1.12.0 1.7.18 1.12.1 1.7.20 1.12.12 1.7.3 1.12.13 1.7.34 1.12.15 1.7.35 1.12.17 1.7.39 1.12.2 1.7.40 1.12.20 1.7.41 1.12.23 1.8.1 1.12.24 1.8.11 1.12.25 1.8.12 1.12.28 1.8.13 1.12.29 1.8.2 1.12.30 1.8.5 1.12.32 1.8.8 1.12.34 1.9.0 1.12.35 1.9.13 1.12.37 1.9.15 1.12.39 1.9.17 1.12.4 1.12.40 1.12.6 1.13.1 1.13.11 1.13.12 1.13.15 1.13.16 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.13.7 1.13.8 1.13.9 1.14.10 1.14.11 1.14.12 1.14.13 1.14.2 1.14.3 1.14.4 1.14.5 1.14.7 1.14.9 1.15.0 1.15.2 1.15.3 1.15.5 1.15.6 1.15.7 1.16.0 1.16.10 1.16.11 1.16.12 1.16.13 1.16.14 1.16.15 1.16.16 1.16.17 1.16.20 1.16.21 1.16.22 1.16.23 1.16.24 1.16.25 1.16.26 1.16.28 1.16.29 1.16.32 1.16.34 1.16.35 1.16.36 1.16.37 1.16.4 1.16.40 1.16.41 1.16.42 1.16.43 1.16.44 1.16.45 1.16.46 1.16.47 1.16.48 1.16.49 1.16.5 1.16.50 1.16.51 1.16.53 1.16.55 1.16.56 1.16.59 1.16.6 1.16.60 1.16.61 1.16.62 1.16.63 1.16.64 1.16.65 1.16.66 1.16.67 1.16.68 1.16.69 1.16.7 1.16.8 1.16.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.14 1.2.15 1.2.16 1.2.17 1.2.19 1.2.2 1.2.20 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.33 1.2.35 1.2.36 1.2.38 1.2.39 1.2.4 1.2.40 1.2.41 1.2.42 1.2.43 1.2.44 1.2.45 1.2.46 1.2.5 1.2.7 1.2.8 1.2.9 1.22.1 1.22.10 1.22.11 1.22.12 1.22.14 1.22.15 1.22.16 1.22.17 1.22.18 1.22.19 1.22.20 1.22.21 1.22.22 1.22.23 1.22.24 1.22.3 1.22.4 1.22.5 1.22.6 1.22.7 1.22.8 1.22.9 1.23.1 1.23.10 1.23.11 1.23.12 1.23.13 1.23.15 1.23.16 1.23.2 1.23.3 1.23.4 1.23.5 1.23.6 1.23.7 1.23.8 1.23.9 1.24.1 1.24.10 1.24.11 1.24.12 1.24.2 trunk 1.24.3 0.7.4 1.24.4 0.7.7 1.24.5 0.8.28 1.24.6 0.8.29 1.24.7 0.8.30 1.24.8 0.8.31 1.24.9 0.8.32 1.25.1 0.8.33 1.25.2 0.8.36 1.25.3 0.8.37 1.25.5 0.8.50 1.25.6 0.8.51 1.25.7 0.9.1 1.25.8 0.9.10 1.25.9 0.9.11 1.26.1 0.9.12 1.26.2 0.9.2 1.3.10 0.9.20 1.3.12 0.9.21 1.3.14 0.9.22 1.3.15 1.0.10 1.3.17 1.0.11 1.3.18 1.0.12 1.3.19 1.0.15 1.3.2 1.0.16 1.3.20 1.0.18 1.3.22 1.0.20 1.3.23 1.0.3 1.3.24 1.0.4 1.3.25 1.0.5 1.3.3 1.0.6 1.3.4 1.0.7 1.3.6 1.0.8 1.3.7 1.0.9 1.3.8 1.1.0 1.3.9 1.1.10 1.4.0 1.1.11 1.4.10 1.1.12 1.4.11 1.1.13 1.4.12 1.1.14 1.4.13 1.1.15 1.4.14 1.1.16 1.4.15 1.1.17 1.4.2 1.1.2 1.4.27 1.1.3 1.4.28 1.1.5 1.4.29 1.1.6 1.4.30 1.1.8 1.4.4 1.1.9 1.4.48 1.10.1 1.4.5 1.10.3 1.4.6 1.11.1 1.4.7
updraftplus / js / updraft-admin-restore.js
updraftplus / js Last commit date
tour-1-26-4.min.js 3 weeks ago tour.js 2 years ago updraft-admin-restore-1-26-4.min.js 3 weeks ago updraft-admin-restore.js 1 month ago updraftplus-deactivation-1-26-4.min.js 3 weeks ago updraftplus-deactivation.js 2 months ago
updraft-admin-restore.js
347 lines
1 var updraft_restore_screen = true;
2 jQuery(function($) {
3
4 var job_id = $('#updraftplus_ajax_restore_job_id').val();
5 var action = $('#updraftplus_ajax_restore_action').val();
6 var updraft_restore_update_timer;
7 var last_received = 0;
8 var $output = $('#updraftplus_ajax_restore_output');
9 var $steps_list = $('.updraft_restore_components_list');
10 var previous_stage;
11 var current_stage;
12 var logged_out = false;
13 var auto_resume_count = 0;
14 var server_500_count = 0;
15
16 $('#updraft-restore-hidethis').remove();
17
18 updraft_restore_command(job_id, action);
19
20 /**
21 * This function will start the restore over ajax for the passed in job_id.
22 *
23 * @param {string} job_id - the restore job id
24 * @param {string} action - the restore action
25 */
26 function updraft_restore_command(job_id, action) {
27
28 var xhttp = new XMLHttpRequest();
29 var xhttp_data = 'action=' + action + '&updraftplus_ajax_restore=do_ajax_restore&job_id=' + job_id;
30 if ('updraft_ajaxrestore' === action) xhttp_data += '&nonce=' + updraft_credentialtest_nonce;
31 var previous_data_length = 0;
32 var show_alert = true;
33 var debug = $('#updraftplus_ajax_restore_debug').length;
34
35 xhttp.open("POST", ajaxurl, true);
36 xhttp.onprogress = function(response) {
37 if (response.currentTarget.status >= 200 && response.currentTarget.status < 300) {
38 if (-1 !== response.currentTarget.responseText.indexOf('<html')) {
39 if (show_alert) {
40 show_alert = false;
41 alert("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_invalid_response);
42 }
43 $output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_invalid_response);
44 console.log("UpdraftPlus restore error: HTML detected in response could be a copy of the WordPress front page caused by mod_security");
45 console.log(response.currentTarget.responseText);
46 return;
47 }
48
49 if (previous_data_length == response.currentTarget.responseText.length) return;
50
51 last_received = Math.round(Date.now() / 1000);
52
53 var responseText = response.currentTarget.responseText.substr(previous_data_length);
54
55 previous_data_length = response.currentTarget.responseText.length;
56
57 var i = 0;
58 var end_of_json = 0;
59
60 // Check if there is restore information json in the response if so process it and remove it from the response so that it does not make it to page
61 while (i < responseText.length) {
62 var buffer = responseText.substr(i, 7);
63 if ('RINFO:{' == buffer) {
64 // Output what precedes the RINFO:
65 $output
66 .append(responseText.substring(end_of_json, i).trim()) // add the text to the activity log
67 .scrollTop($output[0].scrollHeight); // Scroll to the bottom of the box
68 // Grab what follows RINFO:
69 var analyse_it = ud_parse_json(responseText.substr(i), true);
70
71 if (1 == debug) { console.log(analyse_it); }
72
73 updraft_restore_process_data(analyse_it.parsed);
74
75 // move the for loop counter to the end of the json
76 end_of_json = i + analyse_it.json_last_pos - analyse_it.json_start_pos + 6;
77 // When the for loop goes round again, it will start with the end of the JSON
78 i = end_of_json;
79 } else {
80 i++;
81 }
82 }
83 $output.append(responseText.substr(end_of_json).trim()).scrollTop($output[0].scrollHeight);
84 // check if the fylesystem form is displayed
85 if ($output.find('input[name=connection_type]').length && $output.find('#upgrade').length) {
86 updraft_restore_setup_filesystem_form();
87 }
88 } else {
89 if (0 == response.currentTarget.status) {
90 $output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_contact_failed);
91 } else {
92 $output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + response.currentTarget.status + ' ' + response.currentTarget.statusText);
93 }
94 console.log("UpdraftPlus restore error: " + response.currentTarget.status + ' ' + response.currentTarget.statusText);
95 console.log(response.currentTarget);
96 }
97 }
98 xhttp.onload = function() {
99 var $result = $output.find('.updraft_restore_successful, .updraft_restore_error');
100
101 // if we don't find the result, exit
102 if (!$result.length) return;
103
104 var $result_output = $('.updraft_restore_result');
105 $result_output.slideDown();
106 $steps_list.slideUp();
107 $steps_list.siblings('h2').slideUp();
108
109 if ($result.is('.updraft_restore_successful')) {
110 $result_output.find('.dashicons').addClass('dashicons-yes');
111 $result_output.find('.updraft_restore_result--text').text($result.text());
112 $result_output.addClass('restore-success');
113 } else if ($result.is('.updraft_restore_error')) {
114 $result_output.find('.dashicons').addClass('dashicons-no-alt');
115 $result_output.find('.updraft_restore_result--text').text($result.text());
116 $result_output.addClass('restore-error');
117 }
118 // scroll log to the bottom
119 setTimeout(function() {
120 $output.scrollTop($output[0].scrollHeight);
121 }, 500);
122 }
123 xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
124 xhttp.send(xhttp_data);
125 }
126
127 /**
128 * This function will process the parsed restore data and make updates to the front end
129 *
130 * @param {object} restore_data - the restore data object contains information on the restore progress to update the front end
131 */
132 function updraft_restore_process_data(restore_data) {
133
134 // If the stage is started then we want to start our restore timer as the restore has now actually began
135 if ('started' == restore_data.stage) {
136 updraft_restore_update_timer = setInterval(function () {
137 updraft_restore_update();
138 }, 5000);
139 }
140
141 // If the stage is finished then we want to remove our timer and clean up the UI
142 if ('finished' == restore_data.stage && updraft_restore_update_timer) {
143 clearInterval(updraft_restore_update_timer);
144 $('#updraftplus_ajax_restore_last_activity').html('');
145 }
146
147 if (restore_data) {
148 if ('state' == restore_data.type || 'state_change' == restore_data.type) {
149 console.log(restore_data.stage, restore_data.data);
150 if ('files' == restore_data.stage) {
151 current_stage = restore_data.data.entity;
152 } else {
153 current_stage = restore_data.stage;
154 }
155
156 var $current = $steps_list.find('[data-component='+current_stage+']');
157
158 // show simplified activity log next to the component's label
159 if ('files' == restore_data.stage) {
160 $current.find('.updraft_component--progress').html(''+updraftlion.restore_files_progress.replace('%1$s', '<strong>'+(restore_data.data.fileindex)+'</strong>').replace('%2$s', '<strong>'+restore_data.data.total_files+'</strong>'));
161 }
162
163 if ('db' == restore_data.stage) {
164 if (restore_data.data.hasOwnProperty('stage')) {
165 if ('table' == restore_data.data.stage) {
166 $current.find('.updraft_component--progress').html(''+updraftlion.restore_db_table_progress.replace('%s', '<strong>'+(restore_data.data.table)+'</strong>'));
167 } else if ('stored_routine' == restore_data.data.stage) {
168 $current.find('.updraft_component--progress').html(''+updraftlion.restore_db_stored_routine_progress.replace('%s', '<strong>'+(restore_data.data.routine_name)+'</strong>'));
169 } else if ('finished' == restore_data.data.stage) {
170 $current.find('.updraft_component--progress').html(''+updraftlion.finished);
171 } else if ('begun' == restore_data.data.stage) {
172 $current.find('.updraft_component--progress').html(''+updraftlion.begun+'...');
173 }
174 }
175 }
176
177 if (previous_stage !== current_stage) {
178 if (previous_stage) {
179 var $prev = $steps_list.find('[data-component='+previous_stage+']');
180 // empty the line's status
181 $prev.find('.updraft_component--progress').html('');
182 $prev.removeClass('active').addClass('done');
183 }
184 if ('finished' == current_stage) {
185 $current.addClass('done');
186 $steps_list.find('[data-component]').each(function(index, el) {
187 $el = $(el);
188 if (!$el.is('.done')) {
189 $el.addClass('error');
190 }
191 });
192 if (restore_data.data.hasOwnProperty('actions') && 'object' == typeof restore_data.data.actions) {
193 updraft_restore_get_pages(restore_data.data.urls, function(pages_found) {
194 if (!$.isEmptyObject(pages_found)) {
195 $('.updraft_restore_result').before(updraftlion.ajax_restore_404_detected);
196 $.each(pages_found, function(index, url) {
197 $('.updraft_missing_pages').append('<li>'+url+'</li>');
198 });
199 }
200 });
201
202 $.each(restore_data.data.actions, function(index, item) {
203 $steps_list.after('<a href="'+item+'" class="button button-primary">'+index+'</a>');
204 });
205 }
206
207 } else {
208 $current.addClass('active');
209 }
210 }
211 previous_stage = current_stage;
212 }
213 }
214
215 }
216
217 /**
218 * This function will update the time in the front end that we last received data, after 120 seconds call the resume restore notice
219 */
220 function updraft_restore_update() {
221 var current_time = Math.round(Date.now() / 1000);
222 var last_activity = current_time - last_received;
223 if (60 > last_activity) {
224 $('#updraftplus_ajax_restore_last_activity').html(updraftlion.last_activity.replace('%d', last_activity));
225 } else {
226 var resume_in = 120 - last_activity;
227 if (0 < resume_in) {
228 $('#updraftplus_ajax_restore_last_activity').html(updraftlion.no_recent_activity.replace('%d', resume_in));
229 } else {
230 $('#updraftplus_ajax_restore_last_activity').html('');
231 updraft_restore_resume_notice();
232 }
233 }
234 }
235
236 /**
237 * This will move the filesystem form to take all the required space
238 */
239 function updraft_restore_setup_filesystem_form() {
240 // Hiding things is handled via CSS
241 $('.updraft_restore_main').addClass('show-credentials-form');
242 if ($('#message').length) {
243 $('.restore-credential-errors .restore-credential-errors--list').appendTo($('#message'));
244 $('.restore-credential-errors .restore-credential-errors--link').appendTo($('#message'));
245 }
246 }
247
248 /**
249 * This function will make a call to the backend to get the resume restore notice so the user can resume the timed out restore from the same page
250 */
251 function updraft_restore_resume_notice() {
252 updraft_send_command('get_restore_resume_notice', { job_id: job_id }, function(response) {
253 if (response.hasOwnProperty('status') && 'success' == response.status && response.hasOwnProperty('html')) {
254 if (updraft_restore_update_timer) clearInterval(updraft_restore_update_timer);
255 if ('plugins' != current_stage && 'db' != current_stage && 5 > auto_resume_count) {
256 auto_resume_count++;
257 updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
258 } else {
259 $('.updraft_restore_main--components').prepend(response.html);
260 }
261 } else if (response.hasOwnProperty('error_code') && response.hasOwnProperty('error_message')) {
262 if (updraft_restore_update_timer) clearInterval(updraft_restore_update_timer);
263 alert(response.error_code + ': ' + response.error_message);
264 console.log(response.error_code + ': ' + response.error_message);
265 }
266 }, {
267 error_callback: function (response, status, error_code, resp) {
268 if (500 == response.status && 3 > server_500_count) {
269 server_500_count++;
270 updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
271 } else {
272 updraft_restore_process_data({stage: 'finished', type: 'state_change'})
273 var error_message = "updraft_send_command: error: " + status + " (" + error_code + ")";
274 alert(error_message);
275 console.log(error_message);
276 console.log(response);
277 }
278 }
279 });
280 }
281
282 /**
283 * This function will make a call to the passed in urls and check if the response code is a 404 if it is then add it to the array of urls that are not found and return it via a callback
284 *
285 * @param {array} urls - the urls we want to test
286 * @param {Function} callback - will be called with the array of urls not found
287 */
288 function updraft_restore_get_pages(urls, callback) {
289 var urls_not_found = [];
290 var ajax_requests = [];
291
292 $.each(urls, function(index, url) {
293 var d = $.Deferred();
294 ajax_requests.push(d.promise());
295
296 var xhttp = new XMLHttpRequest();
297 xhttp.onreadystatechange = function() {
298 if (4 == this.readyState) {
299 if (404 == this.status) urls_not_found.push(url);
300 d.resolve();
301 }
302 };
303 xhttp.open('GET', url, true);
304 xhttp.send(null);
305 });
306
307 $.when.apply($, ajax_requests).done(function() {
308 callback(urls_not_found);
309 });
310 }
311
312 $('#updraftplus_ajax_restore_progress').on('click', '#updraft_restore_resume', function(e) {
313 e.preventDefault();
314 $("#updraftplus_ajax_restore_progress").slideUp(1000, function () {
315 $(this).remove();
316 });
317 updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
318 });
319
320 $(document).on('heartbeat-tick', function (event, heartbeat_data) {
321
322 if (!heartbeat_data.hasOwnProperty('wp-auth-check')) return;
323
324 // check if we are logged out
325 if (!heartbeat_data["wp-auth-check"]) {
326 logged_out = true;
327 return;
328 }
329
330 // if we were previously logged out but are now logged in retry the restore
331 if (logged_out && heartbeat_data["wp-auth-check"]) {
332 last_received = Math.round(Date.now() / 1000);
333 logged_out = false;
334 }
335
336 if (!heartbeat_data.hasOwnProperty('updraftplus')) return;
337
338 var updraftplus_data = heartbeat_data.updraftplus;
339
340 // if we are logged in, check if theres a new nonce
341 if (updraftplus_data.hasOwnProperty('updraft_credentialtest_nonce')) {
342 updraft_credentialtest_nonce = updraftplus_data.updraft_credentialtest_nonce;
343 last_received = Math.round(Date.now() / 1000);
344 }
345 });
346 });
347