1
|
|
|
/** global: ajaxurl */ |
2
|
|
|
/** global: Materialize */ |
3
|
|
|
var dataTable = ""; |
4
|
|
|
|
5
|
|
|
class Xcloner_Manage_Backups { |
6
|
|
|
|
7
|
|
|
constructor() { |
8
|
|
|
this.file_counter = 0 |
9
|
|
|
this.storage_selection = ""; |
10
|
|
|
this.dataTable = ""; |
11
|
|
|
//this.edit_modal = jQuery('.modal').modal(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
download_backup_by_name(id) { |
15
|
|
|
window.open(ajaxurl + "?action=download_backup_by_name&name=" + id); |
16
|
|
|
return false; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
delete_backup_by_name(id, elem, dataTable) { |
20
|
|
|
var $this = this |
|
|
|
|
21
|
|
|
|
22
|
|
|
if (id) { |
23
|
|
|
jQuery.ajax({ |
24
|
|
|
url: ajaxurl, |
25
|
|
|
method: 'post', |
26
|
|
|
data: {action: 'delete_backup_by_name', name: id, storage_selection: this.storage_selection}, |
27
|
|
|
success: function (response) { |
28
|
|
|
if (response.finished) { |
29
|
|
|
dataTable |
30
|
|
|
.row(jQuery(elem).parents('tr')) |
31
|
|
|
.remove() |
32
|
|
|
.draw(); |
33
|
|
|
} else { |
34
|
|
|
alert("There was an error deleting the file"); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
}, |
37
|
|
|
dataType: 'json' |
38
|
|
|
}); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
list_backup_content_callback(backup_file, start = 0, part = 0) { |
43
|
|
|
var $this = this; |
44
|
|
|
|
45
|
|
|
if (backup_file) { |
46
|
|
|
jQuery.ajax({ |
47
|
|
|
url: ajaxurl, |
48
|
|
|
method: 'post', |
49
|
|
|
data: {action: 'list_backup_files', file: backup_file, start: start, part: part}, |
50
|
|
|
success: function (response) { |
51
|
|
|
|
52
|
|
|
if (response.error) { |
53
|
|
|
jQuery("#backup_cotent_modal .files-list").addClass("error").prepend(response.message) |
54
|
|
|
jQuery("#backup_cotent_modal .progress > div").addClass("determinate").removeClass(".indeterminate").css('width', "100%") |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
var files_text = []; |
59
|
|
|
|
60
|
|
|
for (var i in response.files) { |
|
|
|
|
61
|
|
|
|
62
|
|
|
if (response.total_size !== undefined) { |
63
|
|
|
var percent = parseInt(response.start * 100) / parseInt(response.total_size) |
|
|
|
|
64
|
|
|
//jQuery("#backup_cotent_modal .progress .determinate").css('width', percent + "%") |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this.file_counter++ |
68
|
|
|
|
69
|
|
|
files_text[i] = "<li>" + ($this.file_counter + ". <span title='" + response.files[i].mtime + "'>" + response.files[i].path + "</span> (" + response.files[i].size + " bytes)") + "</li>"; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
jQuery("#backup_cotent_modal .modal-content .files-list").prepend(files_text.reverse().join("\n")); |
73
|
|
|
|
74
|
|
|
if (!response.finished && jQuery('#backup_cotent_modal').is(':visible')) { |
75
|
|
|
$this.list_backup_content_callback(backup_file, response.start, response.part) |
76
|
|
|
} else { |
77
|
|
|
jQuery("#backup_cotent_modal .progress > div").addClass('determinate').removeClass(".indeterminate").css('width', "100%") |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
}, |
81
|
|
|
error: function (xhr, textStatus, error) { |
82
|
|
|
jQuery("#backup_cotent_modal .files-list").addClass("error").prepend(textStatus + error) |
83
|
|
|
}, |
84
|
|
|
dataType: 'json' |
85
|
|
|
}); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
list_backup_content(backup_file) { |
92
|
|
|
this.file_counter = 0 |
93
|
|
|
jQuery("#backup_cotent_modal .modal-content .files-list").text("").removeClass("error"); |
94
|
|
|
jQuery("#backup_cotent_modal .modal-content .backup-name").text(backup_file); |
95
|
|
|
jQuery("#backup_cotent_modal").modal('open'); |
96
|
|
|
jQuery("#backup_cotent_modal .progress > div").removeClass('determinate').addClass("indeterminate"); |
97
|
|
|
|
98
|
|
|
this.list_backup_content_callback(backup_file) |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
backup_encryption_callback(backup_file, start = 0, part = 0, iv = 0) { |
102
|
|
|
var $this = this; |
103
|
|
|
|
104
|
|
|
if (backup_file) { |
105
|
|
|
jQuery.ajax({ |
106
|
|
|
url: ajaxurl, |
107
|
|
|
method: 'post', |
108
|
|
|
data: {action: 'backup_encryption', file: backup_file, start: start, part: part, iv: iv}, |
109
|
|
|
success: function (response) { |
110
|
|
|
|
111
|
|
|
if (response.total_size !== undefined) { |
112
|
|
|
jQuery("#backup_encryption_modal .progress > div").removeClass('indeterminate').addClass("determinate"); |
113
|
|
|
var percent = parseInt(response.start * 100) / parseInt(response.total_size) |
114
|
|
|
jQuery("#backup_encryption_modal .progress .determinate").css('width', parseInt(percent) + "%") |
115
|
|
|
jQuery("#backup_encryption_modal .modal-content .files-list").text("Encrypting "+response.processing_file+" "+ parseInt(percent) + "%") |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (response.error) { |
119
|
|
|
jQuery("#backup_encryption_modal .notice").show(); |
120
|
|
|
jQuery("#backup_encryption_modal .files-list").addClass("error").prepend(response.message+" ") |
121
|
|
|
jQuery("#backup_encryption_modal .progress > div").addClass("determinate").removeClass("indeterminate").css('width', "100%") |
122
|
|
|
return; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
if (!response.finished && jQuery('#backup_encryption_modal').is(':visible')) { |
127
|
|
|
$this.backup_encryption_callback(backup_file, response.start, response.part, response.iv) |
128
|
|
|
} else { |
129
|
|
|
jQuery("#backup_encryption_modal .progress > div").addClass('determinate').removeClass("indeterminate").css('width', "100%") |
130
|
|
|
jQuery("#backup_encryption_modal .modal-content .files-list").text("Done Encrypting.") |
131
|
|
|
dataTable.ajax.reload(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
}, |
135
|
|
|
error: function (xhr, textStatus, error) { |
136
|
|
|
jQuery("#backup_encryption_modal .files-list").addClass("error").prepend(textStatus + error) |
137
|
|
|
}, |
138
|
|
|
dataType: 'json' |
139
|
|
|
}); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
backup_encryption(backup_file, start = 0) { |
146
|
|
|
this.file_counter = 0 |
147
|
|
|
|
148
|
|
|
jQuery("#backup_encryption_modal .modal-content .backup-name").text(backup_file); |
149
|
|
|
jQuery("#backup_encryption_modal").modal('open'); |
150
|
|
|
jQuery("#backup_encryption_modal .progress > div"); |
151
|
|
|
jQuery("#backup_encryption_modal .notice").show(); |
152
|
|
|
|
153
|
|
|
jQuery("#backup_encryption_modal a.btn").attr('onclick', "var xcloner_manage_backups = new Xcloner_Manage_Backups();xcloner_manage_backups.backup_encryption('"+backup_file+"', true)"); |
154
|
|
|
jQuery("#backup_encryption_modal .modal-content .files-list").text("").removeClass("error"); |
155
|
|
|
|
156
|
|
|
if( start ) { |
157
|
|
|
jQuery("#backup_encryption_modal .notice").hide(); |
158
|
|
|
this.backup_encryption_callback(backup_file) |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
backup_decryption_callback(backup_file, start = 0, part = 0, iv = 0) { |
163
|
|
|
var $this = this; |
164
|
|
|
|
165
|
|
|
var decryption_key = jQuery('#backup_decryption_modal #decryption_key').val(); |
166
|
|
|
|
167
|
|
|
if (backup_file) { |
168
|
|
|
jQuery.ajax({ |
169
|
|
|
url: ajaxurl, |
170
|
|
|
method: 'post', |
171
|
|
|
data: {action: 'backup_decryption', file: backup_file, start: start, part: part, iv: iv, decryption_key: decryption_key}, |
172
|
|
|
success: function (response) { |
173
|
|
|
|
174
|
|
|
if(!response.start){ |
175
|
|
|
response.start = 0; |
176
|
|
|
} |
177
|
|
|
if (response.total_size !== undefined) { |
178
|
|
|
jQuery("#backup_decryption_modal .progress > div").removeClass('indeterminate').addClass("determinate"); |
179
|
|
|
var percent = parseInt(response.start * 100) / parseInt(response.total_size) |
180
|
|
|
jQuery("#backup_decryption_modal .progress .determinate").css('width', parseInt(percent) + "%") |
181
|
|
|
jQuery("#backup_decryption_modal .modal-content .files-list").text("Decrypting "+response.processing_file+" "+ parseInt(percent) + "%") |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if (response.error) { |
185
|
|
|
jQuery("#backup_decryption_modal .files-list").addClass("error").prepend(response.message+" ") |
186
|
|
|
jQuery("#backup_decryption_modal .progress > div").addClass("determinate").removeClass("indeterminate").css('width', "100%") |
187
|
|
|
jQuery("#backup_decryption_modal .notice").show(); |
188
|
|
|
return; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
if (!response.finished && jQuery('#backup_decryption_modal').is(':visible')) { |
193
|
|
|
$this.backup_decryption_callback(backup_file, response.start, response.part, response.iv) |
194
|
|
|
} else { |
195
|
|
|
jQuery("#backup_decryption_modal .progress > div").addClass('determinate').removeClass("indeterminate").css('width', "100%") |
196
|
|
|
jQuery("#backup_decryption_modal .modal-content .files-list").text("Done Decrypting.") |
197
|
|
|
dataTable.ajax.reload(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
}, |
201
|
|
|
error: function (xhr, textStatus, error) { |
202
|
|
|
jQuery("#backup_decryption_modal .files-list").addClass("error").prepend(textStatus + error) |
203
|
|
|
}, |
204
|
|
|
dataType: 'json' |
205
|
|
|
}); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
backup_decryption(backup_file, start = 0) { |
211
|
|
|
this.file_counter = 0 |
212
|
|
|
|
213
|
|
|
jQuery("#backup_decryption_modal .modal-content .backup-name").text(backup_file); |
214
|
|
|
jQuery("#backup_decryption_modal").modal('open'); |
215
|
|
|
jQuery("#backup_decryption_modal .progress > div"); |
216
|
|
|
jQuery("#backup_decryption_modal .notice").show(); |
217
|
|
|
|
218
|
|
|
jQuery("#backup_decryption_modal a.btn").attr('onclick', "var xcloner_manage_backups = new Xcloner_Manage_Backups();xcloner_manage_backups.backup_decryption('"+backup_file+"', true)"); |
219
|
|
|
jQuery("#backup_decryption_modal .modal-content .files-list").text("").removeClass("error"); |
220
|
|
|
|
221
|
|
|
if( start ) { |
222
|
|
|
jQuery("#backup_decryption_modal .notice").hide(); |
223
|
|
|
this.backup_decryption_callback(backup_file) |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
cloud_upload(backup_file) { |
228
|
|
|
jQuery('#remote_storage_modal').find(".backup_name").text(backup_file) |
229
|
|
|
jQuery('#remote_storage_modal').find("input.backup_name").val(backup_file) |
230
|
|
|
Materialize.updateTextFields(); |
231
|
|
|
jQuery('.col select').material_select(); |
232
|
|
|
jQuery("#remote_storage_modal").modal('open') |
233
|
|
|
jQuery("#remote_storage_modal .status").hide(); |
234
|
|
|
|
235
|
|
|
jQuery(".remote-storage-form").off("submit").on("submit", function () { |
236
|
|
|
jQuery("#remote_storage_modal .status").show(); |
237
|
|
|
jQuery("#remote_storage_modal .status .progress .indeterminate").removeClass("determinate").css("width", "0%"); |
238
|
|
|
jQuery("#remote_storage_modal .status-text").removeClass("error").text(""); |
239
|
|
|
|
240
|
|
|
var storage_type = jQuery("#remote_storage_modal select").val(); |
241
|
|
|
|
242
|
|
|
if (backup_file) { |
243
|
|
|
jQuery.ajax({ |
244
|
|
|
url: ajaxurl, |
245
|
|
|
method: 'post', |
246
|
|
|
data: {action: 'upload_backup_to_remote', file: backup_file, storage_type: storage_type}, |
247
|
|
|
success: function (response) { |
248
|
|
|
if (response.error) { |
249
|
|
|
jQuery("#remote_storage_modal .status-text").addClass("error").text(response.message) |
250
|
|
|
} else { |
251
|
|
|
jQuery("#remote_storage_modal .status-text").removeClass("error").text("done") |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
jQuery("#remote_storage_modal .status .progress .indeterminate").addClass("determinate").css("width", "100%"); |
255
|
|
|
}, |
256
|
|
|
error: function (xhr, textStatus, error) { |
257
|
|
|
jQuery("#remote_storage_modal .status-text").addClass("error").text(textStatus + error) |
258
|
|
|
}, |
259
|
|
|
dataType: 'json' |
260
|
|
|
}); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
return false; |
264
|
|
|
}) |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
copy_remote_to_local(backup_file) { |
268
|
|
|
jQuery("#local_storage_upload_modal").modal('open'); |
269
|
|
|
jQuery("#local_storage_upload_modal .modal-content .backup-name").text(backup_file); |
270
|
|
|
jQuery("#local_storage_upload_modal .status-text").removeClass("error").text(""); |
271
|
|
|
jQuery("#local_storage_upload_modal .status .progress .indeterminate").removeClass("determinate").css("width", "0%"); |
272
|
|
|
|
273
|
|
|
if (backup_file) { |
274
|
|
|
jQuery.ajax({ |
275
|
|
|
url: ajaxurl, |
276
|
|
|
method: 'post', |
277
|
|
|
data: {action: 'copy_backup_remote_to_local', file: backup_file, storage_type: this.storage_selection}, |
278
|
|
|
success: function (response) { |
279
|
|
|
if (response.error) { |
280
|
|
|
jQuery("#local_storage_upload_modal .status-text").addClass("error").text(response.message) |
281
|
|
|
} else { |
282
|
|
|
jQuery("#local_storage_upload_modal .status-text").removeClass("error").text("done") |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
jQuery("#local_storage_upload_modal .status .progress .indeterminate").addClass("determinate").css("width", "100%"); |
286
|
|
|
}, |
287
|
|
|
error: function (xhr, textStatus, error) { |
288
|
|
|
jQuery("#local_storage_upload_modal .status-text").addClass("error").text(textStatus + error) |
289
|
|
|
}, |
290
|
|
|
dataType: 'json' |
291
|
|
|
}); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
//end class |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
jQuery(document).ready(function () { |
300
|
|
|
|
301
|
|
|
var xcloner_manage_backups = new Xcloner_Manage_Backups(); |
302
|
|
|
|
303
|
|
|
xcloner_manage_backups.storage_selection = getUrlParam('storage_selection'); |
304
|
|
|
|
305
|
|
|
dataTable = jQuery('#manage_backups').DataTable({ |
306
|
|
|
'responsive': true, |
307
|
|
|
'bFilter': true, |
308
|
|
|
"order": [[2, "desc"]], |
309
|
|
|
buttons: [ |
310
|
|
|
'selectAll', |
311
|
|
|
'selectNone' |
312
|
|
|
], |
313
|
|
|
"language": { |
314
|
|
|
"emptyTable": "No backups available", |
315
|
|
|
buttons: { |
316
|
|
|
selectAll: "Select all items", |
317
|
|
|
selectNone: "Select none" |
318
|
|
|
} |
319
|
|
|
}, |
320
|
|
|
columnDefs: [ |
321
|
|
|
{targets: 'no-sort', orderable: false} |
322
|
|
|
], |
323
|
|
|
"columns": [ |
324
|
|
|
{"width": "1%"}, |
325
|
|
|
{"width": "25%"}, |
326
|
|
|
{"width": "5%"}, |
327
|
|
|
{"width": "5%"}, |
328
|
|
|
{"width": "9%"}, |
329
|
|
|
], |
330
|
|
|
"oLanguage": { |
331
|
|
|
"sSearch": "", |
332
|
|
|
"sSearchPlaceholder": 'Search Backups', |
333
|
|
|
}, |
334
|
|
|
"ajax": ajaxurl+"?action=get_manage_backups_list&storage_selection="+xcloner_manage_backups.storage_selection, |
335
|
|
|
"fnDrawCallback": function (oSettings) { |
|
|
|
|
336
|
|
|
|
337
|
|
|
jQuery("a.expand-multipart").on("click", function () { |
338
|
|
|
jQuery(this).parent().find("ul.multipart").toggle(); |
339
|
|
|
jQuery(this).parent().find("a.expand-multipart.remove").toggle(); |
340
|
|
|
jQuery(this).parent().find("a.expand-multipart.add").toggle(); |
341
|
|
|
}) |
342
|
|
|
|
343
|
|
|
jQuery(this).off("click", ".delete").on("click", ".delete", function (e) { |
344
|
|
|
|
345
|
|
|
var hash = jQuery(this).attr('href'); |
346
|
|
|
var id = hash.substr(1) |
347
|
|
|
var data = ""; |
|
|
|
|
348
|
|
|
|
349
|
|
|
if (show_delete_alert) { |
350
|
|
|
if (confirm('Are you sure you want to delete it?')) { |
|
|
|
|
351
|
|
|
xcloner_manage_backups.delete_backup_by_name(id, (this), dataTable); |
352
|
|
|
} |
353
|
|
|
} else { |
354
|
|
|
xcloner_manage_backups.delete_backup_by_name(id, (this), dataTable); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
e.preventDefault(); |
359
|
|
|
}) |
360
|
|
|
|
361
|
|
|
jQuery(this).off("click", ".download").on("click", ".download", function (e) { |
362
|
|
|
var hash = jQuery(this).attr('href'); |
363
|
|
|
var id = hash.substr(1) |
364
|
|
|
xcloner_manage_backups.download_backup_by_name(id); |
365
|
|
|
e.preventDefault(); |
366
|
|
|
}) |
367
|
|
|
|
368
|
|
|
jQuery(this).off("click", ".cloud-upload").on("click", ".cloud-upload", function (e) { |
369
|
|
|
var hash = jQuery(this).attr('href'); |
370
|
|
|
var id = hash.substr(1) |
371
|
|
|
xcloner_manage_backups.cloud_upload(id); |
372
|
|
|
e.preventDefault(); |
373
|
|
|
}) |
374
|
|
|
|
375
|
|
|
jQuery(this).off("click", ".copy-remote-to-local").on("click", ".copy-remote-to-local", function (e) { |
376
|
|
|
var hash = jQuery(this).attr('href'); |
377
|
|
|
var id = hash.substr(1) |
378
|
|
|
xcloner_manage_backups.copy_remote_to_local(id); |
379
|
|
|
e.preventDefault(); |
380
|
|
|
}) |
381
|
|
|
|
382
|
|
|
jQuery(this).off("click", ".list-backup-content").on("click", ".list-backup-content", function (e) { |
383
|
|
|
var hash = jQuery(this).attr('href'); |
384
|
|
|
var id = hash.substr(1) |
385
|
|
|
xcloner_manage_backups.list_backup_content(id); |
386
|
|
|
e.preventDefault(); |
387
|
|
|
}) |
388
|
|
|
|
389
|
|
|
jQuery(this).off("click", ".backup-encryption").on("click", ".backup-encryption", function (e) { |
390
|
|
|
var hash = jQuery(this).attr('href'); |
391
|
|
|
var id = hash.substr(1) |
392
|
|
|
xcloner_manage_backups.backup_encryption(id); |
393
|
|
|
e.preventDefault(); |
394
|
|
|
}) |
395
|
|
|
|
396
|
|
|
jQuery(this).off("click", ".backup-decryption").on("click", ".backup-decryption", function (e) { |
397
|
|
|
var hash = jQuery(this).attr('href'); |
398
|
|
|
var id = hash.substr(1) |
399
|
|
|
xcloner_manage_backups.backup_decryption(id); |
400
|
|
|
e.preventDefault(); |
401
|
|
|
}) |
402
|
|
|
|
403
|
|
|
} |
404
|
|
|
}); |
405
|
|
|
|
406
|
|
|
jQuery('#select_all').click(function () { |
407
|
|
|
jQuery('input:checkbox').prop('checked', this.checked); |
408
|
|
|
}); |
409
|
|
|
|
410
|
|
|
jQuery(".delete-all").click(function () { |
411
|
|
|
if (confirm('Are you sure you want to delete selected items?')) { |
|
|
|
|
412
|
|
|
show_delete_alert = 0; |
413
|
|
|
jQuery('input:checkbox').each(function () { |
414
|
|
|
if (jQuery(this).is(":checked")) { |
415
|
|
|
jQuery(this).parent().parent().parent().find(".delete").trigger('click'); |
416
|
|
|
} |
417
|
|
|
}) |
418
|
|
|
show_delete_alert = 1; |
419
|
|
|
} |
420
|
|
|
}) |
421
|
|
|
|
422
|
|
|
jQuery("#remote_storage_modal").modal(); |
423
|
|
|
jQuery("#local_storage_upload_modal").modal(); |
424
|
|
|
|
425
|
|
|
jQuery("#storage_selection").on("change", function () { |
426
|
|
|
window.location = window.location.href.split('&storage_selection')[0] + "&storage_selection=" + jQuery(this).val(); |
427
|
|
|
}) |
428
|
|
|
|
429
|
|
|
jQuery('.modal').on('hide',function(){ |
430
|
|
|
alert('ok') |
|
|
|
|
431
|
|
|
}) |
432
|
|
|
|
433
|
|
|
|
434
|
|
|
var show_delete_alert = 1; |
435
|
|
|
|
436
|
|
|
|
437
|
|
|
}); |
438
|
|
|
|