Project

General

Profile

Download (9.29 KB) Statistics
| Branch: | Tag: | Revision:
1 21f0f60d jim-p
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_smart.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2006 Eric Friesen
8
 * All rights reserved.
9 fd9ebcd5 Stephen Beaver
 *
10 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 fd9ebcd5 Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
22 21f0f60d jim-p
23 a57d9fa2 jim-p
##|+PRIV
24
##|*IDENT=page-diagnostics-smart
25 9718847b k-paulius
##|*NAME=Diagnostics: S.M.A.R.T. Status
26
##|*DESCR=Allow access to the 'Diagnostics: S.M.A.R.T. Status' page.
27 a57d9fa2 jim-p
##|*MATCH=diag_smart.php*
28
##|-PRIV
29
30 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
31 21f0f60d jim-p
32 d88908cf k-paulius
// 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 7f4268b6 Steve Beaver
$action = $_POST['action'];
35 d88908cf k-paulius
36 9718847b k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("S.M.A.R.T. Status"));
37 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
38 d88908cf k-paulius
39
if ($action != 'config') {
40 d49d6033 k-paulius
	$pgtitle[] = htmlspecialchars(gettext('Information & Tests'));
41 d88908cf k-paulius
} else {
42
	$pgtitle[] = gettext('Config');
43
}
44 7f4268b6 Steve Beaver
45 21f0f60d jim-p
$smartctl = "/usr/local/sbin/smartctl";
46
47 24879bc6 jim-p
$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 21f0f60d jim-p
include("head.inc");
52
53 155d9450 sbeaver
// Highlights the words "PASSED", "FAILED", and "WARNING".
54 947141fd Phil Davis
function add_colors($string) {
55 155d9450 sbeaver
	// To add words keep arrays matched by numbers
56 21f0f60d jim-p
	$patterns[0] = '/PASSED/';
57
	$patterns[1] = '/FAILED/';
58
	$patterns[2] = '/Warning/';
59 2eb51b46 Colin Fleming
	$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 21f0f60d jim-p
	ksort($patterns);
63
	ksort($replacements);
64
	return preg_replace($patterns, $replacements, $string);
65
}
66
67 24879bc6 jim-p
$targetdev = basename($_POST['device']);
68 155d9450 sbeaver
69 24879bc6 jim-p
if (!file_exists('/dev/' . $targetdev)) {
70 ff30e319 bruno
	echo gettext("Device does not exist, bailing.");
71 24879bc6 jim-p
	return;
72
}
73 155d9450 sbeaver
74 b4594d39 Chris Buechler
$specplatform = system_identify_specific_platform();
75 66e5d4f2 jim-p
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 b4594d39 Chris Buechler
	include("foot.inc");
78
	exit;
