/** * Send an action over AJAX. A wrapper around jQuery.ajax. In future, all consumers can be reviewed to simplify some of the options, where there is historical cruft. * N.B. updraft_iframe_modal() below uses the Ajax URL for the iframe's src attribute * * @param {string} action - the action to send * @param {*} data - data to send * @param {Function} callback - will be called with the results * @param {object} options -further options. Relevant properties include: * - [json_parse=true] - whether to JSON parse the results * - [alert_on_error=true] - whether to show an alert box if there was a problem (otherwise, suppress it) * - [action='updraft_ajax'] - what to send as the action parameter on the AJAX request (N.B. action parameter to this function goes as the 'subaction' parameter on the AJAX request) * - [nonce=updraft_credentialtest_nonce] - the nonce value to send. * - [nonce_key='nonce'] - the key value for the nonce field * - [timeout=null] - set a timeout after this number of seconds (or if null, none is set) * - [async=true] - control whether the request is asynchronous (almost always wanted) or blocking (would need to have a specific reason) * - [type='POST'] - GET or POST */ function updraft_send_command(action, data, callback, options) { default_options = { json_parse: true, alert_on_error: true, action: 'updraft_ajax', nonce: updraft_credentialtest_nonce, nonce_key: 'nonce', timeout: null, async: true, type: 'POST' } if ('undefined' === typeof options) options = {}; for (var opt in default_options) { if (!options.hasOwnProperty(opt)) { options[opt] = default_options[opt]; } } var ajax_data = { action: options.action, subaction: action, }; ajax_data[options.nonce_key] = options.nonce; // TODO: Once all calls are routed through here, change the listener in admin.php to always take the data from the 'data' attribute, instead of in the naked $_POST/$_GET if (typeof data == 'object') { for (var attrname in data) { ajax_data[attrname] = data[attrname]; } } else { ajax_data.action_data = data; } var ajax_opts = { type: options.type, url: ajaxurl, data: ajax_data, success: function(response, status) { if (options.json_parse) { try { var resp = ud_parse_json(response); } catch (e) { if ('function' == typeof options.error_callback) { return options.error_callback(response, e, 502, resp); } else { console.log(e); console.log(response); if (options.alert_on_error) { alert(updraftlion.unexpectedresponse+' '+response); } return; } } if (resp.hasOwnProperty('fatal_error')) { if ('function' == typeof options.error_callback) { // 500 is internal server error code return options.error_callback(response, status, 500, resp); } else { console.error(resp.fatal_error_message); if (options.alert_on_error) { alert(resp.fatal_error_message); } return false; } } if ('function' == typeof callback) callback(resp, status, response); } else { if ('function' == typeof callback) callback(response, status); } }, error: function(response, status, error_code) { if ('function' == typeof options.error_callback) { options.error_callback(response, status, error_code); } else { console.log("updraft_send_command: error: "+status+" ("+error_code+")"); console.log(response); } }, dataType: 'text', async: options.async }; if (null != options.timeout) { ajax_opts.timeout = options.timeout; } jQuery.ajax(ajax_opts); } /** * Opens the dialog box for confirmation of whether to delete a backup, plus options if relevant * * @param {string} key - The UNIX timestamp of the backup * @param {string} nonce - The backup job ID * @param {boolean} showremote - Whether or not to show the "also delete from remote storage?" checkbox */ function updraft_delete(key, nonce, showremote) { jQuery('#updraft_delete_timestamp').val(key); jQuery('#updraft_delete_nonce').val(nonce); if (showremote) { jQuery('#updraft-delete-remote-section, #updraft_delete_remote').removeAttr('disabled').show(); } else { jQuery('#updraft-delete-remote-section, #updraft_delete_remote').hide().attr('disabled','disabled'); } if (key.indexOf(',') > -1) { jQuery('#updraft_delete_question_singular').hide(); jQuery('#updraft_delete_question_plural').show(); } else { jQuery('#updraft_delete_question_plural').hide(); jQuery('#updraft_delete_question_singular').show(); } jQuery('#updraft-delete-modal').dialog('open'); } function updraft_remote_storage_tab_activation(the_method){ jQuery('.updraftplusmethod').hide(); jQuery('.remote-tab').data('active', false); jQuery('.remote-tab').removeClass('nav-tab-active'); jQuery('.updraftplusmethod.'+the_method).show(); jQuery('.remote-tab-'+the_method).data('active', true); jQuery('.remote-tab-'+the_method).addClass('nav-tab-active'); } /** * Check how many cron jobs are overdue, and display a message if it is several (as determined by the back-end) */ function updraft_check_overduecrons() { updraft_send_command('check_overdue_crons', null, function(response) { if (response && response.hasOwnProperty('m')) { jQuery('#updraft-insert-admin-warning').html(response.m); } }, { alert_on_error: false }); } function updraft_remote_storage_tabs_setup() { var anychecked = 0; var set = jQuery('.updraft_servicecheckbox:checked'); jQuery(set).each(function(ind, obj) { var ser = jQuery(obj).val(); if (jQuery(obj).attr('id') != 'updraft_servicecheckbox_none') { anychecked++; } jQuery('.remote-tab-'+ser).show(); if (ind == jQuery(set).length-1) { updraft_remote_storage_tab_activation(ser); } }); if (anychecked > 0) { jQuery('.updraftplusmethod.none').hide(); jQuery('#remote_storage_tabs').show(); } else { jQuery('#remote_storage_tabs').hide(); } // To allow labelauty remote storage buttons to be used with keyboard jQuery(document).keyup(function(event) { if (32 === event.keyCode || 13 === event.keyCode) { if (jQuery(document.activeElement).is("input.labelauty + label")) { var for_box = jQuery(document.activeElement).attr("for"); if (for_box) { jQuery("#"+for_box).change(); } } } }); jQuery('.updraft_servicecheckbox').change(function() { var sclass = jQuery(this).attr('id'); if ('updraft_servicecheckbox_' == sclass.substring(0,24)) { var serv = sclass.substring(24); if (null != serv && '' != serv) { if (jQuery(this).is(':checked')) { anychecked++; jQuery('.remote-tab-'+serv).fadeIn(); updraft_remote_storage_tab_activation(serv); } else { anychecked--; jQuery('.remote-tab-'+serv).hide(); // Check if this was the active tab, if yes, switch to another if (jQuery('.remote-tab-'+serv).data('active') == true) { updraft_remote_storage_tab_activation(jQuery('.remote-tab:visible').last().attr('name')); } } } } if (anychecked <= 0) { jQuery('.updraftplusmethod.none').fadeIn(); jQuery('#remote_storage_tabs').hide(); } else { jQuery('.updraftplusmethod.none').hide(); jQuery('#remote_storage_tabs').show(); } }); // Add stuff for free version jQuery('.updraft_servicecheckbox:not(.multi)').change(function() { var svalue = jQuery(this).attr('value'); if (jQuery(this).is(':not(:checked)')) { jQuery('.updraftplusmethod.'+svalue).hide(); jQuery('.updraftplusmethod.none').fadeIn(); } else { jQuery('.updraft_servicecheckbox').not(this).prop('checked', false); } }); var servicecheckbox = jQuery('.updraft_servicecheckbox'); if (typeof servicecheckbox.labelauty === 'function') { servicecheckbox.labelauty(); } } /** * Carries out a remote storage test * * @param {string} method - The identifier for the remote storage * @param {callback} result_callback - A callback function to be called with the result * @param {string} instance_id - The particular instance (if any) of the remote storage to be tested (for methods supporting multiple instances) */ function updraft_remote_storage_test(method, result_callback, instance_id) { var $the_button; var settings_selector; if (instance_id) { $the_button = jQuery('#updraft-'+method+'-test-'+instance_id); settings_selector = '.updraftplusmethod.'+method+'-'+instance_id; } else { $the_button = jQuery('#updraft-'+method+'-test'); settings_selector = '.updraftplusmethod.'+method; } var method_label = $the_button.data('method_label'); $the_button.html(updraftlion.testing_settings.replace('%s', method_label)); var data = { method: method }; // Add the other items to the data object. The expert mode settings are for the generic SSL options. jQuery('#updraft-navtab-settings-content '+settings_selector+' input[data-updraft_settings_test], #updraft-navtab-settings-content .expertmode input[data-updraft_settings_test]').each(function(index, item) { var item_key = jQuery(item).data('updraft_settings_test'); var input_type = jQuery(item).attr('type'); if (!item_key) { return; } if (!input_type) { console.log("UpdraftPlus: settings test input item with no type found"); console.log(item); // A default input_type = 'text'; } var value = null; if ('checkbox' == input_type) { value = jQuery(item).is(':checked') ? 1 : 0; } else if ('text' == input_type || 'password' == input_type) { value = jQuery(item).val(); } else { console.log("UpdraftPlus: settings test input item with unrecognised type ("+input_type+") found"); console.log(item); } data[item_key] = value; }); // Data from any text areas or select drop-downs jQuery('#updraft-navtab-settings-content '+settings_selector+' textarea[data-updraft_settings_test], #updraft-navtab-settings-content '+settings_selector+' select[data-updraft_settings_test]').each(function(index, item) { var item_key = jQuery(item).data('updraft_settings_test'); data[item_key] = jQuery(item).val(); }); updraft_send_command('test_storage_settings', data, function(response, status) { $the_button.html(updraftlion.test_settings.replace('%s', method_label)); if ('undefined' !== typeof result_callback && false != result_callback) { result_callback = result_callback.call(this, response, status, data); } if ('undefined' !== typeof result_callback && false === result_callback) { alert(updraftlion.settings_test_result.replace('%s', method_label)+' '+response.output); if (response.hasOwnProperty('data')) { console.log(response.data); } } }, { error_callback: function(response, status, error_code, resp) { $the_button.html(updraftlion.test_settings.replace('%s', method_label)); if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; console.log(error_message); alert(error_message); console.log(response); } } }); } function backupnow_whichfiles_checked(onlythesefileentities){ jQuery('#backupnow_includefiles_moreoptions input[type="checkbox"]').each(function(index) { if (!jQuery(this).is(':checked')) { return; } var name = jQuery(this).attr('name'); if (name.substring(0, 16) != 'updraft_include_') { return; } var entity = name.substring(16); if (onlythesefileentities != '') { onlythesefileentities += ','; } onlythesefileentities += entity; }); // console.log(onlythesefileentities); return onlythesefileentities; } /** * A method to get all the selected table values from the backup now modal * * @param {string} onlythesetableentities an empty string to append values to * * @return {string} a string that contains the values of all selected table entities and the database the belong to */ function backupnow_whichtables_checked(onlythesetableentities){ var send_list = false; jQuery('#backupnow_database_moreoptions input[type="checkbox"]').each(function(index) { if (!jQuery(this).is(':checked')) { send_list = true; return; } }); onlythesetableentities = jQuery("input[name^='updraft_include_tables_']").serializeArray(); if (send_list) { return onlythesetableentities; } else { return true; } } function updraft_deleteallselected() { var howmany = 0; var remote_exists = 0; var key_all = ''; var nonce_all = ''; var remote_all = 0; jQuery('#updraft-navtab-backups-content .updraft_existing_backups .updraft_existing_backups_row.backuprowselected').each(function(index) { howmany++; var nonce = jQuery(this).data('nonce'); if (nonce_all) { nonce_all += ','; } nonce_all += nonce; var key = jQuery(this).data('key'); if (key_all) { key_all += ','; } key_all += key; var has_remote = jQuery(this).find('.updraftplus-remove').data('hasremote'); if (has_remote) remote_all++; }); updraft_delete(key_all, nonce_all, remote_all); } /** * Open main tab which is given as argument * * @param {string} active_tab_key A tab key which you would like to open */ function updraft_open_main_tab(active_tab_key) { updraftlion.main_tabs_keys.forEach(function(tab_key) { if (active_tab_key == tab_key) { jQuery('#updraft-navtab-' + tab_key + '-content').show(); jQuery('#updraft-navtab-' + tab_key).addClass('nav-tab-active'); } else { jQuery('#updraft-navtab-' + tab_key + '-content').hide(); jQuery('#updraft-navtab-' + tab_key).removeClass('nav-tab-active'); } updraft_console_focussed_tab = active_tab_key; }); } /** * Open an existing backups tab * * @param {Boolean} toggly Whether switch on updraft_historytimer or not */ function updraft_openrestorepanel(toggly) { // jQuery('.download-backups').slideDown(); updraft_historytimertoggle(1); jQuery('html,body').animate({scrollTop: jQuery('#updraft_lastlogcontainer').offset().top},'slow'); updraft_historytimertoggle(toggly); updraft_open_main_tab('backups'); } function updraft_delete_old_dirs() { return true; } function updraft_initiate_restore(whichset) { jQuery('#updraft-navtab-backups-content .updraft_existing_backups button[data-backup_timestamp="'+whichset+'"]').click(); } function updraft_restore_setoptions(entities) { var howmany = 0; jQuery('input[name="updraft_restore[]"]').each(function(x,y) { var entity = jQuery(y).val(); var epat = entity+'=([0-9,]+)'; var eregex = new RegExp(epat); var ematch = entities.match(eregex); if (ematch) { jQuery(y).removeAttr('disabled').data('howmany', ematch[1]).parent().show(); howmany++; if ('db' == entity) { howmany += 4.5;} if (jQuery(y).is(':checked')) { // This element may or may not exist. The purpose of explicitly calling show() is that Firefox, when reloading (including via forwards/backwards navigation) will remember checkbox states, but not which DOM elements were showing/hidden - which can result in some being hidden when they should be shown, and the user not seeing the options that are/are not checked. jQuery('#updraft_restorer_'+entity+'options').show(); } } else { jQuery(y).attr('disabled','disabled').parent().hide(); } }); var cryptmatch = entities.match(/dbcrypted=1/); if (cryptmatch) { jQuery('#updraft_restore_db').data('encrypted', 1); jQuery('.updraft_restore_crypteddb').show(); } else { jQuery('#updraft_restore_db').data('encrypted', 0); jQuery('.updraft_restore_crypteddb').hide(); } jQuery('#updraft_restore_db').trigger('change'); var dmatch = entities.match(/meta_foreign=([12])/); if (dmatch) { jQuery('#updraft_restore_meta_foreign').val(dmatch[1]); } else { jQuery('#updraft_restore_meta_foreign').val('0'); } var height = 336+howmany*20; jQuery('#updraft-restore-modal').dialog("option", "height", height); } function updraft_backup_dialog_open() { jQuery('#backupnow_includefiles_moreoptions').hide(); if (updraft_settings_form_changed) { if (window.confirm(updraftlion.unsavedsettingsbackup)) { jQuery('#backupnow_label').val(''); jQuery('#updraft-backupnow-modal').dialog('open'); } } else { jQuery('#backupnow_label').val(''); jQuery('#updraft-backupnow-modal').dialog('open'); } } var onlythesefileentities = backupnow_whichfiles_checked(''); if ('' == onlythesefileentities) { jQuery("#backupnow_includefiles_moreoptions").show(); } else { jQuery("#backupnow_includefiles_moreoptions").hide(); } var updraft_restore_stage = 1; var lastlog_lastmessage = ""; var lastlog_lastdata = ""; var lastlog_jobs = ""; // var lastlog_sdata = { action: 'updraft_ajax', subaction: 'lastlog' }; var updraft_activejobs_nextupdate = (new Date).getTime() + 1000; // Bits: main tab displayed (1); restore dialog open (uses downloader) (2); tab not visible (4) var updraft_page_is_visible = 1; var updraft_console_focussed_tab = updraftlion.tab; var updraft_settings_form_changed = false; window.onbeforeunload = function(e) { if (updraft_settings_form_changed) return updraftlion.unsavedsettings; } /** * N.B. This function works on both the UD settings page and elsewhere * * @param {boolean} firstload Check if this is first load */ function updraft_check_page_visibility(firstload) { if ('hidden' == document["visibilityState"]) { updraft_page_is_visible = 0; } else { updraft_page_is_visible = 1; if (1 !== firstload) { if (jQuery('#updraft-navtab-backups-content').length) { updraft_activejobs_update(true); } } }; } // See http://caniuse.com/#feat=pagevisibility for compatibility (we don't bother with prefixes) if (typeof document.hidden !== "undefined") { document.addEventListener('visibilitychange', function() { updraft_check_page_visibility(0);}, false); } updraft_check_page_visibility(1); var updraft_poplog_log_nonce; var updraft_poplog_log_pointer = 0; var updraft_poplog_lastscroll = -1; var updraft_last_forced_jobid = -1; var updraft_last_forced_resumption = -1; var updraft_last_forced_when = -1; var updraft_backupnow_nonce = ''; var updraft_activejobslist_backupnownonce_only = 0; var updraft_inpage_hasbegun = 0; var updraft_activejobs_update_timer; var updraft_aborted_jobs = []; var updraft_clone_jobs = []; // Manage backups table selection var updraft_backups_selection = {}; // @codingStandardsIgnoreStart - to keep the doc blocks, as they're considered block comments by phpcs (function($) { /** * Toggle row seletion * * @param {HTMLDomElement|jQuery} el - row element */ updraft_backups_selection.toggle = function(el) { var $el = $(el); if ($el.is('.backuprowselected')) { this.deselect(el); } else { this.select(el); } }; /** * Select row * * @param {HTMLDomElement|jQuery} el - row element */ updraft_backups_selection.select = function(el) { $(el).addClass('backuprowselected'); $(el).find('.backup-select input').prop('checked', true); this.checkSelectionStatus(); }; /** * Deselect row * * @param {HTMLDomElement|jQuery} el - row element */ updraft_backups_selection.deselect = function(el) { $(el).removeClass('backuprowselected'); $(el).find('.backup-select input').prop('checked', false); this.checkSelectionStatus(); }; /** * Select all rows */ updraft_backups_selection.selectAll = function() { $('#updraft-navtab-backups-content .updraft_existing_backups .updraft_existing_backups_row').each(function(index, el) { updraft_backups_selection.select(el); }) }; /** * Deselect all rows */ updraft_backups_selection.deselectAll = function() { $('#updraft-navtab-backups-content .updraft_existing_backups .updraft_existing_backups_row').each(function(index, el) { updraft_backups_selection.deselect(el); }) }; /** * Actions after a row selection/deselection */ updraft_backups_selection.checkSelectionStatus = function() { var num_rows = $('#updraft-navtab-backups-content .updraft_existing_backups .updraft_existing_backups_row').length; var num_selected = $('#updraft-navtab-backups-content .updraft_existing_backups .updraft_existing_backups_row.backuprowselected').length; // toggles actions upon seleted items if (num_selected > 0) { $('#ud_massactions').addClass('active'); $('.js--deselect-all-backups, .js--delete-selected-backups').prop('disabled', false); } else { $('#ud_massactions').removeClass('active'); $('.js--deselect-all-backups, .js--delete-selected-backups').prop('disabled', true); } // if all rows are selected, check the headind's checkbox if (num_rows === num_selected) { $('#cb-select-all').prop('checked', true); } else { $('#cb-select-all').prop('checked', false); } // if no backups, hide massaction if (!num_rows) { $('#ud_massactions').hide(); } else { $('#ud_massactions').show(); } } })(jQuery); // @codingStandardsIgnoreEnd /** * Setup migration sections */ function setup_migrate_tabs() { // sets up the section buttons jQuery('#updraft_migrate .updraft_migrate_widget_module_content').each(function(ind, el) { var title = jQuery(el).find('h3').first().html(); var intro_container = jQuery('.updraft_migrate_intro'); var button = jQuery('').html(title).appendTo(intro_container); button.on('click', function(e) { e.preventDefault(); jQuery(el).show(); intro_container.hide(); }); }); } /** * Run a backup with show modal with progress. * * @param {Function} success_callback callback function after backup * @param {String} onlythisfileentity csv list of file entities to be backed up * @param {Array} extradata any extra data to be added * @param {Integer} backupnow_nodb Indicate whether the database should be backed up. Valid values: 0, 1 * @param {Integer} backupnow_nofiles Indicate whether any files should be backed up. Valid values: 0, 1 * @param {Integer} backupnow_nocloud Indicate whether the backup should be uploaded to cloud storage. Valid values: 0, 1 * @param {String} label An optional label to be added to a backup */ function updraft_backupnow_inpage_go(success_callback, onlythisfileentity, extradata, backupnow_nodb, backupnow_nofiles, backupnow_nocloud, label) { backupnow_nodb = ('undefined' === typeof backupnow_nodb) ? 0 : backupnow_nodb; backupnow_nofiles = ('undefined' === typeof backupnow_nofiles) ? 0 : backupnow_nofiles; backupnow_nocloud = ('undefined' === typeof backupnow_nocloud) ? 0 : backupnow_nocloud; label = ('undefined' === typeof label) ? updraftlion.automaticbackupbeforeupdate : label; // N.B. This function should never be called on the UpdraftPlus settings page - it is assumed we are elsewhere. So, it is safe to fake the console-focussing parameter. updraft_console_focussed_tab = 'backups'; updraft_inpage_success_callback = success_callback; updraft_activejobs_update_timer = setInterval(function () { updraft_activejobs_update(false); }, 1250); var updraft_inpage_modal_buttons = {}; var inpage_modal_exists = jQuery('#updraft-backupnow-inpage-modal').length; if (inpage_modal_exists) { jQuery('#updraft-backupnow-inpage-modal').dialog('option', 'buttons', updraft_inpage_modal_buttons); } jQuery('#updraft_inpage_prebackup').hide(); if (inpage_modal_exists) { jQuery('#updraft-backupnow-inpage-modal').dialog('open'); } jQuery('#updraft_inpage_backup').show(); updraft_activejobslist_backupnownonce_only = 1; updraft_inpage_hasbegun = 0; updraft_backupnow_go(backupnow_nodb, backupnow_nofiles, backupnow_nocloud, onlythisfileentity, extradata, label, ''); } var updraftplus_activejobs_list_fatal_error_alert = true; function updraft_activejobs_update(force) { var $ = jQuery; var timenow = (new Date).getTime(); if (false == force && timenow < updraft_activejobs_nextupdate) { return; } updraft_activejobs_nextupdate = timenow + 5500; var downloaders = ''; $('.ud_downloadstatus .updraftplus_downloader, #ud_downloadstatus2 .updraftplus_downloader').each(function(x,y) { var dat = $(y).data('downloaderfor'); if (typeof dat == 'object') { if (downloaders != '') { downloaders = downloaders + ':'; } downloaders = downloaders + dat.base + ',' + dat.nonce + ',' + dat.what + ',' + dat.index; } }); var gdata = { downloaders: downloaders } try { if ($("#updraft-poplog").dialog("isOpen")) { gdata.log_fetch = 1; gdata.log_nonce = updraft_poplog_log_nonce; gdata.log_pointer = updraft_poplog_log_pointer } } catch (err) { console.log(err); } if (updraft_activejobslist_backupnownonce_only && typeof updraft_backupnow_nonce !== 'undefined' && updraft_backupnow_nonce != '') { gdata.thisjobonly = updraft_backupnow_nonce; } updraft_send_command('activejobs_list', gdata, function(resp, status, response) { try { // if (repeat) { setTimeout(function(){updraft_activejobs_update(true);}, nexttimer);} if (resp.hasOwnProperty('l')) { if (resp.l) { $('#updraft_lastlogmessagerow').show(); $('#updraft_lastlogcontainer').html(resp.l); } else { $('#updraft_lastlogmessagerow').hide(); $('#updraft_lastlogcontainer').html('('+updraftlion.nothing_yet_logged+')'); } } var lastactivity = -1; // Requested start of backup text var requeststart_el = $('.updraft_requeststart'); if (resp.j && requeststart_el.length && requeststart_el.data('remove')) { requeststart_el.remove(); } // Parse response to add classes before inserting it, to avoid unwanted artifacts var $list_prepare = $(resp.j); $list_prepare.find('.updraft_jobtimings').each(function(ind, element) { var $el = $(element); if ($el.data('jobid')) { var jobid = $el.data('jobid'); var job_row = $el.closest('.updraft_row'); if (updraft_aborted_jobs[jobid]) { job_row.hide(); } } }); $('#updraft_activejobsrow').html($list_prepare); var $clone_jobs = $list_prepare.find('.job-id[data-isclone="1"]'); if ($clone_jobs.length > 0) { if ($('.updraftclone_action_box .updraftclone_network_info').length == 0 && $('#updraft_activejobsrow .job-id .updraft_clone_url').length > 0) { var clone_url = $('#updraft_activejobsrow .job-id .updraft_clone_url').data('clone_url'); updraft_send_command('get_clone_network_info', { clone_url: clone_url }, function(response) { if (response.hasOwnProperty('html')) { $('.updraftclone_action_box').html(response.html); } }); } $('#updraft_clone_activejobsrow').empty(); $clone_jobs.each(function(ind, element) { var $el = $(element); $el.closest('.updraft_row') // .clone() // Clone allows to have the job on both tabs .appendTo($('#updraft_clone_activejobsrow')); }); } $('#updraft_activejobs .updraft_jobtimings').each(function(ind, element) { var $el = $(element); // lastactivity, nextresumption, nextresumptionafter if ($el.data('lastactivity') && $el.data('jobid')) { var jobid = $el.data('jobid'); var new_lastactivity = $el.data('lastactivity'); if (lastactivity == -1 || new_lastactivity < lastactivity) { lastactivity = new_lastactivity; } var nextresumptionafter = $el.data('nextresumptionafter'); var nextresumption = $el.data('nextresumption'); // console.log("Job ID: "+jobid+", Next resumption: "+nextresumption+", Next resumption after: "+nextresumptionafter+", Last activity: "+new_lastactivity); // Milliseconds timenow = (new Date).getTime(); if (new_lastactivity > 50 && nextresumption >0 && nextresumptionafter < -30 && timenow > updraft_last_forced_when+100000 && (updraft_last_forced_jobid != jobid || nextresumption != updraft_last_forced_resumption)) { updraft_last_forced_resumption = nextresumption; updraft_last_forced_jobid = jobid; updraft_last_forced_when = timenow; console.log('UpdraftPlus: force resumption: job_id='+jobid+', resumption='+nextresumption); updraft_send_command('forcescheduledresumption', { resumption: nextresumption, job_id: jobid }, function(response) { console.log(response); }, { json_parse: false, alert_on_error: false }); } } }); timenow = (new Date).getTime(); updraft_activejobs_nextupdate = timenow + 180000; // More rapid updates needed if a) we are on the main console, or b) a downloader is open (which can only happen on the restore console) if ((updraft_page_is_visible == 1 && 'backups' == updraft_console_focussed_tab)) { if (lastactivity > -1) { if (lastactivity < 5) { updraft_activejobs_nextupdate = timenow + 1750; } else { updraft_activejobs_nextupdate = timenow + 5000; } } else if (lastlog_lastdata == response) { updraft_activejobs_nextupdate = timenow + 7500; } else { updraft_activejobs_nextupdate = timenow + 1750; } } if ($clone_jobs.length > 0) updraft_activejobs_nextupdate = timenow + 6000; lastlog_lastdata = response; if (resp.j != null && resp.j != '') { $('#updraft_activejobsrow').show(); if ($clone_jobs.length > 0) $('#updraft_clone_activejobsrow').show(); if (gdata.hasOwnProperty('thisjobonly') && !updraft_inpage_hasbegun && $('#updraft-jobid-'+gdata.thisjobonly).length) { updraft_inpage_hasbegun = 1; console.log('UpdraftPlus: the start of the requested backup job has been detected'); } else if (!updraft_inpage_hasbegun && updraft_activejobslist_backupnownonce_only && $('.updraft_jobtimings.isautobackup').length) { autobackup_nonce = $('.updraft_jobtimings.isautobackup').first().data('jobid'); if (autobackup_nonce) { updraft_inpage_hasbegun = 1; updraft_backupnow_nonce = autobackup_nonce; gdata.thisjobonly = autobackup_nonce; console.log('UpdraftPlus: the start of the requested backup job has been detected; id: '+autobackup_nonce); } } else if (updraft_inpage_hasbegun == 1 && $('#updraft-jobid-'+gdata.thisjobonly+'.updraft_finished').length) { // This block used to be a straightforward 'if'... switching to 'else if' ensures that it cannot fire on the same run. (If the backup hasn't started, it may be detected as finished before to it began, on an overloaded server if there's a race). // Don't reset to 0 - this will cause the 'began' event to be detected again updraft_inpage_hasbegun = 2; // var updraft_inpage_modal_buttons = {}; // updraft_inpage_modal_buttons[updraftlion.close] = function() { // $(this).dialog("close"); // }; // $('#updraft-backupnow-inpage-modal').dialog('option', 'buttons', updraft_inpage_modal_buttons); console.log('UpdraftPlus: the end of the requested backup job has been detected'); if (updraft_activejobs_update_timer) clearInterval(updraft_activejobs_update_timer); if (typeof updraft_inpage_success_callback !== 'undefined' && updraft_inpage_success_callback != '') { // Move on to next page updraft_inpage_success_callback.call(false); } else { $('#updraft-backupnow-inpage-modal').dialog('close'); } } if ('' == lastlog_jobs) { setTimeout(function() { $('#updraft_backup_started').slideUp();}, 3500); } // detect manual backup if (gdata.hasOwnProperty('thisjobonly') && updraft_backupnow_nonce && gdata.thisjobonly === updraft_backupnow_nonce) { $('.updraft_requeststart').remove(); var thisjob = $('#updraft-jobid-'+updraft_backupnow_nonce); // detect manual backup end if (thisjob.is('.updraft_finished')) { // reset current job vars updraft_activejobslist_backupnownonce_only = 0; // Aborted jobs if (updraft_aborted_jobs[updraft_backupnow_nonce]) { // remove deleted job from deleted jobs list updraft_aborted_jobs = updraft_aborted_jobs.filter(function(val, index) { return val != updraft_backupnow_nonce; }); } else { if (updraft_active_job_is_clone(updraft_backupnow_nonce)) { // A clone job is complete updraft_show_success_modal(updraftlion.clone_backup_complete); updraft_clone_jobs = updraft_clone_jobs.filter(function(val) { return val != updraft_backupnow_nonce; }); } else { // A normal manual backup is complete updraft_show_success_modal(updraftlion.backup_complete); } } updraft_backupnow_nonce = ''; // Force fetch active jobs updraft_activejobs_update(true); } } } else { if (!$('#updraft_activejobsrow').is(':hidden')) { // Backup has now apparently finished - hide the row. If using this for detecting a finished job, be aware that it may never have shown in the first place - so you'll need more than this. if (typeof lastbackup_laststatus != 'undefined') { updraft_showlastbackup(); } updraft_updatehistory(0, 0); $('#updraft_activejobsrow').hide(); } } lastlog_jobs = resp.j; // Download status if (resp.ds != null && resp.ds != '') { updraft_downloader_status_update(resp.ds, response); } if (resp.u != null && resp.u != '' && $("#updraft-poplog").dialog("isOpen")) { var log_append_array = resp.u; if (log_append_array.nonce == updraft_poplog_log_nonce) { updraft_poplog_log_pointer = log_append_array.pointer; if (log_append_array.log != null && log_append_array.log != '') { var oldscroll = $('#updraft-poplog').scrollTop(); $('#updraft-poplog-content').append(log_append_array.log); if (updraft_poplog_lastscroll == oldscroll || updraft_poplog_lastscroll == -1) { $('#updraft-poplog').scrollTop($('#updraft-poplog-content').prop("scrollHeight")); updraft_poplog_lastscroll = $('#updraft-poplog').scrollTop(); } } } } } catch (err) { console.log(updraftlion.unexpectedresponse+' '+response); console.log(err); } }, { type: 'GET', error_callback: function(response, status, error_code, resp) { if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); if (true === updraftplus_activejobs_list_fatal_error_alert) { updraftplus_activejobs_list_fatal_error_alert = false; alert(this.alert_done + ' ' +resp.fatal_error_message); } } else { var msg = (status == error_code) ? error_code : error_code+" ("+status+")"; console.error(msg); console.log(response); } return false; } }); } /** * Shows a modal on success * * @param {string|obj} args The message to display or an object of parameters */ function updraft_show_success_modal(args) { if ('string' == typeof args) { args = { message: args }; } var data = jQuery.extend( { icon: 'yes', close: updraftlion.close, message: '', classes: 'success' }, args ); jQuery.blockUI({ css: { width: '300px', border: 'none', 'border-radius': '10px', left: 'calc(50% - 150px)' }, message: '
'+updraftlion.rescanningremote+'
'); } else { updraft_history_lastchecksum = false; jQuery('#updraft-navtab-backups-content .updraft_existing_backups').html(''+updraftlion.rescanning+'
'); } } var what_op = remotescan ? 'remotescan' : (rescan ? 'rescan' : false); var data = { operation: what_op, debug: debug } updraft_send_command('rescan', data, function(resp) { if (resp.hasOwnProperty('logs_exist') && resp.logs_exist) { // Show the "most recently modified log" link, in case it was previously hidden (if there were no logs until now) jQuery('#updraft_lastlogmessagerow .updraft-log-link').show(); } if (resp.hasOwnProperty('migrate_tab') && resp.migrate_tab) { if (!jQuery('#updraft-navtab-migrate').hasClass('nav-tab-active')) { jQuery('#updraft_migrate_tab_alt').html(''); jQuery('#updraft_migrate').replaceWith(jQuery(resp.migrate_tab).find('#updraft_migrate')); setup_migrate_tabs(); } } if (resp.hasOwnProperty('web_server_disk_space')) { if ('' == resp.web_server_disk_space) { console.log("UpdraftPlus: web_server_disk_space is empty"); if (jQuery('#updraft-navtab-backups-content .updraft-server-disk-space').length) { jQuery('#updraft-navtab-backups-content .updraft-server-disk-space').slideUp('slow', function() { jQuery(this).remove(); }); } } else { if (jQuery('#updraft-navtab-backups-content .updraft-server-disk-space').length) { jQuery('#updraft-navtab-backups-content .updraft-server-disk-space').replaceWith(resp.web_server_disk_space); } else { jQuery('#updraft-navtab-backups-content .updraft-disk-space-actions').prepend(resp.web_server_disk_space); } } } if (resp.n != null) { jQuery('#updraft-existing-backups-heading').html(resp.n); } if (resp.t != null) { if (resp.cksum != null) { if (resp.cksum == updraft_history_lastchecksum) { // Avoid unnecessarily refreshing the HTML if the data is the same. This helps avoid resetting the DOM (annoying when debugging), and keeps user row selections. return; } updraft_history_lastchecksum = resp.cksum; } jQuery('#updraft-navtab-backups-content .updraft_existing_backups').html(resp.t); updraft_backups_selection.checkSelectionStatus(); if (resp.data) { console.log(resp.data); } } }); } /** * Exclude entities hidden input field update * * @param {string} include_entity_name - backup entity name */ function updraft_exclude_entity_update(include_entity_name) { var exclude_entities = []; jQuery('#updraft_include_'+include_entity_name+'_exclude_container .updraft_exclude_entity_wrapper .updraft_exclude_entity_field').each(function() { var data_val = jQuery.trim(jQuery(this).data('val')); if ('' != data_val) { exclude_entities.push(data_val); } }); jQuery('#updraft_include_'+include_entity_name+'_exclude').val(exclude_entities.join(',')); } /** * Check uniqueness of exclude rule in include_backup_file * * @param {string} exclude_rule - exclude rule * @param {string} include_backup_file - the backup file type on which the exclude_rule will be applied * * @return {boolean} true if exclude_rule is unique otherwise false */ function updraft_is_unique_exclude_rule(exclude_rule, include_backup_file) { existing_exclude_rules_str = jQuery('#updraft_include_'+include_backup_file+'_exclude').val(); existing_exclude_rules = existing_exclude_rules_str.split(','); if (jQuery.inArray(exclude_rule, existing_exclude_rules) > -1) { alert(updraftlion.duplicate_exclude_rule_error_msg) return false; } else { return true; } } var updraft_interval_week_val = false; var updraft_interval_month_val = false; function updraft_intervals_monthly_or_not(selector_id, now_showing) { var selector = '#updraft-navtab-settings-content #'+selector_id; var current_length = jQuery(selector+' option').length; var is_monthly = ('monthly' == now_showing) ? true : false; var existing_is_monthly = false; if (current_length > 10) { existing_is_monthly = true; } if (!is_monthly && !existing_is_monthly) { return; } if (is_monthly && existing_is_monthly) { if ('monthly' == now_showing) { // 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. jQuery('.updraft_monthly_extra_words_'+selector_id).remove(); jQuery(selector).before(''+updraftlion.day+' ').after(' '+updraftlion.inthemonth+' '); } return; } jQuery('.updraft_monthly_extra_words_'+selector_id).remove(); if (is_monthly) { // Save the old value updraft_interval_week_val = jQuery(selector+' option:selected').val(); jQuery(selector).html(updraftlion.mdayselector).before(''+updraftlion.day+' ').after(' '+updraftlion.inthemonth+' '); var select_mday = (updraft_interval_month_val === false) ? 1 : updraft_interval_month_val; // Convert from day of the month (ordinal) to option index (starts at 0) select_mday = select_mday - 1; jQuery(selector+" option:eq("+select_mday+")").prop('selected', true); } else { // Save the old value updraft_interval_month_val = jQuery(selector+' option:selected').val(); jQuery(selector).html(updraftlion.dayselector); var select_day = (updraft_interval_week_val === false) ? 1 : updraft_interval_week_val; jQuery(selector+" option:eq("+select_day+")").prop('selected', true); } } function updraft_check_same_times() { var dbmanual = 0; var file_interval = jQuery('#updraft-navtab-settings-content .updraft_interval').val(); if (file_interval == 'manual') { // jQuery('#updraft_files_timings').css('opacity', '0.25'); jQuery('#updraft-navtab-settings-content .updraft_files_timings').hide(); } else { // jQuery('#updraft_files_timings').css('opacity', 1); jQuery('#updraft-navtab-settings-content .updraft_files_timings').show(); } if ('weekly' == file_interval || 'fortnightly' == file_interval || 'monthly' == file_interval) { updraft_intervals_monthly_or_not('updraft_startday_files', file_interval); jQuery('#updraft-navtab-settings-content #updraft_startday_files').show(); } else { jQuery('.updraft_monthly_extra_words_updraft_startday_files').remove(); jQuery('#updraft-navtab-settings-content #updraft_startday_files').hide(); } var db_interval = jQuery('#updraft-navtab-settings-content .updraft_interval_database').val(); if (db_interval == 'manual') { dbmanual = 1; // jQuery('#updraft_db_timings').css('opacity', '0.25'); jQuery('#updraft-navtab-settings-content .updraft_db_timings').hide(); } if ('weekly' == db_interval || 'fortnightly' == db_interval || 'monthly' == db_interval) { updraft_intervals_monthly_or_not('updraft_startday_db', db_interval); jQuery('#updraft-navtab-settings-content #updraft_startday_db').show(); } else { jQuery('.updraft_monthly_extra_words_updraft_startday_db').remove(); jQuery('#updraft-navtab-settings-content #updraft_startday_db').hide(); } if (db_interval == file_interval) { // jQuery('#updraft_db_timings').css('opacity','0.25'); jQuery('#updraft-navtab-settings-content .updraft_db_timings').hide(); // jQuery('#updraft_same_schedules_message').show(); if (0 == dbmanual) { jQuery('#updraft-navtab-settings-content .updraft_same_schedules_message').show(); } else { jQuery('#updraft-navtab-settings-content .updraft_same_schedules_message').hide(); } } else { jQuery('#updraft-navtab-settings-content .updraft_same_schedules_message').hide(); if (0 == dbmanual) { // jQuery('#updraft_db_timings').css('opacity', '1'); jQuery('#updraft-navtab-settings-content .updraft_db_timings').show(); } } } // Visit the site in the background every 3.5 minutes - ensures that backups can progress if you've got the UD settings page open if ('undefined' !== typeof updraft_siteurl) { setInterval(function() { jQuery.get(updraft_siteurl+'/wp-cron.php');}, 210000); } function updraft_activejobs_delete(jobid) { updraft_aborted_jobs[jobid] = 1; jQuery('#updraft-jobid-'+jobid).closest('.updraft_row').addClass('deleting'); updraft_send_command('activejobs_delete', jobid, function(resp) { var job_row = jQuery('#updraft-jobid-'+jobid).closest('.updraft_row'); job_row.addClass('deleting'); if (resp.ok == 'Y') { jQuery('#updraft-jobid-'+jobid).html(resp.m); job_row.remove(); // inpage backup - Close modal if canceling backup if (jQuery('#updraft-backupnow-inpage-modal').dialog('isOpen')) jQuery('#updraft-backupnow-inpage-modal').dialog('close'); updraft_show_success_modal({ message: updraft_active_job_is_clone(jobid) ? updraftlion.clone_backup_aborted : updraftlion.backup_aborted, icon: 'no-alt', classes: 'warning' }); } else if ('N' == resp.ok) { job_row.removeClass('deleting'); alert(resp.m); } else { job_row.removeClass('deleting'); alert(updraftlion.unexpectedresponse); console.log(resp); } }); } function updraftplus_diskspace_entity(key) { jQuery('#updraft_diskspaceused_'+key).html(''+updraftlion.calculating+''); updraft_send_command('get_fragment', { fragment: 'disk_usage', data: key }, function(response) { jQuery('#updraft_diskspaceused_'+key).html(response.output); }, { type: 'GET' }); } /** * Checks if the specified job is a clone * * @param {string} job_id The job ID * * @return {int} */ function updraft_active_job_is_clone(job_id) { return updraft_clone_jobs.filter(function(val) { return val == job_id; }).length; } /** * Open a modal with content fetched from an iframe * * @param {String} getwhat - the subaction parameter to pass to UD's AJAX handler * @param {String} title - the title for the modal */ function updraft_iframe_modal(getwhat, title) { var width = 780; var height = 500; jQuery('#updraft-iframe-modal-innards').html(''); jQuery('#updraft-iframe-modal').dialog('option', 'title', title).dialog('option', 'width', width).dialog('option', 'height', height).dialog('open'); } function updraft_html_modal(showwhat, title, width, height) { jQuery('#updraft-iframe-modal-innards').html(showwhat); var updraft_html_modal_buttons = {}; if (width < 450) { updraft_html_modal_buttons[updraftlion.close] = function() { jQuery(this).dialog("close"); }; } jQuery('#updraft-iframe-modal').dialog('option', 'title', title).dialog('option', 'width', width).dialog('option', 'height', height).dialog('option', 'buttons', updraft_html_modal_buttons).dialog('open'); } function updraftplus_diskspace() { jQuery('#updraft-navtab-backups-content .updraft_diskspaceused').html(''+updraftlion.calculating+''); updraft_send_command('get_fragment', { fragment: 'disk_usage', data: 'updraft' }, function(response) { jQuery('#updraft-navtab-backups-content .updraft_diskspaceused').html(response.output); }, { type: 'GET' }); } var lastlog_lastmessage = ""; function updraftplus_deletefromserver(timestamp, type, findex) { if (!findex) findex=0; var pdata = { stage: 'delete', timestamp: timestamp, type: type, findex: findex }; updraft_send_command('updraft_download_backup', pdata, null, { action: 'updraft_download_backup', nonce: updraft_download_nonce, nonce_key: '_wpnonce' }); } function updraftplus_downloadstage2(timestamp, type, findex) { location.href =ajaxurl+'?_wpnonce='+updraft_download_nonce+'×tamp='+timestamp+'&type='+type+'&stage=2&findex='+findex+'&action=updraft_download_backup'; } function updraftplus_show_contents(timestamp, type, findex) { var modal_content = '' + updraftlion.zip_file_contents_info + ' -
'+updraftlion.browse_download_link+''+resp.fatal_error_message+'
'); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; jQuery('#updraft_zip_files_jstree').html(''+error_message+'
'); console.log(error_message); alert(error_message); console.log(response); } } }); }, "error": function(error) { alert(error); console.log(error); }, }, "search": { "show_only_matches": true }, "plugins": ["search", "sort"], }); // Update modal title once tree loads jQuery('#updraft_zip_files_jstree').on('ready.jstree', function(e, data) { jQuery('#updraft-iframe-modal').dialog('option', 'title', updraftlion.zip_file_contents + ': ' + data.instance.get_node('#').children[0]) }); // Search function for jstree, this will hide nodes that don't match the search var timeout = false; jQuery('#zip_files_jstree_search').keyup(function () { if (timeout) { clearTimeout(timeout); } timeout = setTimeout(function () { var value = jQuery('#zip_files_jstree_search').val(); jQuery('#updraft_zip_files_jstree').jstree(true).search(value); }, 250); }); // Detect change on the tree and update the input that has been marked as editing jQuery('#updraft_zip_files_jstree').on("changed.jstree", function (e, data) { jQuery('#updraft_zip_path_text').text(data.node.li_attr.path); if (data.node.li_attr.size) { jQuery('#updraft_zip_size_text').text(data.node.li_attr.size); jQuery('#updraft_zip_download_item').show(); } else { jQuery('#updraft_zip_size_text').text(''); jQuery('#updraft_zip_download_item').hide(); } }); jQuery('#updraft_zip_download_item').click(function(event) { event.preventDefault(); var path = jQuery('#updraft_zip_path_text').text(); updraft_send_command('get_zipfile_download', {path:path, timestamp:timestamp, type:type, findex:findex}, function(response) { if (response.hasOwnProperty('error')) { alert(response.error); } else if (response.hasOwnProperty('path')) { location.href =ajaxurl+'?_wpnonce='+updraft_download_nonce+'×tamp='+timestamp+'&type='+type+'&stage=2&findex='+findex+'&filepath='+response.path+'&action=updraft_download_backup'; } else { alert(updraftlion.download_timeout); } }, { error_callback: function(response, status, error_code, resp) { if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; console.log(error_message); alert(error_message); console.log(response); } } }); }); } /** * This function will clean up the updraft downloader UI * * @param {object} item - the object pressed in the UI * @param {string} what - the file entity */ function remove_updraft_downloader(item, what) { jQuery(item).parent().fadeOut().remove(); if (0 == jQuery('.updraftplus_downloader_container_'+what+' .updraftplus_downloader').length) jQuery('.updraftplus_downloader_container_'+what).remove(); } /** * This function will prepare the downloader UI and kick of the request to download the file entities. * * @param {string} base - the base string for the id * @param {integer} backup_timestamp - the backup timestamp * @param {string} what - the file entity * @param {string} whicharea - the area we want to append the downloader * @param {string} set_contents - the contents we want to download * @param {string} prettydate - the pretty backup date * @param {boolean} async - boolean to indicate if this is a async request or not */ function updraft_downloader(base, backup_timestamp, what, whicharea, set_contents, prettydate, async) { if (typeof set_contents !== "string") set_contents = set_contents.toString(); jQuery('.ud_downloadstatus').show(); var set_contents = set_contents.split(','); var prdate = (prettydate) ? prettydate : backup_timestamp; // Old-style, from when it was a form // var data = jQuery('#updraft-navtab-backups-content .uddownloadform_'+what+'_'+backup_timestamp+'_'+set_contents[i]).serialize(); var nonce = jQuery('#updraft-navtab-backups-content .uddownloadform_'+what+'_'+backup_timestamp+'_'+set_contents[0]).data('wp_nonce').toString(); jQuery(whicharea).append(''); jQuery('.updraftplus_downloader_container_'+what).append(''+updraftlion.download+' '+what+' ('+prdate+'):'); for (var i = 0; i < set_contents.length; i++) { // Create somewhere for the status to be found var stid = base+backup_timestamp+'_'+what+'_'+set_contents[i]; var stid_selector = '.'+stid; var show_index = parseInt(set_contents[i]); show_index++; var itext = (0 == set_contents[i]) ? '' : ' ('+show_index+')'; if (!jQuery(stid_selector).length) { jQuery('.updraftplus_downloader_container_'+what).append('" + updraftlion.warnings +'
' + resp.w + "
" + updraftlion.errors+'
' + resp.e + "
'+resp.fatal_error_message+'
'); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; jQuery('#updraft-restore-modal-stage2a').html(''+error_message+'
'); console.log(error_message); alert(error_message); console.log(response); } } }); } function updraft_downloader_status(base, nonce, what, findex) { // Short-circuit. See previous versions for the old code. return; } function updraft_downloader_status_update(download_status, response) { var cancel_repeat = 0; jQuery(download_status).each(function (x, dstatus) { if (dstatus.base == '') return; var stid = dstatus.base + dstatus.timestamp + '_' + dstatus.what + '_' + dstatus.findex; var stid_selector = '.' + stid; if (dstatus.e != null) { jQuery(stid_selector + ' .raw').html('' + updraftlion.error + ' ' + dstatus.e); console.log(dstatus); } else if (dstatus.p != null) { jQuery(stid_selector + '_st .dlfileprogress').width(dstatus.p + '%'); // jQuery(stid_selector+'_st .dlsofar').html(Math.round(dstatus.s/1024)); // jQuery(stid_selector+'_st .dlsize').html(Math.round(dstatus.t/1024)); // Is a restart appropriate? // dstatus.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... if (dstatus.a != null && dstatus.a > 0) { var timenow = (new Date).getTime(); var lasttimebegan = jQuery(stid_selector).data('lasttimebegan'); // Remember that this is in milliseconds var sincelastrestart = timenow - lasttimebegan; if (dstatus.a > 90 && sincelastrestart > 60000) { console.log(dstatus.timestamp + " " + dstatus.what + " " + dstatus.findex + ": restarting download: file_age=" + dstatus.a + ", sincelastrestart_ms=" + sincelastrestart); jQuery(stid_selector).data('lasttimebegan', (new Date).getTime()); var $original_button = jQuery('#updraft-navtab-backups-content .uddownloadform_' + dstatus.what + '_' + dstatus.timestamp + '_' + dstatus.findex); var data = { type: dstatus.what, timestamp: dstatus.timestamp, findex: dstatus.findex }; var options = { action: 'updraft_download_backup', nonce_key: '_wpnonce', nonce: $original_button.data('wp_nonce').toString(), timeout: 10000 }; updraft_send_command('updraft_download_backup', data, function (response) {}, options); jQuery(stid_selector).data('lasttimebegan', (new Date).getTime()); } } if (dstatus.m != null) { if (dstatus.p >= 100 && 'udrestoredlstatus_' == dstatus.base) { jQuery(stid_selector + ' .raw').html(dstatus.m); jQuery(stid_selector).fadeOut('slow', function () { remove_updraft_downloader(this, dstatus.what); updraft_restorer_checkstage2(0); }); } else if (dstatus.p < 100 || dstatus.base != 'uddlstatus_') { jQuery(stid_selector + ' .raw').html(dstatus.m); } else { var file_ready_actions = updraftlion.fileready + ' ' + updraftlion.actions + ': \ \ '; if (dstatus.hasOwnProperty('can_show_contents') && dstatus.can_show_contents) { file_ready_actions += ' '; } jQuery(stid_selector + ' .raw').html(file_ready_actions); jQuery(stid_selector + '_st').remove(); } } // dlstatus_lastlog = response; } else if (dstatus.m != null) { jQuery(stid_selector + ' .raw').html(dstatus.m); } else { jQuery(stid_selector + ' .raw').html(updraftlion.jsonnotunderstood + ' (' + response + ')'); cancel_repeat = 1; } }); return cancel_repeat; } /** * Function that sets up a ajax call to start a backup * * @param {Integer} backupnow_nodb Indicate whether the database should be backed up: valid values are 0, 1 * @param {Integer} backupnow_nofiles Indicate whether any files should be backed up: valid values are 0, 1 * @param {Integer} backupnow_nocloud Indicate whether the backup should be uploaded to cloud storage: valid values are 0, 1 * @param {String} onlythesefileentities A csv list of file entities to be backed up * @param {String} onlythesetableentities A csv list of table entities to be backed up * @param {Array} extradata any extra data to be added * @param {String} label A optional label to be added to a backup */ function updraft_backupnow_go(backupnow_nodb, backupnow_nofiles, backupnow_nocloud, onlythesefileentities, extradata, label, onlythesetableentities) { var params = { backupnow_nodb: backupnow_nodb, backupnow_nofiles: backupnow_nofiles, backupnow_nocloud: backupnow_nocloud, backupnow_label: label, extradata: extradata }; if ('' != onlythesefileentities) { params.onlythisfileentity = onlythesefileentities; } if ('' != onlythesetableentities) { params.onlythesetableentities = onlythesetableentities; } params.always_keep = (typeof extradata.always_keep !== 'undefined') ? extradata.always_keep : 0; delete extradata.always_keep; // Display Request start message if (!jQuery('.updraft_requeststart').length) { var requeststart_el = jQuery('').html(''+updraftlion.requeststart); requeststart_el.data('remove', false); setTimeout( function() { requeststart_el.data('remove', true); }, 3000 ); setTimeout( function() { requeststart_el.remove(); }, 75000 ); jQuery('#updraft_activejobsrow').before(requeststart_el); } updraft_activejobslist_backupnownonce_only = 1; updraft_send_command('backupnow', params, function(resp) { jQuery('#updraft_backup_started').html(resp.m); if (resp.hasOwnProperty('nonce')) { // Can't return it from this context updraft_backupnow_nonce = resp.nonce; console.log("UpdraftPlus: ID of started job: "+updraft_backupnow_nonce); } setTimeout(function() { updraft_activejobs_update(true);}, 500); }); } jQuery(document).ready(function($) { // Advanced settings new menu button listeners $('.expertmode .advanced_settings_container .advanced_tools_button').click(function() { advanced_tool_hide($(this).attr("id")); }); function advanced_tool_hide(show_tool) { $('.expertmode .advanced_settings_container .advanced_tools:not(".'+show_tool+'")').hide(); $('.expertmode .advanced_settings_container .advanced_tools.'+show_tool).fadeIn('slow'); $('.expertmode .advanced_settings_container .advanced_tools_button:not(#'+show_tool+')').removeClass('active'); $('.expertmode .advanced_settings_container .advanced_tools_button#'+show_tool).addClass('active'); } // https://github.com/select2/select2/issues/1246#issuecomment-71710835 if (jQuery.ui && jQuery.ui.dialog && jQuery.ui.dialog.prototype._allowInteraction) { var ui_dialog_interaction = jQuery.ui.dialog.prototype._allowInteraction; jQuery.ui.dialog.prototype._allowInteraction = function(e) { if (jQuery(e.target).closest('.select2-dropdown').length) return true; return ui_dialog_interaction.apply(this, arguments); }; } $('#updraftcentral_keys').on('click', 'a.updraftcentral_keys_show', function(e) { e.preventDefault(); $(this).remove(); $('#updraftcentral_keys_table').slideDown(); }); $('#updraftcentral_keycreate_altmethod_moreinfo_get').click(function(e) { e.preventDefault(); $(this).remove(); $('#updraftcentral_keycreate_altmethod_moreinfo').slideDown(); }); // Update WebDAV URL as user edits $('#updraft-navtab-settings-content #remote-storage-holder').on('change keyup paste', '.updraft_webdav_settings', function() { var updraft_webdav_settings = []; $('.updraft_webdav_settings').each(function(index, item) { var id = $(item).attr('id'); if (id && 'updraft_webdav_' == id.substring(0, 15)) { var which_one = id.substring(15); id_split = which_one.split('_'); which_one = id_split[0]; var instance_id = id_split[1]; if ('undefined' == typeof updraft_webdav_settings[instance_id]) updraft_webdav_settings[instance_id] = []; updraft_webdav_settings[instance_id][which_one] = this.value; } }); var updraft_webdav_url = ""; var host = "@"; var slash = "/"; var colon = ":"; var colon_port = ":"; for (var instance_id in updraft_webdav_settings) { if (updraft_webdav_settings[instance_id]['host'].indexOf("@") >= 0 || "" === updraft_webdav_settings[instance_id]['host']) { host = ""; } if (updraft_webdav_settings[instance_id]['host'].indexOf("/") >= 0) { $('#updraft_webdav_host_error').show(); } else { $('#updraft_webdav_host_error').hide(); } if (0 == updraft_webdav_settings[instance_id]['path'].indexOf("/") || "" === updraft_webdav_settings[instance_id]['path']) { slash = ""; } if ("" === updraft_webdav_settings[instance_id]['user'] || "" === updraft_webdav_settings[instance_id]['pass']) { colon = ""; } if ("" === updraft_webdav_settings[instance_id]['host'] || "" === updraft_webdav_settings[instance_id]['port']) { colon_port = ""; } 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']; $('#updraft_webdav_url_' + instance_id).val(updraft_webdav_url); } }); // Delete button $('#updraft-navtab-backups-content').on('click', '.js--delete-selected-backups', function(e) { e.preventDefault(); updraft_deleteallselected(); }); $('#updraft-navtab-backups-content').on('click', '.updraft_existing_backups .backup-select input', function(e) { // e.preventDefault(); updraft_backups_selection.toggle($(this).closest('.updraft_existing_backups_row')); }); $('#updraft-navtab-backups-content').on('click', '#cb-select-all', function(e) { if ($(this).is(':checked')) { updraft_backups_selection.selectAll(); } else { updraft_backups_selection.deselectAll(); } }); $('#updraft-navtab-backups-content').on('click', '.js--select-all-backups', function(e) { updraft_backups_selection.selectAll(); }); $('#updraft-navtab-backups-content').on('click', '.js--deselect-all-backups', function(e) { updraft_backups_selection.deselectAll(); }); $('#updraft-navtab-backups-content').on('click', '.updraft_existing_backups .updraft_existing_backups_row', function(e) { if (!e.ctrlKey && !e.metaKey) return; updraft_backups_selection.toggle(this); }); updraft_backups_selection.checkSelectionStatus(); $('#updraft-navtab-addons-content .wrap').on('click', '.updraftplus_com_login .ud_connectsubmit', function (e) { e.preventDefault(); var email = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_email').val(); var password = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_password').val(); var auto_update = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_auto_updates').is(':checked') ? 1: 0; var options = { email: email, password: password, auto_update: auto_update }; updraftplus_com_login_submit(options); }); $('#updraft-navtab-addons-content .wrap').on('keydown', '.updraftplus_com_login input', function (e) { if (13 == e.which) { e.preventDefault(); var email = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_email').val(); var password = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_password').val(); var auto_update = $('#updraft-navtab-addons-content .wrap .updraftplus_com_login #updraftplus-addons_options_auto_updates').is(':checked') ? 1: 0; var options = { email: email, password: password, auto_update: auto_update }; updraftplus_com_login_submit(options); } }); $('#updraft-navtab-migrate-content').on('click', '.updraftclone_show_step_1', function (e) { $('.updraftplus-clone').addClass('opened'); $('.updraftclone_show_step_1').hide(); $('.updraft_migrate_widget_temporary_clone_stage1').show(); $('.updraft_migrate_widget_temporary_clone_stage0').hide(); }); $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_widget_temporary_clone_show_stage0', function(e) { e.preventDefault(); $('.updraft_migrate_widget_temporary_clone_stage0').toggle(); }); // First tab setup setup_migrate_tabs(); // hide section when clicking the close button $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_widget_module_content .close', function (e) { $('.updraft_migrate_intro').show(); $(this).closest('.updraft_migrate_widget_module_content').hide(); }); // Migrate show Add site button $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_add_site--trigger', function (e) { e.preventDefault(); $('.updraft_migrate_add_site').toggle(); }); $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_widget_module_content .updraftplus_com_login .ud_connectsubmit', function (e) { e.preventDefault(); var email = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_email').val(); var password = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_password').val(); var tfa = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_two_factor_code').val(); var consent = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login .temporary_clone_terms_and_conditions').is(':checked') ? 1 : 0; var options = { form_data: { email: email, password: password, two_factor_code: tfa, consent: consent } }; if (!email || !password) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login_status').html('' + updraftlion.error + ' ' + updraftlion.username_password_required).show(); } else { temporary_clone_submit(options); } }); $('#updraft-navtab-migrate-content').on('keydown', '.updraft_migrate_widget_module_content .updraftplus_com_login input', function (e) { if (13 == e.which) { e.preventDefault(); var email = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_email').val(); var password = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_password').val(); var tfa = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_two_factor_code').val(); var consent = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login .temporary_clone_terms_and_conditions').is(':checked') ? 1 : 0; var options = { form_data: { email: email, password: password, two_factor_code: tfa, consent: consent } }; if (!email || !password) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login_status').html('' + updraftlion.error + ' ' + updraftlion.username_password_required).show(); } else { temporary_clone_submit(options); } } }); $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_widget_module_content .updraftplus_com_key .ud_key_connectsubmit', function (e) { e.preventDefault(); var clone_key = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key #temporary_clone_options_key').val(); var consent = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key .temporary_clone_terms_and_conditions').is(':checked') ? 1 : 0; var options = { form_data: { clone_key: clone_key, consent: consent } }; if (!clone_key) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key_status').html('' + updraftlion.error + ' ' + updraftlion.clone_key_required).show(); } else { temporary_clone_key_submit(options); } }); $('#updraft-navtab-migrate-content').on('keydown', '.updraft_migrate_widget_module_content .updraftplus_com_key input', function (e) { if (13 == e.which) { e.preventDefault(); var clone_key = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key #temporary_clone_options_key').val(); var consent = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key .temporary_clone_terms_and_conditions').is(':checked') ? 1 : 0; var options = { form_data: { clone_key: clone_key, consent: consent } }; if (!clone_key) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key_status').html('' + updraftlion.error + ' ' + updraftlion.clone_key_required).show(); } else { temporary_clone_key_submit(options); } } }); $('#updraft-navtab-migrate-content').on('change', '.updraft_migrate_widget_module_content #updraftplus_clone_php_options', function () { var php_version = $(this).data('php_version'); var selected_version = $(this).val(); if (selected_version < php_version) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(updraftlion.clone_version_warning); } else { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(''); } }); $('#updraft-navtab-migrate-content').on('change', '.updraft_migrate_widget_module_content #updraftplus_clone_wp_options', function () { var wp_version = $(this).data('wp_version'); var selected_version = $(this).val(); if (selected_version < wp_version) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(updraftlion.clone_version_warning); } else { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(''); } }); $('#updraft-navtab-migrate-content').on('click', '.updraft_migrate_widget_module_content #updraft_migrate_createclone', function (e) { e.preventDefault(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content #updraft_migrate_createclone').prop('disabled', true); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(''); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_spinner.spinner').addClass('visible'); var clone_id = $(this).data('clone_id'); var secret_token = $(this).data('secret_token'); var php_version = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content #updraftplus_clone_php_options').val(); var wp_version = $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content #updraftplus_clone_wp_options').val(); var admin_only = $('.updraftplus_clone_admin_login_options').is(':checked'); var options = { form_data: { clone_id: clone_id, secret_token: secret_token, install_info: { php_version: php_version, wp_version: wp_version, admin_only: admin_only, } } }; updraft_send_command('process_updraftplus_clone_create', options, function (response) { try { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content #updraft_migrate_createclone').prop('disabled', false); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_spinner.spinner').removeClass('visible'); if (response.hasOwnProperty('status') && 'error' == response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_clone_status').html(updraftlion.error + ' ' + response.message).show(); return; } if ('success' === response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage2').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage3').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage3').html(response.html); jQuery('#updraft_clone_progress .updraftplus_spinner.spinner').addClass('visible'); temporary_clone_boot_backup(clone_id, secret_token, response.url, response.key); } } catch (err) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content #updraft_migrate_createclone').prop('disabled', false); console.log("Error when processing the response of process_updraftplus_clone_create (as follows)"); console.log(err); } }); }); /** * This function will send an AJAX request to the backend to check the users credentials, then it will either inform the user of any errors or if there are none it will submit the form. * * @param {array} options - an array that includes the users email and password */ function updraftplus_com_login_submit(options) { $('#updraft-navtab-addons-content .wrap .updraftplus_com_login_status').html('').hide(); updraft_send_command('updraftplus_com_login_submit', { data: options, }, function (response) { if (response.hasOwnProperty('success')) { $('#updraft-navtab-addons-content .wrap .updraftplus_com_login').submit(); } else if (response.hasOwnProperty('error')) { $('#updraft-navtab-addons-content .wrap .updraftplus_com_login_status').html(response.message).show(); } }); } /** * This function will send an AJAX request to the backend to check the users credentials, then it will either inform the user of any errors or display UI elements that include their token count and a way to create new clones. * * @param {array} options - an array that includes the users email and password */ function temporary_clone_submit(options) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login_status').html('').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login .updraftplus_spinner.spinner').addClass('visible'); updraft_send_command('process_updraftplus_clone_login', options, function (response) { try { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login .updraftplus_spinner.spinner').removeClass('visible'); if (response.hasOwnProperty('status') && 'error' == response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login_status').html(response.message).show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .tfa_fields').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .non_tfa_fields').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_login #temporary_clone_options_two_factor_code').val(''); return; } if (response.hasOwnProperty('tfa_enabled') && true == response.tfa_enabled) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .non_tfa_fields').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .tfa_fields').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 input#temporary_clone_options_two_factor_code').focus(); } if ('authenticated' === response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .non_tfa_fields').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 .tfa_fields').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1 input#temporary_clone_options_two_factor_code').val(''); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage2').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage2').html(response.html); } } catch (err) { console.log(err); } }); } /** * This function will send an AJAX request to the backend to check the clone key, then it will either inform the user of any errors or display UI elements that include their token count and a way to create new clones. * * @param {array} options - an array that includes the clone key */ function temporary_clone_key_submit(options) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key_status').html('').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key .updraftplus_spinner.spinner').addClass('visible'); updraft_send_command('process_updraftplus_clone_login', options, function (response) { try { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key .updraftplus_spinner.spinner').removeClass('visible'); if (response.hasOwnProperty('status') && 'error' == response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraftplus_com_key_status').html(response.message).show(); return; } if ('authenticated' === response.status) { $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage1').hide(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage2').show(); $('#updraft-navtab-migrate-content .updraft_migrate_widget_module_content .updraft_migrate_widget_temporary_clone_stage2').html(response.html); } } catch (err) { console.log(err); } }); } /** * This function will send an AJAX request to the backend to start a clone backup job * * @param {string} clone_id - the clone id * @param {string} secret_token - the clone secret * @param {string} clone_url - the clone url * @param {string} key - the migration key */ function temporary_clone_boot_backup(clone_id, secret_token, clone_url, key) { var params = { updraftplus_clone_backup: 1, backupnow_nodb: 0, backupnow_nofiles: 0, backupnow_nocloud: 0, backupnow_label: 'UpdraftPlus Clone', extradata: '', onlythisfileentity: 'plugins,themes,uploads,others', clone_id: clone_id, secret_token: secret_token, clone_url: clone_url, key: key }; updraft_activejobslist_backupnownonce_only = 1; updraft_send_command('backupnow', params, function (response) { jQuery('#updraft_clone_progress .updraftplus_spinner.spinner').removeClass('visible'); jQuery('#updraft_backup_started').html(response.m); if (response.hasOwnProperty('nonce')) { // Can't return it from this context updraft_backupnow_nonce = response.nonce; updraft_clone_jobs.push(updraft_backupnow_nonce); updraft_inpage_success_callback = function () { jQuery('#updraft_clone_activejobsrow').hide(); // If user aborts the job if (updraft_aborted_jobs[updraft_backupnow_nonce]) { jQuery('#updraft_clone_progress').html(updraftlion.clone_backup_aborted); } else { jQuery('#updraft_clone_progress').html(updraftlion.clone_backup_complete); } }; console.log("UpdraftPlus: ID of started job: " + updraft_backupnow_nonce); } updraft_activejobs_update(true); }); } $('#updraft-navtab-settings-content #remote-storage-holder').on('click', '.updraftplusmethod a.updraft_add_instance', function(e) { e.preventDefault(); updraft_settings_form_changed = true; var method = $(this).data('method'); add_new_instance(method); }); $('#updraft-navtab-settings-content #remote-storage-holder').on('click', '.updraftplusmethod a.updraft_delete_instance', function(e) { e.preventDefault(); updraft_settings_form_changed = true; var method = $(this).data('method'); var instance_id = $(this).data('instance_id'); if (1 === $('.' + method + '_updraft_remote_storage_border').length) { add_new_instance(method); } $('.' + method + '-' + instance_id).hide('slow', function() { $(this).remove(); }); }); $('#updraft-navtab-settings-content #remote-storage-holder').on('click', '.updraftplusmethod .updraft_edit_label_instance', function(e) { $(this).find('span').hide(); $(this).attr('contentEditable', true).focus(); }); $('#updraft-navtab-settings-content #remote-storage-holder').on('keyup', '.updraftplusmethod .updraft_edit_label_instance', function(e) { var method = jQuery(this).data('method'); var instance_id = jQuery(this).data('instance_id'); var content = jQuery(this).text(); $('#updraft_' + method + '_instance_label_' + instance_id).val(content); }); $('#updraft-navtab-settings-content #remote-storage-holder').on('blur', '.updraftplusmethod .updraft_edit_label_instance', function(e) { $(this).attr('contentEditable', false); $(this).find('span').show(); }); $('#updraft-navtab-settings-content #remote-storage-holder').on('keypress', '.updraftplusmethod .updraft_edit_label_instance', function(e) { if (13 === e.which) { $(this).attr('contentEditable', false); $(this).find('span').show(); $(this).blur(); } }); /** * This method will get the default options and compile a template with them * * @param {string} method - the remote storage name * @param {boolean} first_instance - indicates if this is the first instance of this type */ function add_new_instance(method) { var template = Handlebars.compile(updraftlion.remote_storage_templates[method]); var context = updraftlion.remote_storage_options[method]['default']; context['instance_id'] = 's-' + generate_instance_id(32); context['instance_enabled'] = 1; var html = template(context); jQuery(html).hide().insertAfter('.' + method + '_add_instance_container:first').show('slow'); } /** * This method will return a random instance id string * * @param {integer} length - the length of the string to be generated * * @return string - the instance id */ function generate_instance_id(length) { var uuid = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (var i = 0; i < length; i++) { uuid += characters.charAt(Math.floor(Math.random() * characters.length)); } return uuid; } jQuery('#updraft-navtab-settings-content #remote-storage-holder').on("change", "input[class='updraft_instance_toggle']", function () { updraft_settings_form_changed = true; if (jQuery(this).is(':checked')) { jQuery(this).siblings('label').html(updraftlion.instance_enabled); } else { jQuery(this).siblings('label').html(updraftlion.instance_disabled); } }); jQuery('#updraft-navtab-settings-content #remote-storage-holder').on('click', '.updraftplusmethod button.updraft-test-button', function() { var method = jQuery(this).data('method'); var instance_id = jQuery(this).data('instance_id'); updraft_remote_storage_test(method, function(response, status, data) { if ('sftp' != method) { return false; } if (data.hasOwnProperty('scp') && data.scp) { alert(updraftlion.settings_test_result.replace('%s', 'SCP')+' '+response.output); } else { alert(updraftlion.settings_test_result.replace('%s', 'SFTP')+' '+response.output); } if (response.hasOwnProperty('data') && response.data) { if (response.data.hasOwnProperty('valid_md5_fingerprint') && response.data.valid_md5_fingerprint) { $('#updraft_sftp_fingerprint_'+instance_id).val(response.data.valid_md5_fingerprint); } } return true; }, instance_id); }); $('#updraft-navtab-settings-content select.updraft_interval, #updraft-navtab-settings-content select.updraft_interval_database').change(function() { updraft_check_same_times(); }); $('#backupnow_includefiles_showmoreoptions').click(function(e) { e.preventDefault(); $('#backupnow_includefiles_moreoptions').toggle(); }); $('#backupnow_database_showmoreoptions').click(function(e) { e.preventDefault(); $('#backupnow_database_moreoptions').toggle(); }); $('#updraft-navtab-backups-content').on('click', 'a.updraft_diskspaceused_update',function(e) { e.preventDefault(); updraftplus_diskspace(); }); // For Advanced Tools > Site information > Web-server disk space in use by UpdraftPlus $('.advanced_settings_content a.updraft_diskspaceused_update').click(function(e) { e.preventDefault(); jQuery('.advanced_settings_content .updraft_diskspaceused').html(''+updraftlion.calculating+''); updraft_send_command('get_fragment', { fragment: 'disk_usage', data: 'updraft' }, function(response) { jQuery('.advanced_settings_content .updraft_diskspaceused').html(response.output); }, { type: 'GET' }); }); $('#updraft-navtab-backups-content a.updraft_uploader_toggle').click(function(e) { e.preventDefault(); $('#updraft-plupload-modal').slideToggle(); }); $('#updraft-navtab-backups-content a.updraft_rescan_local').click(function(e) { e.preventDefault(); updraft_updatehistory(1, 0); }); $('#updraft-navtab-backups-content a.updraft_rescan_remote').click(function(e) { e.preventDefault(); updraft_updatehistory(1, 1); }); $('#updraftplus-remote-rescan-debug').click(function(e) { e.preventDefault(); updraft_updatehistory(1, 1, 1); }); function updraftcentral_keys_setupform(on_page_load) { var is_other = jQuery('#updraftcentral_mothership_other').is(':checked') ? true : false; if (is_other) { jQuery('#updraftcentral_keycreate_mothership').prop('disabled', false); if (on_page_load) { jQuery('#updraftcentral_keycreate_mothership_firewalled_container').show(); } else { jQuery('.updraftcentral_wizard_self_hosted_stage2').show(); jQuery('#updraftcentral_keycreate_mothership_firewalled_container').slideDown(); jQuery('#updraftcentral_keycreate_mothership').focus(); } } else { jQuery('#updraftcentral_keycreate_mothership').prop('disabled', true); if (!on_page_load) { jQuery('.updraftcentral_wizard_self_hosted_stage2').hide(); updraftcentral_stage2_go(); } } } function updraftcentral_stage2_go() { // Reset the error message before we continue jQuery('#updraftcentral_wizard_stage1_error').text(''); var host = ''; if (jQuery('#updraftcentral_mothership_updraftpluscom').is(':checked')) { jQuery('.updraftcentral_keycreate_description').hide(); host = 'updraftplus.com'; } else if (jQuery('#updraftcentral_mothership_other').is(':checked')) { jQuery('.updraftcentral_keycreate_description').show(); var mothership = jQuery('#updraftcentral_keycreate_mothership').val(); if ('' == mothership) { jQuery('#updraftcentral_wizard_stage1_error').text(updraftlion.updraftcentral_wizard_empty_url); return; } try { var url = new URL(mothership); host = url.hostname; } catch (e) { // Try and grab the host name a different way if it failed because of no URL object (e.g. IE 11). if ('undefined' === typeof URL) { host = jQuery('').prop('href', mothership).prop('hostname'); } if (!host || 'undefined' !== typeof URL) { jQuery('#updraftcentral_wizard_stage1_error').text(updraftlion.updraftcentral_wizard_invalid_url); return; } } } jQuery('#updraftcentral_keycreate_description').val(host); jQuery('.updraftcentral_wizard_stage1').hide(); jQuery('.updraftcentral_wizard_stage2').show(); } jQuery('#updraftcentral_keys').on('click', 'input[type="radio"]', function() { updraftcentral_keys_setupform(false); }); // Initial setup (for browsers, e.g. Firefox, that remember form selection state but not DOM state, which can leave an inconsistent state) updraftcentral_keys_setupform(true); jQuery('#updraftcentral_keys').on('click', '#updraftcentral_view_log', function(e) { e.preventDefault(); jQuery('#updraftcentral_view_log_container').block({ message: ''+error_message+'
'); console.log(error_message); console.log(response); } } }); } catch (err) { console.log("UpdraftPlus: error (follows) when looking for items needing downloading"); console.log(err); alert(updraftlion.jsonnotunderstood); } // Make sure all are downloaded } else if (2 == updraft_restore_stage) { updraft_restorer_checkstage2(1); } else if (3 == updraft_restore_stage) { var continue_restore = 1; jQuery('#updraft_restoreoptions_ui input.required').each(function(index) { if (continue_restore == 0) return; var sitename = jQuery(this).val(); if (sitename == '') { alert(updraftlion.pleasefillinrequired); continue_restore = 0; } else if (jQuery(this).attr('pattern') != '') { var pattern = jQuery(this).attr('pattern'); var re = new RegExp(pattern, "g"); if (!re.test(sitename)) { alert(jQuery(this).data('invalidpattern')); continue_restore = 0; } } }); if (!continue_restore) return; var restore_options = jQuery('#updraft_restoreoptions_ui select, #updraft_restoreoptions_ui input').serialize(); console.log("Restore options: "+restore_options); jQuery('#updraft_restorer_restore_options').val(restore_options); // This must be done last, as it wipes out the section with #updraft_restoreoptions_ui jQuery('#updraft-restore-modal-stage2a').html(updraftlion.restore_proceeding); jQuery('#updraft_restore_form').submit(); // In progress; prevent the button being pressed again updraft_restore_stage = 4; } } else { alert(updraftlion.youdidnotselectany); } }; updraft_restore_modal_buttons[updraftlion.cancel] = function() { jQuery(this).dialog("close"); }; jQuery("#updraft-restore-modal").dialog({ autoOpen: false, height: 505, width: 590, modal: true, buttons: updraft_restore_modal_buttons }); jQuery("#updraft-iframe-modal").dialog({ autoOpen: false, height: 500, width: 780, modal: true }); jQuery("#updraft-backupnow-inpage-modal").dialog({ autoOpen: false, height: 380, width: 580, modal: true }); var backupnow_modal_buttons = {}; backupnow_modal_buttons[updraftlion.backupnow] = function() { var backupnow_nodb = jQuery('#backupnow_includedb').is(':checked') ? 0 : 1; var backupnow_nofiles = jQuery('#backupnow_includefiles').is(':checked') ? 0 : 1; var backupnow_nocloud = jQuery('#backupnow_includecloud').is(':checked') ? 0 : 1; var onlythesetableentities = backupnow_whichtables_checked(''); var always_keep = jQuery('#always_keep').is(':checked') ? 1 : 0; if ('' == onlythesetableentities && 0 == backupnow_nodb) { alert(updraftlion.notableschosen); jQuery('#backupnow_includefiles_moreoptions').show(); return; } if (typeof onlythesetableentities === 'boolean') { onlythesetableentities = null; } var onlythesefileentities = backupnow_whichfiles_checked(''); if ('' == onlythesefileentities && 0 == backupnow_nofiles) { alert(updraftlion.nofileschosen); jQuery('#backupnow_includefiles_moreoptions').show(); return; } if (backupnow_nodb && backupnow_nofiles) { alert(updraftlion.excludedeverything); return; } jQuery(this).dialog("close"); setTimeout(function() { jQuery('#updraft_lastlogmessagerow').fadeOut('slow', function() { jQuery(this).fadeIn('slow'); }); }, 1700); updraft_backupnow_go(backupnow_nodb, backupnow_nofiles, backupnow_nocloud, onlythesefileentities, {always_keep: always_keep}, jQuery('#backupnow_label').val(), onlythesetableentities); }; backupnow_modal_buttons[updraftlion.cancel] = function() { jQuery(this).dialog("close"); }; jQuery("#updraft-backupnow-modal").dialog({ autoOpen: false, height: 472, width: 610, modal: true, buttons: backupnow_modal_buttons, create: function () { $(this).closest(".ui-dialog") .find(".ui-dialog-buttonpane .ui-button:first") // the first button .addClass("js-tour-backup-now-button"); } }); jQuery("#updraft-poplog").dialog({ autoOpen: false, height: 600, width: '75%', modal: true, }); jQuery('#updraft-navtab-settings-content .enableexpertmode').click(function() { jQuery('#updraft-navtab-settings-content .expertmode').fadeIn(); jQuery('#updraft-navtab-settings-content .enableexpertmode').off('click'); return false; }); jQuery('#updraft-navtab-settings-content .backupdirrow').on('click', 'a.updraft_backup_dir_reset', function() { jQuery('#updraft_dir').val('updraft'); return false; }); function setup_file_entity_exclude_field(field, instant) { if (jQuery('#updraft-navtab-settings-content #updraft_include_'+field).is(':checked')) { if (instant) { jQuery('#updraft-navtab-settings-content #updraft_include_'+field+'_exclude_container').show(); } else { jQuery('#updraft-navtab-settings-content #updraft_include_'+field+'_exclude_container').slideDown(); } } else { if (instant) { jQuery('#updraft-navtab-settings-content #updraft_include_'+field+'_exclude').hide(); } else { jQuery('#updraft-navtab-settings-content #updraft_include_'+field+'_exclude_container').slideUp(); } } } jQuery('#updraft-navtab-settings-content .updraft_include_entity').click(function() { var has_exclude_field = jQuery(this).data('toggle_exclude_field'); if (has_exclude_field) { setup_file_entity_exclude_field(has_exclude_field, false); } }); jQuery('.updraft_exclude_entity_container').on('click', '.updraft_exclude_entity_delete', function(event) { event.preventDefault(); if (!confirm(updraftlion.exclude_rule_remove_conformation_msg)) return; var include_entity_name = jQuery(this).data('include-backup-file'); jQuery.when( jQuery(this).closest('.updraft_exclude_entity_wrapper').remove() ).then( updraft_exclude_entity_update(include_entity_name) ); }); jQuery('.updraft_exclude_entity_container').on('click', '.updraft_exclude_entity_edit', function(event) { event.preventDefault(); var wrapper = jQuery(this).hide().closest('.updraft_exclude_entity_wrapper'); var input = wrapper.find('input'); input.removeProp('readonly').focus(); // place carret at the end of the text var input_val = input.val(); input.val(''); input.val(input_val); wrapper.find('.updraft_exclude_entity_update').addClass('is-active').show(); }); jQuery('.updraft_exclude_entity_container').on('click', '.updraft_exclude_entity_update', function(event) { event.preventDefault(); var wrapper = jQuery(this).closest('.updraft_exclude_entity_wrapper'); var include_backup_file = jQuery(this).data('include-backup-file') var exclude_item_val = jQuery.trim(wrapper.find('input').val()); var should_be_updated = false; if (exclude_item_val == wrapper.find('input').data('val')) { should_be_updated = true; } else if (updraft_is_unique_exclude_rule(exclude_item_val, include_backup_file)) { should_be_updated = true; } if (should_be_updated) { jQuery(this).hide().removeClass('is-active'); jQuery.when( wrapper.find('input').prop('readonly', 'readonly').data('val', exclude_item_val) ).then(function() { wrapper.find('.updraft_exclude_entity_edit').show(); updraft_exclude_entity_update(include_backup_file); }); } }); jQuery('#updraft_exclude_modal').dialog({ autoOpen: false, modal: true, width: 520, height: 'auto', open: function(event,ui) { $(this).parent().focus(); } }); jQuery('.updraft_exclude_container .updraft_add_exclude_item').click(function(event) { event.preventDefault(); var backup_entity = jQuery(this).data('include-backup-file'); jQuery('#updraft_exclude_modal_for').val(backup_entity); jQuery('#updraft_exclude_modal_path').val(jQuery(this).data('path')); if ('uploads' == backup_entity) { jQuery('#updraft-exclude-file-dir-prefix').html(jQuery('#updraft-exclude-upload-base-dir').val()); } jQuery('.updraft-exclude-modal-reset').trigger('click'); jQuery('#updraft_exclude_modal').dialog('open'); }); jQuery('.updraft-exclude-link').click(function(event) { event.preventDefault(); var panel = jQuery(this).data('panel'); if ('file-dir' == panel) { jQuery('#updraft_exclude_files_folders_jstree').jstree({ "core": { "multiple": false, "data": function (nodeid, callback) { updraft_send_command('get_jstree_directory_nodes', {entity: 'filebrowser', node:nodeid, path: jQuery('#updraft_exclude_modal_path').val(), findex: 0, skip_root_node: true}, function(response) { if (response.hasOwnProperty('error')) { alert(response.error); } else { callback.call(this, response.nodes); } }, { error_callback: function(response, status, error_code, resp) { if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); jQuery('#updraft_zip_files_jstree').html(''+resp.fatal_error_message+'
'); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; jQuery('#updraft_zip_files_jstree').html(''+error_message+'
'); console.log(error_message); alert(error_message); console.log(response); } } }); }, "error": function(error) { alert(error); console.log(error); }, }, "search": { "show_only_matches": true }, "plugins": ["sort"], }); } jQuery('#updraft_exclude_modal_main').slideUp(); jQuery('.updraft-exclude-panel').hide(); jQuery('.updraft-exclude-panel[data-panel='+panel+']').slideDown(); }); jQuery('.updraft-exclude-modal-reset').click(function(event) { event.preventDefault(); jQuery('#updraft_exclude_files_folders_jstree').jstree("destroy"); jQuery('#updraft_exclude_extension_field').val(''); jQuery('#updraft_exclude_prefix_field').val(''); jQuery('.updraft-exclude-panel').slideUp(); jQuery('#updraft_exclude_modal_main').slideDown(); }); jQuery('.updraft-exclude-submit').click(function() { var panel = jQuery(this).data('panel'); var exclude_item_val = ''; switch (panel) { case 'file-dir': var exclude_jstree_selected = jQuery("#updraft_exclude_files_folders_jstree").jstree("get_selected"); if (0 == exclude_jstree_selected.length) { alert(updraftlion.exclude_select_file_or_folder_msg); return; } var selected_file_or_folder = exclude_jstree_selected[0]; var prefix_path = jQuery('#updraft_exclude_modal_path').val(); if (selected_file_or_folder.substr(0, prefix_path.length) == prefix_path) { selected_file_or_folder = selected_file_or_folder.substr(prefix_path.length, selected_file_or_folder.length); } if ('/' == selected_file_or_folder.charAt(0)) selected_file_or_folder = selected_file_or_folder.substr(1); if ('/' == selected_file_or_folder.charAt(selected_file_or_folder.length - 1)) selected_file_or_folder = selected_file_or_folder.substr(0, selected_file_or_folder.length - 1); exclude_item_val = selected_file_or_folder; break; case 'extension': var exclude_extension = jQuery('#updraft_exclude_extension_field').val(); if ('' == exclude_extension) { alert(updraftlion.exclude_type_ext_msg); return; } if (!exclude_extension.match(/^[0-9a-zA-Z]+$/)) { alert(updraftlion.exclude_ext_error_msg); return; } exclude_item_val = 'ext:'+exclude_extension; break; case 'begin-with': var prefix = jQuery('#updraft_exclude_prefix_field').val(); if ('' == prefix) { alert(updraftlion.exclude_type_prefix_msg); return; } if (!prefix.match(/^\s*[a-z-_\d,\s]+\s*$/i)) { alert(updraftlion.exclude_prefix_error_msg); return; } exclude_item_val = 'prefix:'+prefix; break; default: return; } var include_backup_file = jQuery('#updraft_exclude_modal_for').val(); if (!updraft_is_unique_exclude_rule(exclude_item_val, include_backup_file)) return; var exclude_entity_html = ''; jQuery('.updraft_exclude_entity_container[data-include-backup-file="' + include_backup_file + '"]').append(exclude_entity_html); updraft_exclude_entity_update(include_backup_file); jQuery('#updraft_exclude_modal').dialog('close'); }); // TODO: This is suspected to be obsolete. Confirm + remove. jQuery('#updraft-navtab-settings-content .updraft-service').change(function() { var active_class = jQuery(this).val(); jQuery('#updraft-navtab-settings-content .updraftplusmethod').hide(); jQuery('#updraft-navtab-settings-content .'+active_class).show(); }); jQuery('#updraft-navtab-settings-content a.updraft_show_decryption_widget').click(function(e) { e.preventDefault(); jQuery('#updraftplus_db_decrypt').val(jQuery('#updraft_encryptionphrase').val()); jQuery('#updraft-manualdecrypt-modal').slideToggle(); }); jQuery('#updraftplus-phpinfo').click(function(e) { e.preventDefault(); updraft_iframe_modal('phpinfo', updraftlion.phpinfo); }); jQuery('#updraftplus-rawbackuphistory').click(function(e) { e.preventDefault(); updraft_iframe_modal('rawbackuphistory', updraftlion.raw); }); // + Added addons navtab jQuery('#updraft-navtab-status').click(function(e) { e.preventDefault(); updraft_open_main_tab('status'); updraft_page_is_visible = 1; updraft_console_focussed_tab = 'status'; // Refresh the console, as its next update might be far away updraft_activejobs_update(true); }); jQuery('#updraft-navtab-expert').click(function(e) { e.preventDefault(); updraft_open_main_tab('expert'); updraft_page_is_visible = 1; }); jQuery('#updraft-navtab-settings, #updraft-navtab-settings2, #updraft_backupnow_gotosettings').click(function(e) { e.preventDefault(); // These next two should only do anything if the relevant selector was clicked jQuery(this).parents('.updraftmessage').remove(); jQuery('#updraft-backupnow-modal').dialog('close'); updraft_open_main_tab('settings'); updraft_page_is_visible = 1; }); jQuery('#updraft-navtab-addons').click(function(e) { e.preventDefault(); jQuery(this).addClass('b#nav-tab-active'); updraft_open_main_tab('addons'); updraft_page_is_visible = 1; }); jQuery('#updraft-navtab-backups').click(function(e) { e.preventDefault(); updraft_console_focussed_tab = 'backups'; updraft_historytimertoggle(1); updraft_open_main_tab('backups'); }); jQuery('#updraft-navtab-migrate').click(function(e) { e.preventDefault(); jQuery('#updraft_migrate_tab_alt').html('').hide(); updraft_open_main_tab('migrate'); updraft_page_is_visible = 1; if (!jQuery('#updraft_migrate .updraft_migrate_widget_module_content').is(':visible')) { jQuery('.updraft_migrate_intro').show(); } }); if ('migrate' == updraftlion.tab) jQuery('#updraft-navtab-migrate').trigger('click'); updraft_send_command('ping', null, function(data, response) { if ('success' == response && data != 'pong' && data.indexOf('pong')>=0) { jQuery('#updraft-navtab-backups-content .ud-whitespace-warning').show(); console.log("UpdraftPlus: Extra output warning: response (which should be just (string)'pong') follows."); console.log(data); } }, { json_parse: false, type: 'GET' }); // Section: Plupload try { if (typeof updraft_plupload_config !== 'undefined') { plupload_init(); } } catch (err) { console.log(err); } function plupload_init() { // create the uploader and pass the config from above var uploader = new plupload.Uploader(updraft_plupload_config); // checks if browser supports drag and drop upload, makes some css adjustments if necessary uploader.bind('Init', function(up) { var uploaddiv = jQuery('#plupload-upload-ui'); if (up.features.dragdrop) { uploaddiv.addClass('drag-drop'); jQuery('#drag-drop-area') .bind('dragover.wp-uploader', function() { uploaddiv.addClass('drag-over'); }) .bind('dragleave.wp-uploader, drop.wp-uploader', function() { uploaddiv.removeClass('drag-over'); }); } else { uploaddiv.removeClass('drag-drop'); jQuery('#drag-drop-area').unbind('.wp-uploader'); } }); uploader.init(); // a file was added in the queue uploader.bind('FilesAdded', function(up, files) { // var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10); plupload.each(files, function(file) { // @codingStandardsIgnoreLine if (! /^backup_([\-0-9]{15})_.*_([0-9a-f]{12})-[\-a-z]+([0-9]+?)?(\.(zip|gz|gz\.crypt))?$/i.test(file.name) && ! /^log\.([0-9a-f]{12})\.txt$/.test(file.name)) { var accepted_file = false; for (var i = 0; i'+resp.r+''); } else { console.log(resp); } }, { type: 'GET' }); } jQuery('#updraft_activejobs_table, #updraft-navtab-migrate-content').on('click', '.updraft_jobinfo_delete', function(e) { e.preventDefault(); var job_id = jQuery(this).data('jobid'); if (job_id) { $(this).addClass('disabled'); updraft_activejobs_delete(job_id); } else { console.log("UpdraftPlus: A stop job link was clicked, but the Job ID could not be found"); } }); jQuery('#updraft_activejobs_table, #updraft-navtab-backups-content .updraft_existing_backups, #updraft-backupnow-inpage-modal, #updraft-navtab-migrate-content').on('click', '.updraft-log-link', function(e) { e.preventDefault(); var job_id = jQuery(this).data('jobid'); if (job_id) { updraft_popuplog(job_id); } else { console.log("UpdraftPlus: A log link was clicked, but the Job ID could not be found"); } }); function updraft_restore_setup(entities, key, show_data) { updraft_restore_setoptions(entities); jQuery('#updraft_restore_timestamp').val(key); jQuery('.updraft_restore_date').html(show_data); updraft_restore_stage = 1; jQuery('#updraft-restore-modal').dialog('open'); jQuery('#updraft-restore-modal-stage1').show(); jQuery('#updraft-restore-modal-stage2').hide(); jQuery('#updraft-restore-modal-stage2a').html(''); updraft_activejobs_update(true); } jQuery('#updraft-navtab-backups-content .updraft_existing_backups').on('click', 'button.choose-components-button', function(e) { var entities = jQuery(this).data('entities'); var backup_timestamp = jQuery(this).data('backup_timestamp'); var show_data = jQuery(this).data('showdata'); updraft_restore_setup(entities, backup_timestamp, show_data); }); /** * Get the value of a named URL parameter - https://stackoverflow.com/questions/4548487/jquery-read-query-string * * @param {string} name - URL parameter to return the value of * * @returns {string} */ function get_parameter_by_name(name) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex_s = "[\\?&]"+name+"=([^]*)"; var regex = new RegExp(regex_s); var results = regex.exec(window.location.href); if (results == null) { return ''; } else { return decodeURIComponent(results[1].replace(/\+/g, ' ')); } } if (get_parameter_by_name('udaction') == 'initiate_restore') { var entities = get_parameter_by_name('entities'); var backup_timestamp = get_parameter_by_name('backup_timestamp'); var show_data = get_parameter_by_name('showdata'); updraft_restore_setup(entities, backup_timestamp, show_data); } var updraft_upload_modal_buttons = {}; updraft_upload_modal_buttons[updraftlion.uploadbutton] = function () { var key = jQuery('#updraft_upload_timestamp').val(); var nonce = jQuery('#updraft_upload_nonce').val(); var services = ''; var send_list = false; jQuery('.updraft_remote_storage_destination').each(function (index) { if (jQuery(this).is(':checked')) { send_list = true; } }); if (!send_list) { jQuery('#updraft-upload-modal-error').html(updraftlion.local_upload_error); return; } else { services = jQuery("input[name^='updraft_remote_storage_destination_']").serializeArray(); } jQuery(this).dialog("close"); alert(updraftlion.local_upload_started); updraft_send_command('upload_local_backup', { use_nonce: nonce, use_timestamp: key, services: services }, function (response) {}); }; updraft_upload_modal_buttons[updraftlion.cancel] = function () { jQuery(this).dialog("close"); }; jQuery("#updraft-upload-modal").dialog({ autoOpen: false, height: 322, width: 430, modal: true, buttons: updraft_upload_modal_buttons }); jQuery('#updraft-navtab-backups-content .updraft_existing_backups').on('click', 'button.updraft-upload-link', function (e) { e.preventDefault(); var nonce = jQuery(this).data('nonce').toString(); var key = jQuery(this).data('key').toString(); var services = jQuery(this).data('services').toString(); if (nonce) { updraft_upload(key, nonce, services); } else { console.log("UpdraftPlus: A upload link was clicked, but the Job ID could not be found"); } }); /** * Opens the dialog box for confirmation of where to upload the backup * * @param {string} key - The UNIX timestamp of the backup * @param {string} nonce - The backup job ID * @param {string} services - A list of services that have not been uploaded to yet */ function updraft_upload(key, nonce, services) { jQuery('#updraft_upload_timestamp').val(key); jQuery('#updraft_upload_nonce').val(nonce); var services_array = services.split(","); jQuery('.updraft_remote_storage_destination').each(function (index) { var name = jQuery(this).val(); if (jQuery.inArray(name, services_array) == -1) { jQuery(this).prop('checked', false); jQuery(this).prop('disabled', true); var label = $(this).prop("labels"); jQuery(label).append(' ' + updraftlion.already_uploaded); } }); jQuery('#updraft-upload-modal').dialog('open'); } jQuery('#updraft-navtab-backups-content .updraft_existing_backups').on('click', '.updraft-delete-link', function(e) { e.preventDefault(); var hasremote = jQuery(this).data('hasremote'); var nonce = jQuery(this).data('nonce').toString(); var key = jQuery(this).data('key').toString(); if (nonce) { updraft_delete(key, nonce, hasremote); } else { console.log("UpdraftPlus: A delete link was clicked, but the Job ID could not be found"); } }); jQuery('#updraft-navtab-backups-content .updraft_existing_backups').on('click', 'button.updraft_download_button', function(e) { e.preventDefault(); var base = 'uddlstatus_'; var backup_timestamp = jQuery(this).data('backup_timestamp'); var what = jQuery(this).data('what'); var whicharea = '.ud_downloadstatus'; var set_contents = jQuery(this).data('set_contents'); var prettydate = jQuery(this).data('prettydate'); var async = true; updraft_downloader(base, backup_timestamp, what, whicharea, set_contents, prettydate, async); }); jQuery('#updraft-navtab-backups-content .updraft_existing_backups').on('dblclick', '.updraft_existingbackup_date', function(e) { e.preventDefault(); var data = jQuery(this).data('rawbackup'); if (data != null && data != '') { updraft_html_modal(data, updraftlion.raw, 780, 500); } }); }); // UpdraftPlus Vault jQuery(document).ready(function($) { var settings_css_prefix = '#updraft-navtab-settings-content '; $(settings_css_prefix+'#remote-storage-holder').on('click', '.updraftvault_backtostart', function(e) { e.preventDefault(); $(settings_css_prefix+'#updraftvault_settings_showoptions').slideUp(); $(settings_css_prefix+'#updraftvault_settings_connect').slideUp(); $(settings_css_prefix+'#updraftvault_settings_connected').slideUp(); $(settings_css_prefix+'#updraftvault_settings_default').slideDown(); }); // Prevent default event when pressing return in the form $(settings_css_prefix).on('keypress','#updraftvault_settings_connect input', function(e) { if (13 == e.which) { $(settings_css_prefix+'#updraftvault_connect_go').click(); return false; } }); $(settings_css_prefix+'#remote-storage-holder').on('click', '#updraftvault_recountquota', function(e) { e.preventDefault(); $(settings_css_prefix+'#updraftvault_recountquota').html(updraftlion.counting); try { updraft_send_command('vault_recountquota', { instance_id: $('#updraftvault_settings_connect').data('instance_id') }, function(response) { $(settings_css_prefix+'#updraftvault_recountquota').html(updraftlion.updatequotacount); if (response.hasOwnProperty('html')) { $(settings_css_prefix+'#updraftvault_settings_connected').html(response.html); if (response.hasOwnProperty('connected')) { if (response.connected) { $(settings_css_prefix+'#updraftvault_settings_default').hide(); $(settings_css_prefix+'#updraftvault_settings_connected').show(); } else { $(settings_css_prefix+'#updraftvault_settings_connected').hide(); $(settings_css_prefix+'#updraftvault_settings_default').show(); } } } }, { error_callback: function(response, status, error_code, resp) { $(settings_css_prefix+'#updraftvault_recountquota').html(updraftlion.updatequotacount); if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; console.log(error_message); alert(error_message); console.log(response); } } }); } catch (err) { $(settings_css_prefix+'#updraftvault_recountquota').html(updraftlion.updatequotacount); console.log(err); } }); $(settings_css_prefix+'#remote-storage-holder').on('click', '#updraftvault_disconnect', function(e) { e.preventDefault(); $(settings_css_prefix+'#updraftvault_disconnect').html(updraftlion.disconnecting); try { updraft_send_command('vault_disconnect', { immediate_echo: true, instance_id: $('#updraftvault_settings_connect').data('instance_id') }, function(response) { $(settings_css_prefix+'#updraftvault_disconnect').html(updraftlion.disconnect); if (response.hasOwnProperty('html')) { $(settings_css_prefix+'#updraftvault_settings_connected').html(response.html).slideUp(); $(settings_css_prefix+'#updraftvault_settings_default').slideDown(); } }, { error_callback: function(response, status, error_code, resp) { $(settings_css_prefix+'#updraftvault_disconnect').html(updraftlion.disconnect); if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; console.log(error_message); alert(error_message); console.log(response); } } }); } catch (err) { $(settings_css_prefix+'#updraftvault_disconnect').html(updraftlion.disconnect); console.log(err); } }); $(settings_css_prefix+'#remote-storage-holder').on('click', '#updraftvault_connect', function(e) { e.preventDefault(); $(settings_css_prefix+'#updraftvault_settings_default').slideUp(); $(settings_css_prefix+'#updraftvault_settings_connect').slideDown(); }); $(settings_css_prefix+'#remote-storage-holder').on('click', '#updraftvault_showoptions', function(e) { e.preventDefault(); $(settings_css_prefix+'#updraftvault_settings_default').slideUp(); $(settings_css_prefix+'#updraftvault_settings_showoptions').slideDown(); }); $('#remote-storage-holder').on('keyup', '.updraftplus_onedrive_folder_input', function(e) { var folder = $(this).val(); var td_container = $(this).closest('td') if (0 == folder.indexOf('https:') || 0 == folder.indexOf('http:')) { if (!td_container.find('.onedrive_folder_error').length) { td_container.append('
'+resp.e+'
', updraftlion.disconnect, 400, 250); if (resp.hasOwnProperty('code') && resp.code == 'no_quota') { $(settings_css_prefix+'#updraftvault_settings_connect').slideUp(); $(settings_css_prefix+'#updraftvault_settings_default').slideDown(); } } else if (resp.hasOwnProperty('connected') && resp.connected && resp.hasOwnProperty('html')) { $(settings_css_prefix+'#updraftvault_settings_connect').slideUp(); $(settings_css_prefix+'#updraftvault_settings_connected').html(resp.html).slideDown(); } else { console.log(resp); alert(updraftlion.unexpectedresponse+' '+response); } }, { error_callback: function(response, status, error_code, resp) { $(settings_css_prefix+'#updraftvault_connect_go').html(updraftlion.connect); if (typeof resp !== 'undefined' && resp.hasOwnProperty('fatal_error')) { console.error(resp.fatal_error_message); alert(resp.fatal_error_message); } else { var error_message = "updraft_send_command: error: "+status+" ("+error_code+")"; console.log(error_message); alert(error_message); console.log(response); } } }); return false; }); // Mark a backup as always keep (do not delete) $('#updraft-iframe-modal').on('change', '#always_keep_this_backup', function() { var backup_key = $(this).data('backup_key'); var params = { backup_key: backup_key, always_keep: $(this).is(':checked') ? 1 : 0, }; updraft_send_command('always_keep_this_backup', params, function(resp) { if (resp.hasOwnProperty('rawbackup')) { jQuery('#updraft-iframe-modal').dialog('close'); jQuery('.updraft_existing_backups_row_'+backup_key+' .updraft_existingbackup_date').data('rawbackup', resp.rawbackup); updraft_html_modal(jQuery('.updraft_existing_backups_row_'+backup_key+' .updraft_existingbackup_date').data('rawbackup'), updraftlion.raw, 780, 500); } }); }); }); // Next: the encrypted database pluploader jQuery(document).ready(function($) { try { if (typeof updraft_plupload_config2 !== 'undefined') { plupload_init(); } } catch (err) { console.log(err); } function plupload_init() { // create the uploader and pass the config from above var uploader = new plupload.Uploader(updraft_plupload_config2); // checks if browser supports drag and drop upload, makes some css adjustments if necessary uploader.bind('Init', function(up) { var uploaddiv = jQuery('#plupload-upload-ui2'); if (up.features.dragdrop) { uploaddiv.addClass('drag-drop'); jQuery('#drag-drop-area2') .bind('dragover.wp-uploader', function() { uploaddiv.addClass('drag-over'); }) .bind('dragleave.wp-uploader, drop.wp-uploader', function() { uploaddiv.removeClass('drag-over'); }); } else { uploaddiv.removeClass('drag-drop'); jQuery('#drag-drop-area2').unbind('.wp-uploader'); } }); uploader.init(); // a file was added in the queue uploader.bind('FilesAdded', function(up, files) { // var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10); plupload.each(files, function(file) { // @codingStandardsIgnoreLine if (!/^backup_([\-0-9]{15})_.*_([0-9a-f]{12})-db([0-9]+)?\.(gz\.crypt)$/i.test(file.name)) { alert(file.name+': '+updraftlion.notdba); uploader.removeFile(file); return; } // a file was added, you may want to update your DOM here... jQuery('#filelist2').append( '