Project

General

Profile

Download (12 KB) Statistics
| Branch: | Tag: | Revision:
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 d961e7e3 Renato Botelho
    Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8 1d2d6b3c Colin Smith
    All rights reserved.
9
10
    Redistribution and use in source and binary forms, with or without
11
    modification, are permitted provided that the following conditions are met:
12
13
    1. Redistributions of source code must retain the above copyright notice,
14
       this list of conditions and the following disclaimer.
15
16
    2. Redistributions in binary form must reproduce the above copyright
17
       notice, this list of conditions and the following disclaimer in the
18
       documentation and/or other materials provided with the distribution.
19
20
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
    POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32 f8ec8de4 Renato Botelho
/*
33 13d193c2 Scott Ullrich
	pfSense_MODULE:	config
34
*/
35
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-diagnostics-configurationhistory
38
##|*NAME=Diagnostics: Configuration History page
39
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
40
##|*MATCH=diag_confbak.php*
41
##|-PRIV
42
43 359893b0 Colin Smith
require("guiconfig.inc");
44 2f8d0729 Bill Marquette
45 e1ebe9e2 jim-p
if (isset($_POST['backupcount'])) {
46
	if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
47
		$config['system']['backupcount'] = $_POST['backupcount'];
48
		$changedescr = $config['system']['backupcount'];
49
	} else {
50
		unset($config['system']['backupcount']);
51
		$changedescr = "(platform default)";
52
	}
53
	write_config("Changed backup revision count to {$changedescr}");
54 b6513591 jim-p
} elseif ($_POST) {
55
	if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm")) || (!isset($_POST['newver']) && !isset($_POST['rmver']))) {
56
		header("Location: diag_confbak.php");
57
		return;
58
	}
59 2f8d0729 Bill Marquette
60 91bfbd00 Scott Ullrich
	conf_mount_rw();
61 1d478d96 Colin Smith
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
62 b6513591 jim-p
	if($_POST['newver'] != "") {
63
		if(config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0)
64 08c1db2d jim-p
		$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']));
65 b6513591 jim-p
		else
66
			$savemsg = gettext("Unable to revert to the selected configuration.");
67
	}
68
	if($_POST['rmver'] != "") {
69
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
70 08c1db2d jim-p
		$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']));
71 b6513591 jim-p
	}
72 91bfbd00 Scott Ullrich
	conf_mount_ro();
73 2f8d0729 Bill Marquette
}
74
75 9f9b88e2 jim-p
if($_GET['getcfg'] != "") {
76 635ee4eb jim-p
	$_GET['getcfg'] = basename($_GET['getcfg']);
77 9f9b88e2 jim-p
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
78
79
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
80
	$exp_data = file_get_contents($file);
81
	$exp_size = strlen($exp_data);
82
83
	header("Content-Type: application/octet-stream");
84
	header("Content-Disposition: attachment; filename={$exp_name}");
85
	header("Content-Length: $exp_size");
86
	echo $exp_data;
87
	exit;
88
}
89
90 957e2f1f jim-p
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
91
      && is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
92
	$diff = "";
93
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
94
	$oldtime = $_GET['oldtime'];
95
	if ($_GET['newtime'] == 'current') {
96
		$newfile = $g['conf_path'] . '/config.xml';
97
		$newtime = $config['revision']['time'];
98
	} else {
99
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
100
		$newtime = $_GET['newtime'];
101
	}
102
	if (file_exists($oldfile) && file_exists($newfile)) {
103
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
104
	}
105
}
106
107 e1ebe9e2 jim-p
cleanup_backupcache(false);
108 359893b0 Colin Smith
$confvers = get_backups();
109
unset($confvers['versions']);
110 1d2d6b3c Colin Smith
111 f8ec8de4 Renato Botelho
$pgtitle = array(gettext("Diagnostics"),gettext("Configuration History"));
112 b63695db Scott Ullrich
include("head.inc");
113
114 1d2d6b3c Colin Smith
?>
115
116
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
117 486b4999 Matthew Grooms
	<?php
118
		include("fbegin.inc");
119
		if($savemsg)
120
			print_info_box($savemsg);
121
	?>
