Project

General

Profile

Download (7.8 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
	$GLABEL_SLICE="pfsense1";
56
	$UFS_ID="1";
57
	$OLD_UFS_ID="0";
58
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
59
} else {
60
	$SLICE="1";
61
	$OLDSLICE="2";
62
	$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
63
	$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
64
	$GLABEL_SLICE="pfsense0";
65
	$UFS_ID="0";
66
	$OLD_UFS_ID="1";
67
	$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
68
}
69

    
70
?>
71

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

    
74
<?php include("fbegin.inc"); ?>
75

    
76
<?php
77

    
78
if($_POST['bootslice']) {
79
	echo <<<EOF
80
	 	<div id="loading">
81
			<img src="/themes/metallic/images/misc/loader.gif"> 
82
			Setting slice information, please wait...
83
			<p/>&nbsp;
84
		</div>
85
EOF;
86
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
87
	ob_implicit_flush(1);
88
	exec("gpart set -a active -i {$SLICE} {$BOOT_DRIVE}");
89
	exec("/usr/sbin/boot0cfg -s {$SLICE} -v /dev/{$BOOT_DRIVE}");
90
	exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
91
	exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
92
	exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
93
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
94
	if($status) {
95
		file_notice("UpgradeFailure","Something went wrong when trying to update the fstab entry.  Aborting upgrade.");
96
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
97
	}
98
	exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
99
	$savemsg = "The boot slice has been set to {$BOOT_DRIVE} {$SLICE}";
100
}
101

    
102
if($_POST['destslice']) {
103

    
104
echo <<<EOF
105
 	<div id="loading">
106
		<img src="/themes/metallic/images/misc/loader.gif">
107
		Duplicaating slice.  Please wait, this will take a moment...
108
		<p/>&nbsp;
109
	</div>
110
EOF;
111
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
112
	ob_implicit_flush(1);
113
	exec("dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
114
	exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
115
	exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
116
	exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
117
	exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
118
	exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
119
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
120
	if($status) {
121
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
122
		$savemsg = "There was an error while duplicating the slice.  Operation aborted.";
123
	} else {
124
		$savemsg = "The slice has been duplicated";
125
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
126
	}
127
}
128

    
129
if ($savemsg)
130
	print_info_box($savemsg)
131

    
132
?>
133
<table width="100%" border="0" cellpadding="0" cellspacing="0">
134
	<tr>
135
		<td>
136
			<!-- tabs here if you want them -->
137
		</td>
138
	</tr>
139
	<tr>
140
		<td id="mainarea">
141
			<div class="tabcont">
142
				<span class="vexpl">
143
					<span class="red">
144
						<strong>NOTE:&nbsp</strong>
145
					</span>
146
					The options on this page are intended for use by advanced users only.
147
					<br/>&nbsp;
148
				</span>
149
				<p/>
150
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
151
					<tr>
152
						<td colspan="2" valign="top" class="listtopic">Bootup information</td>
153
					</tr>
154
					<tr>
155
						<td width="22%" valign="top" class="vncell">Bootup</td>
156
						<td width="78%" class="vtable">
157
							<form action="diag_nanobsd.php" method="post" name="iform">
158
								Bootup slice:
159
								<select name='bootslice'>
160
									<option value='<?php echo $BOOTFLASH; ?>'>
161
										<?php echo $BOOTFLASH; ?>
162
									</option>
163
									<option value='<?php echo $TOFLASH; ?>'>
164
										<?php echo $TOFLASH; ?>
165
									</option>
166
								</select>
167
								<br/>
168
								This will set the bootup slice.
169
						</td>
170
					</tr>
171
					<tr>
172
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Set bootup'></form></td>
173
					</tr>
174
					<tr>
175
						<td colspan="2" valign="top" class="">&nbsp;</td>
176
					</tr>					
177
					<tr>
178
						<td colspan="2" valign="top" class="listtopic">Duplicate bootup slice to alternate</td>
179
					</tr>
180
					<tr>
181
						<td width="22%" valign="top" class="vncell">Duplicate bootup slice</td>
182
						<td width="78%" class="vtable">
183
							<form action="diag_nanobsd.php" method="post" name="iform">						
184
								Destination slice:							
185
								<select name='destslice'>
186
									<option value='<?php echo $COMPLETE_PATH; ?>'>
187
										<?php echo $COMPLETE_PATH; ?>
188
									</option>
189
								</select>
190
								<br/>
191
								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.
192
						</td>
193
					</tr>
194
					<tr>
195
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Duplicate slice'></form></td>
196
					</tr>
197
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
198
					<tr>
199
						<td colspan="2" valign="top" class="">&nbsp;</td>
200
					</tr>					
201
					<tr>
202
						<td colspan="2" valign="top" class="listtopic">View upgrade log</td>
203
					</tr>
204
					<tr>
205
						<td width="22%" valign="top" class="vncell">View previous upgrade log</td>
206
						<td width="78%" class="vtable">
207
						<?php
208
							if($_POST['viewupgradelog']) {
209
								echo "<textarea name='log' cols='80' rows='40'>";
210
								echo file_get_contents("/conf/upgrade_log.txt");
211
								echo "</textarea>";
212
							} else {
213
								echo "<form action='diag_nanobsd.php' method='post' name='iform'>";
214
								echo "<input type='submit' name='viewupgradelog' value='View upgrade log'>";
215
							}
216
						?>
217
						</td>
218
					</tr>
219
<?php endif; ?>
220
					<tr>
221
						<td colspan="2" valign="top" class="">&nbsp;</td>
222
					</tr>					
223
				</table>
224
			</div>
225
		</td>
226
	</tr>
227
</table>
228
<?php require("fend.inc"); ?>
229
</body>
230
</html>
231

    
232
<?php
233

    
234
// Clear the loading indicator
235
echo "<script type=\"text/javascript\">";
236
echo "$('loading').innerHTML = '';";
237
echo "</script>";	
238

    
239
?>
(26-26/217)