Project

General

Profile

Download (8.67 KB) Statistics
| Branch: | Tag: | Revision:
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
/*
57
	pfSense_BUILDER_BINARIES:	/sbin/mount	/sbin/glabel	/usr/bin/grep	/usr/bin/cut	/usr/bin/head	/bin/cp
58
	pfSense_BUILDER_BINARIES:	/usr/sbin/boot0cfg	/bin/mkdir	/sbin/fsck_ufs	/sbin/mount	/bin/dd	/sbin/tunefs
59
	pfSense_MODULE:	nanobsd
60
*/
61

    
62
##|+PRIV
63
##|*IDENT=page-diagnostics-nanobsd
64
##|*NAME=Diagnostics: NanoBSD
65
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
66
##|*MATCH=diag_nanobsd.php*
67
##|-PRIV
68

    
69
ini_set('zlib.output_compression', 0);
70
ini_set('implicit_flush', 1);
71
ini_set('max_input_time', '9999');
72

    
73
require_once("guiconfig.inc");
74
require_once("config.inc");
75

    
76
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than executed.
77
// MUST be set to false for production of course
78
define(DEBUG, false);
79

    
80
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
81
include("head.inc");
82

    
83
// Survey slice info
84
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
85
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
86
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
87
nanobsd_detect_slice_info();
88

    
89
$NANOBSD_SIZE = nanobsd_get_size();
90
$class='alert-warning';
91

    
92
if ($_POST['bootslice']) {
93
	if (!DEBUG)
94
	   nanobsd_switch_boot_slice();
95
	else
96
	   sleep(4);
97

    
98
	$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
99
	$class='alert-success';
100
	// Survey slice info
101
	nanobsd_detect_slice_info();
102
}
103

    
104
if ($_POST['destslice'] && $_POST['duplicateslice']) {
105
	$statusmsg = gettext("Duplicating slice.  Please wait, this will take a moment...");
106

    
107
	if (!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
108
		$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.");
109
		$class='alert-success';
110
	} else {
111
		$savemsg = gettext("There was an error while duplicating the slice.	 Operation aborted.");
112
		$class='alert-danger';
113
	}
114
	// Re-Survey slice info
115
	nanobsd_detect_slice_info();
116
}
117

    
118
if ($_POST['changero']) {
119
	if (!DEBUG && is_writable("/")) {
120
		conf_mount_ro();
121
	} else {
122
		conf_mount_rw();
123
	}
124
}
125

    
126
if ($_POST['setrw']) {
127
	if (!DEBUG) {
128
		conf_mount_rw();
129
		if (isset($_POST['nanobsd_force_rw']))
130
			$config['system']['nanobsd_force_rw'] = true;
131
		else
132
			unset($config['system']['nanobsd_force_rw']);
133

    
134
		write_config("Changed Permanent Read/Write Setting");
135
		conf_mount_ro();
136
	}
137
	else {
138
		$savemsg = 'Saved r/w permanently';
139
		$class = 'alert-success';
140
	}
141
}
142

    
143
print_info_box("The options on this page are intended for use by advanced users only.");
144

    
145
if ($savemsg)
146
	print_info_box($savemsg, $class);
147

    
148
require_once('classes/Form.class.php');
149

    
150
$form = new Form(false);
151

    
152
$section = new Form_Section('NanoBSD Option');
153

    
154
$section->addInput(new Form_StaticText(
155
	'Image Size',
156
	$NANOBSD_SIZE
157
));
158

    
159
$slicebtn = new Form_Button('bootslice', 'Switch Slice');
160
$slicebtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
161

    
162
$section->addInput(new Form_StaticText(
163
	'Bootup slice',
164
	$ACTIVE_SLICE . ' ' . $slicebtn
165
));
166

    
167
if (is_writable("/")) {
168
	$refcount = refcount_read(1000);
169
	/* refcount_read returns -1 when shared memory section does not exist */
170
	/* refcount can be zero here when the user has set nanobsd_force_rw */
171
	/* refcount 1 is normal, so only display the count for abnormal values */
172
	if ($refcount == 1 || $refcount == 0 || $refcount == -1) {
173
		$refdisplay = "";
174
	} else {
175
		$refdisplay = " (Reference count " . $refcount . ")";
176
	}
177
	$lbl = gettext("Read/Write") . $refdisplay;
178
	if (!isset($config['system']['nanobsd_force_rw']))
179
		$btnlbl = gettext("Switch to Read-Only");
180
} else {
181
	$lbl = gettext("Read-Only");
182
	if (!isset($config['system']['nanobsd_force_rw']))
183
		$btnlbl = gettext("Switch to Read/Write");
184
}
185

    
186
$robtn = new Form_Button('changero', $btnlbl);
187
$robtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
188

    
189
$section->addInput(new Form_StaticText(
190
	'Read/Write status',
191
	$lbl . ' ' . $robtn
192
));
193

    
194
$section->addInput(new Form_Checkbox(
195
	'nanobsd_force_rw',
196
	'Permanent Read/Write',
197
	'Keep media mounted read/write at all times. ',
198
	isset($config['system']['nanobsd_force_rw'])
199
))->setHelp('This setting is only temporary, and can be switched dynamically in the background.');
200

    
201
$permbtn = new Form_Button('setrw', 'Save');
202
$permbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
203

    
204
$section->addInput(new Form_StaticText(
205
	null,
206
	$permbtn
207
));
208

    
209
$section->addInput(new Form_Input(
210
	'destslice',
211
	null,
212
	'hidden',
213
	$COMPLETE_PATH
214
));
215

    
216
$dupbtn = new Form_Button('duplicateslice', 'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH);
217
$dupbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
218

    
219
$section->addInput(new Form_StaticText(
220
	'Duplicate boot slice',
221
	$dupbtn
222
))->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.');
223

    
224
$section->addInput(new Form_StaticText(
225
	'RRD/DHCP Backup',
226
	'These options have been relocated to the ' . '<a href="system_advanced_misc.php">' . 'System > Advanced, Miscellaneous</a> tab.'
227
));
228

    
229
if (file_exists("/conf/upgrade_log.txt")) {
230
	$viewbtn = new Form_Button('viewupgradelog', 'View log');
231
	$viewbtn->removeClass('btn-primary')->addClass('btn-default 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><?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
247
				<br /><?=gettext("File list:")?>
248
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/file_upgrade_log.txt"))?>
249
				<br /><?=gettext("Misc log:")?>
250
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/firmware_update_misc_log.txt"))?>
251
				<br /><?=gettext("fdisk/bsdlabel log:")?>
252
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/fdisk_upgrade_log.txt"))?>
253
			</pre>
254
	</div>
255
<?php
256
}
257
require("foot.inc");
(27-27/235)