1 |
1d2d6b3c
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
f79f9497
|
Sjon Hortensius
|
diag_confbak.php
|
4 |
0da0d43e
|
Phil Davis
|
*/
|
5 |
|
|
/* ====================================================================
|
6 |
7dc1383a
|
Stephen Beaver
|
* 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 |
1d2d6b3c
|
Colin Smith
|
|
57 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
58 |
|
|
##|*IDENT=page-diagnostics-configurationhistory
|
59 |
5230f468
|
jim-p
|
##|*NAME=Diagnostics: Configuration History
|
60 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
|
61 |
|
|
##|*MATCH=diag_confbak.php*
|
62 |
|
|
##|-PRIV
|
63 |
|
|
|
64 |
359893b0
|
Colin Smith
|
require("guiconfig.inc");
|
65 |
2f8d0729
|
Bill Marquette
|
|
66 |
e1ebe9e2
|
jim-p
|
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 |
ff30e319
|
bruno
|
$changedescr = gettext("(platform default)");
|
73 |
e1ebe9e2
|
jim-p
|
}
|
74 |
ff30e319
|
bruno
|
write_config(sprintf(gettext("Changed backup revision count to %s"), $changedescr));
|
75 |
dbeffa2f
|
Stephen Beaver
|
} elseif ($_GET) {
|
76 |
|
|
if (!isset($_GET['newver']) && !isset($_GET['rmver']) && !isset($_GET['getcfg']) && !isset($_GET['diff'])) {
|
77 |
b6513591
|
jim-p
|
header("Location: diag_confbak.php");
|
78 |
|
|
return;
|
79 |
|
|
}
|
80 |
2f8d0729
|
Bill Marquette
|
|
81 |
91bfbd00
|
Scott Ullrich
|
conf_mount_rw();
|
82 |
1d478d96
|
Colin Smith
|
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
|
83 |
0da0d43e
|
Phil Davis
|
|
84 |
dbeffa2f
|
Stephen Beaver
|
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 |
5f601060
|
Phil Davis
|
} else {
|
88 |
b6513591
|
jim-p
|
$savemsg = gettext("Unable to revert to the selected configuration.");
|
89 |
5f601060
|
Phil Davis
|
}
|
90 |
b6513591
|
jim-p
|
}
|
91 |
dbeffa2f
|
Stephen Beaver
|
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 |
b6513591
|
jim-p
|
}
|
95 |
91bfbd00
|
Scott Ullrich
|
conf_mount_ro();
|
96 |
2f8d0729
|
Bill Marquette
|
}
|
97 |
|
|
|
98 |
5f601060
|
Phil Davis
|
if ($_GET['getcfg'] != "") {
|
99 |
3b635066
|
jim-p
|
$_GET['getcfg'] = basename($_GET['getcfg']);
|
100 |
9f9b88e2
|
jim-p
|
$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 |
5f601060
|
Phil Davis
|
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
|
114 |
|
|
(is_numeric($_GET['oldtime'])) &&
|
115 |
288a2a0f
|
Phil Davis
|
(is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
|
116 |
957e2f1f
|
jim-p
|
$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 |
e1ebe9e2
|
jim-p
|
cleanup_backupcache(false);
|
132 |
359893b0
|
Colin Smith
|
$confvers = get_backups();
|
133 |
|
|
unset($confvers['versions']);
|
134 |
1d2d6b3c
|
Colin Smith
|
|
135 |
0f298138
|
k-paulius
|
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), gettext("Config History"));
|
136 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
137 |
|
|
|
138 |
dbeffa2f
|
Stephen Beaver
|
if ($savemsg) {
|
139 |
|
|
print_info_box($savemsg, 'success');
|
140 |
|
|
}
|
141 |
|
|
|
142 |
1d191646
|
Phil Davis
|
$tab_array = array();
|
143 |
0f298138
|
k-paulius
|
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), false, "diag_backup.php");
|
144 |
2b38c46b
|
k-paulius
|
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
|
145 |
1d191646
|
Phil Davis
|
display_top_tabs($tab_array);
|
146 |
|
|
|
147 |
dbeffa2f
|
Stephen Beaver
|
if ($diff) {
|
148 |
f79f9497
|
Sjon Hortensius
|
?>
|
149 |
dbeffa2f
|
Stephen Beaver
|
<div class="panel panel-default">
|
150 |
95fa5cce
|
Phil Davis
|
<div class="panel-heading">
|
151 |
|
|
<h2 class="panel-title">
|
152 |
3d7a8696
|
k-paulius
|
<?=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 |
95fa5cce
|
Phil Davis
|
</h2>
|
154 |
|
|
</div>
|
155 |
dbeffa2f
|
Stephen Beaver
|
<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 |
f79f9497
|
Sjon Hortensius
|
|
159 |
|
|
<?php
|
160 |
dbeffa2f
|
Stephen Beaver
|
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 |
91419f70
|
NewEraCracker
|
<td class="diff-text" style="vertical-align:middle; background-color:<?=$color;?>; white-space:pre-wrap;"><?=htmlentities($line)?></td>
|
177 |
dbeffa2f
|
Stephen Beaver
|
</tr>
|
178 |
0da0d43e
|
Phil Davis
|
<?php
|
179 |
dbeffa2f
|
Stephen Beaver
|
}
|
180 |
f79f9497
|
Sjon Hortensius
|
?>
|
181 |
dbeffa2f
|
Stephen Beaver
|
</table>
|
182 |
|
|
</div>
|
183 |
|
|
</div>
|
184 |
0da0d43e
|
Phil Davis
|
<?php
|
185 |
dbeffa2f
|
Stephen Beaver
|
}
|
186 |
f79f9497
|
Sjon Hortensius
|
|
187 |
89333d37
|
jim-p
|
$form = new Form(false);
|
188 |
b6513591
|
jim-p
|
|
189 |
5dfc79c9
|
Stephen Beaver
|
$section = new Form_Section('Saved Configurations', 'savedconfig', COLLAPSIBLE|SEC_CLOSED);
|
190 |
b6513591
|
jim-p
|
|
191 |
dbeffa2f
|
Stephen Beaver
|
$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 |
89333d37
|
jim-p
|
$section->addInput(new Form_Button(
|
206 |
|
|
'Submit',
|
207 |
827a3812
|
jim-p
|
gettext("Save"),
|
208 |
|
|
null,
|
209 |
|
|
'fa-save'
|
210 |
|
|
))->addClass('btn-primary');
|
211 |
89333d37
|
jim-p
|
|
212 |
dbeffa2f
|
Stephen Beaver
|
$form->add($section);
|
213 |
|
|
|
214 |
|
|
print($form);
|
215 |
|
|
|
216 |
|
|
if (is_array($confvers)) {
|
217 |
e47f1893
|
Phil Davis
|
?>
|
218 |
|
|
<div>
|
219 |
c95dabdd
|
Stephen Beaver
|
<div class="infoblock blockopen">
|
220 |
f6aebbcc
|
NewEraCracker
|
<?php print_info_box(
|
221 |
e47f1893
|
Phil Davis
|
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 |
f6aebbcc
|
NewEraCracker
|
'info', false); ?>
|
226 |
e47f1893
|
Phil Davis
|
</div>
|
227 |
|
|
</div>
|
228 |
|
|
<?php
|
229 |
0da0d43e
|
Phil Davis
|
}
|
230 |
|
|
?>
|
231 |
|
|
|
232 |
dbeffa2f
|
Stephen Beaver
|
<form action="diag_confbak.php" method="get">
|
233 |
12537fdf
|
Phil Davis
|
<div class="table-responsive">
|
234 |
dbeffa2f
|
Stephen Beaver
|
<table class="table table-striped table-hover table-condensed">
|
235 |
0da0d43e
|
Phil Davis
|
<?php
|
236 |
dbeffa2f
|
Stephen Beaver
|
if (is_array($confvers)):
|
237 |
|
|
?>
|
238 |
|
|
<thead>
|
239 |
|
|
<tr>
|
240 |
|
|
<th colspan="2">
|
241 |
827a3812
|
jim-p
|
<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 |
dbeffa2f
|
Stephen Beaver
|
</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 |
ee10332b
|
NewEraCracker
|
<tr style="vertical-align:top;">
|
256 |
dbeffa2f
|
Stephen Beaver
|
<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 |
2d911f2c
|
Phil Davis
|
// And now for the table of prior backups
|
268 |
dbeffa2f
|
Stephen Beaver
|
$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 |
0da0d43e
|
Phil Davis
|
<?php
|
286 |
dbeffa2f
|
Stephen Beaver
|
}
|
287 |
0da0d43e
|
Phil Davis
|
$c++;
|
288 |
dbeffa2f
|
Stephen Beaver
|
?>
|
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 |
a16d923f
|
NOYB
|
<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 |
0da0d43e
|
Phil Davis
|
<a class="fa fa-download" title="<?=gettext('Download config')?>" href="diag_confbak.php?getcfg=<?=$version['time']?>"></a>
|
297 |
33f0b0d5
|
Stephen Beaver
|
<a class="fa fa-trash" title="<?=gettext('Delete config')?>" href="diag_confbak.php?rmver=<?=$version['time']?>"></a>
|
298 |
dbeffa2f
|
Stephen Beaver
|
</td>
|
299 |
|
|
</tr>
|
300 |
0da0d43e
|
Phil Davis
|
<?php
|
301 |
dbeffa2f
|
Stephen Beaver
|
endforeach;
|
302 |
|
|
?>
|
303 |
|
|
<tr>
|
304 |
27d6a45b
|
jim-p
|
<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 |
dbeffa2f
|
Stephen Beaver
|
<td colspan="5"></td>
|
311 |
|
|
</tr>
|
312 |
0da0d43e
|
Phil Davis
|
<?php
|
313 |
dbeffa2f
|
Stephen Beaver
|
else:
|
314 |
|
|
print_info_box(gettext("No backups found."), 'danger');
|
315 |
|
|
endif;
|
316 |
|
|
?>
|
317 |
|
|
</tbody>
|
318 |
|
|
</table>
|
319 |
217cdb81
|
NOYB
|
</div>
|
320 |
|
|
</form>
|
321 |
dbeffa2f
|
Stephen Beaver
|
|
322 |
b782c904
|
Phil Davis
|
<?php include("foot.inc");
|