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