Project

General

Profile

Download (9.96 KB) Statistics
| Branch: | Tag: | Revision:
1 104c11c6 Scott Ullrich
<?php
2
/*
3
	diag_nanobsd.php
4
	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
5 dd447bde Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
6 104c11c6 Scott Ullrich
	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 13d193c2 Scott Ullrich
/*	
31
	pfSense_BUILDER_BINARIES:	/sbin/mount	/sbin/glabel	/usr/bin/grep	/usr/bin/cut	/usr/bin/head	/bin/cp
32 971de1f9 Renato Botelho
	pfSense_BUILDER_BINARIES:	/usr/sbin/boot0cfg	/bin/mkdir	/sbin/fsck_ufs	/sbin/mount	/bin/dd	/sbin/tunefs
33 13d193c2 Scott Ullrich
	pfSense_MODULE:	nanobsd
34
*/
35
36 104c11c6 Scott Ullrich
##|+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 ae396e30 Scott Ullrich
ini_set('zlib.output_compression', 0);
44
ini_set('implicit_flush', 1);
45
ini_set('max_input_time', '9999');
46 104c11c6 Scott Ullrich
47
require_once("guiconfig.inc");
48 96099c6a Renato Botelho
require_once("config.inc");
49 104c11c6 Scott Ullrich
50 9404a104 Renato Botelho
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
51 104c11c6 Scott Ullrich
include("head.inc");
52
53 a3a22a4e Scott Ullrich
// Survey slice info
54 08fd5444 jim-p
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
55
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
56
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
57
nanobsd_detect_slice_info();
58 a3a22a4e Scott Ullrich
59 ae396e30 Scott Ullrich
?>
60
61
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
62 be6e1e8a Scott Ullrich
63 ae396e30 Scott Ullrich
<?php include("fbegin.inc"); ?>
64 be6e1e8a Scott Ullrich
65 ae396e30 Scott Ullrich
<?php
66
67 08fd5444 jim-p
$NANOBSD_SIZE = nanobsd_get_size();
68 62d01a53 Scott Ullrich
69 104c11c6 Scott Ullrich
if($_POST['bootslice']) {
70 cf652f81 Chris Buechler
	$statusmsg = gettext("Setting slice information, please wait..."); 
71 ae396e30 Scott Ullrich
	echo <<<EOF
72
	 	<div id="loading">
73 7bc1b968 Renato Botelho
			<img src="/themes/{$g['theme']}/images/misc/loader.gif"> 
74 cf652f81 Chris Buechler
			$statusmsg
75 ae396e30 Scott Ullrich
			<p/>&nbsp;
76
		</div>
77
EOF;
78 2b5f276f jim-p
	nanobsd_switch_boot_slice();
79 9404a104 Renato Botelho
	$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
80 a3a22a4e Scott Ullrich
	// Survey slice info
81 08fd5444 jim-p
	nanobsd_detect_slice_info();
82 a3a22a4e Scott Ullrich
83 104c11c6 Scott Ullrich
}
84
85
if($_POST['destslice']) {
86 cf652f81 Chris Buechler
	$statusmsg = gettext("Duplicating slice.  Please wait, this will take a moment...");
87 ae396e30 Scott Ullrich
echo <<<EOF
88
 	<div id="loading">
89 7bc1b968 Renato Botelho
		<img src="/themes/{$g['theme']}/images/misc/loader.gif">
90 cf652f81 Chris Buechler
		$statusmsg
91 ae396e30 Scott Ullrich
		<p/>&nbsp;
92
	</div>
93
EOF;
94 08fd5444 jim-p
	if(nanobsd_clone_slice($_POST['destslice'])) {
95 9404a104 Renato Botelho
		$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.");
96 08fd5444 jim-p
	} else {
97 9404a104 Renato Botelho
		$savemsg = gettext("There was an error while duplicating the slice.  Operation aborted.");
98 104c11c6 Scott Ullrich
	}
99 a3a22a4e Scott Ullrich
	// Re-Survey slice info
100 08fd5444 jim-p
	nanobsd_detect_slice_info();
101 104c11c6 Scott Ullrich
}
102
103 7b229013 jim-p
if ($_POST['changero']) {
104
	if (is_writable("/")) {
105
		conf_mount_ro();
106
	} else {
107
		conf_mount_rw();
108
	}
109
}
110
111
if ($_POST['setrw']) {
112 b8250344 Renato Botelho
	conf_mount_rw();
113
	if (isset($_POST['nanobsd_force_rw']))
114 7b229013 jim-p
		$config['system']['nanobsd_force_rw'] = true;
115 b8250344 Renato Botelho
	else
116 7b229013 jim-p
		unset($config['system']['nanobsd_force_rw']);
117
118
	write_config("Changed Permanent Read/Write Setting");
119
	conf_mount_ro();
120
}
121 85405c11 jim-p
122 104c11c6 Scott Ullrich
if ($savemsg)
123
	print_info_box($savemsg)
