Projet

Général

Profil

Télécharger (10,6 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_confbak.php @ a3457472

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 (isset($_POST['backupcount'])) {
45
	if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) {
46
		$config['system']['backupcount'] = $_POST['backupcount'];
47
		$changedescr = $config['system']['backupcount'];
48
	} else {
49
		unset($config['system']['backupcount']);
50
		$changedescr = "(platform default)";
51
	}
52
	write_config("Changed backup revision count to {$changedescr}");
53
}
54

    
55
if($_GET['newver'] != "") {
56
	conf_mount_rw();
57
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
58
	if(config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0)
59

    
60
	$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']);
61
	else
62
		$savemsg = gettext("Unable to revert to the selected configuration.");
63
	conf_mount_ro();
64
}
65

    
66
if($_GET['rmver'] != "") {
67
	conf_mount_rw();
68
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
69
	unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
70
	$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']);
71
	conf_mount_ro();
72
}
73

    
74
if($_GET['getcfg'] != "") {
75
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
76

    
77
	$exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml");
78
	$exp_data = file_get_contents($file);
79
	$exp_size = strlen($exp_data);
80

    
81
	header("Content-Type: application/octet-stream");
82
	header("Content-Disposition: attachment; filename={$exp_name}");
83
	header("Content-Length: $exp_size");
84
	echo $exp_data;
85
	exit;
86
}
87

    
88
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime'])
89
      && is_numeric($_GET['oldtime']) && (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
90
	$diff = "";
91
	$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
92
	$oldtime = $_GET['oldtime'];
93
	if ($_GET['newtime'] == 'current') {
94
		$newfile = $g['conf_path'] . '/config.xml';
95
		$newtime = $config['revision']['time'];
96
	} else {
97
		$newfile = $g['conf_path'] . '/backup/config-' . $_GET['newtime'] . '.xml';
98
		$newtime = $_GET['newtime'];
99
	}
100
	if (file_exists($oldfile) && file_exists($newfile)) {
101
		exec("/usr/bin/diff -u " . escapeshellarg($oldfile) . " " . escapeshellarg($newfile), $diff);
102
	}
103
}
104

    
105
cleanup_backupcache(false);
106
$confvers = get_backups();
107
unset($confvers['versions']);
108

    
109
$pgtitle = array(gettext("Diagnostics"),gettext("Configuration History"));
110
include("head.inc");
111

    
112
?>
113

    
114
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
115
	<?php
116
		include("fbegin.inc");
117
		if($savemsg)
118
			print_info_box($savemsg);
119
	?>
120
	<?php if ($diff) { ?>
121
	<table align="center" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;" summary="diag confbak">
122
		<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>
123
		<?php foreach ($diff as $line) {
124
			switch (substr($line, 0, 1)) {
125
				case "+":
126
					$color = "#caffd3";
127
					break;
128
				case "-":
129
					$color = "#ffe8e8";
130
					break;
131
				case "@":
132
					$color = "#a0a0a0";
133
					break;
134
				default:
135
					$color = "#ffffff";
136
			}
137
			?>
138
		<tr>
139
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
140
		</tr>
141
		<?php } ?>
142
	</table>
143
	<br />
144
	<?php } ?>
145
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="stats">
146
		<tr>
147
			<td>
148
			<?php
149
				$tab_array = array();
150
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
151
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
152
				display_top_tabs($tab_array);
153
			?>
154
			</td>
155
		</tr>
156
		<tr>
157
			<td>
158
				<div id="mainarea">
159
					<form action="diag_confbak.php" method="post">
160
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
161
						<tr>
162
							<td width="10%">&nbsp;</td>
163
							<td width="15%" valign="top"><?=gettext("Backup Count");?></td>
164
							<td width="10%">
165
							<input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/>
166
							</td>
167
							<td width="60%">
168
							<?= gettext("Enter the number of older configurations to keep in the local backup cache. By default this is 30 for a full install or 5 on NanoBSD."); ?>
169
							</td>
170
							<td width= "5%"><input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /></td>
171
						</tr>
172
						<tr>
173
							<td class="vncell">&nbsp;</td>
174
							<td colspan="4" class="vncell">
175
							<?= gettext("NOTE: Be aware of how much space is consumed by backups before adjusting this value. Current space used by backups: "); ?> <?= exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
176
							</td>
177
						</tr>
178
					</table>
179
					</form>
180
					<form action="diag_confbak.php" method="get">
181
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="difference">
182
						<?php if (is_array($confvers)): ?>
183
						<tr>
184
							<td colspan="7" class="list">
185
							<?= gettext("To view the differences between an older configuration and a newer configuration, select the older configuration using the left column of radio options and select the newer configuration in the right colomn, then press the Diff button."); ?>
186
							<br /><br />
187
							</td>
188
						</tr>
189
						<tr>
190
							<td width="5%" colspan="2" valign="middle" align="center" class="list nowrap"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
191
							<td width="20%" class="listhdrr"><?=gettext("Date");?></td>
192
							<td width="5%" class="listhdrr"><?=gettext("Version");?></td>
193
							<td width="5%" class="listhdrr"><?=gettext("Size");?></td>
194
							<td width="60%" class="listhdrr"><?=gettext("Configuration Change");?></td>
195
							<td width="5%" class="list">&nbsp;</td>
196
						</tr>
197
						<tr valign="top">
198
							<td valign="middle" class="list nowrap"></td>
199
							<td class="list">
200
								<input type="radio" name="newtime" value="current" />
201
							</td>
202
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
203
							<td class="listr"> <?= $config['version'] ?></td>
204
							<td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
205
							<td class="listr"> <?= $config['revision']['description'] ?></td>
206
							<td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
207
						</tr>
208
						<?php
209
							$c = 0;
210
							foreach($confvers as $version):
211
								if($version['time'] != 0)
212
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
213
								else
214
									$date = gettext("Unknown");
215
						?>
216
						<tr valign="top">
217
							<td class="list">
218
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>" />
219
							</td>
220
							<td class="list">
221
								<?php if ($c < (count($confvers) - 1)) { ?>
222
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>" />
223
								<?php } else { ?>
224
								&nbsp;
225
								<?php }
226
								$c++; ?>
227
							</td>
228
							<td class="listlr"> <?= $date ?></td>
229
							<td class="listr"> <?= $version['version'] ?></td>
230
							<td class="listr"> <?= format_bytes($version['filesize']) ?></td>
231
							<td class="listr"> <?= $version['description'] ?></td>
232
							<td valign="middle" class="list nowrap">
233
							<a href="diag_confbak.php?newver=<?=$version['time'];?>" onclick="return confirm('<?=gettext("Revert to this configuration?");?>')">
234
							<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");?>" />
235
								</a>
236
							<a href="diag_confbak.php?rmver=<?=$version['time'];?>" onclick="return confirm('<?=gettext("Delete this configuration backup?");?>')">
237
							<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");?>" />
238
								</a>
239
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
240
								<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");?>" />
241
								</a>
242
							</td>
243
						</tr>
244
						<?php endforeach; ?>
245
						<tr>
246
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
247
							<td colspan="5"></td>
248
						</tr>
249
						<?php else: ?>
250
						<tr>
251
							<td>
252
								<?php print_info_box(gettext("No backups found.")); ?>
253
							</td>
254
						</tr>
255
						<?php endif; ?>
256
					</table>
257
					</form>
258
				</div>
259
			</td>
260
		</tr>
261
	</table>
262

    
263
<?php include("fend.inc"); ?>
264
</body>
265
</html>
(8-8/254)