Project

General

Profile

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