124 ae396e30 Scott Ullrich
125 104c11c6 Scott Ullrich
?>
126
<table width="100%" border="0" cellpadding="0" cellspacing="0">
127
	<tr>
128
		<td>
129
			<!-- tabs here if you want them -->
130
		</td>
131
	</tr>
132
	<tr>
133
		<td id="mainarea">
134
			<div class="tabcont">
135
				<span class="vexpl">
136
					<span class="red">
137 45a06eeb Renato Botelho
						<strong><?=gettext("NOTE:")?>&nbsp;</strong>
138 104c11c6 Scott Ullrich
					</span>
139 9404a104 Renato Botelho
					<?=gettext("The options on this page are intended for use by advanced users only.")?>
140 8cd558b6 ayvis
					<br />&nbsp;
141 104c11c6 Scott Ullrich
				</span>
142 ae396e30 Scott Ullrich
				<p/>
143 104c11c6 Scott Ullrich
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
144
					<tr>
145 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Bootup information");?></td>
146 104c11c6 Scott Ullrich
					</tr>
147 b000d606 Scott Ullrich
					<tr>						
148 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("NanoBSD Image size");?></td>
149 b000d606 Scott Ullrich
						<td width="78%" class="vtable">
150 e0d47cb9 Scott Ullrich
							<?php echo $NANOBSD_SIZE; ?>
151 b000d606 Scott Ullrich
						</td>
152
					</tr>
153 104c11c6 Scott Ullrich
					<tr>
154 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("Bootup");?></td>
155 104c11c6 Scott Ullrich
						<td width="78%" class="vtable">
156
							<form action="diag_nanobsd.php" method="post" name="iform">
157 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Bootup slice is currently:");?> <?php echo $ACTIVE_SLICE; ?>
158 8cd558b6 ayvis
								<br /><br /><?=gettext("This will switch the bootup slice to the alternate slice.");?>
159
								<br />
160 2b5f276f jim-p
								<input type='hidden' name='bootslice' value='switch'>
161
								<input type='submit' value='Switch Slice'></form>
162 104c11c6 Scott Ullrich
						</td>
163
					</tr>
164
					<tr>
165
						<td colspan="2" valign="top" class="">&nbsp;</td>
166
					</tr>					
167 7b229013 jim-p
					<tr>
168
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Media Read/Write Status");?></td>
169
					</tr>
170
					<tr>
171
						<td valign="top" class="vncell">Current Read/Write Status:</td>
172
						<td valign="top" class="vncell">
173
							<form action="diag_nanobsd.php" method="post" name="iform">
174
							<?php if (is_writable("/")) {
175 41cc7a54 Phil Davis
								$refcount = refcount_read(1000);
176 b8250344 Renato Botelho
								/* refcount_read returns -1 when shared memory section does not exist */
177
								if ($refcount == 1 || $refcount == -1) {
178 41cc7a54 Phil Davis
									$refdisplay = "";
179
								} else {
180
									$refdisplay = " (reference count " . $refcount . ")";
181
								}
182
								echo gettext("Read/Write") . $refdisplay;
183 7b229013 jim-p
								if (!isset($config['system']['nanobsd_force_rw']))
184 8cd558b6 ayvis
									echo "<br /><input type='submit' name='changero' value='" . gettext("Switch to Read-Only") . "'>";
185 7b229013 jim-p
							} else {
186
								echo gettext("Read-Only");
187
								if (!isset($config['system']['nanobsd_force_rw']))
188 8cd558b6 ayvis
									echo "<br /><input type='submit' name='changero' value='" . gettext("Switch to Read/Write") . "'>";
189 7b229013 jim-p
							} ?>
190
							</form>
191 8cd558b6 ayvis
							<br /><?php echo gettext("NOTE: This setting is only temporary, and can be switched dynamically in the background."); ?>
192 7b229013 jim-p
						</td>
193
					</tr>
194
					<tr>
195
						<td valign="top" class="vncell">Permanent Read/Write:</td>
196
						<td valign="top" class="vncell">
197
							<form action="diag_nanobsd.php" method="post" name="iform">
198
								<input type="checkbox" name="nanobsd_force_rw" <?php if (isset($config['system']['nanobsd_force_rw'])) echo "checked"; ?>> <?php echo gettext("Keep media mounted read/write at all times.") ?>
