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
|
/*
|
30
|
pfSense_BUILDER_BINARIES: /sbin/mount /sbin/glabel /usr/bin/grep /usr/bin/cut /usr/bin/head /bin/cp
|
31
|
pfSense_BUILDER_BINARIES: /usr/sbin/boot0cfg /bin/mkdir /sbin/fsck_ufs /sbin/mount /sbin/sysctl /bin/dd /sbin/tunefs
|
32
|
pfSense_MODULE: nanobsd
|
33
|
*/
|
34
|
|
35
|
##|+PRIV
|
36
|
##|*IDENT=page-diagnostics-nanobsd
|
37
|
##|*NAME=Diagnostics: NanoBSD
|
38
|
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
|
39
|
##|*MATCH=diag_nanobsd.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
ini_set('zlib.output_compression', 0);
|
43
|
ini_set('implicit_flush', 1);
|
44
|
ini_set('max_input_time', '9999');
|
45
|
|
46
|
require_once("guiconfig.inc");
|
47
|
require_once("config.inc");
|
48
|
|
49
|
$pgtitle = array("Diagnostics","NanoBSD");
|
50
|
include("head.inc");
|
51
|
|
52
|
function detect_slice_info() {
|
53
|
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
|
54
|
global $GLABEL_SLIZE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
|
55
|
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE;
|
56
|
|
57
|
$BOOT_DEVICE=trim(`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`);
|
58
|
$REAL_BOOT_DEVICE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/{$BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`);
|
59
|
$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`);
|
60
|
|
61
|
// Detect which slice is active and set information.
|
62
|
if(strstr($REAL_BOOT_DEVICE, "s1")) {
|
63
|
$SLICE="2";
|
64
|
$OLDSLICE="1";
|
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="pfsense1";
|
69
|
$UFS_ID="1";
|
70
|
$OLD_UFS_ID="0";
|
71
|
$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
|
72
|
|
73
|
} else {
|
74
|
$SLICE="1";
|
75
|
$OLDSLICE="2";
|
76
|
$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
|
77
|
$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
|
78
|
$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";
|
79
|
$GLABEL_SLICE="pfsense0";
|
80
|
$UFS_ID="0";
|
81
|
$OLD_UFS_ID="1";
|
82
|
$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
|
83
|
}
|
84
|
}
|
85
|
|
86
|
// Survey slice info
|
87
|
detect_slice_info();
|
88
|
|
89
|
?>
|
90
|
|
91
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
92
|
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
|
93
|
|
94
|
<?php include("fbegin.inc"); ?>
|
95
|
|
96
|
<?php
|
97
|
|
98
|
$NANOBSD_SIZE = strtoupper(file_get_contents("/etc/nanosize.txt"));
|
99
|
|
100
|
if($_POST['bootslice']) {
|
101
|
echo <<<EOF
|
102
|
<div id="loading">
|
103
|
<img src="/themes/metallic/images/misc/loader.gif">
|
104
|
Setting slice information, please wait...
|
105
|
<p/>
|
106
|
</div>
|
107
|
EOF;
|
108
|
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
|
109
|
ob_implicit_flush(1);
|
110
|
if(strstr($_POST['bootslice'], "s2")) {
|
111
|
$ASLICE="2";
|
112
|
$AOLDSLICE="1";
|
113
|
$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
|
114
|
$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
|
115
|
$AGLABEL_SLICE="pfsense1";
|
116
|
$AUFS_ID="1";
|
117
|
$AOLD_UFS_ID="0";
|
118
|
$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
|
119
|
} else {
|
120
|
$ASLICE="1";
|
121
|
$AOLDSLICE="2";
|
122
|
$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
|
123
|
$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
|
124
|
$AGLABEL_SLICE="pfsense0";
|
125
|
$AUFS_ID="0";
|
126
|
$AOLD_UFS_ID="1";
|
127
|
$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
|
128
|
}
|
129
|
conf_mount_rw();
|
130
|
exec("sysctl kern.geom.debugflags=16");
|
131
|
exec("gpart set -a active -i {$ASLICE} {$BOOT_DRIVE}");
|
132
|
exec("/usr/sbin/boot0cfg -s {$ASLICE} -v /dev/{$BOOT_DRIVE}");
|
133
|
exec("/sbin/tunefs -L ${AGLABEL_SLICE} /dev/$ACOMPLETE_PATH");
|
134
|
exec("/bin/mkdir /tmp/{$AGLABEL_SLICE}");
|
135
|
exec("/sbin/fsck_ufs -y /dev/{$ACOMPLETE_PATH}");
|
136
|
exec("/sbin/mount /dev/ufs/{$AGLABEL_SLICE} /tmp/{$AGLABEL_SLICE}");
|
137
|
$fstab = <<<EOF
|
138
|
/dev/ufs/{$AGLABEL_SLICE} / ufs ro 1 1
|
139
|
/dev/ufs/cf /cf ufs ro 1 1
|
140
|
EOF;
|
141
|
file_put_contents("/tmp/{$AGLABEL_SLICE}/etc/fstab", $fstab);
|
142
|
exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
|
143
|
exec("/sbin/sysctl kern.geom.debugflags=0");
|
144
|
conf_mount_ro();
|
145
|
$savemsg = "The boot slice has been set to {$BOOT_DRIVE} {$AGLABEL_SLICE}";
|
146
|
// Survey slice info
|
147
|
detect_slice_info();
|
148
|
|
149
|
}
|
150
|
|
151
|
if($_POST['destslice']) {
|
152
|
|
153
|
echo <<<EOF
|
154
|
<div id="loading">
|
155
|
<img src="/themes/metallic/images/misc/loader.gif">
|
156
|
Duplicating slice. Please wait, this will take a moment...
|
157
|
<p/>
|
158
|
</div>
|
159
|
EOF;
|
160
|
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
|
161
|
ob_implicit_flush(1);
|
162
|
exec("/sbin/sysctl kern.geom.debugflags=16");
|
163
|
exec("/bin/dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
|
164
|
exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
|
165
|
exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
|
166
|
exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
|
167
|
exec("/sbin/fsck_ufs -y /dev/{$COMPLETE_PATH}");
|
168
|
exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
|
169
|
exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
|
170
|
$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
|
171
|
if($status) {
|
172
|
exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
|
173
|
$savemsg = "There was an error while duplicating the slice. Operation aborted.";
|
174
|
} else {
|
175
|
$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.";
|
176
|
exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
|
177
|
}
|
178
|
exec("/sbin/sysctl kern.geom.debugflags=0");
|
179
|
// Re-Survey slice info
|
180
|
detect_slice_info();
|
181
|
}
|
182
|
|
183
|
if ($savemsg)
|
184
|
print_info_box($savemsg)
|
185
|
|
186
|
?>
|
187
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
188
|
<tr>
|
189
|
<td>
|
190
|
<!-- tabs here if you want them -->
|
191
|
</td>
|
192
|
</tr>
|
193
|
<tr>
|
194
|
<td id="mainarea">
|
195
|
<div class="tabcont">
|
196
|
<span class="vexpl">
|
197
|
<span class="red">
|
198
|
<strong>NOTE: </strong>
|
199
|
</span>
|
200
|
The options on this page are intended for use by advanced users only.
|
201
|
<br/>
|
202
|
</span>
|
203
|
<p/>
|
204
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
205
|
<tr>
|
206
|
<td colspan="2" valign="top" class="listtopic">Bootup information</td>
|
207
|
</tr>
|
208
|
<tr>
|
209
|
<td width="22%" valign="top" class="vncell">NanoBSD Image size</td>
|
210
|
<td width="78%" class="vtable">
|
211
|
<?php echo $NANOBSD_SIZE; ?>
|
212
|
</td>
|
213
|
</tr>
|
214
|
<tr>
|
215
|
<td width="22%" valign="top" class="vncell">Bootup</td>
|
216
|
<td width="78%" class="vtable">
|
217
|
<form action="diag_nanobsd.php" method="post" name="iform">
|
218
|
Bootup slice:
|
219
|
<select name='bootslice'>
|
220
|
<option value='<?php echo $BOOTFLASH; ?>'>
|
221
|
<?php echo $BOOTFLASH; ?>
|
222
|
</option>
|
223
|
<option value='<?php echo $TOFLASH; ?>'>
|
224
|
<?php echo "{$TOFLASH}"; ?>
|
225
|
</option>
|
226
|
</select>
|
227
|
<br/>
|
228
|
This will set the bootup slice.
|
229
|
</td>
|
230
|
</tr>
|
231
|
<tr>
|
232
|
<td valign="top" class=""> </td><td><br/><input type='submit' value='Set bootup'></form></td>
|
233
|
</tr>
|
234
|
<tr>
|
235
|
<td colspan="2" valign="top" class=""> </td>
|
236
|
</tr>
|
237
|
<tr>
|
238
|
<td colspan="2" valign="top" class="listtopic">Duplicate bootup slice to alternate</td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td width="22%" valign="top" class="vncell">Duplicate bootup slice</td>
|
242
|
<td width="78%" class="vtable">
|
243
|
<form action="diag_nanobsd.php" method="post" name="iform">
|
244
|
Destination slice:
|
245
|
<select name='destslice'>
|
246
|
<option value='<?php echo $COMPLETE_PATH; ?>'>
|
247
|
<?php echo "{$COMPLETE_BOOT_PATH} -> {$TOFLASH}"; ?>
|
248
|
</option>
|
249
|
</select>
|
250
|
<br/>
|
251
|
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.
|
252
|
</td>
|
253
|
</tr>
|
254
|
<tr>
|
255
|
<td valign="top" class=""> </td><td><br/><input type='submit' value='Duplicate slice'></form></td>
|
256
|
</tr>
|
257
|
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
|
258
|
<tr>
|
259
|
<td colspan="2" valign="top" class=""> </td>
|
260
|
</tr>
|
261
|
<tr>
|
262
|
<td colspan="2" valign="top" class="listtopic">View upgrade log</td>
|
263
|
</tr>
|
264
|
<tr>
|
265
|
<td width="22%" valign="top" class="vncell">View previous upgrade log</td>
|
266
|
<td width="78%" class="vtable">
|
267
|
<?php
|
268
|
if($_POST['viewupgradelog']) {
|
269
|
echo "<textarea name='log' cols='80' rows='40'>";
|
270
|
echo file_get_contents("/conf/upgrade_log.txt");
|
271
|
echo "\nFile list:\n";
|
272
|
echo file_get_contents("/conf/file_upgrade_log.txt");
|
273
|
echo "\nMisc log:\n";
|
274
|
echo file_get_contents("/conf/firmware_update_misc.log");
|
275
|
echo "\nfdisk/bsdlabel log:\n";
|
276
|
echo file_get_contents("/conf/fdisk_upgrade_log.txt");
|
277
|
echo "</textarea>";
|
278
|
} else {
|
279
|
echo "<form action='diag_nanobsd.php' method='post' name='iform'>";
|
280
|
echo "<input type='submit' name='viewupgradelog' value='View upgrade log'>";
|
281
|
}
|
282
|
?>
|
283
|
</td>
|
284
|
</tr>
|
285
|
<?php endif; ?>
|
286
|
<tr>
|
287
|
<td colspan="2" valign="top" class=""> </td>
|
288
|
</tr>
|
289
|
</table>
|
290
|
</div>
|
291
|
</td>
|
292
|
</tr>
|
293
|
</table>
|
294
|
<?php require("fend.inc"); ?>
|
295
|
</body>
|
296
|
</html>
|
297
|
|
298
|
<?php
|
299
|
|
300
|
// Clear the loading indicator
|
301
|
echo "<script type=\"text/javascript\">";
|
302
|
echo "$('loading').innerHTML = '';";
|
303
|
echo "</script>";
|
304
|
|
305
|
?>
|