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
|
|
37
|
require_once("guiconfig.inc");
|
38
|
|
39
|
$pgtitle = array("Diagnostics","NanoBSD");
|
40
|
include("head.inc");
|
41
|
|
42
|
$BOOT_DEVICE=trim(`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`);
|
43
|
$REAL_BOOT_DEVICE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/{$BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`);
|
44
|
$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`);
|
45
|
|
46
|
if(strstr($REAL_BOOT_DEVICE, "s1")) {
|
47
|
$SLICE="2";
|
48
|
$OLDSLICE="1";
|
49
|
$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
|
50
|
$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
|
51
|
$GLABEL_SLICE="pfsense1";
|
52
|
$UFS_ID="1";
|
53
|
$OLD_UFS_ID="0";
|
54
|
$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
|
55
|
} else {
|
56
|
$SLICE="1";
|
57
|
$OLDSLICE="2";
|
58
|
$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
|
59
|
$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
|
60
|
$GLABEL_SLICE="pfsense0";
|
61
|
$UFS_ID="0";
|
62
|
$OLD_UFS_ID="1";
|
63
|
$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
|
64
|
}
|
65
|
|
66
|
if($_POST['bootslice']) {
|
67
|
exec("gpart set -a active -i {$SLICE} {$BOOT_DRIVE}");
|
68
|
exec("/usr/sbin/boot0cfg -s {$SLICE} -v /dev/{$BOOT_DRIVE}");
|
69
|
exec("mkdir /tmp/{$GLABEL_SLICE}");
|
70
|
exec("mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
|
71
|
exec("cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
|
72
|
$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
|
73
|
if($status) {
|
74
|
file_notice("UpgradeFailure","Something went wrong when trying to update the fstab entry. Aborting upgrade.");
|
75
|
exec("umount /tmp/$GLABEL_SLICE");
|
76
|
}
|
77
|
exec("umount /tmp/$GLABEL_SLICE");
|
78
|
$savemsg = "The boot slice has been set to {$BOOT_DRIVE} {$SLICE}";
|
79
|
}
|
80
|
|
81
|
if($_POST['destslice']) {
|
82
|
exec("dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
|
83
|
exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} obs=64k");
|
84
|
exec("gpart set -a active -i {$SLICE} {$BOOT_DRIVE}");
|
85
|
exec("mkdir /tmp/{$GLABEL_SLICE}");
|
86
|
exec("mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
|
87
|
exec("cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
|
88
|
$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
|
89
|
if($status) {
|
90
|
file_notice("UpgradeFailure","Something went wrong when trying to update the fstab entry. Aborting upgrade.");
|
91
|
exec("umount /tmp/$GLABEL_SLICE");
|
92
|
}
|
93
|
exec("umount /tmp/$GLABEL_SLICE");
|
94
|
exec("/usr/sbin/boot0cfg -s {$SLICE} -v /dev/{$BOOT_DRIVE}");
|
95
|
}
|
96
|
|
97
|
?>
|
98
|
|
99
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
100
|
<script src="/javascript/sorttable.js" type="text/javascript"></script>
|
101
|
<?php include("fbegin.inc"); ?>
|
102
|
<?php
|
103
|
if ($savemsg)
|
104
|
print_info_box($savemsg)
|
105
|
?>
|
106
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
107
|
<tr>
|
108
|
<td>
|
109
|
<!-- tabs here if you want them -->
|
110
|
</td>
|
111
|
</tr>
|
112
|
<tr>
|
113
|
<td id="mainarea">
|
114
|
<div class="tabcont">
|
115
|
<span class="vexpl">
|
116
|
<span class="red">
|
117
|
<strong>NOTE: </strong>
|
118
|
</span>
|
119
|
The options on this page are intended for use by advanced users only.
|
120
|
<br/>
|
121
|
</span>
|
122
|
<br/>
|
123
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
124
|
<tr>
|
125
|
<td colspan="2" valign="top" class="listtopic">Bootup information</td>
|
126
|
</tr>
|
127
|
<tr>
|
128
|
<td width="22%" valign="top" class="vncell">Bootup</td>
|
129
|
<td width="78%" class="vtable">
|
130
|
<form action="diag_nanobsd.php" method="post" name="iform">
|
131
|
Bootup slice:
|
132
|
<select name='bootslice'>
|
133
|
<option value='<?php echo $BOOTFLASH; ?>'>
|
134
|
<?php echo $BOOTFLASH; ?>
|
135
|
</option>
|
136
|
<option value='<?php echo $TOFLASH; ?>'>
|
137
|
<?php echo $TOFLASH; ?>
|
138
|
</option>
|
139
|
</select>
|
140
|
<br/>
|
141
|
This will set the bootup slice.
|
142
|
</td>
|
143
|
</tr>
|
144
|
<tr>
|
145
|
<td valign="top" class=""> </td><td><br/><input type='submit' value='Set'></form></td>
|
146
|
</tr>
|
147
|
<tr>
|
148
|
<td colspan="2" valign="top" class=""> </td>
|
149
|
</tr>
|
150
|
<tr>
|
151
|
<td colspan="2" valign="top" class="listtopic">Duplicate bootup slice to alternate</td>
|
152
|
</tr>
|
153
|
<tr>
|
154
|
<td width="22%" valign="top" class="vncell">Duplicate bootup slice</td>
|
155
|
<td width="78%" class="vtable">
|
156
|
<form action="diag_nanobsd.php" method="post" name="iform">
|
157
|
Destination slice:
|
158
|
<select name='destslice'>
|
159
|
<option value='<?php echo $COMPLETE_PATH; ?>'>
|
160
|
<?php echo $COMPLETE_PATH; ?>
|
161
|
</option>
|
162
|
</select>
|
163
|
<br/>
|
164
|
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.
|
165
|
</td>
|
166
|
</tr>
|
167
|
<tr>
|
168
|
<td valign="top" class=""> </td><td><br/><input type='submit' value='Duplicate'></form></td>
|
169
|
</tr>
|
170
|
<tr>
|
171
|
<td colspan="2" valign="top" class=""> </td>
|
172
|
</tr>
|
173
|
</table>
|
174
|
</div>
|
175
|
</td>
|
176
|
</tr>
|
177
|
</table>
|
178
|
<?php require("fend.inc"); ?>
|
179
|
</body>
|
180
|
</html>
|