Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*	
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
##|+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
ini_set('zlib.output_compression', 0);
43
ini_set('implicit_flush', 1);
44
ini_set('max_input_time', '9999');
45

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

    
49
$pgtitle = array(gettext("Diagnostics"), gettext("NanoBSD"));
50
include("head.inc");
51

    
52
// Survey slice info
53
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

    
58
?>
59

    
60
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
61

    
62
<?php include("fbegin.inc"); ?>
63

    
64
<?php
65

    
66
$NANOBSD_SIZE = nanobsd_get_size();
67

    
68
if($_POST['bootslice']) {
69
	$statusmsg = gettext("Setting slice information, please wait..."); 
70
	echo <<<EOF
71
	 	<div id="loading">
72
			<img src="/themes/metallic/images/misc/loader.gif"> 
73
			$statusmsg
74
			<p/>&nbsp;
75
		</div>
76
EOF;
77
	nanobsd_switch_boot_slice();
78
	$savemsg = gettext("The boot slice has been set to") . " " . nanobsd_get_active_slice();
79
	// Survey slice info
80
	nanobsd_detect_slice_info();
81

    
82
}
83

    
84
if($_POST['destslice']) {
85
	$statusmsg = gettext("Duplicating slice.  Please wait, this will take a moment...");
86
echo <<<EOF
87
 	<div id="loading">
88
		<img src="/themes/metallic/images/misc/loader.gif">
89
		$statusmsg
90
		<p/>&nbsp;
91
	</div>
92
EOF;
93
	if(nanobsd_clone_slice($_POST['destslice'])) {
94
		$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
	} else {
96
		$savemsg = gettext("There was an error while duplicating the slice.  Operation aborted.");
97
	}
98
	// Re-Survey slice info
99
	nanobsd_detect_slice_info();
100
}
101

    
102
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
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
		if (!is_writable("/")) {
122
			conf_mount_rw();
123
		}
124
		$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

    
133
if ($savemsg)
134
	print_info_box($savemsg)
135

    
136
?>
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
						<strong><?=gettext("NOTE:")?>&nbsp;</strong>
149
					</span>
150
					<?=gettext("The options on this page are intended for use by advanced users only.")?>
151
					<br/>&nbsp;
152
				</span>
153
				<p/>
154
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
155
					<tr>
156
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Bootup information");?></td>
157
					</tr>
158
					<tr>						
159
						<td width="22%" valign="top" class="vncell"><?=gettext("NanoBSD Image size");?></td>
160
						<td width="78%" class="vtable">
161
							<?php echo $NANOBSD_SIZE; ?>
162
						</td>
163
					</tr>
164
					<tr>
165
						<td width="22%" valign="top" class="vncell"><?=gettext("Bootup");?></td>
166
						<td width="78%" class="vtable">
167
							<form action="diag_nanobsd.php" method="post" name="iform">
168
								<?=gettext("Bootup slice is currently:");?> <?php echo $ACTIVE_SLICE; ?>
169
								<br/><br/><?=gettext("This will switch the bootup slice to the alternate slice.");?>
170
								<br/>
171
								<input type='hidden' name='bootslice' value='switch'>
172
								<input type='submit' value='Switch Slice'></form>
173
						</td>
174
					</tr>
175
					<tr>
176
						<td colspan="2" valign="top" class="">&nbsp;</td>
177
					</tr>					
178
					<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
								$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
								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
					<tr>
217
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Duplicate bootup slice to alternate");?></td>
218
					</tr>
219
					<tr>
220
						<td width="22%" valign="top" class="vncell"><?=gettext("Duplicate bootup slice");?></td>
221
						<td width="78%" class="vtable">
222
							<form action="diag_nanobsd.php" method="post" name="iform">
223
								<?=gettext("Destination slice:");?>
224
								<select name='destslice'>
225
									<option value='<?php echo $COMPLETE_PATH; ?>'>
226
										<?php echo "{$COMPLETE_BOOT_PATH} -> {$TOFLASH}"; ?>
227
									</option>
228
								</select>
229
								<br/>
230
								<?=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
						</td>
232
					</tr>
233
					<tr>
234
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Duplicate slice'></form></td>
235
					</tr>
236
					<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
								<?=gettext("Frequency:");?>
247
								<select name='rrdbackup'>
248
									<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
								</select>
253
								<br/>
254
								<?=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
								<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
								<?=gettext("Frequency:");?>
264
								<select name='dhcpbackup'>
265
									<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
								</select>
270
								<br/>
271
								<?=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
								<br/>
273
								<br/>
274
						</td>
275
					</tr>
276
					<tr>
277
						<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='<?=gettext("Save"); ?>'></form></td>
278
					</tr>
279
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
280
					<tr>
281
						<td colspan="2" valign="top" class="">&nbsp;</td>
282
					</tr>					
283
					<tr>
284
						<td colspan="2" valign="top" class="listtopic"><?=gettext("View upgrade log");?></td>
285
					</tr>
286
					<tr>
287
						<td width="22%" valign="top" class="vncell"><?=gettext("View previous upgrade log");?></td>
288
						<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
								echo "\nFile list:\n";
294
								echo file_get_contents("/conf/file_upgrade_log.txt");
295
								echo "\nMisc log:\n";
296
								echo file_get_contents("/conf/firmware_update_misc_log.txt");
297
								echo "\nfdisk/bsdlabel log:\n";
298
								echo file_get_contents("/conf/fdisk_upgrade_log.txt");
299
								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
					<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

    
320
<?php
321

    
322
// Clear the loading indicator
323
echo "<script type=\"text/javascript\">";
324
echo "jQuery('#loading').html('');";
325
echo "</script>";	
326

    
327
?>
(35-35/249)