Project

General

Profile

Download (14.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_confbak.php
5
	Copyright (C) 2005 Colin Smith
6
	Copyright (C) 2010 Jim Pingle
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	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
/*
33
	pfSense_MODULE:	config
34
*/
35

    
36
##|+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
require("guiconfig.inc");
44

    
45
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
} 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

    
60
	conf_mount_rw();
61
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
62
	if ($_POST['newver'] != "") {
63
		if (config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0) {
64
			$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
		} else {
66
			$savemsg = gettext("Unable to revert to the selected configuration.");
67
		}
68
	}
69
	if ($_POST['rmver'] != "") {
70
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
71
		$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']));
72
	}
73
	conf_mount_ro();
74
}
75

    
76
if ($_GET['getcfg'] != "") {
77
	$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
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
91
    (is_numeric($_GET['oldtime'])) &&
92
	(is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
93
	$diff = "";
94
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
95
	$oldtime = $_GET['oldtime'];
96
	if ($_GET['newtime'] == 'current') {
97
		$newfile = $g['conf_path'] . '/config.xml';
98
		$newtime = $config['revision']['time'];
99
	} else {
100
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
101
		$newtime = $_GET['newtime'];
102
	}
103
	if (file_exists($oldfile) && file_exists($newfile)) {
104
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
105
	}
106
}
107

    
108
cleanup_backupcache(false);
109
$confvers = get_backups();
110
unset($confvers['versions']);
111

    
112
$pgtitle = array(gettext("Diagnostics"), gettext("Configuration History"));
113
include("head.inc");
114

    
115
if($savemsg)
116
	print_info_box($savemsg);
117
?>
118
	<?php if ($diff):?>
119
		<h3><?=gettext("Configuration diff from")?><?=date(gettext("n/j/y H:i:s"), $oldtime)?><?=gettext("to")?><?=date(gettext("n/j/y H:i:s"), $newtime)?></h3>
120
		<pre><?php foreach ($diff as $line) {
121
			switch (substr($line, 0, 1)) {
122
				case "+":
123
					$color = "#caffd3";
124
					break;
125
				case "-":
126
					$color = "#ffe8e8";
127
					break;
128
				case "@":
129
					$color = "#a0a0a0";
130
					break;
131
				default:
132
					$color = "#ffffff";
133
			}
134

    
135
			print '<span style="background-color: '.$color .'">'. htmlentities($line) .'</span><br/>';
136
		}
137
		?></pre>
138
<?php endif?>
139
<?PHP if ($_GET["newver"] || $_GET["rmver"]):?>
140
	<h2><?=gettext("Confirm Action")?></h2>
141
	<form action="diag_confbak.php" method="post">
142
		<div class="alert alert-danger">
143
			<p><?=gettext("Please confirm you wish to ")?>
144
			<?PHP
145
				if (!empty($_GET["newver"])) {
146
					echo gettext("restore from Configuration Backup");
147
					$target_config = $_GET["newver"]?>
148
				<input type="hidden" name="newver" value="<?PHP echo htmlspecialchars($_GET["newver"])?>" />
149
			<?PHP
150
				} elseif (!empty($_GET["rmver"])) {
151
					echo gettext("remove Configuration Backup");
152
					$target_config = $_GET["rmver"]?>
153
				<input type="hidden" name="rmver" value="<?PHP echo htmlspecialchars($_GET["rmver"])?>" />
154
			<?PHP
155
				} ?>
156
				<?PHP echo gettext("revert to configuration from ")?> <?=date(gettext("n/j/y H:i:s"), $target_config)?>
157
				<br />
158
				<input type="submit" name="confirm" value="<?PHP echo gettext("Confirm")?>" />
159
			</p>
160
		</div>
161
	</form>
162
<?PHP else:?>
163
<?php
164
	$tab_array = array();
165
	$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
166
	$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
167
	display_top_tabs($tab_array);
168
?>
169
		<form action="diag_confbak.php" method="post">
170
			<div class="form-group">
171
				<label for="backupcount" class="col-sm-2 control-label"><?=gettext("Backup Count")?></label>
172
				<div class="col-sm-10">
173
					<input name="backupcount" type="number" class="form-control" size="5" value="<?=htmlspecialchars($config['system']['backupcount'])?>" />
174
					<?=gettext("Maximum number of old configurations to keep. By default this is 30 for a full install or 5 on NanoBSD.")?>
175
				</div>
176
			</div>
177

    
178
			<div class="form-group">
179
				<div class="col-sm-offset-2 col-sm-10">
180
					<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save")?>" />
181
					<p><?=gettext("Current space used by backups: ")?><?=exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'")?></p>
182
				</div>
183
			</div>
184
		</form>
185
<?php if (!is_array($confvers)): ?>
186
	<?php print_info_box(gettext("No backups found."))?>
187
<?php else: ?>
188
	<form action="diag_confbak.php" method="get">
189
	<div class="table-responsive">
190
	<table class="table table-striped table-hover">
191
	<thead>
192
		<tr>
193
			<th><input type="submit" name="diff" class="btn btn-default" value="<?=gettext("Diff")?>" /></th>
194
			<th><?=gettext("Date")?></th>
195
			<th><?=gettext("Version")?></th>
196
			<th><?=gettext("Size")?></th>
197
			<th><?=gettext("Configuration Change")?></th>
198
			<th></th>
199
		</tr>
200
		</thead>
201

    
202
		<tbody>
203
		<tr>
204
			<td>
205
				<input type="radio" name="oldtime" disabled="disabled" />
206
				<input type="radio" name="newtime" value="current" <?=($_GET['newtime']==$version['time'] ? ' checked="checked"' : '')?>/>
207
			</td>
208
			<td><?=date(gettext("n/j/y H:i:s"), $config['revision']['time'])?></td>
209
			<td><?=$config['version']?></td>
210
			<td><?=format_bytes(filesize("/conf/config.xml"))?></td>
211
			<td><?=$config['revision']['description']?></td>
212
			<td><i><?=gettext("Current")?></i></td>
213
		</tr>
214
		<?php
215
			foreach($confvers as $version):
216
				if($version['time'] != 0)
217
					$date = date(gettext("n/j/y H:i:s"), $version['time']);
218
				else
219
					$date = gettext("Unknown");
220
		?>
221
		<tr>
222
			<td>
223
				<div id="mainarea">
224
					<form action="diag_confbak.php" method="post">
225
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
226

    
227
<?php if ($_GET["newver"] || $_GET["rmver"]): ?>
228
						<tr>
229
							<td colspan="2" valign="top" class="listtopic"><?php echo gettext("Confirm Action"); ?></td>
230
						</tr>
231
						<tr>
232
							<td width="22%" valign="top" class="vncell">&nbsp;</td>
233
							<td width="78%" class="vtable">
234

    
235
								<strong><?php echo gettext("Please confirm the selected action"); ?></strong>:
236
								<br />
237
								<br /><strong><?php echo gettext("Action"); ?>:</strong>
238
							<?php if (!empty($_GET["newver"])) {
239
								echo gettext("Restore from Configuration Backup");
240
								$target_config = $_GET["newver"]; ?>
241
								<input type="hidden" name="newver" value="<?php echo htmlspecialchars($_GET["newver"]); ?>" />
242
							<?php } elseif (!empty($_GET["rmver"])) {
243
								echo gettext("Remove Configuration Backup");
244
								$target_config = $_GET["rmver"]; ?>
245
								<input type="hidden" name="rmver" value="<?php echo htmlspecialchars($_GET["rmver"]); ?>" />
246
							<?php } ?>
247
								<br /><strong><?php echo gettext("Target Configuration"); ?>:</strong>
248
								<?php echo sprintf(gettext('Timestamp %1$s'), date(gettext("n/j/y H:i:s"), $target_config)); ?>
249
								<br /><input type="submit" name="confirm" value="<?php echo gettext("Confirm"); ?>" />
250
							</td>
251
						</tr>
252
<?php else: ?>
253

    
254
						<tr>
255
							<td width="10%">&nbsp;</td>
256
							<td width="15%" valign="top"><?=gettext("Backup Count");?></td>
257
							<td width="10%">
258
								<input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/>
259
							</td>
260
							<td width="60%">
261
								<?= 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."); ?>
262
							</td>
263
							<td width= "5%"><input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /></td>
264
						</tr>
265
						<tr>
266
							<td class="vncell">&nbsp;</td>
267
							<td colspan="4" class="vncell">
268
								<?= 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;}'") ?>
