Project

General

Profile

Download (8.96 KB) Statistics
| Branch: | Tag: | Revision:
1 1d2d6b3c Colin Smith
<?php
2
/* $Id$ */
3
/*
4 f79f9497 Sjon Hortensius
	diag_confbak.php
5
	Copyright (C) 2005 Colin Smith
6
	Copyright (C) 2010 Jim Pingle
7 8a07e316 Sjon Hortensius
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8 f79f9497 Sjon Hortensius
	All rights reserved.
9 1d2d6b3c Colin Smith
10 f79f9497 Sjon Hortensius
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 1d2d6b3c Colin Smith
13 f79f9497 Sjon Hortensius
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 1d2d6b3c Colin Smith
16 f79f9497 Sjon Hortensius
	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 1d2d6b3c Colin Smith
20 f79f9497 Sjon Hortensius
	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 1d2d6b3c Colin Smith
*/
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 dbeffa2f Stephen Beaver
} elseif ($_GET) {
55
	if (!isset($_GET['newver']) && !isset($_GET['rmver']) && !isset($_GET['getcfg']) && !isset($_GET['diff'])) {
56 b6513591 jim-p
		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 dbeffa2f Stephen Beaver
	
63
	if ($_GET['newver'] != "") {
64
		if (config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0) {
65
			$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['newver']), htmlspecialchars($confvers[$_GET['newver']]['description']));
66 5f601060 Phil Davis
		} else {
67 b6513591 jim-p
			$savemsg = gettext("Unable to revert to the selected configuration.");
68 5f601060 Phil Davis
		}
69 b6513591 jim-p
	}
70 dbeffa2f Stephen Beaver
	if ($_GET['rmver'] != "") {
71
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
72
		$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['rmver']), htmlspecialchars($confvers[$_GET['rmver']]['description']));
73 b6513591 jim-p
	}
74 91bfbd00 Scott Ullrich
	conf_mount_ro();
75 2f8d0729 Bill Marquette
}
76
77 5f601060 Phil Davis
if ($_GET['getcfg'] != "") {
78 9f9b88e2 jim-p
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
79
80
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
81
	$exp_data = file_get_contents($file);
82
	$exp_size = strlen($exp_data);
83
84
	header("Content-Type: application/octet-stream");
85
	header("Content-Disposition: attachment; filename={$exp_name}");
86
	header("Content-Length: $exp_size");
87
	echo $exp_data;
88
	exit;
89
}
90
91 5f601060 Phil Davis
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
92 dbeffa2f Stephen Beaver
	(is_numeric($_GET['oldtime'])) &&
93 5f601060 Phil Davis
	(is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
94 957e2f1f jim-p
	$diff = "";
95
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
96
	$oldtime = $_GET['oldtime'];
97
	if ($_GET['newtime'] == 'current') {
98
		$newfile = $g['conf_path'] . '/config.xml';
99
		$newtime = $config['revision']['time'];
100
	} else {
101
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
102
		$newtime = $_GET['newtime'];
103
	}
104
	if (file_exists($oldfile) && file_exists($newfile)) {
105
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
106
	}
107
}
108
109 e1ebe9e2 jim-p
cleanup_backupcache(false);
110 359893b0 Colin Smith
$confvers = get_backups();
111
unset($confvers['versions']);
112 1d2d6b3c Colin Smith
113 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Configuration History"));
114 b63695db Scott Ullrich
include("head.inc");
115
116 dbeffa2f Stephen Beaver
if ($savemsg) {
117
	print_info_box($savemsg, 'success');
118
}
119
120
if ($diff) {
121 f79f9497 Sjon Hortensius
?>
122 dbeffa2f Stephen Beaver
<div class="panel panel-default">
123
	<div class="panel-heading"><?=gettext("Configuration diff from ")?><?=date(gettext("n/j/y H:i:s"), $oldtime); ?><?=gettext(" to ")?><?=date(gettext("n/j/y H:i:s"), $newtime); ?></div>
124
	<div class="panel-body table-responsive">
125
	<!-- This table is left un-bootstrapped to maintain the original diff format output -->
126
		<table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
127 f79f9497 Sjon Hortensius
128
<?php
129 dbeffa2f Stephen Beaver
	foreach ($diff as $line) {
130
		switch (substr($line, 0, 1)) {
131
			case "+":
132
				$color = "#caffd3";
133
				break;
134
			case "-":
135
				$color = "#ffe8e8";
136
				break;
137
			case "@":
138
				$color = "#a0a0a0";
139
				break;
140
			default:
141
				$color = "#ffffff";
142
		}
143
?>
144
			<tr>
145
				<td valign="middle" bgcolor="<?=$color; ?>" style="white-space: pre-wrap;"><?=htmlentities($line)?></td>
146
			</tr>
147
<?php 
148
	}
149 f79f9497 Sjon Hortensius
?>
150 dbeffa2f Stephen Beaver
		</table>
151
	</div>
152
</div>
153
<?php 
154
}
155 f79f9497 Sjon Hortensius
156 dbeffa2f Stephen Beaver
$tab_array = array();
157
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
158
$tab_array[] = array(gettext("Backup/Restore"), false, "diag_backup.php");
159
display_top_tabs($tab_array);
160 f79f9497 Sjon Hortensius
161 dbeffa2f Stephen Beaver
require('classes/Form.class.php');
162 b6513591 jim-p
163 dbeffa2f Stephen Beaver
$form = new Form(new Form_Button(
164
	'Submit',
165
	gettext("Save")
166
));
167 b6513591 jim-p
168 dbeffa2f Stephen Beaver
$section = new Form_Section('Saved Configurations');
169 b6513591 jim-p
170 dbeffa2f Stephen Beaver
$section->addInput(new Form_Input(
171
	'backupcount',
172
	'Backup Count',
173
	'number',
174
	$config['system']['backupcount']
175
))->setHelp('Maximum number of old configurations to keep. By default this is 30 for a full install or 5 on NanoBSD. ');
176
177
$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
178
179
$section->addInput(new Form_StaticText(
180
	'Current space used by backups',
181
	$space
182
));
183
184
$form->add($section);
185
186
print($form);
187
188
if (is_array($confvers)) {
189
	print_info_box(gettext('To view the differences between an older configuration and a newer configuration, ' .
190
						   'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
191
						   'then press the "Diff" button.'));
192
}						   
193
?>					
194
					
