1
|
<?php
|
2
|
/*
|
3
|
* diag_confbak.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
|
9
|
* Copyright (c) 2005 Colin Smith
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
* you may not use this file except in compliance with the License.
|
14
|
* You may obtain a copy of the License at
|
15
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* Unless required by applicable law or agreed to in writing, software
|
19
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21
|
* See the License for the specific language governing permissions and
|
22
|
* limitations under the License.
|
23
|
*/
|
24
|
|
25
|
##|+PRIV
|
26
|
##|*IDENT=page-diagnostics-configurationhistory
|
27
|
##|*NAME=Diagnostics: Configuration History
|
28
|
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
|
29
|
##|*WARN=standard-warning-root
|
30
|
##|*MATCH=diag_confbak.php*
|
31
|
##|-PRIV
|
32
|
|
33
|
require_once("guiconfig.inc");
|
34
|
|
35
|
if (isset($_POST['backupcount'])) {
|
36
|
if (!empty($_POST['backupcount']) && (!is_numericint($_POST['backupcount']) || ($_POST['backupcount'] < 0))) {
|
37
|
$input_errors[] = gettext("Invalid Backup Count specified");
|
38
|
}
|
39
|
|
40
|
if (!$input_errors) {
|
41
|
if (is_numericint($_POST['backupcount'])) {
|
42
|
$config['system']['backupcount'] = $_POST['backupcount'];
|
43
|
$changedescr = $config['system']['backupcount'];
|
44
|
} elseif (empty($_POST['backupcount'])) {
|
45
|
unset($config['system']['backupcount']);
|
46
|
$changedescr = gettext("(platform default)");
|
47
|
}
|
48
|
write_config(sprintf(gettext("Changed backup revision count to %s"), $changedescr));
|
49
|
}
|
50
|
}
|
51
|
|
52
|
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
|
53
|
|
54
|
if ($_POST['newver'] != "") {
|
55
|
if (config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0) {
|
56
|
$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['newver']), htmlspecialchars($confvers[$_POST['newver']]['description']));
|
57
|
} else {
|
58
|
$savemsg = gettext("Unable to revert to the selected configuration.");
|
59
|
}
|
60
|
}
|
61
|
|
62
|
if ($_POST['rmver'] != "") {
|
63
|
unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
|
64
|
$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']), htmlspecialchars($confvers[$_POST['rmver']]['description']));
|
65
|
}
|
66
|
|
67
|
if ($_REQUEST['getcfg'] != "") {
|
68
|
$_REQUEST['getcfg'] = basename($_REQUEST['getcfg']);
|
69
|
send_user_download('file',
|
70
|
$g['conf_path'] . '/backup/config-' . $_REQUEST['getcfg'] . '.xml',
|
71
|
"config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_REQUEST['getcfg']}.xml");
|
72
|
}
|
73
|
|
74
|
if (($_REQUEST['diff'] == 'Diff') && isset($_REQUEST['oldtime']) && isset($_REQUEST['newtime']) &&
|
75
|
(is_numeric($_REQUEST['oldtime'])) &&
|
76
|
(is_numeric($_REQUEST['newtime']) || ($_REQUEST['newtime'] == 'current'))) {
|
77
|
$diff = "";
|
78
|
$oldfile = $g['conf_path'] . '/backup/config-' . $_REQUEST['oldtime'] . '.xml';
|
79
|
$oldtime = $_REQUEST['oldtime'];
|
80
|
if ($_REQUEST['newtime'] == 'current') {
|
81
|
$newfile = $g['conf_path'] . '/config.xml';
|
82
|
$newtime = $config['revision']['time'];
|
83
|
} else {
|
84
|
$newfile = $g['conf_path'] . '/backup/config-' . $_REQUEST['newtime'] . '.xml';
|
85
|
$newtime = $_REQUEST['newtime'];
|
86
|
}
|
87
|
if (file_exists($oldfile) && file_exists($newfile)) {
|
88
|
exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
|
89
|
}
|
90
|
}
|
91
|
|
92
|
cleanup_backupcache(false);
|
93
|
$confvers = get_backups();
|
94
|
unset($confvers['versions']);
|
95
|
|
96
|
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), gettext("Config History"));
|
97
|
$pglinks = array("", "diag_backup.php", "@self");
|
98
|
include("head.inc");
|
99
|
|
100
|
if ($input_errors) {
|
101
|
print_input_errors($input_errors);
|
102
|
}
|
103
|
|
104
|
if ($savemsg) {
|
105
|
print_info_box($savemsg, 'success');
|
106
|
}
|
107
|
|
108
|
$tab_array = array();
|
109
|
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), false, "diag_backup.php");
|
110
|
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
|
111
|
display_top_tabs($tab_array);
|
112
|
|
113
|
if ($diff) {
|
114
|
?>
|
115
|
<div class="panel panel-default">
|
116
|
<div class="panel-heading">
|
117
|
<h2 class="panel-title">
|
118
|
<?=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))?>
|
119
|
</h2>
|
120
|
</div>
|
121
|
<div class="panel-body table-responsive">
|
122
|
<!-- This table is left un-bootstrapped to maintain the original diff format output -->
|
123
|
<table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
|
124
|
|
125
|
<?php
|
126
|
foreach ($diff as $line) {
|
127
|
switch (substr($line, 0, 1)) {
|
128
|
case "+":
|
129
|
$color = "#caffd3";
|
130
|
break;
|
131
|
case "-":
|
132
|
$color = "#ffe8e8";
|
133
|
break;
|
134
|
case "@":
|
135
|
$color = "#a0a0a0";
|
136
|
break;
|
137
|
default:
|
138
|
$color = "#ffffff";
|
139
|
}
|
140
|
?>
|
141
|
<tr>
|
142
|
<td class="diff-text" style="vertical-align:middle; background-color:<?=$color;?>; white-space:pre-wrap;"><?=htmlentities($line)?></td>
|
143
|
</tr>
|
144
|
<?php
|
145
|
}
|
146
|
?>
|
147
|
</table>
|
148
|
</div>
|
149
|
</div>
|
150
|
<?php
|
151
|
}
|
152
|
|
153
|
$form = new Form(false);
|
154
|
|
155
|
$section = new Form_Section('Configuration Backup Cache Settings', 'configsettings', COLLAPSIBLE|SEC_CLOSED);
|
156
|
|
157
|
$section->addInput(new Form_Input(
|
158
|
'backupcount',
|
159
|
'Backup Count',
|
160
|
'number',
|
161
|
$config['system']['backupcount'],
|
162
|
['min' => '0']
|
163
|
))->setHelp('Maximum number of old configurations to keep in the cache, 0 for no backups, or leave blank for the default value (%s for the current platform).', $g['default_config_backup_count']);
|
164
|
|
165
|
$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
|
166
|
|
167
|
$section->addInput(new Form_StaticText(
|
168
|
'Current space used by backups',
|
169
|
$space
|
170
|
));
|
171
|
|
172
|
$section->addInput(new Form_Button(
|
173
|
'Submit',
|
174
|
gettext("Save"),
|
175
|
null,
|
176
|
'fa-save'
|
177
|
))->addClass('btn-primary');
|
178
|
|
179
|
$form->add($section);
|
180
|
|
181
|
print($form);
|
182
|
|
183
|
if (is_array($confvers)) {
|
184
|
?>
|
185
|
<div>
|
186
|
<div class="infoblock blockopen">
|
187
|
<?php print_info_box(
|
188
|
gettext(
|
189
|
'To view the differences between an older configuration and a newer configuration, ' .
|
190
|
'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
|
191
|
'then press the "Diff" button.'),
|
192
|
'info', false); ?>
|
193
|
</div>
|
194
|
</div>
|
195
|
<?php
|
196
|
}
|
197
|
?>
|
198
|
|
199
|
<form action="diag_confbak.php" method="get">
|
200
|
<div class="table-responsive">
|
201
|
<table class="table table-striped table-hover table-condensed">
|
202
|
<?php
|
203
|
if (is_array($confvers)):
|
204
|
?>
|
205
|
<thead>
|
206
|
<tr>
|
207
|
<th colspan="2">
|
208
|
<button type="submit" name="diff" class="btn btn-info btn-xs" value="Diff">
|
209
|
<i class="fa fa-exchange icon-embed-btn"></i>
|
210
|
<?=gettext("Diff"); ?>
|
211
|
</button>
|
212
|
</th>
|
213
|
<th><?=gettext("Date")?></th>
|
214
|
<th><?=gettext("Version")?></th>
|
215
|
<th><?=gettext("Size")?></th>
|
216
|
<th><?=gettext("Configuration Change")?></th>
|
217
|
<th><?=gettext("Actions")?></th>
|
218
|
</tr>
|
219
|
</thead>
|
220
|
<tbody>
|
221
|
<!-- First row is the current configuration -->
|
222
|
<tr style="vertical-align:top;">
|
223
|
<td></td>
|
224
|
<td>
|
225
|
<input type="radio" name="newtime" value="current" />
|
226
|
</td>
|
227
|
<td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
|
228
|
<td><?= $config['version'] ?></td>
|
229
|
<td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
|
230
|
<td><?= htmlspecialchars($config['revision']['description']) ?></td>
|
231
|
<td><?=gettext("Current configuration")?></td>
|
232
|
</tr>
|
233
|
<?php
|
234
|
// And now for the table of prior backups
|
235
|
$c = 0;
|
236
|
foreach ($confvers as $version):
|
237
|
if ($version['time'] != 0) {
|
238
|
$date = date(gettext("n/j/y H:i:s"), $version['time']);
|
239
|
} else {
|
240
|
$date = gettext("Unknown");
|
241
|
}
|
242
|
?>
|
243
|
<tr>
|
244
|
<td>
|
245
|
<input type="radio" name="oldtime" value="<?=$version['time']?>" />
|
246
|
</td>
|
247
|
<td>
|
248
|
<?php
|
249
|
if ($c < (count($confvers) - 1)) {
|
250
|
?>
|
251
|
<input type="radio" name="newtime" value="<?=$version['time']?>" />
|
252
|
<?php
|
253
|
}
|
254
|
$c++;
|
255
|
?>
|
256
|
</td>
|
257
|
<td><?= $date ?></td>
|
258
|
<td><?= $version['version'] ?></td>
|
259
|
<td><?= format_bytes($version['filesize']) ?></td>
|
260
|
<td><?= htmlspecialchars($version['description']) ?></td>
|
261
|
<td>
|
262
|
<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.")?>')" usepost></a>
|
263
|
<a class="fa fa-download" title="<?=gettext('Download config')?>" href="diag_confbak.php?getcfg=<?=$version['time']?>"></a>
|
264
|
<a class="fa fa-trash" title="<?=gettext('Delete config')?>" href="diag_confbak.php?rmver=<?=$version['time']?>" usepost></a>
|
265
|
</td>
|
266
|
</tr>
|
267
|
<?php
|
268
|
endforeach;
|
269
|
?>
|
270
|
<tr>
|
271
|
<td colspan="2">
|
272
|
<button type="submit" name="diff" class="btn btn-info btn-xs" value="Diff">
|
273
|
<i class="fa fa-exchange icon-embed-btn"></i>
|
274
|
<?=gettext("Diff"); ?>
|
275
|
</button>
|
276
|
</td>
|
277
|
<td colspan="5"></td>
|
278
|
</tr>
|
279
|
<?php
|
280
|
else:
|
281
|
print_info_box(gettext("No backups found."), 'danger');
|
282
|
endif;
|
283
|
?>
|
284
|
</tbody>
|
285
|
</table>
|
286
|
</div>
|
287
|
</form>
|
288
|
|
289
|
<?php include("foot.inc");
|