1 |
104c11c6
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
diag_nanobsd.php
|
4 |
|
|
*/
|
5 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
6 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
|
|
* Copyright (c) 2009 Scott Ullrich <sullrich@gmail.com>
|
8 |
|
|
*
|
9 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
10 |
|
|
* are permitted provided that the following conditions are met:
|
11 |
|
|
*
|
12 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
* this list of conditions and the following disclaimer.
|
14 |
|
|
*
|
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
* notice, this list of conditions and the following disclaimer in
|
17 |
|
|
* the documentation and/or other materials provided with the
|
18 |
|
|
* distribution.
|
19 |
|
|
*
|
20 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
21 |
|
|
* must display the following acknowledgment:
|
22 |
|
|
* "This product includes software developed by the pfSense Project
|
23 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24 |
|
|
*
|
25 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26 |
|
|
* endorse or promote products derived from this software without
|
27 |
|
|
* prior written permission. For written permission, please contact
|
28 |
|
|
* coreteam@pfsense.org.
|
29 |
|
|
*
|
30 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
31 |
|
|
* nor may "pfSense" appear in their names without prior written
|
32 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
33 |
|
|
*
|
34 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
35 |
|
|
* acknowledgment:
|
36 |
|
|
*
|
37 |
|
|
* "This product includes software developed by the pfSense Project
|
38 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39 |
|
|
*
|
40 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52 |
|
|
*
|
53 |
|
|
* ====================================================================
|
54 |
|
|
*
|
55 |
|
|
*/
|
56 |
104c11c6
|
Scott Ullrich
|
|
57 |
8986ff32
|
Stephen Beaver
|
/*
|
58 |
13d193c2
|
Scott Ullrich
|
pfSense_BUILDER_BINARIES: /sbin/mount /sbin/glabel /usr/bin/grep /usr/bin/cut /usr/bin/head /bin/cp
|
59 |
971de1f9
|
Renato Botelho
|
pfSense_BUILDER_BINARIES: /usr/sbin/boot0cfg /bin/mkdir /sbin/fsck_ufs /sbin/mount /bin/dd /sbin/tunefs
|
60 |
13d193c2
|
Scott Ullrich
|
pfSense_MODULE: nanobsd
|
61 |
|
|
*/
|
62 |
|
|
|
63 |
104c11c6
|
Scott Ullrich
|
##|+PRIV
|
64 |
|
|
##|*IDENT=page-diagnostics-nanobsd
|
65 |
|
|
##|*NAME=Diagnostics: NanoBSD
|
66 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
|
67 |
|
|
##|*MATCH=diag_nanobsd.php*
|
68 |
|
|
##|-PRIV
|
69 |
|
|
|
70 |
ae396e30
|
Scott Ullrich
|
ini_set('zlib.output_compression', 0);
|
71 |
|
|
ini_set('implicit_flush', 1);
|
72 |
|
|
ini_set('max_input_time', '9999');
|
73 |
104c11c6
|
Scott Ullrich
|
|
74 |
|
|
require_once("guiconfig.inc");
|
75 |
96099c6a
|
Renato Botelho
|
require_once("config.inc");
|
76 |
104c11c6
|
Scott Ullrich
|
|
77 |
8986ff32
|
Stephen Beaver
|
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than exectued.
|
78 |
|
|
// MUST be set to false for production of course
|
79 |
|
|
define(DEBUG, true);
|
80 |
|
|
|
81 |
9404a104
|
Renato Botelho
|
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
|
82 |
104c11c6
|
Scott Ullrich
|
include("head.inc");
|
83 |
|
|
|
84 |
a3a22a4e
|
Scott Ullrich
|
// Survey slice info
|
85 |
08fd5444
|
jim-p
|
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
|
86 |
|
|
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
|
87 |
|
|
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
|
88 |
|
|
nanobsd_detect_slice_info();
|
89 |
a3a22a4e
|
Scott Ullrich
|
|
90 |
08fd5444
|
jim-p
|
$NANOBSD_SIZE = nanobsd_get_size();
|
91 |
8986ff32
|
Stephen Beaver
|
$class='alert-warning';
|
92 |
62d01a53
|
Scott Ullrich
|
|
93 |
288a2a0f
|
Phil Davis
|
if ($_POST['bootslice']) {
|
94 |
|
|
if (!DEBUG)
|
95 |
8986ff32
|
Stephen Beaver
|
nanobsd_switch_boot_slice();
|
96 |
|
|
else
|
97 |
|
|
sleep(4);
|
98 |
|
|
|
99 |
9404a104
|
Renato Botelho
|
$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
|
100 |
8986ff32
|
Stephen Beaver
|
$class='alert-success';
|
101 |
a3a22a4e
|
Scott Ullrich
|
// Survey slice info
|
102 |
08fd5444
|
jim-p
|
nanobsd_detect_slice_info();
|
103 |
104c11c6
|
Scott Ullrich
|
}
|
104 |
|
|
|
105 |
288a2a0f
|
Phil Davis
|
if ($_POST['destslice'] && $_POST['duplicateslice']) {
|
106 |
cf652f81
|
Chris Buechler
|
$statusmsg = gettext("Duplicating slice. Please wait, this will take a moment...");
|
107 |
8986ff32
|
Stephen Beaver
|
|
108 |
288a2a0f
|
Phil Davis
|
if (!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
|
109 |
9404a104
|
Renato Botelho
|
$savemsg = gettext("The slice has been duplicated.") . "<p/>" . gettext("If you would like to boot from this newly duplicated slice please set it using the bootup information area.");
|
110 |
8986ff32
|
Stephen Beaver
|
$class='alert-success';
|
111 |
08fd5444
|
jim-p
|
} else {
|
112 |
8986ff32
|
Stephen Beaver
|
$savemsg = gettext("There was an error while duplicating the slice. Operation aborted.");
|
113 |
|
|
$class='alert-danger';
|
114 |
104c11c6
|
Scott Ullrich
|
}
|
115 |
a3a22a4e
|
Scott Ullrich
|
// Re-Survey slice info
|
116 |
08fd5444
|
jim-p
|
nanobsd_detect_slice_info();
|
117 |
104c11c6
|
Scott Ullrich
|
}
|
118 |
|
|
|
119 |
7b229013
|
jim-p
|
if ($_POST['changero']) {
|
120 |
8986ff32
|
Stephen Beaver
|
if (!DEBUG && is_writable("/")) {
|
121 |
7b229013
|
jim-p
|
conf_mount_ro();
|
122 |
|
|
} else {
|
123 |
|
|
conf_mount_rw();
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
if ($_POST['setrw']) {
|
128 |
288a2a0f
|
Phil Davis
|
if (!DEBUG) {
|
129 |
8986ff32
|
Stephen Beaver
|
conf_mount_rw();
|
130 |
|
|
if (isset($_POST['nanobsd_force_rw']))
|
131 |
|
|
$config['system']['nanobsd_force_rw'] = true;
|
132 |
|
|
else
|
133 |
|
|
unset($config['system']['nanobsd_force_rw']);
|
134 |
7b229013
|
jim-p
|
|
135 |
8986ff32
|
Stephen Beaver
|
write_config("Changed Permanent Read/Write Setting");
|
136 |
|
|
conf_mount_ro();
|
137 |
|
|
}
|
138 |
|
|
else {
|
139 |
|
|
$savemsg = 'Saved r/w permanantly';
|
140 |
|
|
$class = 'alert-success';
|
141 |
|
|
}
|
142 |
7b229013
|
jim-p
|
}
|
143 |
85405c11
|
jim-p
|
|
144 |
8986ff32
|
Stephen Beaver
|
print_info_box("The options on this page are intended for use by advanced users only.");
|
145 |
|
|
|
146 |
104c11c6
|
Scott Ullrich
|
if ($savemsg)
|
147 |
8986ff32
|
Stephen Beaver
|
print_info_box($savemsg, $class);
|
148 |
ae396e30
|
Scott Ullrich
|
|
149 |
ad2879b8
|
PiBa-NL
|
require_once('classes/Form.class.php');
|
150 |
ae396e30
|
Scott Ullrich
|
|
151 |
8986ff32
|
Stephen Beaver
|
$form = new Form(false);
|
152 |
|
|
|
153 |
|
|
$section = new Form_Section('NanoBSD Option');
|
154 |
|
|
|
155 |
|
|
$section->addInput(new Form_StaticText(
|
156 |
|
|
'Image Size',
|
157 |
|
|
$NANOBSD_SIZE
|
158 |
|
|
));
|
159 |
|
|
|
160 |
|
|
$slicebtn = new Form_Button('bootslice', 'Switch Slice');
|
161 |
|
|
$slicebtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
162 |
|
|
|
163 |
|
|
$section->addInput(new Form_StaticText(
|
164 |
|
|
'Bootup slice',
|
165 |
|
|
$ACTIVE_SLICE . ' ' . $slicebtn
|
166 |
|
|
));
|
167 |
ae396e30
|
Scott Ullrich
|
|
168 |
8986ff32
|
Stephen Beaver
|
if (is_writable("/")) {
|
169 |
|
|
$refcount = refcount_read(1000);
|
170 |
|
|
/* refcount_read returns -1 when shared memory section does not exist */
|
171 |
|
|
if ($refcount == 1 || $refcount == -1) {
|
172 |
|
|
$refdisplay = "";
|
173 |
|
|
} else {
|
174 |
|
|
$refdisplay = " (Reference count " . $refcount . ")";
|
175 |
|
|
}
|
176 |
|
|
$lbl = gettext("Read/Write") . $refdisplay;
|
177 |
|
|
if (!isset($config['system']['nanobsd_force_rw']))
|
178 |
|
|
$btnlbl = gettext("Switch to Read-Only");
|
179 |
|
|
} else {
|
180 |
|
|
$lbl = gettext("Read-Only");
|
181 |
|
|
if (!isset($config['system']['nanobsd_force_rw']))
|
182 |
|
|
$btnlbl = gettext("Switch to Read/Write");
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
$robtn = new Form_Button('changero', $btnlbl);
|
186 |
|
|
$robtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
187 |
|
|
|
188 |
|
|
$section->addInput(new Form_StaticText(
|
189 |
|
|
'Read/Write status',
|
190 |
|
|
$lbl . ' ' . $robtn
|
191 |
|
|
));
|
192 |
|
|
|
193 |
|
|
$section->addInput(new Form_Checkbox(
|
194 |
|
|
'nanobsd_force_rw',
|
195 |
|
|
'Permanent Read/Write',
|
196 |
|
|
'Keep media mounted read/write at all times. ',
|
197 |
|
|
isset($config['system']['nanobsd_force_rw'])
|
198 |
|
|
))->setHelp('This setting is only temporary, and can be switched dynamically in the background.');
|
199 |
|
|
|
200 |
|
|
$permbtn = new Form_Button('setrw', 'Save');
|
201 |
|
|
$permbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
202 |
|
|
|
203 |
|
|
$section->addInput(new Form_StaticText(
|
204 |
|
|
null,
|
205 |
|
|
$permbtn
|
206 |
|
|
));
|
207 |
|
|
|
208 |
|
|
$section->addInput(new Form_Input(
|
209 |
|
|
'destslice',
|
210 |
|
|
null,
|
211 |
|
|
'hidden',
|
212 |
|
|
$COMPLETE_PATH
|
213 |
|
|
));
|
214 |
|
|
|
215 |
|
|
$dupbtn = new Form_Button('duplicateslice', 'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH);
|
216 |
|
|
$dupbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
217 |
|
|
|
218 |
|
|
$section->addInput(new Form_StaticText(
|
219 |
|
|
'Duplicate boot slice',
|
220 |
|
|
$dupbtn
|
221 |
|
|
))->setHelp('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.');
|
222 |
|
|
|
223 |
|
|
$section->addInput(new Form_StaticText(
|
224 |
|
|
'RRD/DHCP Backup',
|
225 |
|
|
'These options have been relocated to the ' . '<a href="system_advanced_misc.php">' . 'System > Advanced, Miscellaneous</a> tab.'
|
226 |
|
|
));
|
227 |
|
|
|
228 |
288a2a0f
|
Phil Davis
|
if (file_exists("/conf/upgrade_log.txt")) {
|
229 |
8986ff32
|
Stephen Beaver
|
$viewbtn = new Form_Button('viewupgradelog', 'View log');
|
230 |
|
|
$viewbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
231 |
|
|
|
232 |
|
|
$section->addInput(new Form_StaticText(
|
233 |
|
|
'View previous upgrade log',
|
234 |
|
|
$viewbtn
|
235 |
|
|
));
|
236 |
|
|
}
|
237 |
|
|
$form->add($section);
|
238 |
|
|
print($form);
|
239 |
ae396e30
|
Scott Ullrich
|
|
240 |
288a2a0f
|
Phil Davis
|
if (file_exists("/conf/upgrade_log.txt") && $_POST['viewupgradelog']) {
|
241 |
58cd9724
|
Renato Botelho
|
?>
|
242 |
8986ff32
|
Stephen Beaver
|
<div class="panel panel-default">
|
243 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Previous upgrade log")?></h2></div>
|
244 |
8986ff32
|
Stephen Beaver
|
<!-- No white space between the <pre> and the first output or it will appear on the page! -->
|
245 |
|
|
<pre><?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
|
246 |
|
|
<br /><?=gettext("File list:")?>
|
247 |
|
|
<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/file_upgrade_log.txt"))?>
|
248 |
|
|
<br /><?=gettext("Misc log:")?>
|
249 |
|
|
<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/firmware_update_misc_log.txt"))?>
|
250 |
|
|
<br /><?=gettext("fdisk/bsdlabel log:")?>
|
251 |
|
|
<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/fdisk_upgrade_log.txt"))?>
|
252 |
|
|
</pre>
|
253 |
|
|
</div>
|
254 |
|
|
<?php
|
255 |
|
|
}
|
256 |
|
|
require("foot.inc");
|