Project

General

Profile

Download (8.57 KB) Statistics
| Branch: | Tag: | Revision:
1 104c11c6 Scott Ullrich
<?php
2
/*
3 aaec5634 Renato Botelho
 * diag_nanobsd.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, 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 fd9ebcd5 Stephen Beaver
 */
53 104c11c6 Scott Ullrich
54
##|+PRIV
55
##|*IDENT=page-diagnostics-nanobsd
56
##|*NAME=Diagnostics: NanoBSD
57
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
58
##|*MATCH=diag_nanobsd.php*
59
##|-PRIV
60
61 ae396e30 Scott Ullrich
ini_set('zlib.output_compression', 0);
62
ini_set('implicit_flush', 1);
63
ini_set('max_input_time', '9999');
64 104c11c6 Scott Ullrich
65
require_once("guiconfig.inc");
66 96099c6a Renato Botelho
require_once("config.inc");
67 104c11c6 Scott Ullrich
68 0da0d43e Phil Davis
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than executed.
69 8986ff32 Stephen Beaver
// MUST be set to false for production of course
70 820562e8 NewEraCracker
define('DEBUG', false);
71 8986ff32 Stephen Beaver
72 9404a104 Renato Botelho
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
73 104c11c6 Scott Ullrich
include("head.inc");
74
75 a3a22a4e Scott Ullrich
// Survey slice info
76 08fd5444 jim-p
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
77
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
78
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
79
nanobsd_detect_slice_info();
80 a3a22a4e Scott Ullrich
81 08fd5444 jim-p
$NANOBSD_SIZE = nanobsd_get_size();
82 c7593c81 Phil Davis
$class = 'alert-warning';
83 62d01a53 Scott Ullrich
84 288a2a0f Phil Davis
if ($_POST['bootslice']) {
85 947141fd Phil Davis
	if (!DEBUG) {
86 8986ff32 Stephen Beaver
	   nanobsd_switch_boot_slice();
87 947141fd Phil Davis
	} else {
88 8986ff32 Stephen Beaver
	   sleep(4);
89 947141fd Phil Davis
	}
90 8986ff32 Stephen Beaver
91 8545adde k-paulius
	$savemsg = sprintf(gettext("The boot slice has been set to %s."), nanobsd_get_active_slice());
92 c7593c81 Phil Davis
	$class = 'alert-success';
93 a3a22a4e Scott Ullrich
	// Survey slice info
94 08fd5444 jim-p
	nanobsd_detect_slice_info();
95 104c11c6 Scott Ullrich
}
96
97 288a2a0f Phil Davis
if ($_POST['destslice'] && $_POST['duplicateslice']) {
98 cf652f81 Chris Buechler
	$statusmsg = gettext("Duplicating slice.  Please wait, this will take a moment...");
99 8986ff32 Stephen Beaver
100 288a2a0f Phil Davis
	if (!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
101 ce871619 Stephen Beaver
		$savemsg = gettext("The slice has been duplicated.") . "<p/>" . gettext("To boot from this newly duplicated slice set it using the bootup information area.");
102 c7593c81 Phil Davis
		$class = 'alert-success';
103 08fd5444 jim-p
	} else {
104 8545adde k-paulius
		$savemsg = gettext("There was an error while duplicating the slice. Operation aborted.");
105 c7593c81 Phil Davis
		$class = 'alert-danger';
106 104c11c6 Scott Ullrich
	}
107 a3a22a4e Scott Ullrich
	// Re-Survey slice info
108 08fd5444 jim-p
	nanobsd_detect_slice_info();
109 104c11c6 Scott Ullrich
}
110
111 7b229013 jim-p
if ($_POST['changero']) {
112 8986ff32 Stephen Beaver
	if (!DEBUG && is_writable("/")) {
113 7b229013 jim-p
		conf_mount_ro();
114
	} else {
115
		conf_mount_rw();
116
	}
117
}
118
119
if ($_POST['setrw']) {
120 288a2a0f Phil Davis
	if (!DEBUG) {
121 8986ff32 Stephen Beaver
		conf_mount_rw();
122 947141fd Phil Davis
		if (isset($_POST['nanobsd_force_rw'])) {
123 356ba464 Phil Davis
			$savemsg = gettext("Permanent read/write has been set successfully.");
124 c7593c81 Phil Davis
			$class = 'alert-success';
125 8986ff32 Stephen Beaver
			$config['system']['nanobsd_force_rw'] = true;
126 947141fd Phil Davis
		} else {
127 356ba464 Phil Davis
			$savemsg = gettext('Permanent read/write has been cleared successfully.');
128 c7593c81 Phil Davis
			$class = 'alert-success';
129 8986ff32 Stephen Beaver
			unset($config['system']['nanobsd_force_rw']);
130 947141fd Phil Davis
		}
131 7b229013 jim-p
132 ff30e319 bruno
		write_config(gettext("Changed Permanent Read/Write Setting"));
133 8986ff32 Stephen Beaver
		conf_mount_ro();
134 947141fd Phil Davis
	} else {
135 8545adde k-paulius
		$savemsg = gettext('Saved read/write permanently.');
136 8986ff32 Stephen Beaver
		$class = 'alert-success';
137
	}
138 7b229013 jim-p
}
139 85405c11 jim-p
140 babf5d85 Phil Davis
print_info_box(gettext("The options on this page are intended for use by advanced users only."));
141 8986ff32 Stephen Beaver
142 947141fd Phil Davis
if ($savemsg) {
143 8986ff32 Stephen Beaver
	print_info_box($savemsg, $class);
144 947141fd Phil Davis
}
145 ae396e30 Scott Ullrich
146 8986ff32 Stephen Beaver
$form = new Form(false);
147
148 5752d214 Phil Davis
$section = new Form_Section('NanoBSD Options');
149 8986ff32 Stephen Beaver
150
$section->addInput(new Form_StaticText(
151
	'Image Size',
152
	$NANOBSD_SIZE
153
));
154
155 2e7fa7ca jim-p
$slicebtn = new Form_Button(
156
	'bootslice',
157 faab522f Renato Botelho
	'Switch Slice',
158 2e7fa7ca jim-p
	null,
159
	'fa-retweet'
160
);
161
$slicebtn->addClass('btn-warning btn-sm');
162 8986ff32 Stephen Beaver
163
$section->addInput(new Form_StaticText(
164
	'Bootup slice',
165
	$ACTIVE_SLICE . ' ' . $slicebtn
166
));
167 ae396e30 Scott Ullrich
168 356ba464 Phil Davis
$refcount = refcount_read(1000);
169 2e7fa7ca jim-p
$mounted_rw = is_writable("/");
170 356ba464 Phil Davis
171 2e7fa7ca jim-p
if ($mounted_rw) {
172 8986ff32 Stephen Beaver
	/* refcount_read returns -1 when shared memory section does not exist */
173 612d0fb3 Phil Davis
	/* refcount can be zero here when the user has set nanobsd_force_rw */
174
	/* refcount 1 is normal, so only display the count for abnormal values */
175 0972379a Chris Buechler
	/*
176 612d0fb3 Phil Davis
	if ($refcount == 1 || $refcount == 0 || $refcount == -1) {
177 8986ff32 Stephen Beaver
		$refdisplay = "";
178
	} else {
179 babf5d85 Phil Davis
		$refdisplay = " ". sprintf(gettext("(Reference count %s)"), $refcount);
180 8986ff32 Stephen Beaver
	}
181 0972379a Chris Buechler
	*/
182 8986ff32 Stephen Beaver
	$lbl = gettext("Read/Write") . $refdisplay;
183 356ba464 Phil Davis
	$btnlbl = gettext("Switch to Read-Only");
184 8986ff32 Stephen Beaver
} else {
185
	$lbl = gettext("Read-Only");
186 356ba464 Phil Davis
	$btnlbl = gettext("Switch to Read/Write");
187 8986ff32 Stephen Beaver
}
188
189 356ba464 Phil Davis
// 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.
190
// 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.
191 0972379a Chris Buechler
/*
192 2e7fa7ca jim-p
if (!isset($config['system']['nanobsd_force_rw']) || !$mounted_rw || ($refcount > 1)) {
193
	$robtn = new Form_Button(
194
		'changero',
195
		$btnlbl,
196
		null,
197
		($mounted_rw) ? 'fa-lock' : 'fa-unlock'
198
	);
199
	$robtn->addClass(($mounted_rw) ? 'btn-success' : 'btn-warning' . ' btn-sm');
200 356ba464 Phil Davis
	$lbl .= ' ' . $robtn;
201
}
202 0972379a Chris Buechler
*/
203 8986ff32 Stephen Beaver
$section->addInput(new Form_StaticText(
204
	'Read/Write status',
205 356ba464 Phil Davis
	$lbl
206 0972379a Chris Buechler
))->setHelp('NanoBSD is now always read-write to avoid read-write to read-only mount problems.');
207
//))->setHelp('This setting is only temporary, and can be switched dynamically in the background.');
208 8986ff32 Stephen Beaver
209 0972379a Chris Buechler
/*
210 8986ff32 Stephen Beaver
$section->addInput(new Form_Checkbox(
211
	'nanobsd_force_rw',
212
	'Permanent Read/Write',
213
	'Keep media mounted read/write at all times. ',
214
	isset($config['system']['nanobsd_force_rw'])
215 356ba464 Phil Davis
));
216 8986ff32 Stephen Beaver
217 2e7fa7ca jim-p
$permbtn = new Form_Button(
218
	'setrw',
219 faab522f Renato Botelho
	'Save',
220 2e7fa7ca jim-p
	null,
221
	'fa-save'
222
);
223
$permbtn->addClass('btn-primary btn-sm');
224 8986ff32 Stephen Beaver
225
$section->addInput(new Form_StaticText(
226
	null,
227
	$permbtn
228
));
229 0972379a Chris Buechler
*/
230 8986ff32 Stephen Beaver
231
$section->addInput(new Form_Input(
232
	'destslice',
233
	null,
234
	'hidden',
235
	$COMPLETE_PATH
236
));
237
238 2e7fa7ca jim-p
$dupbtn = new Form_Button(
239
	'duplicateslice',
240 faab522f Renato Botelho
	'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH,
241 2e7fa7ca jim-p
	null,
242
	'fa-clone'
243
);
244
$dupbtn->addClass('btn-success btn-sm');
245 8986ff32 Stephen Beaver
246
$section->addInput(new Form_StaticText(
247
	'Duplicate boot slice',
248
	$dupbtn
249 ce871619 Stephen Beaver
))->setHelp('This will duplicate the bootup slice to the alternate slice.  Use this to duplicate the known good working boot partition to the alternate.');
250 8986ff32 Stephen Beaver
251
$section->addInput(new Form_StaticText(
252
	'RRD/DHCP Backup',
253
	'These options have been relocated to the ' . '<a href="system_advanced_misc.php">' . 'System > Advanced, Miscellaneous</a> tab.'
254
));
255
256 288a2a0f Phil Davis
if (file_exists("/conf/upgrade_log.txt")) {
257 2e7fa7ca jim-p
	$viewbtn = new Form_Button(
258
		'viewupgradelog',
259 faab522f Renato Botelho
		'View log',
260 2e7fa7ca jim-p
		null,
261
		'fa-file-text-o'
262
	);
263
	$viewbtn->addClass('btn-primary btn-sm');
264 8986ff32 Stephen Beaver
265
	$section->addInput(new Form_StaticText(
266
		'View previous upgrade log',
267
		$viewbtn
268
	));
269
}
270
$form->add($section);
271
print($form);
272 ae396e30 Scott Ullrich
273 288a2a0f Phil Davis
if (file_exists("/conf/upgrade_log.txt") && $_POST['viewupgradelog']) {
274 58cd9724 Renato Botelho
?>
275 8986ff32 Stephen Beaver
	<div class="panel panel-default">
276 3d7a8696 k-paulius
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Previous Upgrade Log")?></h2></div>
277 8986ff32 Stephen Beaver
			<!-- No white space between the <pre> and the first output or it will appear on the page! -->
278 3ed75e00 Renato Botelho
			<pre>
279
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
280 8986ff32 Stephen Beaver
			</pre>
281
	</div>
282
<?php
283
}
284 aceaf18c Phil Davis
require_once("foot.inc");