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