Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	Part of pfSense
4

    
5
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
6
	All rights reserved
7

    
8
	Some modifications:
9
	Copyright (C) 2010 - Jim Pingle
10

    
11
	Copyright (C) 2006, Eric Friesen
12
	All rights reserved
13

    
14
*/
15

    
16
require("guiconfig.inc");
17

    
18
$pgtitle = array(gettext("Diagnostics"), gettext("S.M.A.R.T. Monitor Tools"));
19
$smartctl = "/usr/local/sbin/smartctl";
20
$smartd = "/usr/local/sbin/smartd";
21
$start_script = "/usr/local/etc/rc.d/smartd.sh";
22

    
23
$valid_test_types = array("offline", "short", "long", "conveyance");
24
$valid_info_types = array("i", "H", "c", "A", "a");
25
$valid_log_types = array("error", "selftest");
26

    
27
$closehead = false;
28
include("head.inc");
29
?>
30

    
31
<style type="text/css">
32
/*<![CDATA[*/
33

    
34
input {
35
	font-family: courier new, courier;
36
	font-weight: normal;
37
	font-size: 9pt;
38
}
39

    
40
pre {
41
	border: 2px solid #435370;
42
	background: #F0F0F0;
43
	padding: 1em;
44
	font-family: courier new, courier;
45
	white-space: pre;
46
	line-height: 10pt;
47
	font-size: 10pt;
48
}
49

    
50
.label {
51
	font-family: tahoma, verdana, arial, helvetica;
52
	font-size: 11px;
53
	font-weight: bold;
54
}
55

    
56
.button {
57
	font-family: tahoma, verdana, arial, helvetica;
58
	font-weight: bold;
59
	font-size: 11px;
60
}
61

    
62
/*]]>*/
63
</style>
64
</head>
65
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
66

    
67
<?php 
68
include("fbegin.inc"); 
69

    
70
// Highlates the words "PASSED", "FAILED", and "WARNING".
71
function add_colors($string)
72
{
73
	// To add words keep arrayes matched by numbers
74
	$patterns[0] = '/PASSED/';
75
	$patterns[1] = '/FAILED/';
76
	$patterns[2] = '/Warning/';
77
	$replacements[0] = '<b><font color="#00ff00">' . gettext("PASSED") . '</font></b>';
78
	$replacements[1] = '<b><font color="#ff0000">' . gettext("FAILED") . '</font></b>';
79
	$replacements[2] = '<font color="#ff0000">' . gettext("Warning") . '</font>';
80
	ksort($patterns);
81
	ksort($replacements);
82
	return preg_replace($patterns, $replacements, $string);
83
}
84

    
85
// Edits smartd.conf file, adds or removes email for failed disk reporting
86
function update_email($email)
87
{
88
	// Did they pass an email?
89
	if(!empty($email))
90
	{
91
		// Put it in the smartd.conf file
92
		shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN -H -m " . escapeshellarg($email) . "/' /usr/local/etc/smartd.conf");
93
	}
94
	// Nope
95
	else
96
	{
97
		// Remove email flags in smartd.conf
98
		shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN/' /usr/local/etc/smartd.conf");
99
	}
100
}
101

    
102
function smartmonctl($action)
103
{
104
	global $start_script;
105
	shell_exec($start_script . escapeshellarg($action));
106
}
107

    
108
// What page, aka. action is being wanted
109
// If they "get" a page but don't pass all arguments, smartctl will throw an error
110
$action = (isset($_POST['action']) ? $_POST['action'] : $_GET['action']);
111
$targetdev = basename($_POST['device']);
112
if (!file_exists('/dev/' . $targetdev)) {
113
	echo "Device does not exist, bailing.";
114
	return;
115
}
116
switch($action) {
117
	// Testing devices
118
	case 'test':
119
	{
120
		$test = $_POST['testType'];
121
		if (!in_array($test, $valid_test_types)) {
122
			echo "Invalid test type, bailing.";
123
			return;
124
		}
125
		$output = add_colors(shell_exec($smartctl . " -t " . escapeshellarg($test) . " /dev/" . escapeshellarg($targetdev)));
126
		echo '<pre>' . $output . '
127
		<form action="diag_smart.php" method="post" name="abort">
128
		<input type="hidden" name="device" value="' . $targetdev . '" />
129
		<input type="hidden" name="action" value="abort" />
130
		<input type="submit" name="submit" value="' . gettext("Abort") . '" />
131
		</form>
132
		</pre>';
133
		break;
134
	}
135

    
136
	// Info on devices
137
	case 'info':
138
	{
139
		$type = $_POST['type'];
140
		if (!in_array($type, $valid_info_types)) {
141
			echo "Invalid info type, bailing.";
142
			return;
143
		}
144
		$output = add_colors(shell_exec($smartctl . " -" . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
145
		echo "<pre>$output</pre>";
146
		break;
147
	}
148

    
149
	// View logs
150
	case 'logs':
151
	{
152
		$type = $_POST['type'];
153
		if (!in_array($type, $valid_log_types)) {
154
			echo "Invalid log type, bailing.";
155
			return;
156
		}
157
		$output = add_colors(shell_exec($smartctl . " -l " . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
158
		echo "<pre>$output</pre>";
159
		break;
160
	}
161

    
162
	// Abort tests
163
	case 'abort':
164
	{
165
		$output = shell_exec($smartctl . " -X /dev/" . escapeshellarg($targetdev));
166
		echo "<pre>$output</pre>";
167
		break;
168
	}
169

    
170
	// Config changes, users email in xml config and write changes to smartd.conf
171
	case 'config':
172
	{
173
		if(isset($_POST['submit']))
174
		{
175
			// DOES NOT WORK YET...
176
			if($_POST['testemail'])
177
			{
178
// FIXME				shell_exec($smartd . " -M test -m " . $config['system']['smartmonemail']);
179
				$savemsg = sprintf(gettext("Email sent to %s"), $config['system']['smartmonemail']);
180
				smartmonctl("stop");
181
				smartmonctl("start");
182
			}
183
			else
184
			{
185
				$config['system']['smartmonemail'] = $_POST['smartmonemail'];
186
				write_config();
187

    
188
				// Don't know what all this means, but it addes the config changed header when config is saved
189
				$retval = 0;
190
				config_lock();
191
				if(stristr($retval, "error") <> true)
192
					$savemsg = get_std_save_message($retval);
193
				else
194
					$savemsg = $retval;
195
				config_unlock();
196

    
197
				if($_POST['email'])
198
				{
199
					// Write the changes to the smartd.conf file
200
					update_email($_POST['smartmonemail']);
201
				}
202

    
203
				// Send sig HUP to smartd, rereads the config file
204
				shell_exec("/usr/bin/killall -HUP smartd");
205
			}
206
		}
207
		// Was the config changed? if so , print the message
208
		if ($savemsg) print_info_box($savemsg);
209
		// Get users email from the xml file
210
		$pconfig['smartmonemail'] = $config['system']['smartmonemail'];
211

    
212
		?>
213
		<!-- Print the tabs across the top -->
214
		<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabs">
215
			<tr>
216
				<td>
217
					<?php
218
					$tab_array = array();
219
					$tab_array[0] = array(gettext("Information/Tests"), false, $_SERVER['PHP_SELF'] . "?action=default");
220
					$tab_array[1] = array(gettext("Config"), true, $_SERVER['PHP_SELF'] . "?action=config");
221
					display_top_tabs($tab_array);
222
				?>
223
				</td>
224
			</tr>
225
		</table>
226
<!-- user email address -->
227
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="config">
228
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="e-mail">
229
			<tbody>
230
				<tr>
231
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Config"); ?></td>
232
				</tr>
233
				<tr>
234
					<td width="22%" valign="top" class="vncell"><?=gettext("Email Address"); ?></td>
235
					<td width="78%" class="vtable">
236
						<input type="text" name="smartmonemail" value="<?=htmlspecialchars($pconfig['smartmonemail'])?>"/>
237
					</td>
238
				</tr>
239
				<tr>
240
					<td width="22%" valign="top">&nbsp;</td>
241
					<td width="78%">
242
						<input type="hidden" name="action" value="config" />
243
						<input type="hidden" name="email" value="true" />
244
						<input type="submit" name="submit" value="<?=gettext("Save"); ?>" class="formbtn" />
245
					</td>
246
				</tr>
247
			</tbody>
248
		</table>
249
		</form>
250

    
251
<!-- test email -->
252
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="config">
253
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="test e-mail">
254
			<tbody>
255
				<tr>
256
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Test email"); ?></td>
257
				</tr>
258
				<tr>
259
					<td width="22%" valign="top" class="vncell">&nbsp;</td>
260
					<td width="78%" class="vtable">
261
						<?php printf(gettext("Send test email to %s"), $config['system']['smartmonemail']); ?>
262
					</td>
263
				</tr>
264
				<tr>
265
					<td width="22%" valign="top">&nbsp;</td>
266
					<td width="78%">
267
						<input type="hidden" name="action" value="config" />
268
						<input type="hidden" name="testemail" value="true" />
269
						<input type="submit" name="submit" value="<?=gettext("Send"); ?>" class="formbtn" />
270
					</td>
271
				</tr>
272
			</tbody>
273
		</table>
274
		</form>
275

    
276
		<?php
277
		break;
278
	}
279

    
280
	// Default page, prints the forms to view info, test, etc...
281
	default:
282
	{
283
		$devs = get_smart_drive_list();
284
		?>
285
		<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="default page">
286
			<tr>
287
				<td>
288
					<?php
289
					$tab_array = array();
290
					$tab_array[0] = array(gettext("Information/Tests"), true, $_SERVER['PHP_SELF']);
291
					//$tab_array[1] = array("Config", false, $_SERVER['PHP_SELF'] . "?action=config");
292
					display_top_tabs($tab_array);
293
				?>
294
				</td>
295
			</tr>
296
		</table>
297
<!--INFO-->
298
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="info">
299
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="info">
300
			<tbody>
301
				<tr>
302
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Info"); ?></td>
303
				</tr>
304
				<tr>
305
					<td width="22%" valign="top" class="vncell"><?=gettext("Info type"); ?></td>
306
					<td width="78%" class="vtable">
307
						<input type="radio" name="type" value="i" /><?=gettext("Info"); ?><br />
308
						<input type="radio" name="type" value="H" checked="checked" /><?=gettext("Health"); ?><br />
309
						<input type="radio" name="type" value="c" /><?=gettext("SMART Capabilities"); ?><br />
310
						<input type="radio" name="type" value="A" /><?=gettext("Attributes"); ?><br />
311
						<input type="radio" name="type" value="a" /><?=gettext("All"); ?><br />
312
					</td>
313
				</tr>
314
				<tr>
315
					<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
316
					<td width="78%" class="vtable">
317
						<select name="device">
318
						<?php
319
						foreach($devs as $dev)
320
						{
321
							echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
322
						}
323
						?>
324
						</select>
325
					</td>
326
				</tr>
327
				<tr>
328
					<td width="22%" valign="top">&nbsp;</td>
329
					<td width="78%">
330
						<input type="hidden" name="action" value="info" />
331
						<input type="submit" name="submit" value="<?=gettext("View"); ?>" class="formbtn" />
332
					</td>
333
				</tr>
334
			</tbody>
335
		</table>
336
		</form>
337
<!--TESTS-->
338
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="tests">
339
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tests">
340
			<tbody>
341
				<tr>
342
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Perform Self-tests"); ?></td>
343
				</tr>
344
				<tr>
345
					<td width="22%" valign="top" class="vncell"><?=gettext("Test type"); ?></td>
346
					<td width="78%" class="vtable">
347
						<input type="radio" name="testType" value="offline" /><?=gettext("Offline"); ?><br />
348
						<input type="radio" name="testType" value="short" checked="checked" /><?=gettext("Short"); ?><br />
349
						<input type="radio" name="testType" value="long" /><?=gettext("Long"); ?><br />
350
						<input type="radio" name="testType" value="conveyance" /><?=gettext("Conveyance (ATA Disks Only)"); ?><br />
351
					</td>
352
				</tr>
353
				<tr>
354
					<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
355
					<td width="78%" class="vtable">
356
						<select name="device">
357
						<?php
358
						foreach($devs as $dev)
359
						{
360
							echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
361
						}
362
						?>
363
						</select>
364
					</td>
365
				</tr>
366
				<tr>
367
					<td width="22%" valign="top">&nbsp;</td>
368
					<td width="78%">
369
						<input type="hidden" name="action" value="test" />
370
						<input type="submit" name="submit" value="<?=gettext("Test"); ?>" class="formbtn" />
371
					</td>
372
				</tr>
373
			</tbody>
374
		</table>
375
		</form>
376
<!--LOGS-->
377
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="logs">
378
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="logs">
379
			<tbody>
380
				<tr>
381
					<td colspan="2" valign="top" class="listtopic"><?=gettext("View Logs"); ?></td>
382
				</tr>
383
				<tr>
384
					<td width="22%" valign="top" class="vncell"><?=gettext("Log type"); ?></td>
385
					<td width="78%" class="vtable">
386
						<input type="radio" name="type" value="error" checked="checked" /><?=gettext("Error"); ?><br />
387
						<input type="radio" name="type" value="selftest" /><?=gettext("Self-test"); ?><br />
388
					</td>
389
				</tr>
390
				<tr>
391
					<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
392
					<td width="78%" class="vtable">
393
						<select name="device">
394
						<?php
395
						foreach($devs as $dev)
396
						{
397
							echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
398
						}
399
						?>
400
						</select>
401
					</td>
402
				</tr>
403
				<tr>
404
					<td width="22%" valign="top">&nbsp;</td>
405
					<td width="78%">
406
						<input type="hidden" name="action" value="logs" />
407
						<input type="submit" name="submit" value="<?=gettext("View"); ?>" class="formbtn" />
408
					</td>
409
				</tr>
410
			</tbody>
411
		</table>
412
		</form>
413
<!--ABORT-->
414
		<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="abort">
415
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="abort">
416
			<tbody>
417
				<tr>
418
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Abort tests"); ?></td>
419
				</tr>
420
				<tr>
421
					<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
422
					<td width="78%" class="vtable">
423
						<select name="device">
424
						<?php
425
						foreach($devs as $dev)
426
						{
427
							echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
428
						}
429
						?>
430
						</select>
431
					</td>
432
				</tr>
433
				<tr>
434
					<td width="22%" valign="top">&nbsp;</td>
435
					<td width="78%">
436
						<input type="hidden" name="action" value="abort" />
437
						<input type="submit" name="submit" value="<?=gettext("Abort"); ?>" class="formbtn" onclick="return confirm('<?=gettext("Do you really want to abort the test?"); ?>')" />
438
					</td>
439
				</tr>
440
			</tbody>
441
		</table>
442
		</form>
443

    
444
		<?php
445
		break;
446
	}
447
}
448

    
449
// print back button on pages
450
if(isset($_POST['submit']) && $_POST['submit'] != "Save")
451
{
452
	echo '<br /><a href="' . $_SERVER['PHP_SELF'] . '">' . gettext("Back") . '</a>';
453
}
454
?>
455
<br />
456
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
457

    
458
<?php include("fend.inc"); ?>
459
</body>
460
</html>
(46-46/256)