Project

General

Profile

Download (8.99 KB) Statistics
| Branch: | Tag: | Revision:
1 1d2d6b3c Colin Smith
<?php
2
/*
3 6173d1f5 Colin Fleming
 * diag_confbak.php
4 c5d81585 Renato Botelho
 *
5
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2005 Colin Smith
10
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 c5d81585 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23 7dc1383a Stephen Beaver
 */
24 1d2d6b3c Colin Smith
25 6b07c15a Matthew Grooms
##|+PRIV
26
##|*IDENT=page-diagnostics-configurationhistory
27 5230f468 jim-p
##|*NAME=Diagnostics: Configuration History
28 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
29 d5a222cc jim-p
##|*WARN=standard-warning-root
30 6b07c15a Matthew Grooms
##|*MATCH=diag_confbak.php*
31
##|-PRIV
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 2f8d0729 Bill Marquette
35 e1ebe9e2 jim-p
if (isset($_POST['backupcount'])) {
36 3057a2ba jim-p
	if (!empty($_POST['backupcount']) && (!is_numericint($_POST['backupcount']) || ($_POST['backupcount'] < 0))) {
37
		$input_errors[] = gettext("Invalid Backup Count specified");
38 e1ebe9e2 jim-p
	}
39 7f4268b6 Steve Beaver
40 3057a2ba jim-p
	if (!$input_errors) {
41
		if (is_numericint($_POST['backupcount'])) {
42
			$config['system']['backupcount'] = $_POST['backupcount'];
43
			$changedescr = $config['system']['backupcount'];
44
		} elseif (empty($_POST['backupcount'])) {
45
			unset($config['system']['backupcount']);
46
			$changedescr = gettext("(platform default)");
47
		}
48
		write_config(sprintf(gettext("Changed backup revision count to %s"), $changedescr));
49
	}
50 7f4268b6 Steve Beaver
}
51 2f8d0729 Bill Marquette
52 7f4268b6 Steve Beaver
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
53 0da0d43e Phil Davis
54 7f4268b6 Steve Beaver
if ($_POST['newver'] != "") {
55
	if (config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0) {
56
		$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']));
57
	} else {
58
		$savemsg = gettext("Unable to revert to the selected configuration.");
59 b6513591 jim-p
	}
60 2f8d0729 Bill Marquette
}
61
62 7f4268b6 Steve Beaver
if ($_POST['rmver'] != "") {
63
	unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
64
	$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']));
65
}
66
67
if ($_REQUEST['getcfg'] != "") {
68
	$_REQUEST['getcfg'] = basename($_REQUEST['getcfg']);
69 ecb594d0 jim-p
	send_user_download('file',
70
				$g['conf_path'] . '/backup/config-' . $_REQUEST['getcfg'] . '.xml',
71
				"config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_REQUEST['getcfg']}.xml");
72 9f9b88e2 jim-p
}
73
74 7f4268b6 Steve Beaver
if (($_REQUEST['diff'] == 'Diff') && isset($_REQUEST['oldtime']) && isset($_REQUEST['newtime']) &&
75
    (is_numeric($_REQUEST['oldtime'])) &&
76
    (is_numeric($_REQUEST['newtime']) || ($_REQUEST['newtime'] == 'current'))) {
77 957e2f1f jim-p
	$diff = "";
78 7f4268b6 Steve Beaver
	$oldfile = $g['conf_path'] . '/backup/config-' . $_REQUEST['oldtime'] . '.xml';
79
	$oldtime = $_REQUEST['oldtime'];
80
	if ($_REQUEST['newtime'] == 'current') {
81 957e2f1f jim-p
		$newfile = $g['conf_path'] . '/config.xml';
82
		$newtime = $config['revision']['time'];
83
	} else {
84 7f4268b6 Steve Beaver
		$newfile = $g['conf_path'] . '/backup/config-' . $_REQUEST['newtime'] . '.xml';
85
		$newtime = $_REQUEST['newtime'];
86 957e2f1f jim-p
	}
87
	if (file_exists($oldfile) && file_exists($newfile)) {
88
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
89
	}
90
}
91
92 e1ebe9e2 jim-p
cleanup_backupcache(false);
93 359893b0 Colin Smith
$confvers = get_backups();
94
unset($confvers['versions']);
95 1d2d6b3c Colin Smith
96 0f298138 k-paulius
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), gettext("Config History"));
97 edcd7535 Phil Davis
$pglinks = array("", "diag_backup.php", "@self");
98 b63695db Scott Ullrich
include("head.inc");
99
100 3057a2ba jim-p
if ($input_errors) {
101
	print_input_errors($input_errors);
102
}
103
104 dbeffa2f Stephen Beaver
if ($savemsg) {
105
	print_info_box($savemsg, 'success');
106
}
107
108 1d191646 Phil Davis
$tab_array = array();
109 0f298138 k-paulius
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), false, "diag_backup.php");
110 2b38c46b k-paulius
$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
111 1d191646 Phil Davis
display_top_tabs($tab_array);
112
113 dbeffa2f Stephen Beaver
if ($diff) {
114 f79f9497 Sjon Hortensius
?>
115 dbeffa2f Stephen Beaver
<div class="panel panel-default">
116 95fa5cce Phil Davis
	<div class="panel-heading">
117
		<h2 class="panel-title">
118 3d7a8696 k-paulius
			<?=sprintf(gettext('Configuration Diff from %1$s to %2$s'), date(gettext("n/j/y H:i:s"), $oldtime), date(gettext("n/j/y H:i:s"), $newtime))?>
119 95fa5cce Phil Davis
		</h2>
120
	</div>
121 dbeffa2f Stephen Beaver
	<div class="panel-body table-responsive">
122
	<!-- This table is left un-bootstrapped to maintain the original diff format output -->
123
		<table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
124 f79f9497 Sjon Hortensius
125
<?php
126 dbeffa2f Stephen Beaver
	foreach ($diff as $line) {
127
		switch (substr($line, 0, 1)) {
128
			case "+":
129
				$color = "#caffd3";
130
				break;
131
			case "-":
132
				$color = "#ffe8e8";
133
				break;
134
			case "@":
135
				$color = "#a0a0a0";
136
				break;
137
			default:
138
				$color = "#ffffff";
139
		}
140
?>
141
			<tr>
142 91419f70 NewEraCracker
				<td class="diff-text" style="vertical-align:middle; background-color:<?=$color;?>; white-space:pre-wrap;"><?=htmlentities($line)?></td>
143 dbeffa2f Stephen Beaver
			</tr>
144 0da0d43e Phil Davis
<?php
145 dbeffa2f Stephen Beaver
	}
146 f79f9497 Sjon Hortensius
?>
147 dbeffa2f Stephen Beaver
		</table>
148
	</div>
149
</div>
150 0da0d43e Phil Davis
<?php
151 dbeffa2f Stephen Beaver
}
152 f79f9497 Sjon Hortensius
153 89333d37 jim-p
$form = new Form(false);
154 b6513591 jim-p
155 ca55edc3 stilez
$section = new Form_Section('Configuration Backup Cache Settings', 'configsettings', COLLAPSIBLE|SEC_CLOSED);
156 b6513591 jim-p
157 dbeffa2f Stephen Beaver
$section->addInput(new Form_Input(
158
	'backupcount',
159
	'Backup Count',
160
	'number',
161 3057a2ba jim-p
	$config['system']['backupcount'],
162
	['min' => '0']
163 4ebcee24 Steve Beaver
))->setHelp('Maximum number of old configurations to keep in the cache, 0 for no backups, or leave blank for the default value (%s for the current platform).', $g['default_config_backup_count']);
164 dbeffa2f Stephen Beaver
165
$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
166
167
$section->addInput(new Form_StaticText(
168
	'Current space used by backups',
169
	$space
170
));
171
172 89333d37 jim-p
$section->addInput(new Form_Button(
173
	'Submit',
174 827a3812 jim-p
	gettext("Save"),
175
	null,
176
	'fa-save'
177
))->addClass('btn-primary');
178 89333d37 jim-p
179 dbeffa2f Stephen Beaver
$form->add($section);
180
181
print($form);
182
183
if (is_array($confvers)) {
184 e47f1893 Phil Davis
?>
185
<div>
186 c95dabdd Stephen Beaver
	<div class="infoblock blockopen">
187 f6aebbcc NewEraCracker
		<?php print_info_box(
188 e47f1893 Phil Davis
			gettext(
189
				'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 f6aebbcc NewEraCracker
			'info', false); ?>
193 e47f1893 Phil Davis
	</div>
194
</div>
195
<?php
196 0da0d43e Phil Davis
}
197
?>
198
199 dbeffa2f Stephen Beaver
<form action="diag_confbak.php" method="get">
200 12537fdf Phil Davis
	<div class="table-responsive">
201 dbeffa2f Stephen Beaver
		<table class="table table-striped table-hover table-condensed">
202 0da0d43e Phil Davis
<?php
203 dbeffa2f Stephen Beaver
if (is_array($confvers)):
204
?>
205
			<thead>
206
				<tr>
207
					<th colspan="2">
208 9006d84f Renato Botelho
						<button type="submit" name="diff" class="btn btn-info btn-xs" value="Diff">
209 827a3812 jim-p
							<i class="fa fa-exchange icon-embed-btn"></i>
210
							<?=gettext("Diff"); ?>
211
						</button>
212 dbeffa2f Stephen Beaver
					</th>
213
					<th><?=gettext("Date")?></th>
214
					<th><?=gettext("Version")?></th>
215
					<th><?=gettext("Size")?></th>
216
					<th><?=gettext("Configuration Change")?></th>
217
					<th><?=gettext("Actions")?></th>
218
				</tr>
219
			</thead>
220
			<tbody>
221
				<!-- First row is the current configuration -->
222 ee10332b NewEraCracker
				<tr style="vertical-align:top;">
223 dbeffa2f Stephen Beaver
					<td></td>
224
					<td>
225
						<input type="radio" name="newtime" value="current" />
226
					</td>
227
					<td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
228
					<td><?= $config['version'] ?></td>
229
					<td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
230
					<td><?= htmlspecialchars($config['revision']['description']) ?></td>
231
					<td><?=gettext("Current configuration")?></td>
232
				</tr>
233
<?php
234 2d911f2c Phil Davis
	// And now for the table of prior backups
235 dbeffa2f Stephen Beaver
	$c = 0;
236
	foreach ($confvers as $version):
237
		if ($version['time'] != 0) {
238
			$date = date(gettext("n/j/y H:i:s"), $version['time']);
239
		} else {
240
			$date = gettext("Unknown");
241
		}
242
?>
243
				<tr>
244
					<td>
245
						<input type="radio" name="oldtime" value="<?=$version['time']?>" />
246
					</td>
247
					<td>
248
<?php
249
		if ($c < (count($confvers) - 1)) {
250
?>
251
								<input type="radio" name="newtime" value="<?=$version['time']?>" />
252 0da0d43e Phil Davis
<?php
253 dbeffa2f Stephen Beaver
		}
254 0da0d43e Phil Davis
		$c++;
255 dbeffa2f Stephen Beaver
?>
256
					</td>
257
					<td><?= $date ?></td>
258
					<td><?= $version['version'] ?></td>
259
					<td><?= format_bytes($version['filesize']) ?></td>
260
					<td><?= htmlspecialchars($version['description']) ?></td>
261
					<td>
262 7f4268b6 Steve Beaver
						<a class="fa fa-undo"		title="<?=gettext('Revert config')?>"	href="diag_confbak.php?newver=<?=$version['time']?>" onclick="return confirm('<?=gettext("Confirmation Required to replace the current configuration with this backup.")?>')" usepost></a>
263 0da0d43e Phil Davis
						<a class="fa fa-download"	title="<?=gettext('Download config')?>"	href="diag_confbak.php?getcfg=<?=$version['time']?>"></a>
264 7f4268b6 Steve Beaver
						<a class="fa fa-trash"		title="<?=gettext('Delete config')?>"	href="diag_confbak.php?rmver=<?=$version['time']?>" usepost></a>
265 dbeffa2f Stephen Beaver
					</td>
266
				</tr>
267 0da0d43e Phil Davis
<?php
268 dbeffa2f Stephen Beaver
	endforeach;
269
?>
270
				<tr>
271 27d6a45b jim-p
					<td colspan="2">
272 9006d84f Renato Botelho
						<button type="submit" name="diff" class="btn btn-info btn-xs" value="Diff">
273 27d6a45b jim-p
							<i class="fa fa-exchange icon-embed-btn"></i>
274
							<?=gettext("Diff"); ?>
275
						</button>
276
					</td>
277 dbeffa2f Stephen Beaver
					<td colspan="5"></td>
278
				</tr>
279 0da0d43e Phil Davis
<?php
280 dbeffa2f Stephen Beaver
else:
281
	print_info_box(gettext("No backups found."), 'danger');
282
endif;
283
?>
284
			</tbody>
285
		</table>
286 217cdb81 NOYB
	</div>
287
</form>
288 dbeffa2f Stephen Beaver
289 b782c904 Phil Davis
<?php include("foot.inc");