1 |
1d2d6b3c
|
Colin Smith
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
359893b0
|
Colin Smith
|
diag_confbak.php
|
5 |
|
|
Copyright (C) 2005 Colin Smith
|
6 |
957e2f1f
|
jim-p
|
Copyright (C) 2010 Jim Pingle
|
7 |
1d2d6b3c
|
Colin Smith
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, 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 the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
13d193c2
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_MODULE: config
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-diagnostics-configurationhistory
|
37 |
|
|
##|*NAME=Diagnostics: Configuration History page
|
38 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
|
39 |
|
|
##|*MATCH=diag_confbak.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
359893b0
|
Colin Smith
|
require("guiconfig.inc");
|
43 |
2f8d0729
|
Bill Marquette
|
|
44 |
359893b0
|
Colin Smith
|
if($_GET['newver'] != "") {
|
45 |
91bfbd00
|
Scott Ullrich
|
conf_mount_rw();
|
46 |
1d478d96
|
Colin Smith
|
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
|
47 |
486b4999
|
Matthew Grooms
|
if(config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0)
|
48 |
cdc0ed31
|
Colin Smith
|
$savemsg = "Successfully reverted to timestamp " . date("n/j/y H:i:s", $_GET['newver']) . " with description \"" . $confvers[$_GET['newver']]['description'] . "\".";
|
49 |
486b4999
|
Matthew Grooms
|
else
|
50 |
cdc0ed31
|
Colin Smith
|
$savemsg = "Unable to revert to the selected configuration.";
|
51 |
91bfbd00
|
Scott Ullrich
|
conf_mount_ro();
|
52 |
359893b0
|
Colin Smith
|
}
|
53 |
2f8d0729
|
Bill Marquette
|
|
54 |
359893b0
|
Colin Smith
|
if($_GET['rmver'] != "") {
|
55 |
91bfbd00
|
Scott Ullrich
|
conf_mount_rw();
|
56 |
1d478d96
|
Colin Smith
|
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
|
57 |
359893b0
|
Colin Smith
|
unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
|
58 |
cdc0ed31
|
Colin Smith
|
$savemsg = "Deleted backup with timestamp " . date("n/j/y H:i:s", $_GET['rmver']) . " and description \"" . $confvers[$_GET['rmver']]['description'] . "\".";
|
59 |
91bfbd00
|
Scott Ullrich
|
conf_mount_ro();
|
60 |
2f8d0729
|
Bill Marquette
|
}
|
61 |
|
|
|
62 |
9f9b88e2
|
jim-p
|
if($_GET['getcfg'] != "") {
|
63 |
|
|
$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
|
64 |
|
|
|
65 |
|
|
$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
|
66 |
|
|
$exp_data = file_get_contents($file);
|
67 |
|
|
$exp_size = strlen($exp_data);
|
68 |
|
|
|
69 |
|
|
header("Content-Type: application/octet-stream");
|
70 |
|
|
header("Content-Disposition: attachment; filename={$exp_name}");
|
71 |
|
|
header("Content-Length: $exp_size");
|
72 |
|
|
echo $exp_data;
|
73 |
|
|
exit;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
957e2f1f
|
jim-p
|
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
|
77 |
|
|
&& is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
|
78 |
|
|
$diff = "";
|
79 |
|
|
$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
|
80 |
|
|
$oldtime = $_GET['oldtime'];
|
81 |
|
|
if ($_GET['newtime'] == 'current') {
|
82 |
|
|
$newfile = $g['conf_path'] . '/config.xml';
|
83 |
|
|
$newtime = $config['revision']['time'];
|
84 |
|
|
} else {
|
85 |
|
|
$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
|
86 |
|
|
$newtime = $_GET['newtime'];
|
87 |
|
|
}
|
88 |
|
|
if (file_exists($oldfile) && file_exists($newfile)) {
|
89 |
|
|
exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
|
93 |
359893b0
|
Colin Smith
|
cleanup_backupcache();
|
94 |
|
|
$confvers = get_backups();
|
95 |
|
|
unset($confvers['versions']);
|
96 |
1d2d6b3c
|
Colin Smith
|
|
97 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("Diagnostics","Configuration History");
|
98 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
99 |
|
|
|
100 |
1d2d6b3c
|
Colin Smith
|
?>
|
101 |
|
|
|
102 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
103 |
486b4999
|
Matthew Grooms
|
<?php
|
104 |
|
|
include("fbegin.inc");
|
105 |
|
|
if($savemsg)
|
106 |
|
|
print_info_box($savemsg);
|
107 |
|
|
?>
|
108 |
957e2f1f
|
jim-p
|
<? if ($diff) { ?>
|
109 |
db67053a
|
jim-p
|
<table align="center" valign="middle" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px;">
|
110 |
957e2f1f
|
jim-p
|
<tr><td>Configuration diff from <?php echo date("n/j/y H:i:s", $oldtime); ?> to <?php echo date("n/j/y H:i:s", $newtime); ?></td></tr>
|
111 |
db67053a
|
jim-p
|
<?php foreach ($diff as $line) {
|
112 |
|
|
switch (substr($line, 0, 1)) {
|
113 |
|
|
case "+":
|
114 |
|
|
$color = "#caffd3";
|
115 |
|
|
break;
|
116 |
|
|
case "-":
|
117 |
|
|
$color = "#ffe8e8";
|
118 |
|
|
break;
|
119 |
|
|
case "@":
|
120 |
|
|
$color = "#a0a0a0";
|
121 |
|
|
break;
|
122 |
|
|
default:
|
123 |
|
|
$color = "";
|
124 |
|
|
}
|
125 |
|
|
?>
|
126 |
957e2f1f
|
jim-p
|
<tr>
|
127 |
db67053a
|
jim-p
|
<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
|
128 |
957e2f1f
|
jim-p
|
</tr>
|
129 |
db67053a
|
jim-p
|
<?php } ?>
|
130 |
957e2f1f
|
jim-p
|
</table>
|
131 |
db67053a
|
jim-p
|
<br />
|
132 |
957e2f1f
|
jim-p
|
<? } ?>
|
133 |
486b4999
|
Matthew Grooms
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
134 |
|
|
<tr>
|
135 |
|
|
<td>
|
136 |
|
|
<?php
|
137 |
|
|
$tab_array = array();
|
138 |
|
|
$tab_array[0] = array("Config History", true, "diag_confbak.php");
|
139 |
|
|
$tab_array[1] = array("Backup/Restore", false, "diag_backup.php");
|
140 |
|
|
display_top_tabs($tab_array);
|
141 |
|
|
?>
|
142 |
|
|
</td>
|
143 |
|
|
</tr>
|
144 |
|
|
<tr>
|
145 |
|
|
<td>
|
146 |
|
|
<div id="mainarea">
|
147 |
957e2f1f
|
jim-p
|
<form action="diag_confbak.php" method="GET">
|
148 |
486b4999
|
Matthew Grooms
|
<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
|
149 |
|
|
<?php if (is_array($confvers)): ?>
|
150 |
|
|
<tr>
|
151 |
db67053a
|
jim-p
|
<td colspan="2" valign="middle" align="center" class="list" nowrap><input type="submit" name="diff" value="Diff"></td>
|
152 |
486b4999
|
Matthew Grooms
|
<td width="30%" class="listhdrr">Date</td>
|
153 |
|
|
<td width="70%" class="listhdrr">Configuration Change</td>
|
154 |
|
|
</tr>
|
155 |
|
|
<tr valign="top">
|
156 |
957e2f1f
|
jim-p
|
<td valign="middle" class="list" nowrap></td>
|
157 |
|
|
<td class="list">
|
158 |
|
|
<input type="radio" name="newtime" value="current">
|
159 |
|
|
</td>
|
160 |
486b4999
|
Matthew Grooms
|
<td class="listlr"> <?= date("n/j/y H:i:s", $config['revision']['time']) ?></td>
|
161 |
|
|
<td class="listr"> <?= $config['revision']['description'] ?></td>
|
162 |
957e2f1f
|
jim-p
|
<td colspan="3" valign="middle" class="list" nowrap><b>Current</b></td>
|
163 |
486b4999
|
Matthew Grooms
|
</tr>
|
164 |
|
|
<?php
|
165 |
957e2f1f
|
jim-p
|
$c = 0;
|
166 |
486b4999
|
Matthew Grooms
|
foreach($confvers as $version):
|
167 |
|
|
if($version['time'] != 0)
|
168 |
|
|
$date = date("n/j/y H:i:s", $version['time']);
|
169 |
|
|
else
|
170 |
|
|
$date = "Unknown";
|
171 |
|
|
$desc = $version['description'];
|
172 |
|
|
?>
|
173 |
|
|
<tr valign="top">
|
174 |
957e2f1f
|
jim-p
|
<td class="list">
|
175 |
|
|
<input type="radio" name="oldtime" value="<?php echo $version['time'];?>">
|
176 |
|
|
</td>
|
177 |
|
|
<td class="list">
|
178 |
|
|
<?php if ($c < (count($confvers) - 1)) { ?>
|
179 |
|
|
<input type="radio" name="newtime" value="<?php echo $version['time'];?>">
|
180 |
|
|
<? } else { ?>
|
181 |
|
|
|
182 |
|
|
<? }
|
183 |
|
|
$c++; ?>
|
184 |
|
|
</td>
|
185 |
486b4999
|
Matthew Grooms
|
<td class="listlr"> <?= $date ?></td>
|
186 |
|
|
<td class="listr"> <?= $desc ?></td>
|
187 |
|
|
<td valign="middle" class="list" nowrap>
|
188 |
85183d57
|
jim-p
|
<a href="diag_confbak.php?newver=<?=$version['time'];?>" onclick="return confirm('Revert to this configuration?')">
|
189 |
|
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="Revert to this configuration" title="Revert to this configuration">
|
190 |
486b4999
|
Matthew Grooms
|
</a>
|
191 |
|
|
</td>
|
192 |
|
|
<td valign="middle" class="list" nowrap>
|
193 |
85183d57
|
jim-p
|
<a href="diag_confbak.php?rmver=<?=$version['time'];?>" onclick="return confirm('Delete this configuration backup?')">
|
194 |
|
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="Remove this backup" title="Remove this backup">
|
195 |
486b4999
|
Matthew Grooms
|
</a>
|
196 |
|
|
</td>
|
197 |
9f9b88e2
|
jim-p
|
<td valign="middle" class="list" nowrap>
|
198 |
|
|
<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
|
199 |
|
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" width="17" height="17" border="0" alt="Download this backup" title="Download this backup">
|
200 |
|
|
</a>
|
201 |
|
|
</td>
|
202 |
486b4999
|
Matthew Grooms
|
</tr>
|
203 |
|
|
<?php endforeach; ?>
|
204 |
957e2f1f
|
jim-p
|
<tr>
|
205 |
|
|
<td colspan="2"><input type="submit" name="diff" value="Diff"></td>
|
206 |
|
|
<td colspan="5"></td>
|
207 |
|
|
</tr>
|
208 |
486b4999
|
Matthew Grooms
|
<?php else: ?>
|
209 |
|
|
<tr>
|
210 |
|
|
<td>
|
211 |
|
|
<?php print_info_box("No backups found."); ?>
|
212 |
|
|
</td>
|
213 |
|
|
</tr>
|
214 |
|
|
<?php endif; ?>
|
215 |
|
|
</table>
|
216 |
957e2f1f
|
jim-p
|
</form>
|
217 |
486b4999
|
Matthew Grooms
|
</div>
|
218 |
|
|
</td>
|
219 |
2e2d1de7
|
Bill Marquette
|
</tr>
|
220 |
0f10aee4
|
Bill Marquette
|
</table>
|
221 |
cdb0814b
|
Scott Ullrich
|
</form>
|
222 |
359893b0
|
Colin Smith
|
<?php include("fend.inc"); ?>
|
223 |
12af52d9
|
Scott Ullrich
|
</body>
|
224 |
310b2c06
|
Bill Marquette
|
</html>
|