122 8cb8751e Renato Botelho
	<?php if ($diff) { ?>
123 a3457472 Colin Fleming
	<table align="center" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;" summary="diag confbak">
124 f8ec8de4 Renato Botelho
		<tr><td><?=gettext("Configuration diff from");?> <?php echo date(gettext("n/j/y H:i:s"), $oldtime); ?> <?=gettext("to");?> <?php echo date(gettext("n/j/y H:i:s"), $newtime); ?></td></tr>
125 db67053a jim-p
		<?php foreach ($diff as $line) {
126
			switch (substr($line, 0, 1)) {
127
				case "+":
128
					$color = "#caffd3";
129
					break;
130
				case "-":
131
					$color = "#ffe8e8";
132
					break;
133
				case "@":
134
					$color = "#a0a0a0";
135
					break;
136
				default:
137 a3457472 Colin Fleming
					$color = "#ffffff";
138 db67053a jim-p
			}
139
			?>
140 957e2f1f jim-p
		<tr>
141 db67053a jim-p
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
142 957e2f1f jim-p
		</tr>
143 db67053a jim-p
		<?php } ?>
144 957e2f1f jim-p
	</table>
145 db67053a jim-p
	<br />
146 8cb8751e Renato Botelho
	<?php } ?>
147 a3457472 Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="stats">
148 486b4999 Matthew Grooms
		<tr>
149
			<td>
150
			<?php
151
				$tab_array = array();
152 f8ec8de4 Renato Botelho
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
153
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
154 486b4999 Matthew Grooms
				display_top_tabs($tab_array);
155 f8ec8de4 Renato Botelho
			?>
156 486b4999 Matthew Grooms
			</td>
157
		</tr>
158
		<tr>
159
			<td>
160
				<div id="mainarea">
161 e1ebe9e2 jim-p
					<form action="diag_confbak.php" method="post">
162 a3457472 Colin Fleming
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
163 b6513591 jim-p
164
<?PHP if ($_GET["newver"] || $_GET["rmver"]): ?>
165
					<tr>
166
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Confirm Action"); ?></td>
167
					</tr>
168
					<tr>
169
						<td width="22%" valign="top" class="vncell">&nbsp;</td>
170
						<td width="78%" class="vtable">
171
172
							<strong><?PHP echo gettext("Please confirm the selected action"); ?></strong>:
173
							<br />
174
							<br /><strong><?PHP echo gettext("Action"); ?>:</strong>
175
						<?PHP	if (!empty($_GET["newver"])) {
176
							echo gettext("Restore from Configuration Backup");
177
							$target_config = $_GET["newver"]; ?>
178
							<input type="hidden" name="newver" value="<?PHP echo htmlspecialchars($_GET["newver"]); ?>" />
179
						<?PHP	} elseif (!empty($_GET["rmver"])) {
180
							echo gettext("Remove Configuration Backup");
181
							$target_config = $_GET["rmver"]; ?>
182
							<input type="hidden" name="rmver" value="<?PHP echo htmlspecialchars($_GET["rmver"]); ?>" />
183
						<?PHP	} ?>
184
							<br /><strong><?PHP echo gettext("Target Configuration"); ?>:</strong>
185
							<?PHP echo sprintf(gettext('Timestamp %1$s'), date(gettext("n/j/y H:i:s"), $target_config)); ?>
186
							<br /><input type="submit" name="confirm" value="<?PHP echo gettext("Confirm"); ?>" />
187
						</td>
188
					</tr>
189
<?PHP else: ?>
190
191 e1ebe9e2 jim-p
						<tr>
192
							<td width="10%">&nbsp;</td>
193
							<td width="15%" valign="top"><?=gettext("Backup Count");?></td>
194 a3457472 Colin Fleming
							<td width="10%">
195 e1ebe9e2 jim-p
							<input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/>
196
							</td>
197
							<td width="60%">
198
							<?= gettext("Enter the number of older configurations to keep in the local backup cache. By default this is 30 for a full install or 5 on NanoBSD."); ?>
199
							</td>
200 a3457472 Colin Fleming
							<td width= "5%"><input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /></td>
201 e1ebe9e2 jim-p
						</tr>
202
						<tr>
203
							<td class="vncell">&nbsp;</td>
204
							<td colspan="4" class="vncell">
205
							<?= gettext("NOTE: Be aware of how much space is consumed by backups before adjusting this value. Current space used by backups: "); ?> <?= exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
206
							</td>
207
						</tr>
208
					</table>
209
					</form>
210 3ae16b9b Colin Fleming
					<form action="diag_confbak.php" method="get">
211 a3457472 Colin Fleming
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="difference">
212 486b4999 Matthew Grooms
						<?php if (is_array($confvers)): ?>
213 e1ebe9e2 jim-p
						<tr>
214
							<td colspan="7" class="list">
215 8430c546 Chris Buechler
							<?= gettext("To view the differences between an older configuration and a newer configuration, select the older configuration using the left column of radio options and select the newer configuration in the right column, then press the Diff button."); ?>
216 8cd558b6 ayvis
							<br /><br />
217 e1ebe9e2 jim-p
							</td>
218
						</tr>
219 486b4999 Matthew Grooms
						<tr>
