From 21f0f60de583cd02343e5e186d75b5f367de30be Mon Sep 17 00:00:00 2001 From: jim-p Date: Mon, 12 Jul 2010 17:18:04 -0400 Subject: Add Diagnostics > SMART Status for ATA HDDs. (Some functionality disabled, still needs hooked into notifications, and service code for smartd) --- usr/local/www/diag_smart.php | 436 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 436 insertions(+) create mode 100644 usr/local/www/diag_smart.php (limited to 'usr/local/www/diag_smart.php') diff --git a/usr/local/www/diag_smart.php b/usr/local/www/diag_smart.php new file mode 100644 index 0000000..47ec2b1 --- /dev/null +++ b/usr/local/www/diag_smart.php @@ -0,0 +1,436 @@ + + + + + + +PASSED'; + $replacements[1] = 'FAILED'; + $replacements[2] = 'Warning'; + ksort($patterns); + ksort($replacements); + return preg_replace($patterns, $replacements, $string); +} + +// Edits smartd.conf file, adds or removes email for failed disk reporting +function update_email($email) +{ + // Did they pass an email? + if(!empty($email)) + { + // Put it in the smartd.conf file + shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN -H -m " . $email . "/' /usr/local/etc/smartd.conf"); + } + // Nope + else + { + // Remove email flags in smartd.conf + shell_exec("/usr/bin/sed -i old 's/^DEVICESCAN.*/DEVICESCAN/' /usr/local/etc/smartd.conf"); + } +} + +function smartmonctl($action) +{ + global $start_script; + shell_exec($start_script . $action); +} + +// What page, aka. action is being wanted +// If they "get" a page but don't pass all arguments, smartctl will throw an error +$action = (isset($_POST['action']) ? $_POST['action'] : $_GET['action']); +switch($action) +{ + // Testing devices + case 'test': + { + $test = $_POST['testType']; + $output = add_colors(shell_exec($smartctl . " -t " . $test . " /dev/" . $_POST['device'])); + echo '
' . $output . '
+		
+ + + +
+
'; + break; + } + + // Info on devices + case 'info': + { + $type = $_POST['type']; + $output = add_colors(shell_exec($smartctl . " -" . $type . " /dev/" . $_POST['device'])); + echo "
$output
"; + break; + } + + // View logs + case 'logs': + { + $type = $_POST['type']; + $output = add_colors(shell_exec($smartctl . " -l " . $type . " /dev/" . $_POST['device'])); + echo "
$output
"; + break; + } + + // Abort tests + case 'abort': + { + $output = shell_exec($smartctl . " -X /dev/" . $_POST['device']); + echo "
$output
"; + break; + } + + // Config changes, users email in xml config and write changes to smartd.conf + case 'config': + { + if(isset($_POST['submit'])) + { + // DOES NOT WORK YET... + if($_POST['testemail']) + { +// FIXME shell_exec($smartd . " -M test -m " . $config['system']['smartmonemail']); + $savemsg = "Email sent to " . $config['system']['smartmonemail']; + smartmonctl("stop"); + smartmonctl("start"); + } + else + { + $config['system']['smartmonemail'] = $_POST['smartmonemail']; + write_config(); + + // Don't know what all this means, but it addes the config changed header when config is saved + $retval = 0; + config_lock(); + if(stristr($retval, "error") <> true) + $savemsg = get_std_save_message($retval); + else + $savemsg = $retval; + config_unlock(); + + if($_POST['email']) + { + // Write the changes to the smartd.conf file + update_email($_POST['smartmonemail']); + } + + // Send sig HUP to smartd, rereads the config file + shell_exec("/usr/bin/killall -HUP smartd"); + } + } + // Was the config changed? if so , print the message + if ($savemsg) print_info_box($savemsg); + // Get users email from the xml file + $pconfig['smartmonemail'] = $config['system']['smartmonemail']; + + ?> + + + + + +
+ +
+ +
+ + + + + + + + + + + + + + +
Config
Email Adress + +
  + + + +
+
+ + +
+ + + + + + + + + + + + + + +
Test email
  + Send test email to +
  + + + +
+
+ + + + + + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + +
Info
Info type + Info
+ Health
+ SMART Capabilities
+ Attributes
+ All
+
Device: /dev/ + +
  + + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
Perform Self Tests
Test type + Offline
+ Short
+ Long
+ Conveyance (ATA Disks Only)
+
Device: /dev/ + +
  + + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
View Logs
Log type + Error
+ Self Test
+
Device: /dev/ + +
  + + +
+
+ +
+ + + + + + + + + + + + + + +
Abort tests
Device: /dev/ + +
  + + +
+
+ + Back'; +} +?> +
+" . $ulmsg . "

\n"; ?> + + + + \ No newline at end of file -- cgit v1.1