269
							</td>
270
						</tr>
271
					</table>
272
					</form>
273
					<form action="diag_confbak.php" method="get">
274
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="difference">
275
						<?php if (is_array($confvers)): ?>
276
						<tr>
277
							<td colspan="7" class="list">
278
								<?= 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."); ?>
279
								<br /><br />
280
							</td>
281
						</tr>
282
						<tr>
283
							<td width="5%" colspan="2" valign="middle" align="center" class="list nowrap"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
284
							<td width="20%" class="listhdrr"><?=gettext("Date");?></td>
285
							<td width="5%" class="listhdrr"><?=gettext("Version");?></td>
286
							<td width="5%" class="listhdrr"><?=gettext("Size");?></td>
287
							<td width="60%" class="listhdrr"><?=gettext("Configuration Change");?></td>
288
							<td width="5%" class="list">&nbsp;</td>
289
						</tr>
290
						<tr valign="top">
291
							<td valign="middle" class="list nowrap"></td>
292
							<td class="list">
293
								<input type="radio" name="newtime" value="current" />
294
							</td>
295
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
296
							<td class="listr"> <?= $config['version'] ?></td>
297
							<td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
298
							<td class="listr"> <?= htmlspecialchars($config['revision']['description']) ?></td>
299
							<td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
300
						</tr>
