Project

General

Profile

Download (8.55 KB) Statistics
| Branch: | Tag: | Revision:
1 1d2d6b3c Colin Smith
<?php
2
/* $Id$ */
3
/*
4 359893b0 Colin Smith
    diag_confbak.php
5
    Copyright (C) 2005 Colin Smith
6 957e2f1f jim-p
    Copyright (C) 2010 Jim Pingle
7 1d2d6b3c Colin Smith
    All rights reserved.
8
9
    Redistribution and use in source and binary forms, with or without
10
    modification, 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 the
17
       documentation and/or other materials provided with the distribution.
18
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31 f8ec8de4 Renato Botelho
/*
32 13d193c2 Scott Ullrich
	pfSense_MODULE:	config
33
*/
34
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-diagnostics-configurationhistory
37
##|*NAME=Diagnostics: Configuration History page
38
##|*DESCR=Allow access to the 'Diagnostics: Configuration History' page.
39
##|*MATCH=diag_confbak.php*
40
##|-PRIV
41
42 359893b0 Colin Smith
require("guiconfig.inc");
43 2f8d0729 Bill Marquette
44 359893b0 Colin Smith
if($_GET['newver'] != "") {
45 91bfbd00 Scott Ullrich
	conf_mount_rw();
46 1d478d96 Colin Smith
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
47 486b4999 Matthew Grooms
	if(config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0)
48 f8ec8de4 Renato Botelho
49 ddc55e12 Erik Fonnesbeck
	$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['newver']), $confvers[$_GET['newver']]['description']);
50 486b4999 Matthew Grooms
	else
51 f8ec8de4 Renato Botelho
		$savemsg = gettext("Unable to revert to the selected configuration.");
52 91bfbd00 Scott Ullrich
	conf_mount_ro();
53 359893b0 Colin Smith
}
54 2f8d0729 Bill Marquette
55 359893b0 Colin Smith
if($_GET['rmver'] != "") {
56 91bfbd00 Scott Ullrich
	conf_mount_rw();
57 1d478d96 Colin Smith
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
58 359893b0 Colin Smith
	unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
59 ddc55e12 Erik Fonnesbeck
	$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['rmver']),$confvers[$_GET['rmver']]['description']);
60 91bfbd00 Scott Ullrich
	conf_mount_ro();
61 2f8d0729 Bill Marquette
}
62
63 9f9b88e2 jim-p
if($_GET['getcfg'] != "") {
64
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
65
66
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
67
	$exp_data = file_get_contents($file);
68
	$exp_size = strlen($exp_data);
69
70
	header("Content-Type: application/octet-stream");
71
	header("Content-Disposition: attachment; filename={$exp_name}");
72
	header("Content-Length: $exp_size");
73
	echo $exp_data;
74
	exit;
75
}
76
77 957e2f1f jim-p
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
78
      && is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
79
	$diff = "";
80
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
81
	$oldtime = $_GET['oldtime'];
82
	if ($_GET['newtime'] == 'current') {
83
		$newfile = $g['conf_path'] . '/config.xml';
84
		$newtime = $config['revision']['time'];
85
	} else {
86
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
87
		$newtime = $_GET['newtime'];
88
	}
89
	if (file_exists($oldfile) && file_exists($newfile)) {
90
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
91
	}
92
}
93
94 359893b0 Colin Smith
cleanup_backupcache();
95
$confvers = get_backups();
96
unset($confvers['versions']);
97 1d2d6b3c Colin Smith
98 f8ec8de4 Renato Botelho
$pgtitle = array(gettext("Diagnostics"),gettext("Configuration History"));
99 b63695db Scott Ullrich
include("head.inc");
100
101 1d2d6b3c Colin Smith
?>
102
103
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
104 486b4999 Matthew Grooms
	<?php
105
		include("fbegin.inc");
106
		if($savemsg)
107
			print_info_box($savemsg);
108
	?>
109 8cb8751e Renato Botelho
	<?php if ($diff) { ?>
110 db67053a jim-p
	<table align="center" valign="middle" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px;">
111 f8ec8de4 Renato Botelho
		<tr><td><?=gettext("Configuration diff from");?> <?php echo date(gettext("n/j/y H:i:s"), $oldtime); ?> <?=gettext("to");?> <?php echo date(gettext("n/j/y H:i:s"), $newtime); ?></td></tr>
112 db67053a jim-p
		<?php foreach ($diff as $line) {
113
			switch (substr($line, 0, 1)) {
114
				case "+":
115
					$color = "#caffd3";
116
					break;
117
				case "-":
118
					$color = "#ffe8e8";
119
					break;
120
				case "@":
121
					$color = "#a0a0a0";
122
					break;
123
				default:
124
					$color = "";
125
			}
126
			?>
127 957e2f1f jim-p
		<tr>
128 db67053a jim-p
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
129 957e2f1f jim-p
		</tr>
130 db67053a jim-p
		<?php } ?>
131 957e2f1f jim-p
	</table>
132 db67053a jim-p
	<br />
133 8cb8751e Renato Botelho
	<?php } ?>
