Project

General

Profile

Download (11.8 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 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 f8ec8de4 Renato Botelho
/*
32 13d193c2 Scott Ullrich
	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 e1ebe9e2 jim-p
if (isset($_POST['backupcount'])) {
45
	if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
46
		$config['system']['backupcount'] = $_POST['backupcount'];
47
		$changedescr = $config['system']['backupcount'];
48
	} else {
49
		unset($config['system']['backupcount']);
50
		$changedescr = "(platform default)";
51
	}
52
	write_config("Changed backup revision count to {$changedescr}");
53 b6513591 jim-p
} elseif ($_POST) {
54
	if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm")) || (!isset($_POST['newver']) && !isset($_POST['rmver']))) {
55
		header("Location: diag_confbak.php");
56
		return;
57
	}
58 2f8d0729 Bill Marquette
59 91bfbd00 Scott Ullrich
	conf_mount_rw();
60 1d478d96 Colin Smith
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
61 b6513591 jim-p
	if($_POST['newver'] != "") {
62
		if(config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0)
63
		$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['newver']), $confvers[$_POST['newver']]['description']);
64
		else
65
			$savemsg = gettext("Unable to revert to the selected configuration.");
66
	}
67
	if($_POST['rmver'] != "") {
68
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
69
		$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']),$confvers[$_POST['rmver']]['description']);
70
	}
71 91bfbd00 Scott Ullrich
	conf_mount_ro();
72 2f8d0729 Bill Marquette
}
73
74 9f9b88e2 jim-p
if($_GET['getcfg'] != "") {
75
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
76
77
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
78
	$exp_data = file_get_contents($file);
79
	$exp_size = strlen($exp_data);
80
81
	header("Content-Type: application/octet-stream");
82
	header("Content-Disposition: attachment; filename={$exp_name}");
83
	header("Content-Length: $exp_size");
84
	echo $exp_data;
85
	exit;
86
}
87
88 957e2f1f jim-p
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
89
      && is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
90
	$diff = "";
91
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
92
	$oldtime = $_GET['oldtime'];
93
	if ($_GET['newtime'] == 'current') {
94
		$newfile = $g['conf_path'] . '/config.xml';
95
		$newtime = $config['revision']['time'];
96
	} else {
97
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
98
		$newtime = $_GET['newtime'];
99
	}
100
	if (file_exists($oldfile) && file_exists($newfile)) {
101
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
102
	}
103
}
104
105 e1ebe9e2 jim-p
cleanup_backupcache(false);
106 359893b0 Colin Smith
$confvers = get_backups();
107
unset($confvers['versions']);
108 1d2d6b3c Colin Smith
109 f8ec8de4 Renato Botelho
$pgtitle = array(gettext("Diagnostics"),gettext("Configuration History"));
110 b63695db Scott Ullrich
include("head.inc");
111
112 1d2d6b3c Colin Smith
?>
113
114
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
115 486b4999 Matthew Grooms
	<?php
116
		include("fbegin.inc");
117
		if($savemsg)
118
			print_info_box($savemsg);
119
	?>
120 8cb8751e Renato Botelho
	<?php if ($diff) { ?>
121 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">
122 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>
123 db67053a jim-p
		<?php foreach ($diff as $line) {
124
			switch (substr($line, 0, 1)) {
125
				case "+":
126
					$color = "#caffd3";
127
					break;
128
				case "-":
129
					$color = "#ffe8e8";
130
					break;
131
				case "@":
132
					$color = "#a0a0a0";
133
					break;
134
				default:
135 a3457472 Colin Fleming
					$color = "#ffffff";
136 db67053a jim-p
			}
137
			?>
138 957e2f1f jim-p
		<tr>
139 db67053a jim-p
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
140 957e2f1f jim-p
		</tr>
141 db67053a jim-p
		<?php } ?>
142 957e2f1f jim-p
	</table>
143 db67053a jim-p
	<br />
144 8cb8751e Renato Botelho
	<?php } ?>
145 a3457472 Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="stats">
146 486b4999 Matthew Grooms
		<tr>
147
			<td>
148
			<?php
149
				$tab_array = array();
150 f8ec8de4 Renato Botelho
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
151
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
152 486b4999 Matthew Grooms
				display_top_tabs($tab_array);
153 f8ec8de4 Renato Botelho
			?>
154 486b4999 Matthew Grooms
			</td>
155
		</tr>
156
		<tr>
157
			<td>
158
				<div id="mainarea">
159 e1ebe9e2 jim-p
					<form action="diag_confbak.php" method="post">
160 a3457472 Colin Fleming
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
161 b6513591 jim-p
162
<?PHP if ($_GET["newver"] || $_GET["rmver"]): ?>
163
					<tr>
164
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Confirm Action"); ?></td>
165
					</tr>
166
					<tr>
167
						<td width="22%" valign="top" class="vncell">&nbsp;</td>
168
						<td width="78%" class="vtable">
169
170
							<strong><?PHP echo gettext("Please confirm the selected action"); ?></strong>:
171
							<br />
172
							<br /><strong><?PHP echo gettext("Action"); ?>:</strong>
173
						<?PHP	if (!empty($_GET["newver"])) {
174
							echo gettext("Restore from Configuration Backup");
175
							$target_config = $_GET["newver"]; ?>
176
							<input type="hidden" name="newver" value="<?PHP echo htmlspecialchars($_GET["newver"]); ?>" />
177
						<?PHP	} elseif (!empty($_GET["rmver"])) {
178
							echo gettext("Remove Configuration Backup");
179
							$target_config = $_GET["rmver"]; ?>
180
							<input type="hidden" name="rmver" value="<?PHP echo htmlspecialchars($_GET["rmver"]); ?>" />
181
						<?PHP	} ?>
182
							<br /><strong><?PHP echo gettext("Target Configuration"); ?>:</strong>
183
							<?PHP echo sprintf(gettext('Timestamp %1$s'), date(gettext("n/j/y H:i:s"), $target_config)); ?>
184
							<br /><input type="submit" name="confirm" value="<?PHP echo gettext("Confirm"); ?>" />
185
						</td>
186
					</tr>
187
<?PHP else: ?>
188
189 e1ebe9e2 jim-p
						<tr>
190
							<td width="10%">&nbsp;</td>
191
							<td width="15%" valign="top"><?=gettext("Backup Count");?></td>
192 a3457472 Colin Fleming
							<td width="10%">
193 e1ebe9e2 jim-p
							<input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/>
194
							</td>
195
							<td width="60%">
196
							<?= 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."); ?>
197
							</td>
198 a3457472 Colin Fleming
							<td width= "5%"><input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /></td>
199 e1ebe9e2 jim-p
						</tr>
200
						<tr>
201
							<td class="vncell">&nbsp;</td>
202
							<td colspan="4" class="vncell">
203
							<?= 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;}'") ?>
204
							</td>
205
						</tr>
206
					</table>
207
					</form>
208 3ae16b9b Colin Fleming
					<form action="diag_confbak.php" method="get">
209 a3457472 Colin Fleming
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="difference">
210 486b4999 Matthew Grooms
						<?php if (is_array($confvers)): ?>
211 e1ebe9e2 jim-p
						<tr>
212
							<td colspan="7" class="list">
213 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."); ?>
214 8cd558b6 ayvis
							<br /><br />
215 e1ebe9e2 jim-p
							</td>
216
						</tr>
217 486b4999 Matthew Grooms
						<tr>
218 a3457472 Colin Fleming
							<td width="5%" colspan="2" valign="middle" align="center" class="list nowrap"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
219 bfe615ee jim-p
							<td width="20%" class="listhdrr"><?=gettext("Date");?></td>
220
							<td width="5%" class="listhdrr"><?=gettext("Version");?></td>
221
							<td width="5%" class="listhdrr"><?=gettext("Size");?></td>
222
							<td width="60%" class="listhdrr"><?=gettext("Configuration Change");?></td>
223
							<td width="5%" class="list">&nbsp;</td>
224 486b4999 Matthew Grooms
						</tr>
225
						<tr valign="top">
226 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap"></td>
227 957e2f1f jim-p
							<td class="list">
228 a3457472 Colin Fleming
								<input type="radio" name="newtime" value="current" />
229 957e2f1f jim-p
							</td>
230 f8ec8de4 Renato Botelho
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
231 92420c0a jim-p
							<td class="listr"> <?= $config['version'] ?></td>
232 bfe615ee jim-p
							<td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
233 486b4999 Matthew Grooms
							<td class="listr"> <?= $config['revision']['description'] ?></td>
234 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
235 486b4999 Matthew Grooms
						</tr>
236
						<?php
237 957e2f1f jim-p
							$c = 0;
238 486b4999 Matthew Grooms
							foreach($confvers as $version):
239
								if($version['time'] != 0)
240 f8ec8de4 Renato Botelho
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
241 486b4999 Matthew Grooms
								else
242 f8ec8de4 Renato Botelho
									$date = gettext("Unknown");
243 486b4999 Matthew Grooms
						?>
244
						<tr valign="top">
245 957e2f1f jim-p
							<td class="list">
246 a3457472 Colin Fleming
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>" />
247 957e2f1f jim-p
							</td>
248
							<td class="list">
249
								<?php if ($c < (count($confvers) - 1)) { ?>
250 a3457472 Colin Fleming
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>" />
251 8cb8751e Renato Botelho
								<?php } else { ?>
252 957e2f1f jim-p
								&nbsp;
253 8cb8751e Renato Botelho
								<?php }
254 957e2f1f jim-p
								$c++; ?>
255
							</td>
256 486b4999 Matthew Grooms
							<td class="listlr"> <?= $date ?></td>
257 92420c0a jim-p
							<td class="listr"> <?= $version['version'] ?></td>
258 bfe615ee jim-p
							<td class="listr"> <?= format_bytes($version['filesize']) ?></td>
259 92420c0a jim-p
							<td class="listr"> <?= $version['description'] ?></td>
260 a3457472 Colin Fleming
							<td valign="middle" class="list nowrap">
261 b6513591 jim-p
							<a href="diag_confbak.php?newver=<?=$version['time'];?>">
262 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");?>" />
263 486b4999 Matthew Grooms
								</a>
264 b6513591 jim-p
							<a href="diag_confbak.php?rmver=<?=$version['time'];?>">
265 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");?>" />
266 486b4999 Matthew Grooms
								</a>
267 9f9b88e2 jim-p
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
268 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");?>" />
269 9f9b88e2 jim-p
								</a>
270
							</td>
271 486b4999 Matthew Grooms
						</tr>
272
						<?php endforeach; ?>
273 957e2f1f jim-p
						<tr>
274 a3457472 Colin Fleming
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
275 957e2f1f jim-p
							<td colspan="5"></td>
276
						</tr>
277 486b4999 Matthew Grooms
						<?php else: ?>
278
						<tr>
279
							<td>
280 f8ec8de4 Renato Botelho
								<?php print_info_box(gettext("No backups found.")); ?>
281 486b4999 Matthew Grooms
							</td>
282
						</tr>
283
						<?php endif; ?>
284 b6513591 jim-p
<?php endif; ?>
285 486b4999 Matthew Grooms
					</table>
286 957e2f1f jim-p
					</form>
287 486b4999 Matthew Grooms
				</div>
288
			</td>
289 2e2d1de7 Bill Marquette
		</tr>
290 0f10aee4 Bill Marquette
	</table>
291 a3457472 Colin Fleming
292 359893b0 Colin Smith
<?php include("fend.inc"); ?>
293 12af52d9 Scott Ullrich
</body>
294 310b2c06 Bill Marquette
</html>