Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../js
File: updraft-admin-restore.js
var updraft_restore_screen = true;
[0] Fix | Delete
jQuery(function($) {
[1] Fix | Delete
[2] Fix | Delete
var job_id = $('#updraftplus_ajax_restore_job_id').val();
[3] Fix | Delete
var action = $('#updraftplus_ajax_restore_action').val();
[4] Fix | Delete
var updraft_restore_update_timer;
[5] Fix | Delete
var last_received = 0;
[6] Fix | Delete
var $output = $('#updraftplus_ajax_restore_output');
[7] Fix | Delete
var $steps_list = $('.updraft_restore_components_list');
[8] Fix | Delete
var previous_stage;
[9] Fix | Delete
var current_stage;
[10] Fix | Delete
var logged_out = false;
[11] Fix | Delete
var auto_resume_count = 0;
[12] Fix | Delete
var server_500_count = 0;
[13] Fix | Delete
[14] Fix | Delete
$('#updraft-restore-hidethis').remove();
[15] Fix | Delete
[16] Fix | Delete
updraft_restore_command(job_id, action);
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* This function will start the restore over ajax for the passed in job_id.
[20] Fix | Delete
*
[21] Fix | Delete
* @param {string} job_id - the restore job id
[22] Fix | Delete
* @param {string} action - the restore action
[23] Fix | Delete
*/
[24] Fix | Delete
function updraft_restore_command(job_id, action) {
[25] Fix | Delete
[26] Fix | Delete
var xhttp = new XMLHttpRequest();
[27] Fix | Delete
var xhttp_data = 'action=' + action + '&updraftplus_ajax_restore=do_ajax_restore&job_id=' + job_id;
[28] Fix | Delete
var previous_data_length = 0;
[29] Fix | Delete
var show_alert = true;
[30] Fix | Delete
var debug = $('#updraftplus_ajax_restore_debug').length;
[31] Fix | Delete
[32] Fix | Delete
xhttp.open("POST", ajaxurl, true);
[33] Fix | Delete
xhttp.onprogress = function(response) {
[34] Fix | Delete
if (response.currentTarget.status >= 200 && response.currentTarget.status < 300) {
[35] Fix | Delete
if (-1 !== response.currentTarget.responseText.indexOf('<html')) {
[36] Fix | Delete
if (show_alert) {
[37] Fix | Delete
show_alert = false;
[38] Fix | Delete
alert("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_invalid_response);
[39] Fix | Delete
}
[40] Fix | Delete
$output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_invalid_response);
[41] Fix | Delete
console.log("UpdraftPlus restore error: HTML detected in response could be a copy of the WordPress front page caused by mod_security");
[42] Fix | Delete
console.log(response.currentTarget.responseText);
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if (previous_data_length == response.currentTarget.responseText.length) return;
[47] Fix | Delete
[48] Fix | Delete
last_received = Math.round(Date.now() / 1000);
[49] Fix | Delete
[50] Fix | Delete
var responseText = response.currentTarget.responseText.substr(previous_data_length);
[51] Fix | Delete
[52] Fix | Delete
previous_data_length = response.currentTarget.responseText.length;
[53] Fix | Delete
[54] Fix | Delete
var i = 0;
[55] Fix | Delete
var end_of_json = 0;
[56] Fix | Delete
[57] Fix | Delete
// 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
[58] Fix | Delete
while (i < responseText.length) {
[59] Fix | Delete
var buffer = responseText.substr(i, 7);
[60] Fix | Delete
if ('RINFO:{' == buffer) {
[61] Fix | Delete
// Output what precedes the RINFO:
[62] Fix | Delete
$output
[63] Fix | Delete
.append(responseText.substring(end_of_json, i).trim()) // add the text to the activity log
[64] Fix | Delete
.scrollTop($output[0].scrollHeight); // Scroll to the bottom of the box
[65] Fix | Delete
// Grab what follows RINFO:
[66] Fix | Delete
var analyse_it = ud_parse_json(responseText.substr(i), true);
[67] Fix | Delete
[68] Fix | Delete
if (1 == debug) { console.log(analyse_it); }
[69] Fix | Delete
[70] Fix | Delete
updraft_restore_process_data(analyse_it.parsed);
[71] Fix | Delete
[72] Fix | Delete
// move the for loop counter to the end of the json
[73] Fix | Delete
end_of_json = i + analyse_it.json_last_pos - analyse_it.json_start_pos + 6;
[74] Fix | Delete
// When the for loop goes round again, it will start with the end of the JSON
[75] Fix | Delete
i = end_of_json;
[76] Fix | Delete
} else {
[77] Fix | Delete
i++;
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
$output.append(responseText.substr(end_of_json).trim()).scrollTop($output[0].scrollHeight);
[81] Fix | Delete
// check if the fylesystem form is displayed
[82] Fix | Delete
if ($output.find('input[name=connection_type]').length && $output.find('#upgrade').length) {
[83] Fix | Delete
updraft_restore_setup_filesystem_form();
[84] Fix | Delete
}
[85] Fix | Delete
} else {
[86] Fix | Delete
if (0 == response.currentTarget.status) {
[87] Fix | Delete
$output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + updraftlion.ajax_restore_contact_failed);
[88] Fix | Delete
} else {
[89] Fix | Delete
$output.append("UpdraftPlus " + updraftlion.ajax_restore_error + ' ' + response.currentTarget.status + ' ' + response.currentTarget.statusText);
[90] Fix | Delete
}
[91] Fix | Delete
console.log("UpdraftPlus restore error: " + response.currentTarget.status + ' ' + response.currentTarget.statusText);
[92] Fix | Delete
console.log(response.currentTarget);
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
xhttp.onload = function() {
[96] Fix | Delete
var $result = $output.find('.updraft_restore_successful, .updraft_restore_error');
[97] Fix | Delete
[98] Fix | Delete
// if we don't find the result, exit
[99] Fix | Delete
if (!$result.length) return;
[100] Fix | Delete
[101] Fix | Delete
var $result_output = $('.updraft_restore_result');
[102] Fix | Delete
$result_output.slideDown();
[103] Fix | Delete
$steps_list.slideUp();
[104] Fix | Delete
$steps_list.siblings('h2').slideUp();
[105] Fix | Delete
[106] Fix | Delete
if ($result.is('.updraft_restore_successful')) {
[107] Fix | Delete
$result_output.find('.dashicons').addClass('dashicons-yes');
[108] Fix | Delete
$result_output.find('.updraft_restore_result--text').text($result.text());
[109] Fix | Delete
$result_output.addClass('restore-success');
[110] Fix | Delete
} else if ($result.is('.updraft_restore_error')) {
[111] Fix | Delete
$result_output.find('.dashicons').addClass('dashicons-no-alt');
[112] Fix | Delete
$result_output.find('.updraft_restore_result--text').text($result.text());
[113] Fix | Delete
$result_output.addClass('restore-error');
[114] Fix | Delete
}
[115] Fix | Delete
// scroll log to the bottom
[116] Fix | Delete
setTimeout(function() {
[117] Fix | Delete
$output.scrollTop($output[0].scrollHeight);
[118] Fix | Delete
}, 500);
[119] Fix | Delete
}
[120] Fix | Delete
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
[121] Fix | Delete
xhttp.send(xhttp_data);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* This function will process the parsed restore data and make updates to the front end
[126] Fix | Delete
*
[127] Fix | Delete
* @param {object} restore_data - the restore data object contains information on the restore progress to update the front end
[128] Fix | Delete
*/
[129] Fix | Delete
function updraft_restore_process_data(restore_data) {
[130] Fix | Delete
[131] Fix | Delete
// If the stage is started then we want to start our restore timer as the restore has now actually began
[132] Fix | Delete
if ('started' == restore_data.stage) {
[133] Fix | Delete
updraft_restore_update_timer = setInterval(function () {
[134] Fix | Delete
updraft_restore_update();
[135] Fix | Delete
}, 5000);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// If the stage is finished then we want to remove our timer and clean up the UI
[139] Fix | Delete
if ('finished' == restore_data.stage && updraft_restore_update_timer) {
[140] Fix | Delete
clearInterval(updraft_restore_update_timer);
[141] Fix | Delete
$('#updraftplus_ajax_restore_last_activity').html('');
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
if (restore_data) {
[145] Fix | Delete
if ('state' == restore_data.type || 'state_change' == restore_data.type) {
[146] Fix | Delete
console.log(restore_data.stage, restore_data.data);
[147] Fix | Delete
if ('files' == restore_data.stage) {
[148] Fix | Delete
current_stage = restore_data.data.entity;
[149] Fix | Delete
} else {
[150] Fix | Delete
current_stage = restore_data.stage;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
var $current = $steps_list.find('[data-component='+current_stage+']');
[154] Fix | Delete
[155] Fix | Delete
// show simplified activity log next to the component's label
[156] Fix | Delete
if ('files' == restore_data.stage) {
[157] Fix | Delete
$current.find('.updraft_component--progress').html(' — '+updraftlion.restore_files_progress.replace('%s1', '<strong>'+(restore_data.data.fileindex)+'</strong>').replace('%s2', '<strong>'+restore_data.data.total_files+'</strong>'));
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if ('db' == restore_data.stage) {
[161] Fix | Delete
if (restore_data.data.hasOwnProperty('stage')) {
[162] Fix | Delete
if ('table' == restore_data.data.stage) {
[163] Fix | Delete
$current.find('.updraft_component--progress').html(' — '+updraftlion.restore_db_table_progress.replace('%s', '<strong>'+(restore_data.data.table)+'</strong>'));
[164] Fix | Delete
} else if ('stored_routine' == restore_data.data.stage) {
[165] Fix | Delete
$current.find('.updraft_component--progress').html(' — '+updraftlion.restore_db_stored_routine_progress.replace('%s', '<strong>'+(restore_data.data.routine_name)+'</strong>'));
[166] Fix | Delete
} else if ('finished' == restore_data.data.stage) {
[167] Fix | Delete
$current.find('.updraft_component--progress').html(' — '+updraftlion.finished);
[168] Fix | Delete
} else if ('begun' == restore_data.data.stage) {
[169] Fix | Delete
$current.find('.updraft_component--progress').html(' — '+updraftlion.begun+'...');
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
if (previous_stage !== current_stage) {
[175] Fix | Delete
if (previous_stage) {
[176] Fix | Delete
var $prev = $steps_list.find('[data-component='+previous_stage+']');
[177] Fix | Delete
// empty the line's status
[178] Fix | Delete
$prev.find('.updraft_component--progress').html('');
[179] Fix | Delete
$prev.removeClass('active').addClass('done');
[180] Fix | Delete
}
[181] Fix | Delete
if ('finished' == current_stage) {
[182] Fix | Delete
$current.addClass('done');
[183] Fix | Delete
$steps_list.find('[data-component]').each(function(index, el) {
[184] Fix | Delete
$el = $(el);
[185] Fix | Delete
if (!$el.is('.done')) {
[186] Fix | Delete
$el.addClass('error');
[187] Fix | Delete
}
[188] Fix | Delete
});
[189] Fix | Delete
if (restore_data.data.hasOwnProperty('actions') && 'object' == typeof restore_data.data.actions) {
[190] Fix | Delete
[191] Fix | Delete
var pages_found = updraft_restore_get_pages(restore_data.data.urls);
[192] Fix | Delete
if (!$.isEmptyObject(pages_found)) {
[193] Fix | Delete
$('.updraft_restore_result').before(updraftlion.ajax_restore_404_detected);
[194] Fix | Delete
$.each(pages_found, function(index, url) {
[195] Fix | Delete
$('.updraft_missing_pages').append('<li>'+url+'</li>');
[196] Fix | Delete
});
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
$.each(restore_data.data.actions, function(index, item) {
[200] Fix | Delete
$steps_list.after('<a href="'+item+'" class="button button-primary">'+index+'</a>');
[201] Fix | Delete
});
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
} else {
[205] Fix | Delete
$current.addClass('active');
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
previous_stage = current_stage;
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* This function will update the time in the front end that we last recived data, after 120 seconds call the resume restore notice
[216] Fix | Delete
*/
[217] Fix | Delete
function updraft_restore_update() {
[218] Fix | Delete
var current_time = Math.round(Date.now() / 1000);
[219] Fix | Delete
var last_activity = current_time - last_received;
[220] Fix | Delete
if (60 > last_activity) {
[221] Fix | Delete
$('#updraftplus_ajax_restore_last_activity').html(updraftlion.last_activity.replace('%d', last_activity));
[222] Fix | Delete
} else {
[223] Fix | Delete
var resume_in = 120 - last_activity;
[224] Fix | Delete
if (0 < resume_in) {
[225] Fix | Delete
$('#updraftplus_ajax_restore_last_activity').html(updraftlion.no_recent_activity.replace('%d', resume_in));
[226] Fix | Delete
} else {
[227] Fix | Delete
$('#updraftplus_ajax_restore_last_activity').html('');
[228] Fix | Delete
updraft_restore_resume_notice();
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* This will move the filesystem form to take all the required space
[235] Fix | Delete
*/
[236] Fix | Delete
function updraft_restore_setup_filesystem_form() {
[237] Fix | Delete
// Hiding things is handled via CSS
[238] Fix | Delete
$('.updraft_restore_main').addClass('show-credentials-form');
[239] Fix | Delete
if ($('#message').length) {
[240] Fix | Delete
$('.restore-credential-errors .restore-credential-errors--list').appendTo($('#message'));
[241] Fix | Delete
$('.restore-credential-errors .restore-credential-errors--link').appendTo($('#message'));
[242] Fix | Delete
}
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* 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
[247] Fix | Delete
*/
[248] Fix | Delete
function updraft_restore_resume_notice() {
[249] Fix | Delete
updraft_send_command('get_restore_resume_notice', { job_id: job_id }, function(response) {
[250] Fix | Delete
if (response.hasOwnProperty('status') && 'success' == response.status && response.hasOwnProperty('html')) {
[251] Fix | Delete
if (updraft_restore_update_timer) clearInterval(updraft_restore_update_timer);
[252] Fix | Delete
if ('plugins' != current_stage && 'db' != current_stage && 5 > auto_resume_count) {
[253] Fix | Delete
auto_resume_count++;
[254] Fix | Delete
updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
[255] Fix | Delete
} else {
[256] Fix | Delete
$('.updraft_restore_main--components').prepend(response.html);
[257] Fix | Delete
}
[258] Fix | Delete
} else if (response.hasOwnProperty('error_code') && response.hasOwnProperty('error_message')) {
[259] Fix | Delete
if (updraft_restore_update_timer) clearInterval(updraft_restore_update_timer);
[260] Fix | Delete
alert(response.error_code + ': ' + response.error_message);
[261] Fix | Delete
console.log(response.error_code + ': ' + response.error_message);
[262] Fix | Delete
}
[263] Fix | Delete
}, {
[264] Fix | Delete
error_callback: function (response, status, error_code, resp) {
[265] Fix | Delete
if (500 == response.status && 3 > server_500_count) {
[266] Fix | Delete
server_500_count++;
[267] Fix | Delete
updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
[268] Fix | Delete
} else {
[269] Fix | Delete
updraft_restore_process_data({stage: 'finished', type: 'state_change'})
[270] Fix | Delete
var error_message = "updraft_send_command: error: " + status + " (" + error_code + ")";
[271] Fix | Delete
alert(error_message);
[272] Fix | Delete
console.log(error_message);
[273] Fix | Delete
console.log(response);
[274] Fix | Delete
}
[275] Fix | Delete
}
[276] Fix | Delete
});
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* 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
[281] Fix | Delete
*
[282] Fix | Delete
* @param {array} urls - the urls we want to test
[283] Fix | Delete
*
[284] Fix | Delete
* @return {array} an array of urls not found
[285] Fix | Delete
*/
[286] Fix | Delete
function updraft_restore_get_pages(urls) {
[287] Fix | Delete
[288] Fix | Delete
var urls_not_found = [];
[289] Fix | Delete
[290] Fix | Delete
$.each(urls, function(index, url) {
[291] Fix | Delete
var xhttp = new XMLHttpRequest();
[292] Fix | Delete
xhttp.open('GET', url, false);
[293] Fix | Delete
xhttp.send(null);
[294] Fix | Delete
if (xhttp.status == 404) urls_not_found.push(url);
[295] Fix | Delete
});
[296] Fix | Delete
[297] Fix | Delete
return urls_not_found;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$('#updraftplus_ajax_restore_progress').on('click', '#updraft_restore_resume', function(e) {
[301] Fix | Delete
e.preventDefault();
[302] Fix | Delete
$("#updraftplus_ajax_restore_progress").slideUp(1000, function () {
[303] Fix | Delete
$(this).remove();
[304] Fix | Delete
});
[305] Fix | Delete
updraft_restore_command(job_id, 'updraft_ajaxrestore_continue');
[306] Fix | Delete
});
[307] Fix | Delete
[308] Fix | Delete
$(document).on('heartbeat-tick', function (event, heartbeat_data) {
[309] Fix | Delete
[310] Fix | Delete
if (!heartbeat_data.hasOwnProperty('wp-auth-check')) return;
[311] Fix | Delete
[312] Fix | Delete
// check if we are logged out
[313] Fix | Delete
if (!heartbeat_data["wp-auth-check"]) {
[314] Fix | Delete
logged_out = true;
[315] Fix | Delete
return;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
// if we were previously logged out but are now logged in retry the restore
[319] Fix | Delete
if (logged_out && heartbeat_data["wp-auth-check"]) {
[320] Fix | Delete
last_received = Math.round(Date.now() / 1000);
[321] Fix | Delete
logged_out = false;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
if (!heartbeat_data.hasOwnProperty('updraftplus')) return;
[325] Fix | Delete
[326] Fix | Delete
var updraftplus_data = heartbeat_data.updraftplus;
[327] Fix | Delete
[328] Fix | Delete
// if we are logged in, check if theres a new nonce
[329] Fix | Delete
if (updraftplus_data.hasOwnProperty('updraft_credentialtest_nonce')) {
[330] Fix | Delete
updraft_credentialtest_nonce = updraftplus_data.updraft_credentialtest_nonce;
[331] Fix | Delete
last_received = Math.round(Date.now() / 1000);
[332] Fix | Delete
}
[333] Fix | Delete
});
[334] Fix | Delete
});
[335] Fix | Delete
[336] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function