1
|
<?php
|
2
|
/*
|
3
|
* diag_nanobsd.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
* you may not use this file except in compliance with the License.
|
11
|
* You may obtain a copy of the License at
|
12
|
*
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14
|
*
|
15
|
* Unless required by applicable law or agreed to in writing, software
|
16
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
* See the License for the specific language governing permissions and
|
19
|
* limitations under the License.
|
20
|
*/
|
21
|
|
22
|
##|+PRIV
|
23
|
##|*IDENT=page-diagnostics-nanobsd
|
24
|
##|*NAME=Diagnostics: NanoBSD
|
25
|
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
|
26
|
##|*MATCH=diag_nanobsd.php*
|
27
|
##|-PRIV
|
28
|
|
29
|
ini_set('zlib.output_compression', 0);
|
30
|
ini_set('implicit_flush', 1);
|
31
|
ini_set('max_input_time', '9999');
|
32
|
|
33
|
require_once("guiconfig.inc");
|
34
|
require_once("config.inc");
|
35
|
|
36
|
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than executed.
|
37
|
// MUST be set to false for production of course
|
38
|
define('DEBUG', false);
|
39
|
|
40
|
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
|
41
|
include("head.inc");
|
42
|
|
43
|
// Survey slice info
|
44
|
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
|
45
|
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
|
46
|
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
|
47
|
nanobsd_detect_slice_info();
|
48
|
|
49
|
$NANOBSD_SIZE = nanobsd_get_size();
|
50
|
$class = 'alert-warning';
|
51
|
|
52
|
if ($_POST['bootslice']) {
|
53
|
if (!DEBUG) {
|
54
|
nanobsd_switch_boot_slice();
|
55
|
} else {
|
56
|
sleep(4);
|
57
|
}
|
58
|
|
59
|
$savemsg = sprintf(gettext("The boot slice has been set to %s."), nanobsd_get_active_slice());
|
60
|
$class = 'alert-success';
|
61
|
// Survey slice info
|
62
|
nanobsd_detect_slice_info();
|
63
|
}
|
64
|
|
65
|
if ($_POST['destslice'] && $_POST['duplicateslice']) {
|
66
|
$statusmsg = gettext("Duplicating slice. Please wait, this will take a moment...");
|
67
|
|
68
|
if (!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
|
69
|
$savemsg = gettext("The slice has been duplicated.") . "<p/>" . gettext("To boot from this newly duplicated slice set it using the bootup information area.");
|
70
|
$class = 'alert-success';
|
71
|
} else {
|
72
|
$savemsg = gettext("There was an error while duplicating the slice. Operation aborted.");
|
73
|
$class = 'alert-danger';
|
74
|
}
|
75
|
// Re-Survey slice info
|
76
|
nanobsd_detect_slice_info();
|
77
|
}
|
78
|
|
79
|
if ($_POST['changero']) {
|
80
|
if (!DEBUG && is_writable("/")) {
|
81
|
conf_mount_ro();
|
82
|
} else {
|
83
|
conf_mount_rw();
|
84
|
}
|
85
|
}
|
86
|
|
87
|
if ($_POST['setrw']) {
|
88
|
if (!DEBUG) {
|
89
|
conf_mount_rw();
|
90
|
if (isset($_POST['nanobsd_force_rw'])) {
|
91
|
$savemsg = gettext("Permanent read/write has been set successfully.");
|
92
|
$class = 'alert-success';
|
93
|
$config['system']['nanobsd_force_rw'] = true;
|
94
|
} else {
|
95
|
$savemsg = gettext('Permanent read/write has been cleared successfully.');
|
96
|
$class = 'alert-success';
|
97
|
unset($config['system']['nanobsd_force_rw']);
|
98
|
}
|
99
|
|
100
|
write_config(gettext("Changed Permanent Read/Write Setting"));
|
101
|
conf_mount_ro();
|
102
|
} else {
|
103
|
$savemsg = gettext('Saved read/write permanently.');
|
104
|
$class = 'alert-success';
|
105
|
}
|
106
|
}
|
107
|
|
108
|
print_info_box(gettext("The options on this page are intended for use by advanced users only."));
|
109
|
|
110
|
if ($savemsg) {
|
111
|
print_info_box($savemsg, $class);
|
112
|
}
|
113
|
|
114
|
$form = new Form(false);
|
115
|
|
116
|
$section = new Form_Section('NanoBSD Options');
|
117
|
|
118
|
$section->addInput(new Form_StaticText(
|
119
|
'Image Size',
|
120
|
$NANOBSD_SIZE
|
121
|
));
|
122
|
|
123
|
$slicebtn = new Form_Button(
|
124
|
'bootslice',
|
125
|
'Switch Slice',
|
126
|
null,
|
127
|
'fa-retweet'
|
128
|
);
|
129
|
$slicebtn->addClass('btn-warning btn-sm');
|
130
|
|
131
|
$section->addInput(new Form_StaticText(
|
132
|
'Bootup slice',
|
133
|
$ACTIVE_SLICE . ' ' . $slicebtn
|
134
|
));
|
135
|
|
136
|
$refcount = refcount_read(1000);
|
137
|
$mounted_rw = is_writable("/");
|
138
|
|
139
|
if ($mounted_rw) {
|
140
|
/* refcount_read returns -1 when shared memory section does not exist */
|
141
|
/* refcount can be zero here when the user has set nanobsd_force_rw */
|
142
|
/* refcount 1 is normal, so only display the count for abnormal values */
|
143
|
/*
|
144
|
if ($refcount == 1 || $refcount == 0 || $refcount == -1) {
|
145
|
$refdisplay = "";
|
146
|
} else {
|
147
|
$refdisplay = " ". sprintf(gettext("(Reference count %s)"), $refcount);
|
148
|
}
|
149
|
*/
|
150
|
$lbl = gettext("Read/Write") . $refdisplay;
|
151
|
$btnlbl = gettext("Switch to Read-Only");
|
152
|
} else {
|
153
|
$lbl = gettext("Read-Only");
|
154
|
$btnlbl = gettext("Switch to Read/Write");
|
155
|
}
|
156
|
|
157
|
// 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.
|
158
|
// 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.
|
159
|
/*
|
160
|
if (!isset($config['system']['nanobsd_force_rw']) || !$mounted_rw || ($refcount > 1)) {
|
161
|
$robtn = new Form_Button(
|
162
|
'changero',
|
163
|
$btnlbl,
|
164
|
null,
|
165
|
($mounted_rw) ? 'fa-lock' : 'fa-unlock'
|
166
|
);
|
167
|
$robtn->addClass(($mounted_rw) ? 'btn-success' : 'btn-warning' . ' btn-sm');
|
168
|
$lbl .= ' ' . $robtn;
|
169
|
}
|
170
|
*/
|
171
|
$section->addInput(new Form_StaticText(
|
172
|
'Read/Write status',
|
173
|
$lbl
|
174
|
))->setHelp('NanoBSD is now always read-write to avoid read-write to read-only mount problems.');
|
175
|
//))->setHelp('This setting is only temporary, and can be switched dynamically in the background.');
|
176
|
|
177
|
/*
|
178
|
$section->addInput(new Form_Checkbox(
|
179
|
'nanobsd_force_rw',
|
180
|
'Permanent Read/Write',
|
181
|
'Keep media mounted read/write at all times. ',
|
182
|
isset($config['system']['nanobsd_force_rw'])
|
183
|
));
|
184
|
|
185
|
$permbtn = new Form_Button(
|
186
|
'setrw',
|
187
|
'Save',
|
188
|
null,
|
189
|
'fa-save'
|
190
|
);
|
191
|
$permbtn->addClass('btn-primary btn-sm');
|
192
|
|
193
|
$section->addInput(new Form_StaticText(
|
194
|
null,
|
195
|
$permbtn
|
196
|
));
|
197
|
*/
|
198
|
|
199
|
$section->addInput(new Form_Input(
|
200
|
'destslice',
|
201
|
null,
|
202
|
'hidden',
|
203
|
$COMPLETE_PATH
|
204
|
));
|
205
|
|
206
|
$dupbtn = new Form_Button(
|
207
|
'duplicateslice',
|
208
|
'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH,
|
209
|
null,
|
210
|
'fa-clone'
|
211
|
);
|
212
|
$dupbtn->addClass('btn-success btn-sm');
|
213
|
|
214
|
$section->addInput(new Form_StaticText(
|
215
|
'Duplicate boot slice',
|
216
|
$dupbtn
|
217
|
))->setHelp('This will duplicate the bootup slice to the alternate slice. Use this to duplicate the known good working boot partition to the alternate.');
|
218
|
|
219
|
$section->addInput(new Form_StaticText(
|
220
|
'RRD/DHCP Backup',
|
221
|
'These options have been relocated to the ' . '<a href="system_advanced_misc.php">' . 'System > Advanced, Miscellaneous</a> tab.'
|
222
|
));
|
223
|
|
224
|
if (file_exists("/conf/upgrade_log.txt")) {
|
225
|
$viewbtn = new Form_Button(
|
226
|
'viewupgradelog',
|
227
|
'View log',
|
228
|
null,
|
229
|
'fa-file-text-o'
|
230
|
);
|
231
|
$viewbtn->addClass('btn-primary btn-sm');
|
232
|
|
233
|
$section->addInput(new Form_StaticText(
|
234
|
'View previous upgrade log',
|
235
|
$viewbtn
|
236
|
));
|
237
|
}
|
238
|
$form->add($section);
|
239
|
print($form);
|
240
|
|
241
|
if (file_exists("/conf/upgrade_log.txt") && $_POST['viewupgradelog']) {
|
242
|
?>
|
243
|
<div class="panel panel-default">
|
244
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Previous Upgrade Log")?></h2></div>
|
245
|
<!-- No white space between the <pre> and the first output or it will appear on the page! -->
|
246
|
<pre>
|
247
|
<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
|
248
|
</pre>
|
249
|
</div>
|
250
|
<?php
|
251
|
}
|
252
|
require_once("foot.inc");
|