Project

General

Profile

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

    
57
/*
58
	pfSense_MODULE:	config
59
*/
60

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

    
68
require("guiconfig.inc");
69

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

    
85
	conf_mount_rw();
86
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
87

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

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

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

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

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

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

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

    
142
if ($savemsg) {
143
	print_info_box($savemsg, 'success');
144
}
145

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

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

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

    
187
require('classes/Form.class.php');
188

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

    
194
$section = new Form_Section('Saved Configurations');
195

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

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

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

    
210
$form->add($section);
211

    
212
print($form);
213

    
214
if (is_array($confvers)) {
215
	print_info_box(gettext('To view the differences between an older configuration and a newer configuration, ' .
216
						   'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
217
						   'then press the "Diff" button.'));
218
}
219
?>
220

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

    
303
<?php include("foot.inc");
(9-9/228)