220 a3457472 Colin Fleming
							<td width="5%" colspan="2" valign="middle" align="center" class="list nowrap"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
221 bfe615ee jim-p
							<td width="20%" class="listhdrr"><?=gettext("Date");?></td>
222
							<td width="5%" class="listhdrr"><?=gettext("Version");?></td>
223
							<td width="5%" class="listhdrr"><?=gettext("Size");?></td>
224
							<td width="60%" class="listhdrr"><?=gettext("Configuration Change");?></td>
225
							<td width="5%" class="list">&nbsp;</td>
226 486b4999 Matthew Grooms
						</tr>
227
						<tr valign="top">
228 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap"></td>
229 957e2f1f jim-p
							<td class="list">
230 a3457472 Colin Fleming
								<input type="radio" name="newtime" value="current" />
231 957e2f1f jim-p
							</td>
232 f8ec8de4 Renato Botelho
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
233 92420c0a jim-p
							<td class="listr"> <?= $config['version'] ?></td>
234 bfe615ee jim-p
							<td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
235 08c1db2d jim-p
							<td class="listr"> <?= htmlspecialchars($config['revision']['description']) ?></td>
236 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
237 486b4999 Matthew Grooms
						</tr>
238
						<?php
239 957e2f1f jim-p
							$c = 0;
240 486b4999 Matthew Grooms
							foreach($confvers as $version):
241
								if($version['time'] != 0)
242 f8ec8de4 Renato Botelho
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
243 486b4999 Matthew Grooms
								else
244 f8ec8de4 Renato Botelho
									$date = gettext("Unknown");
245 486b4999 Matthew Grooms
						?>
246
						<tr valign="top">
247 957e2f1f jim-p
							<td class="list">
248 a3457472 Colin Fleming
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>" />
249 957e2f1f jim-p
							</td>
250
							<td class="list">
251
								<?php if ($c < (count($confvers) - 1)) { ?>
252 a3457472 Colin Fleming
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>" />
253 8cb8751e Renato Botelho
								<?php } else { ?>
254 957e2f1f jim-p
								&nbsp;
255 8cb8751e Renato Botelho
								<?php }
256 957e2f1f jim-p
								$c++; ?>
257
							</td>
258 486b4999 Matthew Grooms
							<td class="listlr"> <?= $date ?></td>
259 92420c0a jim-p
							<td class="listr"> <?= $version['version'] ?></td>
260 bfe615ee jim-p
							<td class="listr"> <?= format_bytes($version['filesize']) ?></td>
261 08c1db2d jim-p
							<td class="listr"> <?= htmlspecialchars($version['description']) ?></td>
262 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap">
263 b6513591 jim-p
							<a href="diag_confbak.php?newver=<?=$version['time'];?>">
264 a3457472 Colin Fleming
							<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="<?=gettext("Revert to this configuration");?>" title="<?=gettext("Revert to this configuration");?>" />
265 486b4999 Matthew Grooms
								</a>
266 b6513591 jim-p
							<a href="diag_confbak.php?rmver=<?=$version['time'];?>">
267 a3457472 Colin Fleming
							<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="<?=gettext("Remove this backup");?>" title="<?=gettext("Remove this backup");?>" />
268 486b4999 Matthew Grooms
								</a>
269 9f9b88e2 jim-p
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
270 a3457472 Colin Fleming
								<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" width="17" height="17" border="0" alt="<?=gettext("Download this backup");?>" title="<?=gettext("Download this backup");?>" />
271 9f9b88e2 jim-p
								</a>
272
							</td>
273 486b4999 Matthew Grooms
						</tr>
274
						<?php endforeach; ?>
275 957e2f1f jim-p
						<tr>
276 a3457472 Colin Fleming
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
277 957e2f1f jim-p
							<td colspan="5"></td>
278
						</tr>
279 486b4999 Matthew Grooms
						<?php else: ?>
280
						<tr>
281
							<td>
282 f8ec8de4 Renato Botelho
								<?php print_info_box(gettext("No backups found.")); ?>
283 486b4999 Matthew Grooms
							</td>
284
						</tr>
285
						<?php endif; ?>
286 b6513591 jim-p
<?php endif; ?>
287 486b4999 Matthew Grooms
					</table>
288 957e2f1f jim-p
					</form>
289 486b4999 Matthew Grooms
				</div>
290
			</td>
291 2e2d1de7 Bill Marquette
		</tr>
292 0f10aee4 Bill Marquette
	</table>
293 a3457472 Colin Fleming
294 359893b0 Colin Smith
<?php include("fend.inc"); ?>
295 12af52d9 Scott Ullrich
</body>
296 310b2c06 Bill Marquette
</html>