Project

General

Profile

Download (9.04 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
require_once("config.inc");
42

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

    
46
$BOOT_DEVICE=trim(`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`);
47
$REAL_BOOT_DEVICE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/{$BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`);
48
$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`);
49

    
50
// Detect which slice is active and set information.
51
if(strstr($REAL_BOOT_DEVICE, "s1")) {
52
	$SLICE="2";
53
	$OLDSLICE="1";
54
	$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
55
	$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
56
	$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";	
57
	$GLABEL_SLICE="pfsense1";
58
	$UFS_ID="1";
59
	$OLD_UFS_ID="0";
60
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
61

    
62
} else {
63
	$SLICE="1";
64
	$OLDSLICE="2";
65
	$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
66
	$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
67
	$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";
68
	$GLABEL_SLICE="pfsense0";
69
	$UFS_ID="0";
70
	$OLD_UFS_ID="1";
71
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
72
}
73

    
74
?>
75

    
76
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
77
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
78

    
79
<?php include("fbegin.inc"); ?>
80

    
81
<?php
82

    
83
if($_POST['bootslice']) {
84
	echo <<<EOF
85
	 	<div id="loading">
86
			<img src="/themes/metallic/images/misc/loader.gif"> 
87
			Setting slice information, please wait...
88
			<p/>&nbsp;
89
		</div>
90
EOF;
91
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
92
	ob_implicit_flush(1);
93
	if(strstr($_POST['bootslice'], "s2")) {
94
		$ASLICE="2";
95
		$AOLDSLICE="1";
96
		$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
97
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
98
		$AGLABEL_SLICE="pfsense1";
99
		$AUFS_ID="1";
100
		$AOLD_UFS_ID="0";
101
		$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
102
	} else {
103
		$ASLICE="1";
104
		$AOLDSLICE="2";
105
		$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
106
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
107
		$AGLABEL_SLICE="pfsense0";
108
		$AUFS_ID="0";
109
		$AOLD_UFS_ID="1";
110
		$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
111
	}
112
	conf_mount_rw();
113
	exec("sysctl kern.geom.debugflags=16");	
114
	exec("gpart set -a active -i {$ASLICE} {$BOOT_DRIVE}");
115
	exec("/usr/sbin/boot0cfg -s {$ASLICE} -v /dev/{$BOOT_DRIVE}");
116
	exec("/bin/mkdir /tmp/{$AGLABEL_SLICE}");
117
	exec("/sbin/fsck_ufs -y /dev/{$ACOMPLETE_PATH}");
118
	exec("/sbin/mount /dev/ufs/{$AGLABEL_SLICE} /tmp/{$AGLABEL_SLICE}");
119
	$fstab = <<<EOF
120
/dev/ufs/{$AGLABEL_SLICE} / ufs ro 1 1
121
/dev/ufs/cf /cf ufs ro 1 1	
122
EOF;
123
	file_put_contents("/tmp/{$AGLABEL_SLICE}/etc/fstab", $fstab);
124
	exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
125
	exec("sysctl kern.geom.debugflags=0");
126
	conf_mount_ro();
127
	$savemsg = "The boot slice has been set to {$BOOT_DRIVE} {$AGLABEL_SLICE}";
128
}
129

    
130
if($_POST['destslice']) {
131

    
132
echo <<<EOF
133
 	<div id="loading">
134
		<img src="/themes/metallic/images/misc/loader.gif">
135
		Duplicating slice.  Please wait, this will take a moment...
136
		<p/>&nbsp;
137
	</div>
138
EOF;
139
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
140
	ob_implicit_flush(1);
141
	exec("sysctl kern.geom.debugflags=16");
142
	exec("dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
143
	exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
144
	exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
145
	exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
146
	exec("/sbin/fsck_ufs -y /dev/{$COMPLETE_PATH}");
147
	exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
148
	exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
149
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
150
	if($status) {
151
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
152
		$savemsg = "There was an error while duplicating the slice.  Operation aborted.";
153
	} else {
154
		$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.";
155
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
156
	}
157
	exec("sysctl kern.geom.debugflags=0");
158
}
159

    
160
if ($savemsg)
161
	print_info_box($savemsg)
162

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

    
269
<?php
270

    
271
// Clear the loading indicator
272
echo "<script type=\"text/javascript\">";
273
echo "$('loading').innerHTML = '';";
274
echo "</script>";	
275

    
276
?>
(26-26/217)