Project

General

Profile

Download (8.01 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    diag_confbak.php
5
    Copyright (C) 2005 Colin Smith
6
    Copyright (C) 2010 Jim Pingle
7
    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
/*	
32
	pfSense_MODULE:	config
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43

    
44
if($_GET['newver'] != "") {
45
	conf_mount_rw();
46
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
47
	if(config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0)
48
		$savemsg = "Successfully reverted to timestamp " . date("n/j/y H:i:s", $_GET['newver']) . " with description \"" . $confvers[$_GET['newver']]['description'] . "\".";
49
	else
50
		$savemsg = "Unable to revert to the selected configuration.";
51
	conf_mount_ro();
52
}
53

    
54
if($_GET['rmver'] != "") {
55
	conf_mount_rw();
56
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
57
	unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
58
	$savemsg = "Deleted backup with timestamp " . date("n/j/y H:i:s", $_GET['rmver']) . " and description \"" . $confvers[$_GET['rmver']]['description'] . "\".";
59
	conf_mount_ro();
60
}
61

    
62
if($_GET['getcfg'] != "") {
63
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
64

    
65
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
66
	$exp_data = file_get_contents($file);
67
	$exp_size = strlen($exp_data);
68

    
69
	header("Content-Type: application/octet-stream");
70
	header("Content-Disposition: attachment; filename={$exp_name}");
71
	header("Content-Length: $exp_size");
72
	echo $exp_data;
73
	exit;
74
}
75

    
76
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
77
      && is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
78
	$diff = "";
79
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
80
	$oldtime = $_GET['oldtime'];
81
	if ($_GET['newtime'] == 'current') {
82
		$newfile = $g['conf_path'] . '/config.xml';
83
		$newtime = $config['revision']['time'];
84
	} else {
85
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
86
		$newtime = $_GET['newtime'];
87
	}
88
	if (file_exists($oldfile) && file_exists($newfile)) {
89
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
90
	}
91
}
92

    
93
cleanup_backupcache();
94
$confvers = get_backups();
95
unset($confvers['versions']);
96

    
97
$pgtitle = array("Diagnostics","Configuration History");
98
include("head.inc");
99

    
100
?>
101

    
102
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
103
	<?php
104
		include("fbegin.inc");
105
		if($savemsg)
106
			print_info_box($savemsg);
107
	?>
108
	<? if ($diff) { ?>
109
	<table align="center" valign="middle" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px;">
110
		<tr><td>Configuration diff from <?php echo date("n/j/y H:i:s", $oldtime); ?> to <?php echo date("n/j/y H:i:s", $newtime); ?></td></tr>
111
		<?php foreach ($diff as $line) {
112
			switch (substr($line, 0, 1)) {
113
				case "+":
114
					$color = "#caffd3";
115
					break;
116
				case "-":
117
					$color = "#ffe8e8";
118
					break;
119
				case "@":
120
					$color = "#a0a0a0";
121
					break;
122
				default:
123
					$color = "";
124
			}
125
			?>
126
		<tr>
127
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
128
		</tr>
129
		<?php } ?>
130
	</table>
131
	<br />
132
	<? } ?>
133
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
134
		<tr>
135
			<td>
136
			<?php
137
				$tab_array = array();
138
				$tab_array[0] = array("Config History", true, "diag_confbak.php");
139
				$tab_array[1] = array("Backup/Restore", false, "diag_backup.php");
140
				display_top_tabs($tab_array);
141
			?>			
142
			</td>
143
		</tr>
144
		<tr>
145
			<td>
146
				<div id="mainarea">
147
					<form action="diag_confbak.php" method="GET">
148
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
149
						<?php if (is_array($confvers)): ?>
150
						<tr>
151
							<td colspan="2" valign="middle" align="center" class="list" nowrap><input type="submit" name="diff" value="Diff"></td>
152
							<td width="30%" class="listhdrr">Date</td>
153
							<td width="70%" class="listhdrr">Configuration Change</td>
154
						</tr>
155
						<tr valign="top">
156
							<td valign="middle" class="list" nowrap></td>
157
							<td class="list">
158
								<input type="radio" name="newtime" value="current">
159
							</td>
160
							<td class="listlr"> <?= date("n/j/y H:i:s", $config['revision']['time']) ?></td>
161
							<td class="listr"> <?= $config['revision']['description'] ?></td>
162
							<td colspan="3" valign="middle" class="list" nowrap><b>Current</b></td>
163
						</tr>
164
						<?php
165
							$c = 0;
166
							foreach($confvers as $version):
167
								if($version['time'] != 0)
168
									$date = date("n/j/y H:i:s", $version['time']);
169
								else
170
									$date = "Unknown";
171
								$desc = $version['description'];
172
						?>
173
						<tr valign="top">
174
							<td class="list">
175
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>">
176
							</td>
177
							<td class="list">
178
								<?php if ($c < (count($confvers) - 1)) { ?>
179
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>">
180
								<? } else { ?>
181
								&nbsp;
182
								<? } 
183
								$c++; ?>
184
							</td>
185
							<td class="listlr"> <?= $date ?></td>
186
							<td class="listr"> <?= $desc ?></td>
187
							<td valign="middle" class="list" nowrap>
188
								<a href="diag_confbak.php?newver=<?=$version['time'];?>" onclick="return confirm('Revert to this configuration?')">
189
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="Revert to this configuration" title="Revert to this configuration">
190
								</a>
191
							</td>
192
							<td valign="middle" class="list" nowrap>
193
								<a href="diag_confbak.php?rmver=<?=$version['time'];?>" onclick="return confirm('Delete this configuration backup?')">
194
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="Remove this backup" title="Remove this backup">
195
								</a>
196
							</td>
197
							<td valign="middle" class="list" nowrap>
198
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
199
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" width="17" height="17" border="0" alt="Download this backup" title="Download this backup">
200
								</a>
201
							</td>
202
						</tr>
203
						<?php endforeach; ?>
204
						<tr>
205
							<td colspan="2"><input type="submit" name="diff" value="Diff"></td>
206
							<td colspan="5"></td>
207
						</tr>
208
						<?php else: ?>
209
						<tr>
210
							<td>
211
								<?php print_info_box("No backups found."); ?>
212
							</td>
213
						</tr>
214
						<?php endif; ?>
215
					</table>
216
					</form>
217
				</div>
218
			</td>
219
		</tr>
220
	</table>
221
</form>
222
<?php include("fend.inc"); ?>
223
</body>
224
</html>
(7-7/221)