1
|
<?php
|
2
|
/*
|
3
|
Part of pfSense
|
4
|
|
5
|
Copyright (C) 2006, Eric Friesen
|
6
|
All rights reserved
|
7
|
|
8
|
Some modifications:
|
9
|
Copyright (C) 2010 - Jim Pingle
|
10
|
*/
|
11
|
|
12
|
require("guiconfig.inc");
|
13
|
|
14
|
$pgtitle = array(gettext("Diagnostics"), gettext("S.M.A.R.T. Monitor Tools"));
|
15
|
$smartctl = "/usr/local/sbin/smartctl";
|
16
|
$smartd = "/usr/local/sbin/smartd";
|
17
|
$start_script = "/usr/local/etc/rc.d/smartd.sh";
|
18
|
|
19
|
$valid_test_types = array("offline", "short", "long", "conveyance");
|
20
|
$valid_info_types = array("i", "H", "c", "A", "a");
|
21
|
$valid_log_types = array("error", "selftest");
|
22
|
|
23
|
$closehead = false;
|
24
|
include("head.inc");
|
25
|
?>
|
26
|
|
27
|
<style type="text/css">
|
28
|
/*<![CDATA[*/
|
29
|
|
30
|
input {
|
31
|
font-family: courier new, courier;
|
32
|
font-weight: normal;
|
33
|
font-size: 9pt;
|
34
|
}
|
35
|
|
36
|
pre {
|
37
|
border: 2px solid #435370;
|
38
|
background: #F0F0F0;
|
39
|
padding: 1em;
|
40
|
font-family: courier new, courier;
|
41
|
white-space: pre;
|
42
|
line-height: 10pt;
|
43
|
font-size: 10pt;
|
44
|
}
|
45
|
|
46
|
.label {
|
47
|
font-family: tahoma, verdana, arial, helvetica;
|
48
|
font-size: 11px;
|
49
|
font-weight: bold;
|
50
|
}
|
51
|
|
52
|
.button {
|
53
|
font-family: tahoma, verdana, arial, helvetica;
|
54
|
font-weight: bold;
|
55
|
font-size: 11px;
|
56
|
}
|
57
|
|
58
|
/*]]>*/
|
59
|
</style>
|
60
|
</head>
|
61
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
62
|
|
63
|
<?php
|
64
|
include("fbegin.inc");
|
65
|
|
66
|
// Highlates the words "PASSED", "FAILED", and "WARNING".
|
67
|
function add_colors($string)
|
68
|
{
|
69
|
// To add words keep arrayes matched by numbers
|
70
|
$patterns[0] = '/PASSED/';
|
71
|
$patterns[1] = '/FAILED/';
|
72
|
$patterns[2] = '/Warning/';
|
73
|
$replacements[0] = '<b><font color="#00ff00">' . gettext("PASSED") . '</font></b>';
|
74
|
$replacements[1] = '<b><font color="#ff0000">' . gettext("FAILED") . '</font></b>';
|
75
|
$replacements[2] = '<font color="#ff0000">' . gettext("Warning") . '</font>';
|
76
|
ksort($patterns);
|
77
|
ksort($replacements);
|
78
|
return preg_replace($patterns, $replacements, $string);
|
79
|
}
|
80
|
|
81
|
// Edits smartd.conf file, adds or removes email for failed disk reporting
|
82
|
function update_email($email)
|
83
|
{
|
84
|
// Did they pass an email?
|
85
|
if(!empty($email))
|
86
|
{
|
87
|
// Put it in the smartd.conf file
|
88
|
shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN -H -m " . escapeshellarg($email) . "/' /usr/local/etc/smartd.conf");
|
89
|
}
|
90
|
// Nope
|
91
|
else
|
92
|
{
|
93
|
// Remove email flags in smartd.conf
|
94
|
shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN/' /usr/local/etc/smartd.conf");
|
95
|
}
|
96
|
}
|
97
|
|
98
|
function smartmonctl($action)
|
99
|
{
|
100
|
global $start_script;
|
101
|
shell_exec($start_script . escapeshellarg($action));
|
102
|
}
|
103
|
|
104
|
// What page, aka. action is being wanted
|
105
|
// If they "get" a page but don't pass all arguments, smartctl will throw an error
|
106
|
$action = (isset($_POST['action']) ? $_POST['action'] : $_GET['action']);
|
107
|
$targetdev = basename($_POST['device']);
|
108
|
if (!file_exists('/dev/' . $targetdev)) {
|
109
|
echo "Device does not exist, bailing.";
|
110
|
return;
|
111
|
}
|
112
|
switch($action) {
|
113
|
// Testing devices
|
114
|
case 'test':
|
115
|
{
|
116
|
$test = $_POST['testType'];
|
117
|
if (!in_array($test, $valid_test_types)) {
|
118
|
echo "Invalid test type, bailing.";
|
119
|
return;
|
120
|
}
|
121
|
$output = add_colors(shell_exec($smartctl . " -t " . escapeshellarg($test) . " /dev/" . escapeshellarg($targetdev)));
|
122
|
echo '<pre>' . $output . '
|
123
|
<form action="diag_smart.php" method="post" name="abort">
|
124
|
<input type="hidden" name="device" value="' . $targetdev . '" />
|
125
|
<input type="hidden" name="action" value="abort" />
|
126
|
<input type="submit" name="submit" value="' . gettext("Abort") . '" />
|
127
|
</form>
|
128
|
</pre>';
|
129
|
break;
|
130
|
}
|
131
|
|
132
|
// Info on devices
|
133
|
case 'info':
|
134
|
{
|
135
|
$type = $_POST['type'];
|
136
|
if (!in_array($type, $valid_info_types)) {
|
137
|
echo "Invalid info type, bailing.";
|
138
|
return;
|
139
|
}
|
140
|
$output = add_colors(shell_exec($smartctl . " -" . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
|
141
|
echo "<pre>$output</pre>";
|
142
|
break;
|
143
|
}
|
144
|
|
145
|
// View logs
|
146
|
case 'logs':
|
147
|
{
|
148
|
$type = $_POST['type'];
|
149
|
if (!in_array($type, $valid_log_types)) {
|
150
|
echo "Invalid log type, bailing.";
|
151
|
return;
|
152
|
}
|
153
|
$output = add_colors(shell_exec($smartctl . " -l " . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
|
154
|
echo "<pre>$output</pre>";
|
155
|
break;
|
156
|
}
|
157
|
|
158
|
// Abort tests
|
159
|
case 'abort':
|
160
|
{
|
161
|
$output = shell_exec($smartctl . " -X /dev/" . escapeshellarg($targetdev));
|
162
|
echo "<pre>$output</pre>";
|
163
|
break;
|
164
|
}
|
165
|
|
166
|
// Config changes, users email in xml config and write changes to smartd.conf
|
167
|
case 'config':
|
168
|
{
|
169
|
if(isset($_POST['submit']))
|
170
|
{
|
171
|
// DOES NOT WORK YET...
|
172
|
if($_POST['testemail'])
|
173
|
{
|
174
|
// FIXME shell_exec($smartd . " -M test -m " . $config['system']['smartmonemail']);
|
175
|
$savemsg = sprintf(gettext("Email sent to %s"), $config['system']['smartmonemail']);
|
176
|
smartmonctl("stop");
|
177
|
smartmonctl("start");
|
178
|
}
|
179
|
else
|
180
|
{
|
181
|
$config['system']['smartmonemail'] = $_POST['smartmonemail'];
|
182
|
write_config();
|
183
|
|
184
|
// Don't know what all this means, but it addes the config changed header when config is saved
|
185
|
$retval = 0;
|
186
|
config_lock();
|
187
|
if(stristr($retval, "error") <> true)
|
188
|
$savemsg = get_std_save_message($retval);
|
189
|
else
|
190
|
$savemsg = $retval;
|
191
|
config_unlock();
|
192
|
|
193
|
if($_POST['email'])
|
194
|
{
|
195
|
// Write the changes to the smartd.conf file
|
196
|
update_email($_POST['smartmonemail']);
|
197
|
}
|
198
|
|
199
|
// Send sig HUP to smartd, rereads the config file
|
200
|
shell_exec("/usr/bin/killall -HUP smartd");
|
201
|
}
|
202
|
}
|
203
|
// Was the config changed? if so , print the message
|
204
|
if ($savemsg) print_info_box($savemsg);
|
205
|
// Get users email from the xml file
|
206
|
$pconfig['smartmonemail'] = $config['system']['smartmonemail'];
|
207
|
|
208
|
?>
|
209
|
<!-- Print the tabs across the top -->
|
210
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabs">
|
211
|
<tr>
|
212
|
<td>
|
213
|
<?php
|
214
|
$tab_array = array();
|
215
|
$tab_array[0] = array(gettext("Information/Tests"), false, $_SERVER['PHP_SELF'] . "?action=default");
|
216
|
$tab_array[1] = array(gettext("Config"), true, $_SERVER['PHP_SELF'] . "?action=config");
|
217
|
display_top_tabs($tab_array);
|
218
|
?>
|
219
|
</td>
|
220
|
</tr>
|
221
|
</table>
|
222
|
<!-- user email address -->
|
223
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="config">
|
224
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="e-mail">
|
225
|
<tbody>
|
226
|
<tr>
|
227
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Config"); ?></td>
|
228
|
</tr>
|
229
|
<tr>
|
230
|
<td width="22%" valign="top" class="vncell"><?=gettext("Email Address"); ?></td>
|
231
|
<td width="78%" class="vtable">
|
232
|
<input type="text" name="smartmonemail" value="<?=htmlspecialchars($pconfig['smartmonemail'])?>"/>
|
233
|
</td>
|
234
|
</tr>
|
235
|
<tr>
|
236
|
<td width="22%" valign="top"> </td>
|
237
|
<td width="78%">
|
238
|
<input type="hidden" name="action" value="config" />
|
239
|
<input type="hidden" name="email" value="true" />
|
240
|
<input type="submit" name="submit" value="<?=gettext("Save"); ?>" class="formbtn" />
|
241
|
</td>
|
242
|
</tr>
|
243
|
</tbody>
|
244
|
</table>
|
245
|
</form>
|
246
|
|
247
|
<!-- test email -->
|
248
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="config">
|
249
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="test e-mail">
|
250
|
<tbody>
|
251
|
<tr>
|
252
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Test email"); ?></td>
|
253
|
</tr>
|
254
|
<tr>
|
255
|
<td width="22%" valign="top" class="vncell"> </td>
|
256
|
<td width="78%" class="vtable">
|
257
|
<?php printf(gettext("Send test email to %s"), $config['system']['smartmonemail']); ?>
|
258
|
</td>
|
259
|
</tr>
|
260
|
<tr>
|
261
|
<td width="22%" valign="top"> </td>
|
262
|
<td width="78%">
|
263
|
<input type="hidden" name="action" value="config" />
|
264
|
<input type="hidden" name="testemail" value="true" />
|
265
|
<input type="submit" name="submit" value="<?=gettext("Send"); ?>" class="formbtn" />
|
266
|
</td>
|
267
|
</tr>
|
268
|
</tbody>
|
269
|
</table>
|
270
|
</form>
|
271
|
|
272
|
<?php
|
273
|
break;
|
274
|
}
|
275
|
|
276
|
// Default page, prints the forms to view info, test, etc...
|
277
|
default:
|
278
|
{
|
279
|
$devs = get_smart_drive_list();
|
280
|
?>
|
281
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="default page">
|
282
|
<tr>
|
283
|
<td>
|
284
|
<?php
|
285
|
$tab_array = array();
|
286
|
$tab_array[0] = array(gettext("Information/Tests"), true, $_SERVER['PHP_SELF']);
|
287
|
//$tab_array[1] = array("Config", false, $_SERVER['PHP_SELF'] . "?action=config");
|
288
|
display_top_tabs($tab_array);
|
289
|
?>
|
290
|
</td>
|
291
|
</tr>
|
292
|
</table>
|
293
|
<!--INFO-->
|
294
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="info">
|
295
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="info">
|
296
|
<tbody>
|
297
|
<tr>
|
298
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Info"); ?></td>
|
299
|
</tr>
|
300
|
<tr>
|
301
|
<td width="22%" valign="top" class="vncell"><?=gettext("Info type"); ?></td>
|
302
|
<td width="78%" class="vtable">
|
303
|
<input type="radio" name="type" value="i" /><?=gettext("Info"); ?><br />
|
304
|
<input type="radio" name="type" value="H" checked="checked" /><?=gettext("Health"); ?><br />
|
305
|
<input type="radio" name="type" value="c" /><?=gettext("SMART Capabilities"); ?><br />
|
306
|
<input type="radio" name="type" value="A" /><?=gettext("Attributes"); ?><br />
|
307
|
<input type="radio" name="type" value="a" /><?=gettext("All"); ?><br />
|
308
|
</td>
|
309
|
</tr>
|
310
|
<tr>
|
311
|
<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
|
312
|
<td width="78%" class="vtable">
|
313
|
<select name="device">
|
314
|
<?php
|
315
|
foreach($devs as $dev)
|
316
|
{
|
317
|
echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
|
318
|
}
|
319
|
?>
|
320
|
</select>
|
321
|
</td>
|
322
|
</tr>
|
323
|
<tr>
|
324
|
<td width="22%" valign="top"> </td>
|
325
|
<td width="78%">
|
326
|
<input type="hidden" name="action" value="info" />
|
327
|
<input type="submit" name="submit" value="<?=gettext("View"); ?>" class="formbtn" />
|
328
|
</td>
|
329
|
</tr>
|
330
|
</tbody>
|
331
|
</table>
|
332
|
</form>
|
333
|
<!--TESTS-->
|
334
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="tests">
|
335
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tests">
|
336
|
<tbody>
|
337
|
<tr>
|
338
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Perform Self-tests"); ?></td>
|
339
|
</tr>
|
340
|
<tr>
|
341
|
<td width="22%" valign="top" class="vncell"><?=gettext("Test type"); ?></td>
|
342
|
<td width="78%" class="vtable">
|
343
|
<input type="radio" name="testType" value="offline" /><?=gettext("Offline"); ?><br />
|
344
|
<input type="radio" name="testType" value="short" checked="checked" /><?=gettext("Short"); ?><br />
|
345
|
<input type="radio" name="testType" value="long" /><?=gettext("Long"); ?><br />
|
346
|
<input type="radio" name="testType" value="conveyance" /><?=gettext("Conveyance (ATA Disks Only)"); ?><br />
|
347
|
</td>
|
348
|
</tr>
|
349
|
<tr>
|
350
|
<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
|
351
|
<td width="78%" class="vtable">
|
352
|
<select name="device">
|
353
|
<?php
|
354
|
foreach($devs as $dev)
|
355
|
{
|
356
|
echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
|
357
|
}
|
358
|
?>
|
359
|
</select>
|
360
|
</td>
|
361
|
</tr>
|
362
|
<tr>
|
363
|
<td width="22%" valign="top"> </td>
|
364
|
<td width="78%">
|
365
|
<input type="hidden" name="action" value="test" />
|
366
|
<input type="submit" name="submit" value="<?=gettext("Test"); ?>" class="formbtn" />
|
367
|
</td>
|
368
|
</tr>
|
369
|
</tbody>
|
370
|
</table>
|
371
|
</form>
|
372
|
<!--LOGS-->
|
373
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="logs">
|
374
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="logs">
|
375
|
<tbody>
|
376
|
<tr>
|
377
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("View Logs"); ?></td>
|
378
|
</tr>
|
379
|
<tr>
|
380
|
<td width="22%" valign="top" class="vncell"><?=gettext("Log type"); ?></td>
|
381
|
<td width="78%" class="vtable">
|
382
|
<input type="radio" name="type" value="error" checked="checked" /><?=gettext("Error"); ?><br />
|
383
|
<input type="radio" name="type" value="selftest" /><?=gettext("Self-test"); ?><br />
|
384
|
</td>
|
385
|
</tr>
|
386
|
<tr>
|
387
|
<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
|
388
|
<td width="78%" class="vtable">
|
389
|
<select name="device">
|
390
|
<?php
|
391
|
foreach($devs as $dev)
|
392
|
{
|
393
|
echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
|
394
|
}
|
395
|
?>
|
396
|
</select>
|
397
|
</td>
|
398
|
</tr>
|
399
|
<tr>
|
400
|
<td width="22%" valign="top"> </td>
|
401
|
<td width="78%">
|
402
|
<input type="hidden" name="action" value="logs" />
|
403
|
<input type="submit" name="submit" value="<?=gettext("View"); ?>" class="formbtn" />
|
404
|
</td>
|
405
|
</tr>
|
406
|
</tbody>
|
407
|
</table>
|
408
|
</form>
|
409
|
<!--ABORT-->
|
410
|
<form action="<?= $_SERVER['PHP_SELF']?>" method="post" name="abort">
|
411
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="abort">
|
412
|
<tbody>
|
413
|
<tr>
|
414
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Abort tests"); ?></td>
|
415
|
</tr>
|
416
|
<tr>
|
417
|
<td width="22%" valign="top" class="vncell"><?=gettext("Device: /dev/"); ?></td>
|
418
|
<td width="78%" class="vtable">
|
419
|
<select name="device">
|
420
|
<?php
|
421
|
foreach($devs as $dev)
|
422
|
{
|
423
|
echo "<option value=\"" . $dev . "\">" . $dev . "</option>";
|
424
|
}
|
425
|
?>
|
426
|
</select>
|
427
|
</td>
|
428
|
</tr>
|
429
|
<tr>
|
430
|
<td width="22%" valign="top"> </td>
|
431
|
<td width="78%">
|
432
|
<input type="hidden" name="action" value="abort" />
|
433
|
<input type="submit" name="submit" value="<?=gettext("Abort"); ?>" class="formbtn" onclick="return confirm('<?=gettext("Do you really want to abort the test?"); ?>')" />
|
434
|
</td>
|
435
|
</tr>
|
436
|
</tbody>
|
437
|
</table>
|
438
|
</form>
|
439
|
|
440
|
<?php
|
441
|
break;
|
442
|
}
|
443
|
}
|
444
|
|
445
|
// print back button on pages
|
446
|
if(isset($_POST['submit']) && $_POST['submit'] != "Save")
|
447
|
{
|
448
|
echo '<br /><a href="' . $_SERVER['PHP_SELF'] . '">' . gettext("Back") . '</a>';
|
449
|
}
|
450
|
?>
|
451
|
<br />
|
452
|
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
|
453
|
|
454
|
<?php include("fend.inc"); ?>
|
455
|
</body>
|
456
|
</html>
|