Projet

Général

Profil

Télécharger (8,55 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_confbak.php @ 7e736f38

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

    
49
	$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
	else
51
		$savemsg = gettext("Unable to revert to the selected configuration.");
52
	conf_mount_ro();
53
}
54

    
55
if($_GET['rmver'] != "") {
56
	conf_mount_rw();
57
	$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
58
	unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
59
	$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
	conf_mount_ro();
61
}
62

    
63
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
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
cleanup_backupcache();
95
$confvers = get_backups();
96
unset($confvers['versions']);
97

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

    
101
?>
102

    
103
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
104
	<?php
105
		include("fbegin.inc");
106
		if($savemsg)
107
			print_info_box($savemsg);
108
	?>
109
	<?php if ($diff) { ?>
110
	<table align="center" valign="middle" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px;">
111
		<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
		<?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
		<tr>
128
			<td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
129
		</tr>
130
		<?php } ?>
131
	</table>
132
	<br />
133
	<?php } ?>
134
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
135
		<tr>
136
			<td>
137
			<?php
138
				$tab_array = array();
139
				$tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
140
				$tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
141
				display_top_tabs($tab_array);
142
			?>
143
			</td>
144
		</tr>
145
		<tr>
146
			<td>
147
				<div id="mainarea">
148
					<form action="diag_confbak.php" method="get">
149
					<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
150
						<?php if (is_array($confvers)): ?>
151
						<tr>
152
							<td colspan="2" valign="middle" align="center" class="list" nowrap><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
153
							<td width="22%" class="listhdrr"><?=gettext("Date");?></td>
154
							<td width="8%" class="listhdrr"><?=gettext("Version");?></td>
155
							<td width="70%" class="listhdrr"><?=gettext("Configuration Change");?></td>
156
						</tr>
157
						<tr valign="top">
158
							<td valign="middle" class="list" nowrap></td>
159
							<td class="list">
160
								<input type="radio" name="newtime" value="current">
161
							</td>
162
							<td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
163
							<td class="listr"> <?= $config['version'] ?></td>
164
							<td class="listr"> <?= $config['revision']['description'] ?></td>
165
							<td colspan="3" valign="middle" class="list" nowrap><b><?=gettext("Current");?></b></td>
166
						</tr>
167
						<?php
168
							$c = 0;
169
							foreach($confvers as $version):
170
								if($version['time'] != 0)
171
									$date = date(gettext("n/j/y H:i:s"), $version['time']);
172
								else
173
									$date = gettext("Unknown");
174
						?>
175
						<tr valign="top">
176
							<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
								<?php } else { ?>
183
								&nbsp;
184
								<?php }
185
								$c++; ?>
186
							</td>
187
							<td class="listlr"> <?= $date ?></td>
188
							<td class="listr"> <?= $version['version'] ?></td>
189
							<td class="listr"> <?= $version['description'] ?></td>
190
							<td valign="middle" class="list" nowrap>
191
							<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
								</a>
194
							</td>
195
							<td valign="middle" class="list" nowrap>
196
							<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
								</a>
199
							</td>
200
							<td valign="middle" class="list" nowrap>
201
								<a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
202
								<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
								</a>
204
							</td>
205
						</tr>
206
						<?php endforeach; ?>
207
						<tr>
208
							<td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>"></td>
209
							<td colspan="5"></td>
210
						</tr>
211
						<?php else: ?>
212
						<tr>
213
							<td>
214
								<?php print_info_box(gettext("No backups found.")); ?>
215
							</td>
216
						</tr>
217
						<?php endif; ?>
218
					</table>
219
					</form>
220
				</div>
221
			</td>
222
		</tr>
223
	</table>
224
</form>
225
<?php include("fend.inc"); ?>
226
</body>
227
</html>
(8-8/246)