199 8cd558b6 ayvis
								<br /><input type='submit' name='setrw' value='<?php echo gettext("Save") ?>'>
200 7b229013 jim-p
							</form>
201
						</td>
202
					</tr>
203
					<tr>
204
						<td colspan="2" valign="top" class="">&nbsp;</td>
205
					</tr>
206 104c11c6 Scott Ullrich
					<tr>
207 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Duplicate bootup slice to alternate");?></td>
208 104c11c6 Scott Ullrich
					</tr>
209
					<tr>
210 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("Duplicate bootup slice");?></td>
211 104c11c6 Scott Ullrich
						<td width="78%" class="vtable">
212 c0948c6c Renato Botelho
							<form action="diag_nanobsd.php" method="post" name="iform">
213 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Destination slice:");?>
214 104c11c6 Scott Ullrich
								<select name='destslice'>
215
									<option value='<?php echo $COMPLETE_PATH; ?>'>
216 9cd8fd11 Scott Ullrich
										<?php echo "{$COMPLETE_BOOT_PATH} -> {$TOFLASH}"; ?>
217 104c11c6 Scott Ullrich
									</option>
218
								</select>
219 8cd558b6 ayvis
								<br />
220 9404a104 Renato Botelho
								<?=gettext("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.");?>
221 63673f3c Phil Davis
								<br /><input type='submit' name='duplicateslice' value='<?php echo gettext("Duplicate slice") ?>'>
222
							</form>
223 104c11c6 Scott Ullrich
						</td>
224
					</tr>
225 85405c11 jim-p
					<tr>
226
						<td colspan="2" valign="top" class="">&nbsp;</td>
227
					</tr>
228
					<tr>
229
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Periodic Data Backup");?></td>
230
					</tr>
231
					<tr>
232 e92e83d4 jim-p
						<td width="22%" valign="top" class="vncell"><?=gettext("RRD/DHCP Backup");?></td>
233 85405c11 jim-p
						<td width="78%" class="vtable">
234 e92e83d4 jim-p
							<?=gettext("These options have been relocated to");?> <a href="system_advanced_misc.php"><?=gettext("System > Advanced, Miscellaneous tab")?></a>.
235 85405c11 jim-p
						</td>
236
					</tr>
237 bcb03f4b Scott Ullrich
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
238
					<tr>
239
						<td colspan="2" valign="top" class="">&nbsp;</td>
240
					</tr>					
241
					<tr>
242 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("View upgrade log");?></td>
243 bcb03f4b Scott Ullrich
					</tr>
244
					<tr>
245 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("View previous upgrade log");?></td>
246 bcb03f4b Scott Ullrich
						<td width="78%" class="vtable">
247
						<?php
248 2df0e712 Warren Baker
							if ($_POST['viewupgradelog']) {
249 bcb03f4b Scott Ullrich
								echo "<textarea name='log' cols='80' rows='40'>";
250 2df0e712 Warren Baker
								echo str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/upgrade_log.txt"));
251 ad3c7724 Scott Ullrich
								echo "\nFile list:\n";
252 2df0e712 Warren Baker
								echo str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/file_upgrade_log.txt"));
253 ad3c7724 Scott Ullrich
								echo "\nMisc log:\n";
254 2df0e712 Warren Baker
								echo str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/firmware_update_misc_log.txt"));
255 c5eb3a17 Scott Ullrich
								echo "\nfdisk/bsdlabel log:\n";
256 2df0e712 Warren Baker
								echo str_ireplace("pfsense", $g['product_name'], file_get_contents("/conf/fdisk_upgrade_log.txt"));
257 bcb03f4b Scott Ullrich
								echo "</textarea>";
258
							} else {
259
								echo "<form action='diag_nanobsd.php' method='post' name='iform'>";
260
								echo "<input type='submit' name='viewupgradelog' value='View upgrade log'>";
261
							}
262
						?>
263
						</td>
264
					</tr>
265
<?php endif; ?>
266 104c11c6 Scott Ullrich
					<tr>
267
						<td colspan="2" valign="top" class="">&nbsp;</td>
268
					</tr>					
269
				</table>
270
			</div>
271
		</td>
272
	</tr>
273
</table>
274
<?php require("fend.inc"); ?>
275
</body>
276
</html>
277 ae396e30 Scott Ullrich
278
<?php
279
280 be6e1e8a Scott Ullrich
// Clear the loading indicator
281 ae396e30 Scott Ullrich
echo "<script type=\"text/javascript\">";
282 ebfc87d6 Vinicius Coque
echo "jQuery('#loading').html('');";
283 ae396e30 Scott Ullrich
echo "</script>";	
284
285 58cd9724 Renato Botelho
?>