301
						<?php
302
							$c = 0;
303
							foreach ($confvers as $version):
304
								if ($version['time'] != 0) {
305
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
306
								} else {
307
									$date = gettext("Unknown");
308
								}
309
						?>
310
						<tr valign="top">
311
							<td class="list">
312
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>" />
313
							</td>
314
							<td class="list">
315
								<?php if ($c < (count($confvers) - 1)) { ?>
316
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>" />
317
								<?php } else { ?>
318
								&nbsp;
319
								<?php }
320
								$c++; ?>
321
							</td>
322
							<td class="listlr"> <?= $date ?></td>
323
							<td class="listr"> <?= $version['version'] ?></td>
324
							<td class="listr"> <?= format_bytes($version['filesize']) ?></td>
325
							<td class="listr"> <?= htmlspecialchars($version['description']) ?></td>
326
							<td valign="middle" class="list nowrap">
327
								<a href="diag_confbak.php?newver=<?=$version['time'];?>">
328
									<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");?>" />
329
								</a>
330
								<a href="diag_confbak.php?rmver=<?=$version['time'];?>">
331
									<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");?>" />
332
								</a>
333
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
334
									<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");?>" />
335
								</a>
336
							</td>
337
						</tr>
338
						<?php endforeach; ?>
339
						<tr>
340
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
341
							<td colspan="5"></td>
342
						</tr>
343
						<?php else: ?>
344
						<tr>
345
							<td>
346
								<?php print_info_box(gettext("No backups found.")); ?>
347
							</td>
348
						</tr>
349
						<?php endif; ?>
350
<?php endif; ?>
351
					</table>
352
					</form>
353
				</div>
354
			</td>
355
		</tr>
356
		<?php endforeach?>
357
		</tbody>
358
		<tfoot>
359
		<tr>
360
			<td colspan="6"><input type="submit" name="diff" class="btn btn-default" value="<?=gettext("Compare selected")?>" /></td>
361
		</tr>
362
	<?php endif; ?>
363
<?php endif?>
364
	</table>
365
	</div>
366
	</form>
367
<?php include("foot.inc")?>
(9-9/237)