134 486b4999 Matthew Grooms
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
135
		<tr>
136
			<td>
137
			<?php
138
				$tab_array = array();
139 f8ec8de4 Renato Botelho
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
140
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
141 486b4999 Matthew Grooms
				display_top_tabs($tab_array);
142 f8ec8de4 Renato Botelho
			?>
143 486b4999 Matthew Grooms
			</td>
144
		</tr>
145
		<tr>
146
			<td>
147
				<div id="mainarea">
148 957e2f1f jim-p
					<form action="diag_confbak.php" method="GET">
149 486b4999 Matthew Grooms
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
150
						<?php if (is_array($confvers)): ?>
151
						<tr>
152 d8e1797a Carlos Eduardo Ramos
							<td colspan="2" valign="middle" align="center" class="list" nowrap><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
153 92420c0a jim-p
							<td width="22%" class="listhdrr"><?=gettext("Date");?></td>
154
							<td width="8%" class="listhdrr"><?=gettext("Version");?></td>
155 f8ec8de4 Renato Botelho
							<td width="70%" class="listhdrr"><?=gettext("Configuration Change");?></td>
156 486b4999 Matthew Grooms
						</tr>
157
						<tr valign="top">
158 957e2f1f jim-p
							<td valign="middle" class="list" nowrap></td>
159
							<td class="list">
160
								<input type="radio" name="newtime" value="current">
161
							</td>
162 f8ec8de4 Renato Botelho
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
163 92420c0a jim-p
							<td class="listr"> <?= $config['version'] ?></td>
164 486b4999 Matthew Grooms
							<td class="listr"> <?= $config['revision']['description'] ?></td>
165 f8ec8de4 Renato Botelho
							<td colspan="3" valign="middle" class="list" nowrap><b><?=gettext("Current");?></b></td>
166 486b4999 Matthew Grooms
						</tr>
167
						<?php
168 957e2f1f jim-p
							$c = 0;
169 486b4999 Matthew Grooms
							foreach($confvers as $version):
170
								if($version['time'] != 0)
171 f8ec8de4 Renato Botelho
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
172 486b4999 Matthew Grooms
								else
173 f8ec8de4 Renato Botelho
									$date = gettext("Unknown");
174 486b4999 Matthew Grooms
						?>
175
						<tr valign="top">
176 957e2f1f jim-p
							<td class="list">
177
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>">
178
							</td>
179
							<td class="list">
180
								<?php if ($c < (count($confvers) - 1)) { ?>
181
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>">
182 8cb8751e Renato Botelho
								<?php } else { ?>
183 957e2f1f jim-p
								&nbsp;
184 8cb8751e Renato Botelho
								<?php }
185 957e2f1f jim-p
								$c++; ?>
186
							</td>
187 486b4999 Matthew Grooms
							<td class="listlr"> <?= $date ?></td>
188 92420c0a jim-p
							<td class="listr"> <?= $version['version'] ?></td>
189
							<td class="listr"> <?= $version['description'] ?></td>
190 486b4999 Matthew Grooms
							<td valign="middle" class="list" nowrap>
191 f8ec8de4 Renato Botelho
							<a href="diag_confbak.php?newver=<?=$version['time'];?>" onclick="return confirm('<?=gettext("Revert to this configuration?");?>'")>
192
							<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");?>">
193 486b4999 Matthew Grooms
								</a>
194
							</td>
195
							<td valign="middle" class="list" nowrap>
196 f8ec8de4 Renato Botelho
							<a href="diag_confbak.php?rmver=<?=$version['time'];?>" onclick="return confirm('<?=gettext("Delete this configuration backup?");?>')">
197
							<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");?>">
198 486b4999 Matthew Grooms
								</a>
199
							</td>
200 9f9b88e2 jim-p
							<td valign="middle" class="list" nowrap>
201
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
202 f8ec8de4 Renato Botelho
								<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");?>">
203 9f9b88e2 jim-p
								</a>
204
							</td>
205 486b4999 Matthew Grooms
						</tr>
206
						<?php endforeach; ?>
207 957e2f1f jim-p
						<tr>
208 d8e1797a Carlos Eduardo Ramos
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
209 957e2f1f jim-p
							<td colspan="5"></td>
210
						</tr>
211 486b4999 Matthew Grooms
						<?php else: ?>
212
						<tr>
213
							<td>
214 f8ec8de4 Renato Botelho
								<?php print_info_box(gettext("No backups found.")); ?>
215 486b4999 Matthew Grooms
							</td>
216
						</tr>
217
						<?php endif; ?>
218
					</table>
219 957e2f1f jim-p
					</form>
220 486b4999 Matthew Grooms
				</div>
221
			</td>
222 2e2d1de7 Bill Marquette
		</tr>
223 0f10aee4 Bill Marquette
	</table>
224 cdb0814b Scott Ullrich
</form>
225 359893b0 Colin Smith
<?php include("fend.inc"); ?>
226 12af52d9 Scott Ullrich
</body>
227 310b2c06 Bill Marquette
</html>