Projet

Général

Profil

Télécharger (9,88 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_confbak.php @ 889c83d7

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 ($_POST) {
45
	if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm")) || (!isset($_POST['newver']) && !isset($_POST['rmver']))) {
46
		header("Location: diag_confbak.php");
47
		return;
48
	}
49

    
50
	conf_mount_rw();
51
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
52
	if($_POST['newver'] != "") {
53
		if(config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0)
54
		$savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['newver']), $confvers[$_POST['newver']]['description']);
55
		else
56
			$savemsg = gettext("Unable to revert to the selected configuration.");
57
	}
58
	if($_POST['rmver'] != "") {
59
		unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
60
		$savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']),$confvers[$_POST['rmver']]['description']);
61
	}
62
	conf_mount_ro();
63
}
64

    
65
if($_GET['getcfg'] != "") {
66
	$file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml';
67

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

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

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

    
96
cleanup_backupcache();
97
$confvers = get_backups();
98
unset($confvers['versions']);
99

    
100
$pgtitle = array(gettext("Diagnostics"),gettext("Configuration History"));
101
include("head.inc");
102

    
103
?>
104

    
105
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
106
	<?php
107
		include("fbegin.inc");
108
		if($savemsg)
109
			print_info_box($savemsg);
110
	?>
111
	<?php if ($diff) { ?>
112
	<table align="center" valign="middle" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px;">
113
		<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>
114
		<?php foreach ($diff as $line) {
115
			switch (substr($line, 0, 1)) {
116
				case "+":
117
					$color = "#caffd3";
118
					break;
119
				case "-":
120
					$color = "#ffe8e8";
121
					break;
122
				case "@":
123
					$color = "#a0a0a0";
124
					break;
125
				default:
126
					$color = "";
127
			}
128
			?>
129
		<tr>
130
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
131
		</tr>
132
		<?php } ?>
133
	</table>
134
	<br />
135
	<?php } ?>
136
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
137
		<tr>
138
			<td>
139
			<?php
140
				$tab_array = array();
141
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
142
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
143
				display_top_tabs($tab_array);
144
			?>
145
			</td>
146
		</tr>
147
		<tr>
148
			<td>
149
				<div id="mainarea">
150
<?PHP if ($_GET["newver"] || $_GET["rmver"]): ?>
151
					<form action="diag_confbak.php" method="post">
152
<?PHP else: ?>
153
					<form action="diag_confbak.php" method="get">
154
<?PHP endif; ?>
155
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
156

    
157
<?PHP if ($_GET["newver"] || $_GET["rmver"]): ?>
158
					<tr>
159
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Confirm Action"); ?></td>
160
					</tr>
161
					<tr>
162
						<td width="22%" valign="top" class="vncell">&nbsp;</td>
163
						<td width="78%" class="vtable">
164

    
165
							<strong><?PHP echo gettext("Please confirm the selected action"); ?></strong>:
166
							<br />
167
							<br /><strong><?PHP echo gettext("Action"); ?>:</strong>
168
						<?PHP	if (!empty($_GET["newver"])) {
169
							echo gettext("Restore from Configuration Backup");
170
							$target_config = $_GET["newver"]; ?>
171
							<input type="hidden" name="newver" value="<?PHP echo htmlspecialchars($_GET["newver"]); ?>" />
172
						<?PHP	} elseif (!empty($_GET["rmver"])) {
173
							echo gettext("Remove Configuration Backup");
174
							$target_config = $_GET["rmver"]; ?>
175
							<input type="hidden" name="rmver" value="<?PHP echo htmlspecialchars($_GET["rmver"]); ?>" />
176
						<?PHP	} ?>
177
							<br /><strong><?PHP echo gettext("Target Configuration"); ?>:</strong>
178
							<?PHP echo sprintf(gettext('Timestamp %1$s'), date(gettext("n/j/y H:i:s"), $target_config)); ?>
179
							<br /><input type="submit" name="confirm" value="<?PHP echo gettext("Confirm"); ?>" />
180
						</td>
181
					</tr>
182
<?PHP else: ?>
183

    
184
						<?php if (is_array($confvers)): ?>
185
						<tr>
186
							<td colspan="2" valign="middle" align="center" class="list" nowrap><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
187
							<td width="22%" class="listhdrr"><?=gettext("Date");?></td>
188
							<td width="8%" class="listhdrr"><?=gettext("Version");?></td>
189
							<td width="70%" class="listhdrr"><?=gettext("Configuration Change");?></td>
190
						</tr>
191
						<tr valign="top">
192
							<td valign="middle" class="list" nowrap></td>
193
							<td class="list">
194
								<input type="radio" name="newtime" value="current">
195
							</td>
196
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
197
							<td class="listr"> <?= $config['version'] ?></td>
198
							<td class="listr"> <?= $config['revision']['description'] ?></td>
199
							<td colspan="3" valign="middle" class="list" nowrap><b><?=gettext("Current");?></b></td>
200
						</tr>
201
						<?php
202
							$c = 0;
203
							foreach($confvers as $version):
204
								if($version['time'] != 0)
205
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
206
								else
207
									$date = gettext("Unknown");
208
						?>
209
						<tr valign="top">
210
							<td class="list">
211
								<input type="radio" name="oldtime" value="<?php echo $version['time'];?>">
212
							</td>
213
							<td class="list">
214
								<?php if ($c < (count($confvers) - 1)) { ?>
215
								<input type="radio" name="newtime" value="<?php echo $version['time'];?>">
216
								<?php } else { ?>
217
								&nbsp;
218
								<?php }
219
								$c++; ?>
220
							</td>
221
							<td class="listlr"> <?= $date ?></td>
222
							<td class="listr"> <?= $version['version'] ?></td>
223
							<td class="listr"> <?= $version['description'] ?></td>
224
							<td valign="middle" class="list" nowrap>
225
							<a href="diag_confbak.php?newver=<?=$version['time'];?>">
226
							<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");?>">
227
								</a>
228
							</td>
229
							<td valign="middle" class="list" nowrap>
230
							<a href="diag_confbak.php?rmver=<?=$version['time'];?>">
231
							<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");?>">
232
								</a>
233
							</td>
234
							<td valign="middle" class="list" nowrap>
235
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
236
								<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");?>">
237
								</a>
238
							</td>
239
						</tr>
240
						<?php endforeach; ?>
241
						<tr>
242
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
243
							<td colspan="5"></td>
244
						</tr>
245
						<?php else: ?>
246
						<tr>
247
							<td>
248
								<?php print_info_box(gettext("No backups found.")); ?>
249
							</td>
250
						</tr>
251
						<?php endif; ?>
252

    
253
<?php endif; ?>
254
					</table>
255
					</form>
256
				</div>
257
			</td>
258
		</tr>
259
	</table>
260
</form>
261
<?php include("fend.inc"); ?>
262
</body>
263
</html>
(8-8/246)