1
|
<?php
|
2
|
/*
|
3
|
* diag_smart.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7
|
* Copyright (c) 2006 Eric Friesen
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
##|+PRIV
|
24
|
##|*IDENT=page-diagnostics-smart
|
25
|
##|*NAME=Diagnostics: S.M.A.R.T. Status
|
26
|
##|*DESCR=Allow access to the 'Diagnostics: S.M.A.R.T. Status' page.
|
27
|
##|*MATCH=diag_smart.php*
|
28
|
##|-PRIV
|
29
|
|
30
|
require_once("guiconfig.inc");
|
31
|
|
32
|
// What page, aka. action is being wanted
|
33
|
// If they "get" a page but don't pass all arguments, smartctl will throw an error
|
34
|
$action = (isset($_POST['action']) ? $_POST['action'] : $_GET['action']);
|
35
|
|
36
|
$pgtitle = array(gettext("Diagnostics"), gettext("S.M.A.R.T. Status"));
|
37
|
$pglinks = array("", "@self", "@self");
|
38
|
|
39
|
if ($action != 'config') {
|
40
|
$pgtitle[] = htmlspecialchars(gettext('Information & Tests'));
|
41
|
} else {
|
42
|
$pgtitle[] = gettext('Config');
|
43
|
}
|
44
|
$smartctl = "/usr/local/sbin/smartctl";
|
45
|
|
46
|
$valid_test_types = array("offline", "short", "long", "conveyance");
|
47
|
$valid_info_types = array("i", "H", "c", "A", "a");
|
48
|
$valid_log_types = array("error", "selftest");
|
49
|
|
50
|
include("head.inc");
|
51
|
|
52
|
// Highlights the words "PASSED", "FAILED", and "WARNING".
|
53
|
function add_colors($string) {
|
54
|
// To add words keep arrays matched by numbers
|
55
|
$patterns[0] = '/PASSED/';
|
56
|
$patterns[1] = '/FAILED/';
|
57
|
$patterns[2] = '/Warning/';
|
58
|
$replacements[0] = '<span class="text-success">' . gettext("PASSED") . '</span>';
|
59
|
$replacements[1] = '<span class="text-alert">' . gettext("FAILED") . '</span>';
|
60
|
$replacements[2] = '<span class="text-warning">' . gettext("Warning") . '</span>';
|
61
|
ksort($patterns);
|
62
|
ksort($replacements);
|
63
|
return preg_replace($patterns, $replacements, $string);
|
64
|
}
|
65
|
|
66
|
$targetdev = basename($_POST['device']);
|
67
|
|
68
|
if (!file_exists('/dev/' . $targetdev)) {
|
69
|
echo gettext("Device does not exist, bailing.");
|
70
|
return;
|
71
|
}
|
72
|
|
73
|
$specplatform = system_identify_specific_platform();
|
74
|
if (($specplatform['name'] == "Hyper-V") || ($specplatform['name'] == "uFW")) {
|
75
|
echo sprintf(gettext("S.M.A.R.T. is not supported on this system (%s)."), $specplatform['descr']);
|
76
|
include("foot.inc");
|
77
|
exit;
|
78
|
}
|
79
|
|
80
|
switch ($action) {
|
81
|
// Testing devices
|
82
|
case 'test':
|
83
|
{
|
84
|
$test = $_POST['testType'];
|
85
|
if (!in_array($test, $valid_test_types)) {
|
86
|
echo gettext("Invalid test type, bailing.");
|
87
|
return;
|
88
|
}
|
89
|
|
90
|
$output = add_colors(shell_exec($smartctl . " -t " . escapeshellarg($test) . " /dev/" . escapeshellarg($targetdev)));
|
91
|
?>
|
92
|
<div class="panel panel-default">
|
93
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Test Results')?></h2></div>
|
94
|
<div class="panel-body">
|
95
|
<pre><?=$output?></pre>
|
96
|
</div>
|
97
|
</div>
|
98
|
|
99
|
<form action="diag_smart.php" method="post" name="abort">
|
100
|
<input type="hidden" name="device" value="<?=$targetdev?>" />
|
101
|
<input type="hidden" name="action" value="abort" />
|
102
|
<nav class="action-buttons">
|
103
|
<button type="submit" name="submit" class="btn btn-danger" value="<?=gettext("Abort")?>">
|
104
|
<i class="fa fa-times icon-embed-btn"></i>
|
105
|
<?=gettext("Abort Test")?>
|
106
|
</button>
|
107
|
<a href="<?=$_SERVER['PHP_SELF']?>" class="btn btn-info">
|
108
|
<i class="fa fa-undo icon-embed-btn"></i>
|
109
|
<?=gettext("Back")?>
|
110
|
</a>
|
111
|
</nav>
|
112
|
</form>
|
113
|
|
114
|
<?php
|
115
|
break;
|
116
|
}
|
117
|
|
118
|
// Info on devices
|
119
|
case 'info':
|
120
|
{
|
121
|
$type = $_POST['type'];
|
122
|
|
123
|
if (!in_array($type, $valid_info_types)) {
|
124
|
print_info_box(gettext("Invalid info type, bailing."), 'danger');
|
125
|
return;
|
126
|
}
|
127
|
|
128
|
$output = add_colors(shell_exec($smartctl . " -" . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
|
129
|
?>
|
130
|
<div class="panel panel-default">
|
131
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Information')?></h2></div>
|
132
|
<div class="panel-body">
|
133
|
<pre><?=$output?></pre>
|
134
|
</div>
|
135
|
</div>
|
136
|
|
137
|
<nav class="action-buttons">
|
138
|
<a href="<?=$_SERVER['PHP_SELF']?>" class="btn btn-info">
|
139
|
<i class="fa fa-undo icon-embed-btn"></i>
|
140
|
<?=gettext("Back")?>
|
141
|
</a>
|
142
|
</nav>
|
143
|
<?php
|
144
|
break;
|
145
|
}
|
146
|
|
147
|
// View logs
|
148
|
case 'logs':
|
149
|
{
|
150
|
$type = $_POST['type'];
|
151
|
if (!in_array($type, $valid_log_types)) {
|
152
|
print_info_box(gettext("Invalid log type, bailing."), 'danger');
|
153
|
return;
|
154
|
}
|
155
|
|
156
|
$output = add_colors(shell_exec($smartctl . " -l " . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
|
157
|
?>
|
158
|
<div class="panel panel-default">
|
159
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Logs')?></h2></div>
|
160
|
<div class="panel-body">
|
161
|
<pre><?=$output?></pre>
|
162
|
</div>
|
163
|
</div>
|
164
|
|
165
|
<nav class="action-buttons">
|
166
|
<a href="<?=$_SERVER['PHP_SELF']?>" class="btn btn-info">
|
167
|
<i class="fa fa-undo icon-embed-btn"></i>
|
168
|
<?=gettext("Back")?>
|
169
|
</a>
|
170
|
</nav>
|
171
|
<?php
|
172
|
break;
|
173
|
}
|
174
|
|
175
|
// Abort tests
|
176
|
case 'abort':
|
177
|
{
|
178
|
$output = shell_exec($smartctl . " -X /dev/" . escapeshellarg($targetdev));
|
179
|
?>
|
180
|
<div class="panel panel-default">
|
181
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Abort')?></h2></div>
|
182
|
<div class="panel-body">
|
183
|
<pre><?=$output?></pre>
|
184
|
</div>
|
185
|
</div>
|
186
|
<?php
|
187
|
break;
|
188
|
}
|
189
|
|
190
|
// Default page, prints the forms to view info, test, etc...
|
191
|
default: {
|
192
|
// Information
|
193
|
$devs = get_smart_drive_list();
|
194
|
|
195
|
$form = new Form(false);
|
196
|
|
197
|
$btnview = new Form_Button(
|
198
|
'submit',
|
199
|
'View',
|
200
|
null,
|
201
|
'fa-file-text-o'
|
202
|
);
|
203
|
$btnview->addClass('btn-primary');
|
204
|
$btnview->setAttribute('id');
|
205
|
|
206
|
$section = new Form_Section('Information');
|
207
|
|
208
|
$section->addInput(new Form_Input(
|
209
|
'action',
|
210
|
null,
|
211
|
'hidden',
|
212
|
'info'
|
213
|
))->setAttribute('id');
|
214
|
|
215
|
$group = new Form_Group('Info type');
|
216
|
|
217
|
$group->add(new Form_Checkbox(
|
218
|
'type',
|
219
|
null,
|
220
|
'Info',
|
221
|
false,
|
222
|
'i'
|
223
|
))->displayAsRadio();
|
224
|
|
225
|
$group->add(new Form_Checkbox(
|
226
|
'type',
|
227
|
null,
|
228
|
'Health',
|
229
|
true,
|
230
|
'H'
|
231
|
))->displayAsRadio();
|
232
|
|
233
|
$group->add(new Form_Checkbox(
|
234
|
'type',
|
235
|
null,
|
236
|
'S.M.A.R.T. Capabilities',
|
237
|
false,
|
238
|
'c'
|
239
|
))->displayAsRadio();
|
240
|
|
241
|
$group->add(new Form_Checkbox(
|
242
|
'type',
|
243
|
null,
|
244
|
'Attributes',
|
245
|
false,
|
246
|
'A'
|
247
|
))->displayAsRadio();
|
248
|
|
249
|
$group->add(new Form_Checkbox(
|
250
|
'type',
|
251
|
null,
|
252
|
'All',
|
253
|
false,
|
254
|
'a'
|
255
|
))->displayAsRadio();
|
256
|
|
257
|
$section->add($group);
|
258
|
|
259
|
$section->addInput(new Form_Select(
|
260
|
'device',
|
261
|
'Device: /dev/',
|
262
|
false,
|
263
|
array_combine($devs, $devs)
|
264
|
))->setAttribute('id');
|
265
|
|
266
|
$section->addInput(new Form_StaticText(
|
267
|
'',
|
268
|
$btnview
|
269
|
));
|
270
|
|
271
|
$form->add($section);
|
272
|
print($form);
|
273
|
|
274
|
// Tests
|
275
|
$form = new Form(false);
|
276
|
|
277
|
$btntest = new Form_Button(
|
278
|
'submit',
|
279
|
'Test',
|
280
|
null,
|
281
|
'fa-wrench'
|
282
|
);
|
283
|
$btntest->addClass('btn-primary');
|
284
|
$btntest->setAttribute('id');
|
285
|
|
286
|
$section = new Form_Section('Perform self-tests');
|
287
|
|
288
|
$section->addInput(new Form_Input(
|
289
|
'action',
|
290
|
null,
|
291
|
'hidden',
|
292
|
'test'
|
293
|
))->setAttribute('id');
|
294
|
|
295
|
$group = new Form_Group('Test type');
|
296
|
|
297
|
$group->add(new Form_Checkbox(
|
298
|
'testType',
|
299
|
null,
|
300
|
'Offline',
|
301
|
false,
|
302
|
'offline'
|
303
|
))->displayAsRadio();
|
304
|
|
305
|
$group->add(new Form_Checkbox(
|
306
|
'testType',
|
307
|
null,
|
308
|
'Short',
|
309
|
true,
|
310
|
'short'
|
311
|
))->displayAsRadio();
|
312
|
|
313
|
$group->add(new Form_Checkbox(
|
314
|
'testType',
|
315
|
null,
|
316
|
'Long',
|
317
|
false,
|
318
|
'long'
|
319
|
))->displayAsRadio();
|
320
|
|
321
|
$group->add(new Form_Checkbox(
|
322
|
'testType',
|
323
|
null,
|
324
|
'Conveyance',
|
325
|
false,
|
326
|
'conveyance'
|
327
|
))->displayAsRadio();
|
328
|
|
329
|
$group->setHelp('Select "Conveyance" for ATA disks only.');
|
330
|
$section->add($group);
|
331
|
|
332
|
$section->addInput(new Form_Select(
|
333
|
'device',
|
334
|
'Device: /dev/',
|
335
|
false,
|
336
|
array_combine($devs, $devs)
|
337
|
))->setAttribute('id');
|
338
|
|
339
|
$section->addInput(new Form_StaticText(
|
340
|
'',
|
341
|
$btntest
|
342
|
));
|
343
|
|
344
|
$form->add($section);
|
345
|
print($form);
|
346
|
|
347
|
// Logs
|
348
|
$form = new Form(false);
|
349
|
|
350
|
$btnview = new Form_Button(
|
351
|
'submit',
|
352
|
'View',
|
353
|
null,
|
354
|
'fa-file-text-o'
|
355
|
);
|
356
|
$btnview->addClass('btn-primary');
|
357
|
$btnview->setAttribute('id');
|
358
|
|
359
|
$section = new Form_Section('View Logs');
|
360
|
|
361
|
$section->addInput(new Form_Input(
|
362
|
'action',
|
363
|
null,
|
364
|
'hidden',
|
365
|
'logs'
|
366
|
))->setAttribute('id');
|
367
|
|
368
|
$group = new Form_Group('Log type');
|
369
|
|
370
|
$group->add(new Form_Checkbox(
|
371
|
'type',
|
372
|
null,
|
373
|
'Error',
|
374
|
true,
|
375
|
'error'
|
376
|
))->displayAsRadio();
|
377
|
|
378
|
$group->add(new Form_Checkbox(
|
379
|
'type',
|
380
|
null,
|
381
|
'Self-test',
|
382
|
false,
|
383
|
'selftest'
|
384
|
))->displayAsRadio();
|
385
|
|
386
|
$section->add($group);
|
387
|
|
388
|
$section->addInput(new Form_Select(
|
389
|
'device',
|
390
|
'Device: /dev/',
|
391
|
false,
|
392
|
array_combine($devs, $devs)
|
393
|
))->setAttribute('id');
|
394
|
|
395
|
$section->addInput(new Form_StaticText(
|
396
|
'',
|
397
|
$btnview
|
398
|
));
|
399
|
|
400
|
$form->add($section);
|
401
|
print($form);
|
402
|
|
403
|
// Abort
|
404
|
$btnabort = new Form_Button(
|
405
|
'submit',
|
406
|
'Abort',
|
407
|
null,
|
408
|
'fa-times'
|
409
|
);
|
410
|
|
411
|
$btnabort->addClass('btn-danger')->setAttribute('id');
|
412
|
|
413
|
$form = new Form(false);
|
414
|
|
415
|
$section = new Form_Section('Abort');
|
416
|
|
417
|
$section->addInput(new Form_Input(
|
418
|
'action',
|
419
|
null,
|
420
|
'hidden',
|
421
|
'abort'
|
422
|
))->setAttribute('id');
|
423
|
|
424
|
$section->addInput(new Form_Select(
|
425
|
'device',
|
426
|
'Device: /dev/',
|
427
|
false,
|
428
|
array_combine($devs, $devs)
|
429
|
))->setAttribute('id');
|
430
|
|
431
|
$section->addInput(new Form_StaticText(
|
432
|
'',
|
433
|
$btnabort
|
434
|
));
|
435
|
|
436
|
$form->add($section);
|
437
|
print($form);
|
438
|
|
439
|
break;
|
440
|
}
|
441
|
}
|
442
|
|
443
|
include("foot.inc");
|