79
}
80
81 288a2a0f Phil Davis
switch ($action) {
82 21f0f60d jim-p
	// Testing devices
83
	case 'test':
84
	{
85
		$test = $_POST['testType'];
86 24879bc6 jim-p
		if (!in_array($test, $valid_test_types)) {
87 ff30e319 bruno
			echo gettext("Invalid test type, bailing.");
88 24879bc6 jim-p
			return;
89
		}
90 155d9450 sbeaver
91 24879bc6 jim-p
		$output = add_colors(shell_exec($smartctl . " -t " . escapeshellarg($test) . " /dev/" . escapeshellarg($targetdev)));
92 155d9450 sbeaver
?>
93
		<div class="panel  panel-default">
94 3d7a8696 k-paulius
			<div class="panel-heading"><h2 class="panel-title"><?=gettext('Test Results')?></h2></div>
95 155d9450 sbeaver
			<div class="panel-body">
96
				<pre><?=$output?></pre>
97
			</div>
98
		</div>
99
100 1d2add88 jim-p
		<form action="diag_smart.php" method="post" name="abort">
101 155d9450 sbeaver
			<input type="hidden" name="device" value="<?=$targetdev?>" />
102
			<input type="hidden" name="action" value="abort" />
103
			<nav class="action-buttons">
104 37676f4e jim-p
				<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 155d9450 sbeaver
			</nav>
113 21f0f60d jim-p
		</form>
114 155d9450 sbeaver
115
<?php
116 21f0f60d jim-p
		break;
117
	}
118
119
	// Info on devices
120
	case 'info':
121
	{
122
		$type = $_POST['type'];
123 155d9450 sbeaver
124 24879bc6 jim-p
		if (!in_array($type, $valid_info_types)) {
125 155d9450 sbeaver
			print_info_box(gettext("Invalid info type, bailing."), 'danger');
126 24879bc6 jim-p
			return;
127
		}
128 155d9450 sbeaver
129 24879bc6 jim-p
		$output = add_colors(shell_exec($smartctl . " -" . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
130 155d9450 sbeaver
?>
131
		<div class="panel  panel-default">
132 f17594c7 Sjon Hortensius
			<div class="panel-heading"><h2 class="panel-title"><?=gettext('Information')?></h2></div>
133 155d9450 sbeaver
			<div class="panel-body">
134
				<pre><?=$output?></pre>
135
			</div>
136
		</div>
137
138
		<nav class="action-buttons">
139 37676f4e jim-p
			<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 155d9450 sbeaver
		</nav>
144
<?php
145 21f0f60d jim-p
		break;
146
	}
147
148
	// View logs
149
	case 'logs':
150
	{
151
		$type = $_POST['type'];
152 24879bc6 jim-p
		if (!in_array($type, $valid_log_types)) {
153 155d9450 sbeaver
			print_info_box(gettext("Invalid log type, bailing."), 'danger');
154 24879bc6 jim-p
			return;
155
		}
156 155d9450 sbeaver
157 24879bc6 jim-p
		$output = add_colors(shell_exec($smartctl . " -l " . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev)));
158 155d9450 sbeaver
?>
159
		<div class="panel  panel-default">
160 f17594c7 Sjon Hortensius
			<div class="panel-heading"><h2 class="panel-title"><?=gettext('Logs')?></h2></div>
161 155d9450 sbeaver
			<div class="panel-body">
162
				<pre><?=$output?></pre>
163
			</div>
164
		</div>
165
166
		<nav class="action-buttons">
167 37676f4e jim-p
			<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 155d9450 sbeaver
		</nav>
172
<?php
173 21f0f60d jim-p
		break;
174
	}
175
176
	// Abort tests
177
	case 'abort':
178
	{
179 24879bc6 jim-p
		$output = shell_exec($smartctl . " -X /dev/" . escapeshellarg($targetdev));
180 155d9450 sbeaver
?>
181
		<div class="panel  panel-default">
182 f17594c7 Sjon Hortensius
			<div class="panel-heading"><h2 class="panel-title"><?=gettext('Abort')?></h2></div>
183 155d9450 sbeaver
			<div class="panel-body">
184
				<pre><?=$output?></pre>
185
			</div>
186
		</div>
187
<?php
188 21f0f60d jim-p
		break;
189
	}
190
191
	// Default page, prints the forms to view info, test, etc...
192 155d9450 sbeaver
	default: {
193 0da0d43e Phil Davis
// Information
194 ea20169a jim-p
		$devs = get_smart_drive_list();
195 21f0f60d jim-p
196 d254b99e Stephen Beaver
		$form = new Form(false);
197
198
		$btnview = new Form_Button(
199 155d9450 sbeaver
			'submit',
200 faab522f Renato Botelho
			'View',
201 37676f4e jim-p
			null,
202 84d961c3 jim-p
			'fa-file-text-o'
203 d254b99e Stephen Beaver
		);
204 37676f4e jim-p
		$btnview->addClass('btn-primary');
205 4d3a1005 NOYB
		$btnview->setAttribute('id');
206
207 155d9450 sbeaver
		$section = new Form_Section('Information');
208
209
		$section->addInput(new Form_Input(
210
			'action',
211
			null,
212
			'hidden',
213
			'info'
214 4d3a1005 NOYB
		))->setAttribute('id');
215 155d9450 sbeaver
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 9718847b k-paulius
			'S.M.A.R.T. Capabilities',
238 155d9450 sbeaver
			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 4d3a1005 NOYB
		))->setAttribute('id');
266 155d9450 sbeaver
267 d254b99e Stephen Beaver
		$section->addInput(new Form_StaticText(
268
			'',
269
			$btnview
270
		));
271
272 155d9450 sbeaver
		$form->add($section);
273
		print($form);
274
275
// Tests
276 d254b99e Stephen Beaver
		$form = new Form(false);
277
278
		$btntest = new Form_Button(
279 155d9450 sbeaver
			'submit',
280 faab522f Renato Botelho
			'Test',
281 37676f4e jim-p
			null,
282
			'fa-wrench'
283 d254b99e Stephen Beaver
		);
284 37676f4e jim-p
		$btntest->addClass('btn-primary');
285 4d3a1005 NOYB
		$btntest->setAttribute('id');
286
287 155d9450 sbeaver
		$section = new Form_Section('Perform self-tests');
288
289
		$section->addInput(new Form_Input(
290
			'action',
291
			null,
292
			'hidden',
293
			'test'
294 4d3a1005 NOYB
		))->setAttribute('id');
295 155d9450 sbeaver
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 3728bbe5 NOYB
		$group->setHelp('Select "Conveyance" for ATA disks only.');
331 155d9450 sbeaver
		$section->add($group);
332
333
		$section->addInput(new Form_Select(
334
			'device',
335
			'Device: /dev/',
336
			false,
337
			array_combine($devs, $devs)
338 4d3a1005 NOYB
		))->setAttribute('id');
339 155d9450 sbeaver
340 d254b99e Stephen Beaver
		$section->addInput(new Form_StaticText(
341
			'',
342
			$btntest
343
		));
344
345 155d9450 sbeaver
		$form->add($section);
346
		print($form);
347
348
// Logs
349 d254b99e Stephen Beaver
		$form = new Form(false);
350
351
		$btnview =  new Form_Button(
352 155d9450 sbeaver
			'submit',
353 faab522f Renato Botelho
			'View',
354 37676f4e jim-p
			null,
355 84d961c3 jim-p
			'fa-file-text-o'
356 d254b99e Stephen Beaver
		);
357 37676f4e jim-p
		$btnview->addClass('btn-primary');
358 4d3a1005 NOYB
		$btnview->setAttribute('id');
359
360 5f88f964 k-paulius
		$section = new Form_Section('View Logs');
361 155d9450 sbeaver
362
		$section->addInput(new Form_Input(
363
			'action',
364
			null,
365
			'hidden',
366
			'logs'
367 4d3a1005 NOYB
		))->setAttribute('id');
368 155d9450 sbeaver
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 655c577b Stephen Beaver
			'type',
381 155d9450 sbeaver
			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 4d3a1005 NOYB
		))->setAttribute('id');
