' . gettext("PASSED") . '';
$replacements[1] = '' . gettext("FAILED") . '';
$replacements[2] = '' . gettext("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 " . escapeshellarg($email) . "/' /usr/local/etc/smartd.conf");
} 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 . escapeshellarg($action));
}
$targetdev = basename($_POST['device']);
if (!file_exists('/dev/' . $targetdev)) {
echo gettext("Device does not exist, bailing.");
return;
}
$tab_array = array();
$tab_array[0] = array(htmlspecialchars(gettext("Information & Tests")), ($action != 'config'), $_SERVER['PHP_SELF'] . "?action=default");
$tab_array[1] = array(gettext("Config"), ($action == 'config'), $_SERVER['PHP_SELF'] . "?action=config");
display_top_tabs($tab_array);
switch ($action) {
// Testing devices
case 'test':
{
$test = $_POST['testType'];
if (!in_array($test, $valid_test_types)) {
echo gettext("Invalid test type, bailing.");
return;
}
$output = add_colors(shell_exec($smartctl . " -t " . escapeshellarg($test) . " /dev/" . escapeshellarg($targetdev)));
?>
=gettext('Test Results')?>
=gettext('Information')?>
addInput(new Form_Input(
'smartmonemail',
'Email Address',
'text',
$pconfig['smartmonemail']
));
$form->add($section);
if (!empty($pconfig['smartmonemail'])) {
$form->addGlobal(new Form_Button(
'test',
'Send test email'
))->removeClass('btn-primary')->addClass('btn-default');
}
print($form);
break;
}
// Default page, prints the forms to view info, test, etc...
default: {
// Information
$devs = get_smart_drive_list();
$form = new Form(false);
$btnview = new Form_Button(
'submit',
'View'
);
$section = new Form_Section('Information');
$section->addInput(new Form_Input(
'action',
null,
'hidden',
'info'
));
$group = new Form_Group('Info type');
$group->add(new Form_Checkbox(
'type',
null,
'Info',
false,
'i'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'type',
null,
'Health',
true,
'H'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'type',
null,
'S.M.A.R.T. Capabilities',
false,
'c'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'type',
null,
'Attributes',
false,
'A'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'type',
null,
'All',
false,
'a'
))->displayAsRadio();
$section->add($group);
$section->addInput(new Form_Select(
'device',
'Device: /dev/',
false,
array_combine($devs, $devs)
));
$section->addInput(new Form_StaticText(
'',
$btnview
));
$form->add($section);
print($form);
// Tests
$form = new Form(false);
$btntest = new Form_Button(
'submit',
'Test'
);
$section = new Form_Section('Perform self-tests');
$section->addInput(new Form_Input(
'action',
null,
'hidden',
'test'
));
$group = new Form_Group('Test type');
$group->add(new Form_Checkbox(
'testType',
null,
'Offline',
false,
'offline'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'testType',
null,
'Short',
true,
'short'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'testType',
null,
'Long',
false,
'long'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'testType',
null,
'Conveyance',
false,
'conveyance'
))->displayAsRadio();
$group->setHelp('Select "Conveyance" for ATA disks only');
$section->add($group);
$section->addInput(new Form_Select(
'device',
'Device: /dev/',
false,
array_combine($devs, $devs)
));
$section->addInput(new Form_StaticText(
'',
$btntest
));
$form->add($section);
print($form);
// Logs
$form = new Form(false);
$btnview = new Form_Button(
'submit',
'View'
);
$section = new Form_Section('View Logs');
$section->addInput(new Form_Input(
'action',
null,
'hidden',
'logs'
));
$group = new Form_Group('Log type');
$group->add(new Form_Checkbox(
'type',
null,
'Error',
true,
'error'
))->displayAsRadio();
$group->add(new Form_Checkbox(
'type',
null,
'Self-test',
false,
'selftest'
))->displayAsRadio();
$section->add($group);
$section->addInput(new Form_Select(
'device',
'Device: /dev/',
false,
array_combine($devs, $devs)
));
$section->addInput(new Form_StaticText(
'',
$btnview
));
$form->add($section);
print($form);
// Abort
$btnabort = new Form_Button(
'submit',
'Abort'
);
$btnabort->removeClass('btn-primary')->addClass('btn-danger');
$form = new Form(false);
$section = new Form_Section('Abort');
$section->addInput(new Form_Input(
'action',
null,
'hidden',
'abort'
));
$section->addInput(new Form_Select(
'device',
'Device: /dev/',
false,
array_combine($devs, $devs)
));
$section->addInput(new Form_StaticText(
'',
$btnabort
));
$form->add($section);
print($form);
break;
}
}
include("foot.inc");