/
index.phtml
479 lines (403 loc) · 16.3 KB
/
index.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<?php
/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
$title = _('Restore');
$this->headTitle($title);
?>
<ul class="nav nav-tabs">
<li class="active"><a href="<?php echo $this->url('restore', array('action'=>'index')); ?>"><?php echo $this->translate('Restore multiple files'); ?></a></li>
<li><a href="<?php echo $this->url('restore', array('action'=>'versions')); ?>"><?php echo $this->translate('Restore specific file version'); ?></a></li>
</ul>
<br />
<?php if($this->acl_alert) : echo $this->ACLAlert($this->invalid_commands); elseif(!$this->acl_alert) : ?>
<!-- modal-001 start -->
<div id="modal-001" class="modal fade modal-001" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel1">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate("Failed to retrieve data from Bareos director"); ?></h4>
</div>
<div class="modal-body">
<p><?php echo $this->translate("Error message received:"); ?></p>
<p class="text-danger"><?php echo $this->errors; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php echo $this->translate("Close"); ?></button>
</div>
</div>
</div>
</div>
<!-- modal-001 end -->
<!-- modal-002 start -->
<div id="modal-002" class="modal fade modal-002" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel2">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate("Director message"); ?></h4>
</div>
<div class="modal-body">
<pre><code>
<?php echo $this->result; ?>
</code></pre>
</div>
<div class="modal-footer">
<?php $jobid = substr($this->result, stripos($this->result, 'JobId=') + 6 ); ?>
<a class="btn btn-primary" href="<?php echo $this->basePath() . '/job/details/' . $jobid; ?>"><?php echo $this->translate("Job report"); ?></a>
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php echo $this->translate("Close"); ?></button>
</div>
</div>
</div>
</div>
<!-- modal-002 end -->
<!-- modal-003 start -->
<div id="modal-003" class="modal fade modal-002" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel2">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate("Confirm restore job submit"); ?></h4>
</div>
<div class="modal-body">
<p>A restore job with the parameters given below will be scheduled.</p>
<table id="restore-params-table" style="border-collapse: separate; border-spacing: 10px;">
</table>
</div>
<div class="modal-footer">
<button id="modal-003-btn-cancel" type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate("Cancel"); ?></button>
<button id="modal-003-btn-ok" type="button" class="btn btn-primary"><?php echo $this->translate("OK"); ?></button>
</div>
</div>
</div>
</div>
<!-- modal-003 end -->
<!-- modal-004 start -->
<div id="modal-004" class="modal fade modal-002" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel2">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body">
<p><?php echo $this->translate("No files or directories selected to restore!"); ?></p>
</div>
<div class="modal-footer">
<button id="modal-004-btn-ok" type="button" class="btn btn-primary" data-dismiss="modal"><?php echo $this->translate("OK"); ?></button>
</div>
</div>
</div>
</div>
<!-- modal-004 end -->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Restore</h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<?php
$form->prepare();
$form->setAttribute('class','form-horizontal');
echo $this->form()->openTag($form);
?>
<div class="row">
<div class="col-md-3">
<?php
echo '<p>'.$this->formRow($form->get('client')).'</p>';
echo '<p>'.$this->formRow($form->get('backups')).'</p>';
echo '<p>'.$this->formRow($form->get('mergefilesets')).'</p>';
echo '<p>'.$this->formRow($form->get('mergejobs')).'</p>';
echo '<p>'.$this->formRow($form->get('restorejob')).'</p>';
echo '<p>'.$this->formRow($form->get('restoreclient')).'</p>';
echo '<p>'.$this->formRow($form->get('replace')).'</p>';
echo '<p>'.$this->formRow($form->get('where')).'</p>';
echo '<p>'.$this->formRow($form->get('form-submit')).'</p>';
// Hidden fields
echo $this->formRow($form->get('checked_files'));
echo $this->formRow($form->get('checked_directories'));
echo $this->formRow($form->get('jobids_hidden'));
?>
</div>
<div class="col-md-9">
<?php
echo '<strong>';
echo $this->translate("File selection");
echo '</strong>';
?>
<div class="panel panel-default">
<div id="filebrowser"></div>
</div>
<?php
?>
</div>
</div>
<?php
echo $this->form()->closeTag($form);
?>
</div>
</div>
</div>
<?php
echo $this->headScript()->prependFile($this->basePath() . '/js/jstreegrid.js');
echo $this->headScript()->prependFile($this->basePath() . '/js/jstree.min.js');
echo $this->headLink()->prependStylesheet($this->basePath() . '/css/jstree.min.css');
?>
<style>
.jsTreeGridHeader {
background-color: #eeeeee;
color: #000000;
}
</style>
<script type="text/javascript">
function format_bibytes(v) {
if (v === 0) {
return "0.00 B";
} else {
const units = ["B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"];
const i = Math.floor(Math.log2(v) / 10);
return parseFloat((v / (1 << (i * 10))).toFixed(2)) + " " + units[i];
}
}
var modalConfirm = function(callback) {
$("#modal-003-btn-ok").on("click", function() {
callback(true);
$("#modal-003").modal('hide');
});
$("#modal-003-btn-cancel").on("click", function() {
callback(false);
$("#modal-003").modal('hide');
});
}
modalConfirm(function(confirm) {
if(confirm){
submitRestoreFormData();
} else{
return false;
}
});
function verifyRestoreFormDataFileSelection() {
var checked_files = [];
var checked_directories = [];
var checked_ids = $('#filebrowser').jstree('get_checked','full',true);
$(checked_ids).each(function () {
if(this.data.type === 'F') {
checked_files.push(this.id);
}
else if(this.data.type === 'D') {
checked_directories.push(Math.abs(this.id));
}
});
document.getElementById('checked_files').value = checked_files.join(",");
document.getElementById('checked_directories').value = checked_directories.join(",");
if(checked_ids.length === 0) {
$("#modal-004").modal();
} else {
let client = document.getElementById('client').value;
let restoreclient = document.getElementById('restoreclient').value;
let replace = document.getElementById('replace').value;
let where = document.getElementById('where').value;
let selectedNumberOfDirectories = checked_directories.length;
let selectedNumberOfFiles = checked_files.length;
updateModalRestoreParamsTable(client, restoreclient, replace, where, selectedNumberOfDirectories, selectedNumberOfFiles);
$("#modal-003").modal();
}
}
function submitRestoreFormData() {
//document.getElementById('restore').submit();
document.restore.submit();
}
function updateModalRestoreParamsTable(client, restoreclient, replace, where, selectedNumberOfDirectories, selectedNumberOfFiles) {
$('#restore-params-table').empty();
$('#restore-params-table').append("<tr><td><b>Client:</b></td><td>" + client + "</td></tr>");
$('#restore-params-table').append("<tr><td><b>Restore to client:</b></td><td>" + restoreclient + "</td></tr>");
$('#restore-params-table').append("<tr><td><b>Replace files on client:</b></td><td>" + replace + "</td></tr>");
$('#restore-params-table').append("<tr><td><b>Restore location on client:</b></td><td>" + where + "</td></tr>");
$('#restore-params-table').append("<tr><td><b>Directories selected:</b></td><td>" + selectedNumberOfDirectories + "</td></tr>");
$('#restore-params-table').append("<tr><td><b>Files selected:</b></td><td>" + selectedNumberOfFiles + "</td></tr>");
}
function updateRestoreParams(k, v) {
var p = [];
var params = [];
if(k === 'client') {
p['jobid'] = '';
}
else {
p['jobid'] = '<?php echo $this->restore_params['jobid']; ?>';
}
p['client'] = '<?php echo $this->restore_params['client']; ?>';
if(k === 'client') {
p['restoreclient'] = '';
}
else {
p['restoreclient'] = '<?php echo $this->restore_params['restoreclient']; ?>';
}
p['restorejob'] = '<?php echo $this->restore_params['restorejob']; ?>';
p['where'] = '<?php echo $this->restore_params['where']; ?>';
p['fileset'] = '<?php echo $this->restore_params['fileset']; ?>';
if(k === 'mergejobs' && v === '1') {
p['mergefilesets'] = '1';
}
else {
p['mergefilesets'] = '<?php echo $this->restore_params['mergefilesets']; ?>';
}
if(k === 'mergefilesets' && v === '0') {
p['mergejobs'] = '0';
}
else {
p['mergejobs'] = '<?php echo $this->restore_params['mergejobs']; ?>';
}
p['limit'] = '<?php echo $this->restore_params['limit']; ?>';
p[k] = v;
var key;
for(key in p) {
params.push(key + "=" + p[key]);
}
return params.join('&');
}
function displayBvfsCacheUpdateInfo() {
$('#filebrowser').append("<br>");
$('#filebrowser').append("<div id='alert-bvfs' class='alert alert-info' role='alert'>");
$('#alert-bvfs').append("Update the Bvfs cache frequently to avoid timeouts.<br>");
$('#alert-bvfs').append("Please read the Bareos Documentation for further details.");
$('#filebrowser').append("</div>");
}
$(".search-input").keyup(function() {
var searchString = $(this).val();
console.log(searchString);
$('#filebrowser').jstree('search', searchString);
});
$("#filebrowser").bind("loading.jstree", function() {
displayBvfsCacheUpdateInfo();
$('#spinner').fadeIn('slow');
});
$("#filebrowser").bind("ready.jstree", function() {
$('#spinner').fadeOut('slow');
});
$('#filebrowser').jstree({
'plugins' : [ "grid", "checkbox", "state", "sort", "search", "types" ],
'core' : {
'animation': false,
'force_text': true,
'error': function (e) {
$('#filebrowser').html(
"<h4>There was an error while loading data for this tree.</h4>" +
"<p><b>Error: </b>" + e.error + "</p>" +
"<p><b>Plugin: </b>" + e.plugin + "</p>" +
"<p><b>Reason: </b> " + e.reason + "</p>" +
"<p><b>Data:</b></p>" +
"<pre><code>" + e.data + "</code></pre>"
);
displayBvfsCacheUpdateInfo();
},
'data' :{
'url' : '<?php echo $this->basePath() . "/restore/filebrowser?jobid=" . $this->restore_params['jobid'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'dataType' : 'json',
'data' : function (node) {
return { 'id' : node.id };
},
timeout: <?php echo $_SESSION['bareos']['filetree_refresh_timeout']; ?>,
},
},
'state' : {
'key': 'restore'
},
'grid' : {
width: '100%',
height: '60vh',
fixedHeader: true,
resizable: false,
columns: [
{
width: '100%',
height: '100%',
header: '<?php echo $this->translate("Name"); ?>',
headerClass: 'jsTreeGridHeader',
title: "_DATA_"
},
{
width: 150,
header: '<?php echo $this->translate("Size"); ?>',
headerClass: 'jsTreeGridHeader',
value: function(node) {
if(node.data.stat.size === 0) {
return null;
}
else {
return(format_bibytes(node.data.stat.size));
}
}
},
{
width: 150,
header: '<?php echo $this->translate("Last modification"); ?>',
headerClass: 'jsTreeGridHeader',
value: function(node) {
if(node.data.stat.mtime === 0) {
return null;
}
else {
return(moment.unix(node.data.stat.mtime).format("YYYY-MM-DD HH:mm:ss"));
}
}
}
],
},
'search' : {
"case_sensitive" : false,
"show_only_matches" : false
}
});
$('#jobid').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('jobid', this.value);
});
$('#client').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('client', this.value);
});
$('#restorejob').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('restorejob', this.value);
});
$('#mergefilesets').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('mergefilesets', this.value);
});
$('#mergejobs').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('mergejobs', this.value);
});
$('#limit').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('limit', this.value);
});
$("#btn-form-submit").on("click", function() {
verifyRestoreFormDataFileSelection();
});
$(document).ready(function(){
var errors = '<?php echo str_replace(array("\n","\r"), "", $this->errors); ?>';
if(errors.length > 0) {
$("#modal-001").modal();
}
var result = '<?php echo str_replace(array("\n","\r"), "", $this->result); ?>';
if(result.length > 0) {
$("#modal-002").modal();
}
});
</script>
<?php endif; ?>