Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_confbak.php
5

    
6
 /* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004, 2005 Scott Ullrich
9
 *	Copyright (c)  2005 Colin Smith
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58

    
59
/*
60
	pfSense_MODULE:	config
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-diagnostics-configurationhistory
65
##|*NAME=Diagnostics: Configuration History page
66
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
67
##|*MATCH=diag_confbak.php*
68
##|-PRIV
69

    
70
require("guiconfig.inc");
71

    
72
if (isset($_POST['backupcount'])) {
73
	if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
74
		$config['system']['backupcount'] = $_POST['backupcount'];
75
		$changedescr = $config['system']['backupcount'];
76
	} else {
77
		unset($config['system']['backupcount']);
78
		$changedescr = "(platform default)";
79
	}
80
	write_config("Changed backup revision count to {$changedescr}");
81
} elseif ($_GET) {
82
	if (!isset($_GET['newver']) && !isset($_GET['rmver']) && !isset($_GET['getcfg']) && !isset($_GET['diff'])) {
83
		header("Location: diag_confbak.php");
84
		return;
85
	}
86

    
87
	conf_mount_rw();
88
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
89
	
90
	if ($_GET['newver'] != "") {
91
		if (config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0) {
92
			$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']));
93
		} else {
94
			$savemsg = gettext("Unable to revert to the selected configuration.");
95
		}
96
	}
97
	if ($_GET['rmver'] != "") {
98
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
99
		$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']));
100
	}
101
	conf_mount_ro();
102
}
103

    
104
if ($_GET['getcfg'] != "") {
105
	$_GET['getcfg'] = basename($_GET['getcfg']);
106
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
107

    
108
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
109
	$exp_data = file_get_contents($file);
110
	$exp_size = strlen($exp_data);
111

    
112
	header("Content-Type: application/octet-stream");
113
	header("Content-Disposition: attachment; filename={$exp_name}");
114
	header("Content-Length: $exp_size");
115
	echo $exp_data;
116
	exit;
117
}
118

    
119
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
120
    (is_numeric($_GET['oldtime'])) &&
121
    (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
122
	$diff = "";
123
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
124
	$oldtime = $_GET['oldtime'];
125
	if ($_GET['newtime'] == 'current') {
126
		$newfile = $g['conf_path'] . '/config.xml';
127
		$newtime = $config['revision']['time'];
128
	} else {
129
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
130
		$newtime = $_GET['newtime'];
131
	}
132
	if (file_exists($oldfile) && file_exists($newfile)) {
133
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
134
	}
135
}
136

    
137
cleanup_backupcache(false);
138
$confvers = get_backups();
139
unset($confvers['versions']);
140

    
141
$pgtitle = array(gettext("Diagnostics"), gettext("Configuration History"));
142
include("head.inc");
143

    
144
if ($savemsg) {
145
	print_info_box($savemsg, 'success');
146
}
147

    
148
if ($diff) {
149
?>
150
<div class="panel panel-default">
151
	<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>
152
	<div class="panel-body table-responsive">
153
	<!-- This table is left un-bootstrapped to maintain the original diff format output -->
154
		<table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
155

    
156
<?php
157
	foreach ($diff as $line) {
158
		switch (substr($line, 0, 1)) {
159
			case "+":
160
				$color = "#caffd3";
161
				break;
162
			case "-":
163
				$color = "#ffe8e8";
164
				break;
165
			case "@":
166
				$color = "#a0a0a0";
167
				break;
168
			default:
169
				$color = "#ffffff";
170
		}
171
?>
172
			<tr>
173
				<td valign="middle" bgcolor="<?=$color; ?>" style="white-space: pre-wrap;"><?=htmlentities($line)?></td>
174
			</tr>
175
<?php 
176
	}
177
?>
178
		</table>
179
	</div>
180
</div>
181
<?php 
182
}
183

    
184
$tab_array = array();
185
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
186
$tab_array[] = array(gettext("Backup/Restore"), false, "diag_backup.php");
187
display_top_tabs($tab_array);
188

    
189
require('classes/Form.class.php');
190

    
191
$form = new Form(new Form_Button(
192
	'Submit',
193
	gettext("Save")
194
));
195

    
196
$section = new Form_Section('Saved Configurations');
197

    
198
$section->addInput(new Form_Input(
199
	'backupcount',
200
	'Backup Count',
201
	'number',
202
	$config['system']['backupcount']
203
))->setHelp('Maximum number of old configurations to keep. By default this is 30 for a full install or 5 on NanoBSD. ');
204

    
205
$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
206

    
207
$section->addInput(new Form_StaticText(
208
	'Current space used by backups',
209
	$space
210
));
211

    
212
$form->add($section);
213

    
214
print($form);
215

    
216
if (is_array($confvers)) {
217
	print_info_box(gettext('To view the differences between an older configuration and a newer configuration, ' .
218
						   'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
219
						   'then press the "Diff" button.'));
220
}						   
221
?>					
222
					
223
<form action="diag_confbak.php" method="get">
224
	<div class="table-resposive">
225
		<table class="table table-striped table-hover table-condensed">
226
<?php 
227
if (is_array($confvers)):
228
?>
229
			<thead>
230
				<tr>
231
					<th colspan="2">
232
						<input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" />
233
					</th>
234
					<th><?=gettext("Date")?></th>
235
					<th><?=gettext("Version")?></th>
236
					<th><?=gettext("Size")?></th>
237
					<th><?=gettext("Configuration Change")?></th>
238
					<th><?=gettext("Actions")?></th>
239
				</tr>
240
			</thead>
241
			<tbody>
242
				<!-- First row is the current configuration -->
243
				<tr valign="top">
244
					<td></td>
245
					<td>
246
						<input type="radio" name="newtime" value="current" />
247
					</td>
248
					<td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
249
					<td><?= $config['version'] ?></td>
250
					<td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
251
					<td><?= htmlspecialchars($config['revision']['description']) ?></td>
252
					<td><?=gettext("Current configuration")?></td>
253
				</tr>
254
<?php
255
	// And now for the table of prior backups
256
	$c = 0;
257
	foreach ($confvers as $version):
258
		if ($version['time'] != 0) {
259
			$date = date(gettext("n/j/y H:i:s"), $version['time']);
260
		} else {
261
			$date = gettext("Unknown");
262
		}
263
?>
264
				<tr>
265
					<td>
266
						<input type="radio" name="oldtime" value="<?=$version['time']?>" />
267
					</td>
268
					<td>
269
<?php
270
		if ($c < (count($confvers) - 1)) {
271
?>
272
								<input type="radio" name="newtime" value="<?=$version['time']?>" />
273
<?php 
274
		}
275
		$c++; 
276
?>
277
					</td>
278
					<td><?= $date ?></td>
279
					<td><?= $version['version'] ?></td>
280
					<td><?= format_bytes($version['filesize']) ?></td>
281
					<td><?= htmlspecialchars($version['description']) ?></td>
282
					<td>
283
						<a href="diag_confbak.php?newver=<?=$version['time']?>" class="btn btn-xs btn-success" 
284
							onclick="return confirm('<?=gettext("Are you sure you want to replace the current configuration with this backup?")?>')">
285
							<?=gettext("Revert")?>
286
						</a>
287
						<a href="diag_confbak.php?rmver=<?=$version['time']?>" class="btn btn-xs btn-danger">
288
							<?=gettext("Delete")?>
289
						</a>
290
						<a href="diag_confbak.php?getcfg=<?=$version['time']?>" class="btn btn-xs btn-default">
291
							<?=gettext("Download")?>
292
						</a>
293
					</td>
294
				</tr>
295
<?php 
296
	endforeach;
297
?>
298
				<tr>
299
					<td colspan="2"><input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" /></td>
300
					<td colspan="5"></td>
301
				</tr>
302
<?php 
303
else:
304
	print_info_box(gettext("No backups found."), 'danger');
305
endif;
306
?>
307
			</tbody>
308
		</table>
309
	</form>
310
</div>
311

    
312
<?php include("foot.inc");
(9-9/233)