Project

General

Profile

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