395 155d9450 sbeaver
396 d254b99e Stephen Beaver
		$section->addInput(new Form_StaticText(
397
			'',
398
			$btnview
399
		));
400
401 155d9450 sbeaver
		$form->add($section);
402
		print($form);
403
404
// Abort
405
		$btnabort = new Form_Button(
406
			'submit',
407 faab522f Renato Botelho
			'Abort',
408 37676f4e jim-p
			null,
409
			'fa-times'
410 155d9450 sbeaver
		);
411
412 37676f4e jim-p
		$btnabort->addClass('btn-danger')->setAttribute('id');
413 155d9450 sbeaver
414 d254b99e Stephen Beaver
		$form = new Form(false);
415 155d9450 sbeaver
416
		$section = new Form_Section('Abort');
417
418
		$section->addInput(new Form_Input(
419
			'action',
420
			null,
421
			'hidden',
422
			'abort'
423 4d3a1005 NOYB
		))->setAttribute('id');
424 155d9450 sbeaver
425
		$section->addInput(new Form_Select(
426
			'device',
427
			'Device: /dev/',
428
			false,
429
			array_combine($devs, $devs)
430 4d3a1005 NOYB
		))->setAttribute('id');
431 155d9450 sbeaver
432 d254b99e Stephen Beaver
		$section->addInput(new Form_StaticText(
433
			'',
434
			$btnabort
435
		));
436
437 155d9450 sbeaver
		$form->add($section);
438
		print($form);
439
440 21f0f60d jim-p
		break;
441
	}
442
}
443
444 c10cb196 Stephen Beaver
include("foot.inc");