Project

General

Profile

Download (8.56 KB) Statistics
| Branch: | Tag: | Revision:
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
 * 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
 */
53

    
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
ini_set('zlib.output_compression', 0);
62
ini_set('implicit_flush', 1);
63
ini_set('max_input_time', '9999');
64

    
65
require_once("guiconfig.inc");
66
require_once("config.inc");
67

    
68
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than executed.
69
// MUST be set to false for production of course
70
define('DEBUG', false);
71

    
72
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
73
include("head.inc");
74

    
75
// Survey slice info
76
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

    
81
$NANOBSD_SIZE = nanobsd_get_size();
82
$class = 'alert-warning';
83

    
84
if ($_POST['bootslice']) {
85
	if (!DEBUG) {
86
	   nanobsd_switch_boot_slice();
87
	} else {
88
	   sleep(4);
89
	}
90

    
91
	$savemsg = sprintf(gettext("The boot slice has been set to %s."), nanobsd_get_active_slice());
92
	$class = 'alert-success';
93
	// Survey slice info
94
	nanobsd_detect_slice_info();
95
}
96

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

    
100
	if (!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
101
		$savemsg = gettext("The slice has been duplicated.") . "<p/>" . gettext("To boot from this newly duplicated slice set it using the bootup information area.");
102
		$class = 'alert-success';
103
	} else {
104
		$savemsg = gettext("There was an error while duplicating the slice. Operation aborted.");
105
		$class = 'alert-danger';
106
	}
107
	// Re-Survey slice info
108
	nanobsd_detect_slice_info();
109
}
110

    
111
if ($_POST['changero']) {
112
	if (!DEBUG && is_writable("/")) {
113
		conf_mount_ro();
114
	} else {
115
		conf_mount_rw();
116
	}
117
}
118

    
119
if ($_POST['setrw']) {
120
	if (!DEBUG) {
121
		conf_mount_rw();
122
		if (isset($_POST['nanobsd_force_rw'])) {
123
			$savemsg = gettext("Permanent read/write has been set successfully.");
124
			$class = 'alert-success';
125
			$config['system']['nanobsd_force_rw'] = true;
126
		} else {
127
			$savemsg = gettext('Permanent read/write has been cleared successfully.');
128
			$class = 'alert-success';
129
			unset($config['system']['nanobsd_force_rw']);
130
		}
131

    
132
		write_config(gettext("Changed Permanent Read/Write Setting"));
133
		conf_mount_ro();
134
	} else {
135
		$savemsg = gettext('Saved read/write permanently.');
136
		$class = 'alert-success';
137
	}
138
}
139

    
140
print_info_box(gettext("The options on this page are intended for use by advanced users only."));
141

    
142
if ($savemsg) {
143
	print_info_box($savemsg, $class);
144
}
145

    
146
$form = new Form(false);
147

    
148
$section = new Form_Section('NanoBSD Options');
149

    
150
$section->addInput(new Form_StaticText(
151
	'Image Size',
152
	$NANOBSD_SIZE
153
));
154

    
155
$slicebtn = new Form_Button(
156
	'bootslice',
157
	'Switch Slice',
158
	null,
159
	'fa-retweet'
160
);
161
$slicebtn->addClass('btn-warning btn-sm');
162

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

    
168
$refcount = refcount_read(1000);
169
$mounted_rw = is_writable("/");
170

    
171
if ($mounted_rw) {
172
	/* refcount_read returns -1 when shared memory section does not exist */
173
	/* 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
	/*
176
	if ($refcount == 1 || $refcount == 0 || $refcount == -1) {
177
		$refdisplay = "";
178
	} else {
179
		$refdisplay = " ". sprintf(gettext("(Reference count %s)"), $refcount);
180
	}
181
	*/
182
	$lbl = gettext("Read/Write") . $refdisplay;
183
	$btnlbl = gettext("Switch to Read-Only");
184
} else {
185
	$lbl = gettext("Read-Only");
186
	$btnlbl = gettext("Switch to Read/Write");
187
}
188

    
189
// 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
/*
192
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
	$lbl .= ' ' . $robtn;
201
}
202
*/
203
$section->addInput(new Form_StaticText(
204
	'Read/Write status',
205
	$lbl
206
))->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

    
209
/*
210
$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
));
216

    
217
$permbtn = new Form_Button(
218
	'setrw',
219
	'Save',
220
	null,
221
	'fa-save'
222
);
223
$permbtn->addClass('btn-primary btn-sm');
224

    
225
$section->addInput(new Form_StaticText(
226
	null,
227
	$permbtn
228
));
229
*/
230

    
231
$section->addInput(new Form_Input(
232
	'destslice',
233
	null,
234
	'hidden',
235
	$COMPLETE_PATH
236
));
237

    
238
$dupbtn = new Form_Button(
239
	'duplicateslice',
240
	'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH,
241
	null,
242
	'fa-clone'
243
);
244
$dupbtn->addClass('btn-success btn-sm');
245

    
246
$section->addInput(new Form_StaticText(
247
	'Duplicate boot slice',
248
	$dupbtn
249
))->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

    
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
if (file_exists("/conf/upgrade_log.txt")) {
257
	$viewbtn = new Form_Button(
258
		'viewupgradelog',
259
		'View log',
260
		null,
261
		'fa-file-text-o'
262
	);
263
	$viewbtn->addClass('btn-primary btn-sm');
264

    
265
	$section->addInput(new Form_StaticText(
266
		'View previous upgrade log',
267
		$viewbtn
268
	));
269
}
270
$form->add($section);
271
print($form);
272

    
273
if (file_exists("/conf/upgrade_log.txt") && $_POST['viewupgradelog']) {
274
?>
275
	<div class="panel panel-default">
276
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Previous Upgrade Log")?></h2></div>
277
			<!-- No white space between the <pre> and the first output or it will appear on the page! -->
278
			<pre>
279
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
280
			</pre>
281
	</div>
282
<?php
283
}
284
require_once("foot.inc");
(17-17/225)