1
|
<?php
|
2
|
/*
|
3
|
diag_confbak.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
* Copyright (c) 2005 Colin Smith
|
8
|
*
|
9
|
* Redistribution and use in source and binary forms, with or without modification,
|
10
|
* are permitted provided that the following conditions are met:
|
11
|
*
|
12
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13
|
* this list of conditions and the following disclaimer.
|
14
|
*
|
15
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
* notice, this list of conditions and the following disclaimer in
|
17
|
* the documentation and/or other materials provided with the
|
18
|
* distribution.
|
19
|
*
|
20
|
* 3. All advertising materials mentioning features or use of this software
|
21
|
* must display the following acknowledgment:
|
22
|
* "This product includes software developed by the pfSense Project
|
23
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24
|
*
|
25
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26
|
* endorse or promote products derived from this software without
|
27
|
* prior written permission. For written permission, please contact
|
28
|
* coreteam@pfsense.org.
|
29
|
*
|
30
|
* 5. Products derived from this software may not be called "pfSense"
|
31
|
* nor may "pfSense" appear in their names without prior written
|
32
|
* permission of the Electric Sheep Fencing, LLC.
|
33
|
*
|
34
|
* 6. Redistributions of any form whatsoever must retain the following
|
35
|
* acknowledgment:
|
36
|
*
|
37
|
* "This product includes software developed by the pfSense Project
|
38
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39
|
*
|
40
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52
|
*
|
53
|
* ====================================================================
|
54
|
*
|
55
|
*/
|
56
|
|
57
|
##|+PRIV
|
58
|
##|*IDENT=page-diagnostics-configurationhistory
|
59
|
##|*NAME=Diagnostics: Configuration History
|
60
|
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
|
61
|
##|*MATCH=diag_confbak.php*
|
62
|
##|-PRIV
|
63
|
|
64
|
require("guiconfig.inc");
|
65
|
|
66
|
if (isset($_POST['backupcount'])) {
|
67
|
if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
|
68
|
$config['system']['backupcount'] = $_POST['backupcount'];
|
69
|
$changedescr = $config['system']['backupcount'];
|
70
|
} else {
|
71
|
unset($config['system']['backupcount']);
|
72
|
$changedescr = gettext("(platform default)");
|
73
|
}
|
74
|
write_config(sprintf(gettext("Changed backup revision count to %s"), $changedescr));
|
75
|
} elseif ($_GET) {
|
76
|
if (!isset($_GET['newver']) && !isset($_GET['rmver']) && !isset($_GET['getcfg']) && !isset($_GET['diff'])) {
|
77
|
header("Location: diag_confbak.php");
|
78
|
return;
|
79
|
}
|
80
|
|
81
|
conf_mount_rw();
|
82
|
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
|
83
|
|
84
|
if ($_GET['newver'] != "") {
|
85
|
if (config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0) {
|
86
|
$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['newver']), htmlspecialchars($confvers[$_GET['newver']]['description']));
|
87
|
} else {
|
88
|
$savemsg = gettext("Unable to revert to the selected configuration.");
|
89
|
}
|
90
|
}
|
91
|
if ($_GET['rmver'] != "") {
|
92
|
unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
|
93
|
$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['rmver']), htmlspecialchars($confvers[$_GET['rmver']]['description']));
|
94
|
}
|
95
|
conf_mount_ro();
|
96
|
}
|
97
|
|
98
|
if ($_GET['getcfg'] != "") {
|
99
|
$_GET['getcfg'] = basename($_GET['getcfg']);
|
100
|
$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
|
101
|
|
102
|
$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
|
103
|
$exp_data = file_get_contents($file);
|
104
|
$exp_size = strlen($exp_data);
|
105
|
|
106
|
header("Content-Type: application/octet-stream");
|
107
|
header("Content-Disposition: attachment; filename={$exp_name}");
|
108
|
header("Content-Length: $exp_size");
|
109
|
echo $exp_data;
|
110
|
exit;
|
111
|
}
|
112
|
|
113
|
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
|
114
|
(is_numeric($_GET['oldtime'])) &&
|
115
|
(is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
|
116
|
$diff = "";
|
117
|
$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
|
118
|
$oldtime = $_GET['oldtime'];
|
119
|
if ($_GET['newtime'] == 'current') {
|
120
|
$newfile = $g['conf_path'] . '/config.xml';
|
121
|
$newtime = $config['revision']['time'];
|
122
|
} else {
|
123
|
$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
|
124
|
$newtime = $_GET['newtime'];
|
125
|
}
|
126
|
if (file_exists($oldfile) && file_exists($newfile)) {
|
127
|
exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
|
128
|
}
|
129
|
}
|
130
|
|
131
|
cleanup_backupcache(false);
|
132
|
$confvers = get_backups();
|
133
|
unset($confvers['versions']);
|
134
|
|
135
|
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), gettext("Config History"));
|
136
|
include("head.inc");
|
137
|
|
138
|
if ($savemsg) {
|
139
|
print_info_box($savemsg, 'success');
|
140
|
}
|
141
|
|
142
|
$tab_array = array();
|
143
|
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), false, "diag_backup.php");
|
144
|
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
|
145
|
display_top_tabs($tab_array);
|
146
|
|
147
|
if ($diff) {
|
148
|
?>
|
149
|
<div class="panel panel-default">
|
150
|
<div class="panel-heading">
|
151
|
<h2 class="panel-title">
|
152
|
<?=sprintf(gettext('Configuration Diff from %1$s to %2$s'), date(gettext("n/j/y H:i:s"), $oldtime), date(gettext("n/j/y H:i:s"), $newtime))?>
|
153
|
</h2>
|
154
|
</div>
|
155
|
<div class="panel-body table-responsive">
|
156
|
<!-- This table is left un-bootstrapped to maintain the original diff format output -->
|
157
|
<table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
|
158
|
|
159
|
<?php
|
160
|
foreach ($diff as $line) {
|
161
|
switch (substr($line, 0, 1)) {
|
162
|
case "+":
|
163
|
$color = "#caffd3";
|
164
|
break;
|
165
|
case "-":
|
166
|
$color = "#ffe8e8";
|
167
|
break;
|
168
|
case "@":
|
169
|
$color = "#a0a0a0";
|
170
|
break;
|
171
|
default:
|
172
|
$color = "#ffffff";
|
173
|
}
|
174
|
?>
|
175
|
<tr>
|
176
|
<td class="diff-text" style="vertical-align:middle; background-color:<?=$color;?>; white-space:pre-wrap;"><?=htmlentities($line)?></td>
|
177
|
</tr>
|
178
|
<?php
|
179
|
}
|
180
|
?>
|
181
|
</table>
|
182
|
</div>
|
183
|
</div>
|
184
|
<?php
|
185
|
}
|
186
|
|
187
|
$form = new Form(false);
|
188
|
|
189
|
$section = new Form_Section('Saved Configurations', 'savedconfig', COLLAPSIBLE|SEC_CLOSED);
|
190
|
|
191
|
$section->addInput(new Form_Input(
|
192
|
'backupcount',
|
193
|
'Backup Count',
|
194
|
'number',
|
195
|
$config['system']['backupcount']
|
196
|
))->setHelp('Maximum number of old configurations to keep. By default this is 30 for a full install or 5 on NanoBSD. ');
|
197
|
|
198
|
$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
|
199
|
|
200
|
$section->addInput(new Form_StaticText(
|
201
|
'Current space used by backups',
|
202
|
$space
|
203
|
));
|
204
|
|
205
|
$section->addInput(new Form_Button(
|
206
|
'Submit',
|
207
|
gettext("Save"),
|
208
|
null,
|
209
|
'fa-save'
|
210
|
))->addClass('btn-primary');
|
211
|
|
212
|
$form->add($section);
|
213
|
|
214
|
print($form);
|
215
|
|
216
|
if (is_array($confvers)) {
|
217
|
?>
|
218
|
<div>
|
219
|
<div class="infoblock blockopen">
|
220
|
<?php print_info_box(
|
221
|
gettext(
|
222
|
'To view the differences between an older configuration and a newer configuration, ' .
|
223
|
'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
|
224
|
'then press the "Diff" button.'),
|
225
|
'info', false); ?>
|
226
|
</div>
|
227
|
</div>
|
228
|
<?php
|
229
|
}
|
230
|
?>
|
231
|
|
232
|
<form action="diag_confbak.php" method="get">
|
233
|
<div class="table-responsive">
|
234
|
<table class="table table-striped table-hover table-condensed">
|
235
|
<?php
|
236
|
if (is_array($confvers)):
|
237
|
?>
|
238
|
<thead>
|
239
|
<tr>
|
240
|
<th colspan="2">
|
241
|
<button type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>">
|
242
|
<i class="fa fa-exchange icon-embed-btn"></i>
|
243
|
<?=gettext("Diff"); ?>
|
244
|
</button>
|
245
|
</th>
|
246
|
<th><?=gettext("Date")?></th>
|
247
|
<th><?=gettext("Version")?></th>
|
248
|
<th><?=gettext("Size")?></th>
|
249
|
<th><?=gettext("Configuration Change")?></th>
|
250
|
<th><?=gettext("Actions")?></th>
|
251
|
</tr>
|
252
|
</thead>
|
253
|
<tbody>
|
254
|
<!-- First row is the current configuration -->
|
255
|
<tr style="vertical-align:top;">
|
256
|
<td></td>
|
257
|
<td>
|
258
|
<input type="radio" name="newtime" value="current" />
|
259
|
</td>
|
260
|
<td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
|
261
|
<td><?= $config['version'] ?></td>
|
262
|
<td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
|
263
|
<td><?= htmlspecialchars($config['revision']['description']) ?></td>
|
264
|
<td><?=gettext("Current configuration")?></td>
|
265
|
</tr>
|
266
|
<?php
|
267
|
// And now for the table of prior backups
|
268
|
$c = 0;
|
269
|
foreach ($confvers as $version):
|
270
|
if ($version['time'] != 0) {
|
271
|
$date = date(gettext("n/j/y H:i:s"), $version['time']);
|
272
|
} else {
|
273
|
$date = gettext("Unknown");
|
274
|
}
|
275
|
?>
|
276
|
<tr>
|
277
|
<td>
|
278
|
<input type="radio" name="oldtime" value="<?=$version['time']?>" />
|
279
|
</td>
|
280
|
<td>
|
281
|
<?php
|
282
|
if ($c < (count($confvers) - 1)) {
|
283
|
?>
|
284
|
<input type="radio" name="newtime" value="<?=$version['time']?>" />
|
285
|
<?php
|
286
|
}
|
287
|
$c++;
|
288
|
?>
|
289
|
</td>
|
290
|
<td><?= $date ?></td>
|
291
|
<td><?= $version['version'] ?></td>
|
292
|
<td><?= format_bytes($version['filesize']) ?></td>
|
293
|
<td><?= htmlspecialchars($version['description']) ?></td>
|
294
|
<td>
|
295
|
<a class="fa fa-undo" title="<?=gettext('Revert config')?>" href="diag_confbak.php?newver=<?=$version['time']?>" onclick="return confirm('<?=gettext("Confirmation Required to replace the current configuration with this backup.")?>')"></a>
|
296
|
<a class="fa fa-download" title="<?=gettext('Download config')?>" href="diag_confbak.php?getcfg=<?=$version['time']?>"></a>
|
297
|
<a class="fa fa-trash" title="<?=gettext('Delete config')?>" href="diag_confbak.php?rmver=<?=$version['time']?>"></a>
|
298
|
</td>
|
299
|
</tr>
|
300
|
<?php
|
301
|
endforeach;
|
302
|
?>
|
303
|
<tr>
|
304
|
<td colspan="2">
|
305
|
<button type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>">
|
306
|
<i class="fa fa-exchange icon-embed-btn"></i>
|
307
|
<?=gettext("Diff"); ?>
|
308
|
</button>
|
309
|
</td>
|
310
|
<td colspan="5"></td>
|
311
|
</tr>
|
312
|
<?php
|
313
|
else:
|
314
|
print_info_box(gettext("No backups found."), 'danger');
|
315
|
endif;
|
316
|
?>
|
317
|
</tbody>
|
318
|
</table>
|
319
|
</div>
|
320
|
</form>
|
321
|
|
322
|
<?php include("foot.inc");
|