Project

General

Profile

Download (8.92 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_nanobsd.php
4
	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
5
	All rights reserved.
6

    
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9

    
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12

    
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16

    
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28

    
29
##|+PRIV
30
##|*IDENT=page-diagnostics-nanobsd
31
##|*NAME=Diagnostics: NanoBSD
32
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
33
##|*MATCH=diag_nanobsd.php*
34
##|-PRIV
35

    
36
ini_set('zlib.output_compression', 0);
37
ini_set('implicit_flush', 1);
38
ini_set('max_input_time', '9999');
39

    
40
require_once("guiconfig.inc");
41

    
42
$pgtitle = array("Diagnostics","NanoBSD");
43
include("head.inc");
44

    
45
$BOOT_DEVICE=trim(`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`);
46
$REAL_BOOT_DEVICE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/{$BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`);
47
$BOOT_DRIVE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/pfsense | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' ' | /usr/bin/cut -d's' -f1`);
48

    
49
// Detect which slice is active and set information.
50
if(strstr($REAL_BOOT_DEVICE, "s1")) {
51
	$SLICE="2";
52
	$OLDSLICE="1";
53
	$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
54
	$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
55
	$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";	
56
	$GLABEL_SLICE="pfsense1";
57
	$UFS_ID="1";
58
	$OLD_UFS_ID="0";
59
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
60
} else {
61
	$SLICE="1";
62
	$OLDSLICE="2";
63
	$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
64
	$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
65
	$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";
66
	$GLABEL_SLICE="pfsense0";
67
	$UFS_ID="0";
68
	$OLD_UFS_ID="1";
69
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
70
}
71

    
72
?>
73

    
74
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
75

    
76
<?php include("fbegin.inc"); ?>
77

    
78
<?php
79

    
80
if($_POST['bootslice']) {
81
	echo <<<EOF
82
	 	<div id="loading">
83
			<img src="/themes/metallic/images/misc/loader.gif"> 
84
			Setting slice information, please wait...
85
			<p/>&nbsp;
86
		</div>
87
EOF;
88
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
89
	ob_implicit_flush(1);
90
	if(strstr($_POST['bootslice'], "s1")) {
91
		$ASLICE="2";
92
		$AOLDSLICE="1";
93
		$ATOFLASH="{$BOOT_DRIVE}s{$SLICE}";
94
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
95
		$AGLABEL_SLICE="pfsense1";
96
		$AUFS_ID="1";
97
		$AOLD_UFS_ID="0";
98
		$ABOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
99
	} else {
100
		$ASLICE="1";
101
		$AOLDSLICE="2";
102
		$ATOFLASH="{$BOOT_DRIVE}s{$SLICE}";
103
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
104
		$AGLABEL_SLICE="pfsense0";
105
		$AUFS_ID="0";
106
		$AOLD_UFS_ID="1";
107
		$ABOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
108
	}
109
	exec("gpart set -a active -i {$ASLICE} {$ABOOT_DRIVE}");
110
	exec("/usr/sbin/boot0cfg -s {$ASLICE} -v /dev/{$ABOOT_DRIVE}");
111
	exec("/bin/mkdir /tmp/{$AGLABEL_SLICE}");
112
	exec("/sbin/fsck_ufs -y /dev/{$ACOMPLETE_PATH}");
113
	exec("/sbin/mount /dev/ufs/{$AGLABEL_SLICE} /tmp/{$AGLABEL_SLICE}");
114
	exec("/bin/cp /etc/fstab /tmp/{$AGLABEL_SLICE}/etc/fstab");
115
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$AGLABEL_SLICE}/etc/fstab");
116
	if($status) {
117
		file_notice("UpgradeFailure","Something went wrong when trying to update the fstab entry.  Aborting upgrade.");
118
		exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
119
	}
120
	exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
121
	$savemsg = "The boot slice has been set to {$ABOOT_DRIVE} {$ASLICE}";
122
}
123

    
124
if($_POST['destslice']) {
125

    
126
echo <<<EOF
127
 	<div id="loading">
128
		<img src="/themes/metallic/images/misc/loader.gif">
129
		Duplicaating slice.  Please wait, this will take a moment...
130
		<p/>&nbsp;
131
	</div>
132
EOF;
133
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
134
	ob_implicit_flush(1);
135
	exec("dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
136
	exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
137
	exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
138
	exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
139
	exec("/sbin/fsck_ufs -y /dev/{$COMPLETE_PATH}");
140
	exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
141
	exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
142
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
143
	if($status) {
144
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
145
		$savemsg = "There was an error while duplicating the slice.  Operation aborted.";
146
	} else {
147
		$savemsg = "The slice has been duplicated.<p/>If you would like to boot from this newly duplicated slice please set it using the bootup information area.";
148
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
149
	}
150
}
151

    
152
if ($savemsg)
153
	print_info_box($savemsg)
154

    
155
?>
156
<table width="100%" border="0" cellpadding="0" cellspacing="0">
157
	<tr>
158
		<td>
159
			<!-- tabs here if you want them -->
160
		</td>
161
	</tr>
162
	<tr>
163
		<td id="mainarea">
164
			<div class="tabcont">
165
				<span class="vexpl">
166
					<span class="red">
167
						<strong>NOTE:&nbsp</strong>
168
					</span>
169
					The options on this page are intended for use by advanced users only.
170
					<br/>&nbsp;
171
				</span>
172
				<p/>
173
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
174
					<tr>
175
						<td colspan="2" valign="top" class="listtopic">Bootup information</td>
176
					</tr>
177
					<tr>
178
						<td width="22%" valign="top" class="vncell">Bootup</td>
179
						<td width="78%" class="vtable">
180
							<form action="diag_nanobsd.php" method="post" name="iform">
181
								Bootup slice:
182
								<select name='bootslice'>
183
									<option value='<?php echo $BOOTFLASH; ?>'>
184
										<?php echo $BOOTFLASH; ?>
185
									</option>
186
									<option value='<?php echo $TOFLASH; ?>'>
187
										<?php echo "{$TOFLASH}"; ?>
188
									</option>
189
								</select>
190
								<br/>
191
								This will set the bootup slice.
192
						</td>
193
					</tr>
194
					<tr>
195
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Set bootup'></form></td>
196
					</tr>
197
					<tr>
198
						<td colspan="2" valign="top" class="">&nbsp;</td>
199
					</tr>					
200
					<tr>
201
						<td colspan="2" valign="top" class="listtopic">Duplicate bootup slice to alternate</td>
202
					</tr>
203
					<tr>
204
						<td width="22%" valign="top" class="vncell">Duplicate bootup slice</td>
205
						<td width="78%" class="vtable">
206
							<form action="diag_nanobsd.php" method="post" name="iform">						
207
								Destination slice:							
208
								<select name='destslice'>
209
									<option value='<?php echo $COMPLETE_PATH; ?>'>
210
										<?php echo "{$COMPLETE_BOOT_PATH} -> {$TOFLASH}"; ?>
211
									</option>
212
								</select>
213
								<br/>
214
								This will duplicate the bootup slice to the alternate slice.  Use this if you would like to duplicate the known good working boot partition to the alternate.
215
						</td>
216
					</tr>
217
					<tr>
218
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Duplicate slice'></form></td>
219
					</tr>
220
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
221
					<tr>
222
						<td colspan="2" valign="top" class="">&nbsp;</td>
223
					</tr>					
224
					<tr>
225
						<td colspan="2" valign="top" class="listtopic">View upgrade log</td>
226
					</tr>
227
					<tr>
228
						<td width="22%" valign="top" class="vncell">View previous upgrade log</td>
229
						<td width="78%" class="vtable">
230
						<?php
231
							if($_POST['viewupgradelog']) {
232
								echo "<textarea name='log' cols='80' rows='40'>";
233
								echo file_get_contents("/conf/upgrade_log.txt");
234
								echo "\nFile list:\n";
235
								echo file_get_contents("/conf/file_upgrade_log.txt");
236
								echo "\nMisc log:\n";
237
								echo file_get_contents("/conf/firmware_update_misc.log");
238
								echo "\nfdisk/bsdlabel log:\n";
239
								echo file_get_contents("/conf/fdisk_upgrade_log.txt");
240
								echo "</textarea>";
241
							} else {
242
								echo "<form action='diag_nanobsd.php' method='post' name='iform'>";
243
								echo "<input type='submit' name='viewupgradelog' value='View upgrade log'>";
244
							}
245
						?>
246
						</td>
247
					</tr>
248
<?php endif; ?>
249
					<tr>
250
						<td colspan="2" valign="top" class="">&nbsp;</td>
251
					</tr>					
252
				</table>
253
			</div>
254
		</td>
255
	</tr>
256
</table>
257
<?php require("fend.inc"); ?>
258
</body>
259
</html>
260

    
261
<?php
262

    
263
// Clear the loading indicator
264
echo "<script type=\"text/javascript\">";
265
echo "$('loading').innerHTML = '';";
266
echo "</script>";	
267

    
268
?>
(24-24/175)