Project

General

Profile

Download (11.9 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
	All rights reserved.
6
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29 13d193c2 Scott Ullrich
/*	
30
	pfSense_BUILDER_BINARIES:	/sbin/mount	/sbin/glabel	/usr/bin/grep	/usr/bin/cut	/usr/bin/head	/bin/cp
31
	pfSense_BUILDER_BINARIES:	/usr/sbin/boot0cfg	/bin/mkdir	/sbin/fsck_ufs	/sbin/mount	/sbin/sysctl	/bin/dd	/sbin/tunefs
32
	pfSense_MODULE:	nanobsd
33
*/
34
35 104c11c6 Scott Ullrich
##|+PRIV
36
##|*IDENT=page-diagnostics-nanobsd
37
##|*NAME=Diagnostics: NanoBSD
38
##|*DESCR=Allow access to the 'Diagnostics: NanoBSD' page.
39
##|*MATCH=diag_nanobsd.php*
40
##|-PRIV
41
42 ae396e30 Scott Ullrich
ini_set('zlib.output_compression', 0);
43
ini_set('implicit_flush', 1);
44
ini_set('max_input_time', '9999');
45 104c11c6 Scott Ullrich
46
require_once("guiconfig.inc");
47 96099c6a Renato Botelho
require_once("config.inc");
48 104c11c6 Scott Ullrich
49 9404a104 Renato Botelho
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
50 104c11c6 Scott Ullrich
include("head.inc");
51
52 a3a22a4e Scott Ullrich
// Survey slice info
53 08fd5444 jim-p
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
54
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
55
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
56
nanobsd_detect_slice_info();
57 a3a22a4e Scott Ullrich
58 ae396e30 Scott Ullrich
?>
59
60
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
61 be6e1e8a Scott Ullrich
62 ae396e30 Scott Ullrich
<?php include("fbegin.inc"); ?>
63 be6e1e8a Scott Ullrich
64 ae396e30 Scott Ullrich
<?php
65
66 08fd5444 jim-p
$NANOBSD_SIZE = nanobsd_get_size();
67 62d01a53 Scott Ullrich
68 104c11c6 Scott Ullrich
if($_POST['bootslice']) {
69 cf652f81 Chris Buechler
	$statusmsg = gettext("Setting slice information, please wait..."); 
70 ae396e30 Scott Ullrich
	echo <<<EOF
71
	 	<div id="loading">
72 be6e1e8a Scott Ullrich
			<img src="/themes/metallic/images/misc/loader.gif"> 
73 cf652f81 Chris Buechler
			$statusmsg
74 ae396e30 Scott Ullrich
			<p/>&nbsp;
75
		</div>
76
EOF;
77 2b5f276f jim-p
	nanobsd_switch_boot_slice();
78 9404a104 Renato Botelho
	$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
79 a3a22a4e Scott Ullrich
	// Survey slice info
80 08fd5444 jim-p
	nanobsd_detect_slice_info();
81 a3a22a4e Scott Ullrich
82 104c11c6 Scott Ullrich
}
83
84
if($_POST['destslice']) {
85 cf652f81 Chris Buechler
	$statusmsg = gettext("Duplicating slice.  Please wait, this will take a moment...");
86 ae396e30 Scott Ullrich
echo <<<EOF
87
 	<div id="loading">
88 be6e1e8a Scott Ullrich
		<img src="/themes/metallic/images/misc/loader.gif">
89 cf652f81 Chris Buechler
		$statusmsg
90 ae396e30 Scott Ullrich
		<p/>&nbsp;
91
	</div>
92
EOF;
93 08fd5444 jim-p
	if(nanobsd_clone_slice($_POST['destslice'])) {
94 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.");
95 08fd5444 jim-p
	} else {
96 9404a104 Renato Botelho
		$savemsg = gettext("There was an error while duplicating the slice.  Operation aborted.");
97 104c11c6 Scott Ullrich
	}
98 a3a22a4e Scott Ullrich
	// Re-Survey slice info
99 08fd5444 jim-p
	nanobsd_detect_slice_info();
100 104c11c6 Scott Ullrich
}
101
102 85405c11 jim-p
if (isset($_POST['rrdbackup'])) {
103
	$config['system']['rrdbackup'] = $_POST['rrdbackup'];
104
	install_cron_job("/etc/rc.backup_rrd.sh", ($config['system']['rrdbackup'] > 0), $minute="0", "*/{$config['system']['rrdbackup']}");
105
}
106
if (isset($_POST['dhcpbackup'])) {
107
	$config['system']['dhcpbackup'] = $_POST['dhcpbackup'];
108
	install_cron_job("/etc/rc.backup_dhcpleases.sh", ($config['system']['dhcpbackup'] > 0), $minute="0", "*/{$config['system']['dhcpbackup']}");
109
}
110
111 7b229013 jim-p
if ($_POST['changero']) {
112
	if (is_writable("/")) {
113
		conf_mount_ro();
114
	} else {
115
		conf_mount_rw();
116
	}
117
}
118
119
if ($_POST['setrw']) {
120
	if (isset($_POST['nanobsd_force_rw'])) {
121 41cc7a54 Phil Davis
		if (!is_writable("/")) {
122
			conf_mount_rw();
123
		}
124 7b229013 jim-p
		$config['system']['nanobsd_force_rw'] = true;
125
	} else {
126
		unset($config['system']['nanobsd_force_rw']);
127
	}
128
129
	write_config("Changed Permanent Read/Write Setting");
130
	conf_mount_ro();
131
}
132 85405c11 jim-p
133 104c11c6 Scott Ullrich
if ($savemsg)
134
	print_info_box($savemsg)
135 ae396e30 Scott Ullrich
136 104c11c6 Scott Ullrich
?>
137
<table width="100%" border="0" cellpadding="0" cellspacing="0">
138
	<tr>
139
		<td>
140
			<!-- tabs here if you want them -->
141
		</td>
142
	</tr>
143
	<tr>
144
		<td id="mainarea">
145
			<div class="tabcont">
146
				<span class="vexpl">
147
					<span class="red">
148 45a06eeb Renato Botelho
						<strong><?=gettext("NOTE:")?>&nbsp;</strong>
149 104c11c6 Scott Ullrich
					</span>
150 9404a104 Renato Botelho
					<?=gettext("The options on this page are intended for use by advanced users only.")?>
151 ae396e30 Scott Ullrich
					<br/>&nbsp;
152 104c11c6 Scott Ullrich
				</span>
153 ae396e30 Scott Ullrich
				<p/>
154 104c11c6 Scott Ullrich
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
155
					<tr>
156 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Bootup information");?></td>
157 104c11c6 Scott Ullrich
					</tr>
158 b000d606 Scott Ullrich
					<tr>						
159 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("NanoBSD Image size");?></td>
160 b000d606 Scott Ullrich
						<td width="78%" class="vtable">
161 e0d47cb9 Scott Ullrich
							<?php echo $NANOBSD_SIZE; ?>
162 b000d606 Scott Ullrich
						</td>
163
					</tr>
164 104c11c6 Scott Ullrich
					<tr>
165 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("Bootup");?></td>
166 104c11c6 Scott Ullrich
						<td width="78%" class="vtable">
167
							<form action="diag_nanobsd.php" method="post" name="iform">
168 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Bootup slice is currently:");?> <?php echo $ACTIVE_SLICE; ?>
169 9404a104 Renato Botelho
								<br/><br/><?=gettext("This will switch the bootup slice to the alternate slice.");?>
170 104c11c6 Scott Ullrich
								<br/>
171 2b5f276f jim-p
								<input type='hidden' name='bootslice' value='switch'>
172
								<input type='submit' value='Switch Slice'></form>
173 104c11c6 Scott Ullrich
						</td>
174
					</tr>
175
					<tr>
176
						<td colspan="2" valign="top" class="">&nbsp;</td>
177
					</tr>					
178 7b229013 jim-p
					<tr>
179
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Media Read/Write Status");?></td>
180
					</tr>
181
					<tr>
182
						<td valign="top" class="vncell">Current Read/Write Status:</td>
183
						<td valign="top" class="vncell">
184
							<form action="diag_nanobsd.php" method="post" name="iform">
185
							<?php if (is_writable("/")) {
186 41cc7a54 Phil Davis
								$refcount = refcount_read(1000);
187
								if ($refcount == 1) {
188
									$refdisplay = "";
189
								} else {
190
									$refdisplay = " (reference count " . $refcount . ")";
191
								}
192
								echo gettext("Read/Write") . $refdisplay;
193 7b229013 jim-p
								if (!isset($config['system']['nanobsd_force_rw']))
194
									echo "<br/><input type='submit' name='changero' value='" . gettext("Switch to Read-Only") . "'>";
195
							} else {
196
								echo gettext("Read-Only");
197
								if (!isset($config['system']['nanobsd_force_rw']))
198
									echo "<br/><input type='submit' name='changero' value='" . gettext("Switch to Read/Write") . "'>";
199
							} ?>
200
							</form>
201
							<br/><?php echo gettext("NOTE: This setting is only temporary, and can be switched dynamically in the background."); ?>
202
						</td>
203
					</tr>
204
					<tr>
205
						<td valign="top" class="vncell">Permanent Read/Write:</td>
206
						<td valign="top" class="vncell">
207
							<form action="diag_nanobsd.php" method="post" name="iform">
208
								<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.") ?>
209
								<br/><input type='submit' name='setrw' value='<?php echo gettext("Save") ?>'>
210
							</form>
211
						</td>
212
					</tr>
213
					<tr>
214
						<td colspan="2" valign="top" class="">&nbsp;</td>
215
					</tr>
216 104c11c6 Scott Ullrich
					<tr>
217 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Duplicate bootup slice to alternate");?></td>
218 104c11c6 Scott Ullrich
					</tr>
219
					<tr>
220 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("Duplicate bootup slice");?></td>
221 104c11c6 Scott Ullrich
						<td width="78%" class="vtable">
222 c0948c6c Renato Botelho
							<form action="diag_nanobsd.php" method="post" name="iform">
223 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Destination slice:");?>
224 104c11c6 Scott Ullrich
								<select name='destslice'>
225
									<option value='<?php echo $COMPLETE_PATH; ?>'>
226 9cd8fd11 Scott Ullrich
										<?php echo "{$COMPLETE_BOOT_PATH} -> {$TOFLASH}"; ?>
227 104c11c6 Scott Ullrich
									</option>
228
								</select>
229
								<br/>
230 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.");?>
231 104c11c6 Scott Ullrich
						</td>
232
					</tr>
233
					<tr>
234 28949aa1 Scott Ullrich
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Duplicate slice'></form></td>
235 104c11c6 Scott Ullrich
					</tr>
236 85405c11 jim-p
					<tr>
237
						<td colspan="2" valign="top" class="">&nbsp;</td>
238
					</tr>
239
					<tr>
240
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Periodic Data Backup");?></td>
241
					</tr>
242
					<tr>
243
						<td width="22%" valign="top" class="vncell"><?=gettext("RRD Backup");?></td>
244
						<td width="78%" class="vtable">
245
							<form action="diag_nanobsd.php" method="post" name="iform">
246 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Frequency:");?>
247 85405c11 jim-p
								<select name='rrdbackup'>
248 a3381369 Colin Fleming
									<option value='0' <?php if (!isset($config['system']['rrdbackup']) || ($config['system']['rrdbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
249
								<?php for ($x=1; $x<=24; $x++) { ?>
250
									<option value='<?= $x ?>' <?php if ($config['system']['rrdbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
251
								<?php } ?>
252 85405c11 jim-p
								</select>
253
								<br/>
254 f49c41c5 Warren Baker
								<?=gettext("This will periodically backup the RRD data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
255 85405c11 jim-p
								<br/>
256
								<br/>
257
						</td>
258
					</tr>
259
					<tr>
260
						<td width="22%" valign="top" class="vncell"><?=gettext("DHCP Leases Backup");?></td>
261
						<td width="78%" class="vtable">
262
							<form action="diag_nanobsd.php" method="post" name="iform">
263 aaaf679f Carlos Eduardo Ramos
								<?=gettext("Frequency:");?>
264 85405c11 jim-p
								<select name='dhcpbackup'>
265 a3381369 Colin Fleming
									<option value='0' <?php if (!isset($config['system']['dhcpbackup']) || ($config['system']['dhcpbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
266
								<?php for ($x=1; $x<=24; $x++) { ?>
267
									<option value='<?= $x ?>' <?php if ($config['system']['dhcpbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
268
								<?php } ?>
269 85405c11 jim-p
								</select>
270
								<br/>
271 f49c41c5 Warren Baker
								<?=gettext("This will periodically backup the DHCP leases data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
272 85405c11 jim-p
								<br/>
273
								<br/>
274
						</td>
275
					</tr>
276
					<tr>
277 aaaf679f Carlos Eduardo Ramos
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='<?=gettext("Save"); ?>'></form></td>
278 85405c11 jim-p
					</tr>
279 bcb03f4b Scott Ullrich
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
280
					<tr>
281
						<td colspan="2" valign="top" class="">&nbsp;</td>
282
					</tr>					
283
					<tr>
284 9404a104 Renato Botelho
						<td colspan="2" valign="top" class="listtopic"><?=gettext("View upgrade log");?></td>
285 bcb03f4b Scott Ullrich
					</tr>
286
					<tr>
287 9404a104 Renato Botelho
						<td width="22%" valign="top" class="vncell"><?=gettext("View previous upgrade log");?></td>
288 bcb03f4b Scott Ullrich
						<td width="78%" class="vtable">
289
						<?php
290
							if($_POST['viewupgradelog']) {
291
								echo "<textarea name='log' cols='80' rows='40'>";
292
								echo file_get_contents("/conf/upgrade_log.txt");
293 ad3c7724 Scott Ullrich
								echo "\nFile list:\n";
294 dce5cc7c Scott Ullrich
								echo file_get_contents("/conf/file_upgrade_log.txt");
295 ad3c7724 Scott Ullrich
								echo "\nMisc log:\n";
296 2e009ccb phildd
								echo file_get_contents("/conf/firmware_update_misc_log.txt");
297 c5eb3a17 Scott Ullrich
								echo "\nfdisk/bsdlabel log:\n";
298
								echo file_get_contents("/conf/fdisk_upgrade_log.txt");
299 bcb03f4b Scott Ullrich
								echo "</textarea>";
300
							} else {
301
								echo "<form action='diag_nanobsd.php' method='post' name='iform'>";
302
								echo "<input type='submit' name='viewupgradelog' value='View upgrade log'>";
303
							}
304
						?>
305
						</td>
306
					</tr>
307
<?php endif; ?>
308 104c11c6 Scott Ullrich
					<tr>
309
						<td colspan="2" valign="top" class="">&nbsp;</td>
310
					</tr>					
311
				</table>
312
			</div>
313
		</td>
314
	</tr>
315
</table>
316
<?php require("fend.inc"); ?>
317
</body>
318
</html>
319 ae396e30 Scott Ullrich
320
<?php
321
322 be6e1e8a Scott Ullrich
// Clear the loading indicator
323 ae396e30 Scott Ullrich
echo "<script type=\"text/javascript\">";
324 ebfc87d6 Vinicius Coque
echo "jQuery('#loading').html('');";
325 ae396e30 Scott Ullrich
echo "</script>";	
326
327 58cd9724 Renato Botelho
?>