195
<form action="diag_confbak.php" method="get">
196
	<div class="table-resposive">
197
		<table class="table table-striped table-hover table-condensed">
198
<?php 
199
if (is_array($confvers)):
200
?>
201
			<thead>
202
				<tr>
203
					<th colspan="2">
204
						<input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" />
205
					</th>
206
					<th><?=gettext("Date")?></th>
207
					<th><?=gettext("Version")?></th>
208
					<th><?=gettext("Size")?></th>
209
					<th><?=gettext("Configuration Change")?></th>
210
					<th><?=gettext("Actions")?></th>
211
				</tr>
212
			</thead>
213
			<tbody>
214
				<!-- First row is the current configuration -->
215
				<tr valign="top">
216
					<td></td>
217
					<td>
218
						<input type="radio" name="newtime" value="current" />
219
					</td>
220
					<td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
221
					<td><?= $config['version'] ?></td>
222
					<td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
223
					<td><?= htmlspecialchars($config['revision']['description']) ?></td>
224
					<td><?=gettext("Current configuration")?></td>
225
				</tr>
226
<?php
227
	// And now for hte table of prior backups
228
	$c = 0;
229
	foreach ($confvers as $version):
230
		if ($version['time'] != 0) {
231
			$date = date(gettext("n/j/y H:i:s"), $version['time']);
232
		} else {
233
			$date = gettext("Unknown");
234
		}
235
?>
236
				<tr>
237
					<td>
238
						<input type="radio" name="oldtime" value="<?=$version['time']?>" />
239
					</td>
240
					<td>
241
<?php
242
		if ($c < (count($confvers) - 1)) {
243
?>
244
								<input type="radio" name="newtime" value="<?=$version['time']?>" />
245
<?php 
246
		}
247
		$c++; 
248
?>
249
					</td>
250
					<td><?= $date ?></td>
251
					<td><?= $version['version'] ?></td>
252
					<td><?= format_bytes($version['filesize']) ?></td>
253
					<td><?= htmlspecialchars($version['description']) ?></td>
254
					<td>
255
						<a href="diag_confbak.php?newver=<?=$version['time']?>" class="btn btn-xs btn-success" 
256
							onclick="return confirm('<?=gettext("Are you sure you want to replace the current configuration with this backup?")?>')">
257
							<?=gettext("Revert")?>
258
						</a>
259
						<a href="diag_confbak.php?rmver=<?=$version['time']?>" class="btn btn-xs btn-danger">
260
							<?=gettext("Delete")?>
261
						</a>
262
						<a href="diag_confbak.php?getcfg=<?=$version['time']?>" class="btn btn-xs btn-default">
263
							<?=gettext("Download")?>
264
						</a>
265
					</td>
266
				</tr>
267
<?php 
268
	endforeach;
269
?>
270
				<tr>
271
					<td colspan="2"><input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" /></td>
272
					<td colspan="5"></td>
273
				</tr>
274
<?php 
275
else:
276
	print_info_box(gettext("No backups found."), 'danger');
277
endif;
278
?>
279
			</tbody>
280
		</table>
281 f79f9497 Sjon Hortensius
	</form>
282 dbeffa2f Stephen Beaver
</div>
283
284
<?php include("foot.inc");