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

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

347 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2
3 $('#updraftcentral_dashboard_existingsites').on('updraftcentral_dashboard_mode_set_advancedtools', function() {
4
5 UpdraftCentral.register_row_clicker('.updraftcentral_site_advanced_settings', function($site_row) {
6
7 UpdraftCentral.send_site_rpc('updraftplus.get_advanced_settings', { suppress_plugins_for_debugging: true } , $site_row, function(response, code, error_code) {
8 if ('ok' === code) {
9 $site_row.find('.updraftcentral_row_extracontents').empty().append(UpdraftCentral_Library.sanitize_html(response.data));
10 }
11 });
12 }, true);
13
14 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_menu .advanced_tools_button', function(event) {
15 advanced_tool_hide(this.id);
16 });
17
18 /**
19 * Sets the desired tool to be shown and active, hides all other tools
20 *
21 * @param {string} show_tool - the tool that is to be shown and set to active
22 *
23 * @return {void}
24 */
25 function advanced_tool_hide(show_tool) {
26
27 $('.expertmode .advanced_settings_container .advanced_tools:not(".'+show_tool+'")').hide();
28 $('.expertmode .advanced_settings_container .advanced_tools.'+show_tool).fadeIn('slow');
29
30 $('.expertmode .advanced_settings_container .advanced_tools_button:not(#'+show_tool+')').removeClass('active');
31 $('.expertmode .advanced_settings_container .advanced_tools_button#'+show_tool).addClass('active');
32
33 }
34
35 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content a.updraft_diskspaceused_update', function($site_row) {
36 // var spin_this = this.closest('ul');
37 $site_row.find('.updraft_diskspaceused').html('<em>'+ udclion.advancedtools.calculating + '</em>');
38 UpdraftCentral.send_site_rpc('updraftplus.get_fragment', { fragment: 'disk_usage', data: 'updraft' } , $site_row, function(response, code, error_code) {
39 if ('ok' == code && response) {
40 $site_row.find('.updraft_diskspaceused').html(UpdraftCentral_Library.sanitize_html(response.data.output));
41 }
42 });
43 });
44
45 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraftplus-phpinfo', function($site_row, event) {
46
47 UpdraftCentral.send_site_rpc('core.phpinfo', null , $site_row, function(response, code, error_code) {
48 if ('ok' == code && response.data) {
49 var output = '';
50 $.each(response.data, function(name, section) {
51 output += "<h3>"+name+"</h3>\n"+'<table>'+"\n";
52 $.each(section, function(key, val) {
53 if (val.constructor === Array) {
54 output += "<tr><td>"+key+"</td><td>"+val[0]+"</td><td>"+val[1]+"</td></tr>\n";
55 } else if (typeof val === 'string') {
56 if ($.isNumeric(key)) {
57 output += "<tr><td></td><td>"+val+"</td></tr>\n";
58 } else {
59 output += "<tr><td>"+key+"</td><td>"+val+"</td></tr>\n";
60 }
61 } else {
62 console.log("UpdraftCentral: phpinfo: Unrecognised output for key "+key+" (follows)");
63 console.log(val);
64 }
65 });
66 output += "</table>\n";
67 });
68
69 // N.B. open_modal() by default sanitizes the body data
70 UpdraftCentral.open_modal(udclion.advancedtools.php_info, '<div id="updraftcentral_phpinfo_results">'+output+'</div>', null, false, null, true, 'modal-lg');
71 }
72 }, $(this));
73 });
74
75 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraftplus_httpget_go', function($site_row, event) {
76 data = $('#updraftplus_httpget_uri').val()
77 UpdraftCentral.send_site_rpc('updraftplus.http_get', data , $site_row, function(response, code, error_code) {
78 UpdraftCentral.open_modal(udclion.advancedtools.response, '<p>' + UpdraftCentral_Library.sanitize_html(response.data.response) + '</p>', null, false, null, true);
79 });
80 });
81
82 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraftplus_httpget_gocurl', function($site_row, event) {
83 var data = $('#updraftplus_httpget_uri').val();
84
85 UpdraftCentral.send_site_rpc('updraftplus.http_get_curl', data , $site_row, function(response, code, error_code) {
86 UpdraftCentral.open_modal(udclion.advancedtools.response, '<p><pre>' + UpdraftCentral_Library.sanitize_html(response.data.response) + '</pre></p>', null, false, null, true, 'modal-lg');
87 });
88 });
89
90 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraftplus_callwpaction_go', function($site_row, event) {
91 var data = { "wpaction": $('#updraftplus_callwpaction').val()};
92
93 UpdraftCentral.send_site_rpc('core.call_wordpress_action', data , $site_row, function(response, code, error_code) {
94
95 UpdraftCentral.open_modal(udclion.advancedtools.response, '<p>' + UpdraftCentral_Library.sanitize_html(response.data.response) + '</p>', null, false, null, true);
96 });
97 });
98
99 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraft_reset_sid', function($site_row, event) {
100 UpdraftCentral.send_site_rpc('updraftplus.reset_site_id', null , $site_row, function(response, code, error_code) {
101 $('#updraft_show_sid').text(response.data);
102 });
103 });
104
105 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .site_info #updraftplus-rawbackuphistory', function($site_row, event) {
106 UpdraftCentral.send_site_rpc('updraftplus.show_raw_backup_and_file_list', null , $site_row, function(response, code, error_code) {
107 UpdraftCentral.open_modal(udclion.advancedtools.raw_backup_history, '<pre><div id="raw_backup_modal">' + UpdraftCentral_Library.sanitize_html(response.data) + '</div></pre>', null, false, null, true, 'modal-lg');
108 });
109 });
110
111 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .lock_admin .change_lock_settings', function($site_row, event) {
112 var data = {
113 "old_password": $('#updraft_unlockadmin_oldpassword').val(),
114 "password": $('#updraft_unlockadmin_password').val(),
115 "session_length": $('#updraft_unlockadmin_session_length').val(),
116 "support_url": $('#updraft_unlockadmin_support_url').val()
117 };
118
119 UpdraftCentral.send_site_rpc('updraftplus.change_lock_settings', data , $site_row, function(response, code, error_code) {
120 $('#updraft_unlockadmin_oldpassword').val(data.password);
121
122 if (data.password == '') {
123 message = udclion.advancedtools.settings_unlocked;
124 } else {
125 message = udclion.advancedtools.password_changed_to + " '" + data.password + "' ";
126 }
127
128 UpdraftCentral.open_modal(udclion.advancedtools.lock_changed, "<p>" + message + "</p>", null, false, null, true);
129 });
130 });
131
132 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .updraft_central .updraft_debugrow .updraftcentral_key_delete', function($site_row, event) {
133 var key_id = $(this).data('key_id');
134
135 UpdraftCentral.send_site_rpc('updraftplus.delete_key', key_id , $site_row, function(response, code, error_code) {
136 var cont = $site_row.find('#updraftcentral_keys');
137 cont.replaceWith(response.data.keys_table);
138 });
139 });
140
141 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .updraft_central #updraftcentral_view_log', function($site_row, event) {
142 UpdraftCentral.send_site_rpc('updraftplus.fetch_log', null , $site_row, function(response, code, error_code) {
143 UpdraftCentral.open_modal(udclion.advancedtools.log, "<pre>" + UpdraftCentral_Library.sanitize_html(response.data.log_contents) + "</pre>", function() {}, false, null, false, 'modal-lg');
144 });
145 });
146
147 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .search_replace #search_replace_form .search_and_replace', function($site_row, event) {
148 var data = {
149 search: $site_row.find('#search').val(),
150 replace: $site_row.find('#replace').val(),
151 pagesize: $site_row.find('#pagesize').val(),
152 whichtables: $site_row.find('#whichtables').val(),
153 show_return_link: false,
154 show_heading: false
155 }
156
157 UpdraftCentral.send_site_rpc('updraftplus.search_replace', data , $site_row, function(response, code, error_code) {
158 UpdraftCentral.open_modal(udclion.advancedtools.response,
159 '<h2>'+udclion.advancedtools.search_replace+'</h2><pre>'+UpdraftCentral_Library.sanitize_html(response.data.log)+'</pre>',
160 null,
161 false,
162 null,
163 true
164 );
165 });
166 });
167
168 UpdraftCentral.register_modal_listener('.return_to_updraft', function(event) {
169 event.preventDefault();
170 UpdraftCentral.close_modal();
171 });
172
173 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .total_size .count', function(event) {
174 var entity = $(this).data('type');
175
176 jQuery('#updraft_diskspaceused_' + entity).html('<em>'+ udclion.advancedtools.calculating + '</em>');
177
178 var $site_row = $(this).closest('.updraftcentral_site_row');
179 UpdraftCentral.send_site_rpc('core.count', entity , $site_row, function(response, code, error_code) {
180 jQuery('#updraft_diskspaceused_'+entity).html(response.data);
181 });
182 });
183
184 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content #updraftplus-settings-export', function($site_row, event) {
185 UpdraftCentral.send_site_rpc('updraftplus.get_settings', {
186 include_database_decrypter: 0,
187 include_adverts: 0,
188 include_save_button: 1
189 }, $site_row, function(response, code, error_code) {
190 var settings_html = UpdraftCentral_Library.sanitize_html(response.data.settings);
191 export_settings(settings_html, $site_row);
192 });
193 });
194
195 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content #updraftplus-settings-import', function($site_row, event) {
196
197 var updraft_import_file_input = document.getElementById('import_settings');
198 if (updraft_import_file_input.files.length == 0) {
199 UpdraftCentral_Library.dialog.alert(udclion.advancedtools.import_select_file);
200 return;
201 }
202
203 var updraft_import_file_file = updraft_import_file_input.files[0];
204 var updraft_import_file_reader = new FileReader();
205 updraft_import_file_reader.onload = function() {
206 import_settings(this.result);
207 };
208 updraft_import_file_reader.readAsText(updraft_import_file_file);
209
210 });
211
212 UpdraftCentral.register_row_clicker('.advanced_settings_container .advanced_settings_content .updraft_wipe_settings', function($site_row, event) {
213
214 UpdraftCentral.send_site_rpc('updraftplus.wipe_settings', null, $site_row, function(response, code, error_code) {
215
216 if (true == response.data) {
217 message = udclion.advancedtools.settings_wiped;
218 } else {
219 message = udclion.advancedtools.wipe_settings_error;
220 }
221
222 UpdraftCentral.open_modal(udclion.advancedtools.wipe_settings, "<p>" + message + "</p>", null, false, null, true);
223 });
224 });
225 });
226
227 /**
228 * A Method to get the currently saved UpdraftPlus settings in JSON format ready to be saved to a file so the user can import settings to another site.
229 *
230 * @param {String} settings_html The UpdraftPlus settings page HTML to be parsed to gather the current saved settings.
231 * @param {string} $site_row The jQuery row object for the site that the click was for.
232 *
233 * @return {void} The method will output will prompt the user to download a JSON file with the exported settings as it's content
234 */
235 function export_settings(settings_html, $site_row) {
236 var form_data = gather_updraft_settings(settings_html).split('&');
237 var input = {};
238
239 // Function to convert serialized settings to the correct format ready for json encoding
240 $.each(form_data, function(key, value) {
241 var data = value.split('=');
242
243 var name = decodeURIComponent(data[0]);
244 if (name.indexOf("option_page") >= 0 || name.indexOf("_wpnonce") >= 0 || name.indexOf("_wp_http_referer") >= 0) {
245 return true;
246 }
247
248 if (name.indexOf("[") >= 0) {
249 var extract = name.match(/\[(.*)\]/).pop();
250 name = name.substring(0, name.indexOf('['));
251 // some options either have a blank or 0 as their nested array key and need to be delt with differently
252 if (!extract || extract === '0') {
253 if ("undefined" === typeof input[name]) input[name] = [];
254 input[name].push(decodeURIComponent(data[1]));
255 } else {
256 // @codingStandardsIgnoreLine
257 if (typeof input[name] === "undefined") input[name] = {} ;
258 input[name][extract] = decodeURIComponent(data[1]);
259 }
260 } else {
261 input[name] = decodeURIComponent(data[1]);
262 }
263 });
264
265 var date_now = new Date();
266
267 form_data = JSON.stringify({
268 // Indicate the last time the format changed - i.e. do not update this unless there is a format change
269 version: '1.12.19',
270 epoch_date: date_now.getTime(),
271 local_date: date_now.toLocaleString(),
272 network_site_url: $site_row.data("site_url"),
273 data: input
274 });
275
276 $("body").append('<div id="udc_exported_settings" style="display:none;">' + form_data + '</div>');
277
278 UpdraftCentral_Library.download_inner_html('updraftplus-settings.json', 'udc_exported_settings', 'text/json');
279
280 $("#udc_exported_settings").remove();
281 }
282
283 /**
284 * This method will gather the needed settings to be exported from the HTML passed to it.
285 *
286 * @param {String} settings_html - The UpdraftPlus settings page HTML to be parsed to gather the current saved settings
287 *
288 * @return {String} form_data - The parsed UpdraftPlus settings in a serialized format
289 */
290 function gather_updraft_settings(settings_html) {
291 // Attach this data to a hidden div on page
292 $("body").append('<div class="hidden_udp_settings" style="display:none;">' + settings_html + '</div>');
293
294 // Excluding the unnecessary 'action' input avoids triggering a very mis-conceived mod_security rule seen on one user's site
295 var form_data = $(".hidden_udp_settings input[name!='action'], .hidden_udp_settings textarea, .hidden_udp_settings select").serialize();
296
297 // include unchecked checkboxes. user filter to only include unchecked boxes.
298 $.each($('.hidden_udp_settings input[type=checkbox]')
299 .filter(function(idx) {
300 return $(this).prop('checked') == false
301 }),
302 function(idx, el) {
303 // attach matched element names to the form_data with chosen value.
304 var empty_val = '0';
305 form_data += '&' + $(el).attr('name') + '=' + empty_val;
306 }
307 );
308
309 $(".hidden_udp_settings").remove();
310
311 return form_data;
312 }
313
314 /**
315 * Method to parse through the import file and send the data to the UpdraftPlus save handler
316 *
317 * @param {JSON} updraft_file_result - the contents of the imported file
318 *
319 * @return {void}
320 */
321 function import_settings(updraft_file_result) {
322
323 var data = decodeURIComponent(updraft_file_result);
324
325 data = JSON.parse(data);
326
327 UpdraftCentral_Library.dialog.confirm(udclion.advancedtools.importing_data_from + ' ' + data['network_site_url'] + "\n" + udclion.advancedtools.exported_on + ' ' + data['local_date'] + "\n" + udclion.advancedtools.continue_import, function(result) {
328
329 if (result) {
330 data = data['data'];
331
332 UpdraftCentral.send_site_rpc('updraftplus.save_settings', data, $site_row, function(response, code, error_code) {
333
334 if ('ok' === code) {
335 message = udclion.advancedtools.import_success;
336 } else {
337 message = udclion.advancedtools.import_failed;
338 }
339
340 UpdraftCentral.open_modal(udclion.advancedtools.import_settings, "<p>" + message + "</p>", null, false, null, true);
341 });
342 }
343
344 });
345 }
346 });
347