Project

General

Profile

Download (14.5 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
	if($_POST['rmver'] != "") {
69
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
70
		$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
	}
72
	conf_mount_ro();
73
}
74

    
75
if($_GET['getcfg'] != "") {
76
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
77

    
78
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
79
	$exp_data = file_get_contents($file);
80
	$exp_size = strlen($exp_data);
81

    
82
	header("Content-Type: application/octet-stream");
83
	header("Content-Disposition: attachment; filename={$exp_name}");
84
	header("Content-Length: $exp_size");
85
	echo $exp_data;
86
	exit;
87
}
88

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

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

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

    
113
if($savemsg)
114
	print_info_box($savemsg);
115
?>
116
	<?php if ($diff):?>
117
		<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>
118
		<pre><?php foreach ($diff as $line) {
119
			switch (substr($line, 0, 1)) {
120
				case "+":
121
					$color = "#caffd3";
122
					break;
123
				case "-":
124
					$color = "#ffe8e8";
125
					break;
126
				case "@":
127
					$color = "#a0a0a0";
128
					break;
129
				default:
130
					$color = "#ffffff";
131
			}
132

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

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

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

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

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

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