Project

General

Profile

Download (7.31 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_nanobsd.php
4
	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, 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 the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
/*
31
	pfSense_BUILDER_BINARIES:	/sbin/mount /sbin/glabel	/usr/bin/grep	/usr/bin/cut	/usr/bin/head	/bin/cp
32
	pfSense_BUILDER_BINARIES:	/usr/sbin/boot0cfg	/bin/mkdir	/sbin/fsck_ufs	/sbin/mount /bin/dd /sbin/tunefs
33
	pfSense_MODULE: nanobsd
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-diagnostics-nanobsd
38
##|*NAME=Diagnostics: NanoBSD
39
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
40
##|*MATCH=diag_nanobsd.php*
41
##|-PRIV
42

    
43
ini_set('zlib.output_compression', 0);
44
ini_set('implicit_flush', 1);
45
ini_set('max_input_time', '9999');
46

    
47
require_once("guiconfig.inc");
48
require_once("config.inc");
49

    
50
// Setting DEBUG to true causes the dangerous stuff on this page to be simulated rather than exectued.
51
// MUST be set to false for production of course
52
define(DEBUG, true);
53

    
54
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
55
include("head.inc");
56

    
57
// Survey slice info
58
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
59
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
60
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
61
nanobsd_detect_slice_info();
62

    
63
$NANOBSD_SIZE = nanobsd_get_size();
64
$class='alert-warning';
65

    
66
if($_POST['bootslice']) {
67
	if(!DEBUG)
68
	   nanobsd_switch_boot_slice();
69
	else
70
	   sleep(4);
71

    
72
	$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
73
	$class='alert-success';
74
	// Survey slice info
75
	nanobsd_detect_slice_info();
76
}
77

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

    
81
	if(!DEBUG && nanobsd_clone_slice($_POST['destslice'])) {
82
		$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.");
83
		$class='alert-success';
84
	} else {
85
		$savemsg = gettext("There was an error while duplicating the slice.	 Operation aborted.");
86
		$class='alert-danger';
87
	}
88
	// Re-Survey slice info
89
	nanobsd_detect_slice_info();
90
}
91

    
92
if ($_POST['changero']) {
93
	if (!DEBUG && is_writable("/")) {
94
		conf_mount_ro();
95
	} else {
96
		conf_mount_rw();
97
	}
98
}
99

    
100
if ($_POST['setrw']) {
101
	if(!DEBUG) {
102
		conf_mount_rw();
103
		if (isset($_POST['nanobsd_force_rw']))
104
			$config['system']['nanobsd_force_rw'] = true;
105
		else
106
			unset($config['system']['nanobsd_force_rw']);
107

    
108
		write_config("Changed Permanent Read/Write Setting");
109
		conf_mount_ro();
110
	}
111
	else {
112
		$savemsg = 'Saved r/w permanantly';
113
		$class = 'alert-success';
114
	}
115
}
116

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

    
119
if ($savemsg)
120
	print_info_box($savemsg, $class);
121

    
122
require('classes/Form.class.php');
123

    
124
$form = new Form(false);
125

    
126
$section = new Form_Section('NanoBSD Option');
127

    
128
$section->addInput(new Form_StaticText(
129
	'Image Size',
130
	$NANOBSD_SIZE
131
));
132

    
133
$slicebtn = new Form_Button('bootslice', 'Switch Slice');
134
$slicebtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
135

    
136
$section->addInput(new Form_StaticText(
137
	'Bootup slice',
138
	$ACTIVE_SLICE . ' ' . $slicebtn
139
));
140

    
141
if (is_writable("/")) {
142
	$refcount = refcount_read(1000);
143
	/* refcount_read returns -1 when shared memory section does not exist */
144
	if ($refcount == 1 || $refcount == -1) {
145
		$refdisplay = "";
146
	} else {
147
		$refdisplay = " (Reference count " . $refcount . ")";
148
	}
149
	$lbl = gettext("Read/Write") . $refdisplay;
150
	if (!isset($config['system']['nanobsd_force_rw']))
151
		$btnlbl = gettext("Switch to Read-Only");
152
} else {
153
	$lbl = gettext("Read-Only");
154
	if (!isset($config['system']['nanobsd_force_rw']))
155
		$btnlbl = gettext("Switch to Read/Write");
156
}
157

    
158
$robtn = new Form_Button('changero', $btnlbl);
159
$robtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
160

    
161
$section->addInput(new Form_StaticText(
162
	'Read/Write status',
163
	$lbl . ' ' . $robtn
164
));
165

    
166
$section->addInput(new Form_Checkbox(
167
	'nanobsd_force_rw',
168
	'Permanent Read/Write',
169
	'Keep media mounted read/write at all times. ',
170
	isset($config['system']['nanobsd_force_rw'])
171
))->setHelp('This setting is only temporary, and can be switched dynamically in the background.');
172

    
173
$permbtn = new Form_Button('setrw', 'Save');
174
$permbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
175

    
176
$section->addInput(new Form_StaticText(
177
	null,
178
	$permbtn
179
));
180

    
181
$section->addInput(new Form_Input(
182
	'destslice',
183
	null,
184
	'hidden',
185
	$COMPLETE_PATH
186
));
187

    
188
$dupbtn = new Form_Button('duplicateslice', 'Duplicate ' . $COMPLETE_BOOT_PATH . ' -> ' . $TOFLASH);
189
$dupbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
190

    
191
$section->addInput(new Form_StaticText(
192
	'Duplicate boot slice',
193
	$dupbtn
194
))->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.');
195

    
196
$section->addInput(new Form_StaticText(
197
	'RRD/DHCP Backup',
198
	'These options have been relocated to the ' . '<a href="system_advanced_misc.php">' . 'System > Advanced, Miscellaneous</a> tab.'
199
));
200

    
201
if(file_exists("/conf/upgrade_log.txt")) {
202
	$viewbtn = new Form_Button('viewupgradelog', 'View log');
203
	$viewbtn->removeClass('btn-primary')->addClass('btn-default btn-sm');
204

    
205
	$section->addInput(new Form_StaticText(
206
		'View previous upgrade log',
207
		$viewbtn
208
	));
209
}
210
$form->add($section);
211
print($form);
212

    
213
if(file_exists("/conf/upgrade_log.txt") && $_POST['viewupgradelog']) {
214
?>
215
	<div class="panel panel-default">
216
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Previous upgrade log")?></h2></div>
217
			<!-- No white space between the <pre> and the first output or it will appear on the page! -->
218
			<pre><?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"))?>
219
				<br /><?=gettext("File list:")?>
220
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/file_upgrade_log.txt"))?>
221
				<br /><?=gettext("Misc log:")?>
222
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/firmware_update_misc_log.txt"))?>
223
				<br /><?=gettext("fdisk/bsdlabel log:")?>
224
				<?=str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/fdisk_upgrade_log.txt"))?>
225
			</pre>
226
	</div>
227
<?php
228
}
229
require("foot.inc");
(26-26/237)