summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2016-05-19 17:11:28 -0400
committerjim-p <jimp@pfsense.org>2016-05-19 17:13:10 -0400
commit12563b0cb9496cce317f563a60cd7afcba2afd7a (patch)
tree478b4ad969cb152dd8d1dd427f7a1f7b3a8245b1
parent8229d6d876444b9aa8b991dc1f11a77caf34bbaa (diff)
downloadpfsense-12563b0cb9496cce317f563a60cd7afcba2afd7a.zip
pfsense-12563b0cb9496cce317f563a60cd7afcba2afd7a.tar.gz
Fix up diag_smart e-mail handling, and the backend config code was broken/making false assumption about the config file as well. Fixes #6371
-rw-r--r--src/usr/local/www/diag_smart.php50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/usr/local/www/diag_smart.php b/src/usr/local/www/diag_smart.php
index a1ef312..9b6bfd4 100644
--- a/src/usr/local/www/diag_smart.php
+++ b/src/usr/local/www/diag_smart.php
@@ -100,13 +100,21 @@ function add_colors($string) {
// Edits smartd.conf file, adds or removes email for failed disk reporting
function update_email($email) {
+ /* Bail if an e-mail address is invalid */
+ if (!empty($email) && (filter_var($email, FILTER_VALIDATE_EMAIL) === false)) {
+ return;
+ }
+
+ if (!file_exists("/usr/local/etc/smartd.conf") && file_exists("/usr/local/etc/smartd.conf.sample")) {
+ copy("/usr/local/etc/smartd.conf.sample", "/usr/local/etc/smartd.conf");
+ }
// 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");
+ shell_exec("/usr/bin/sed -i .old 's/^DEVICESCAN.*/DEVICESCAN -H -m " . escapeshellarg(str_replace('`', '', $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");
+ shell_exec("/usr/bin/sed -i .old 's/^DEVICESCAN.*/DEVICESCAN/' /usr/local/etc/smartd.conf");
}
}
@@ -254,27 +262,27 @@ switch ($action) {
smartmonctl("start");
$style = 'warning';
} else if (isset($_POST['save'])) {
- $config['system']['smartmonemail'] = $_POST['smartmonemail'];
- write_config();
-
- // Don't know what all this means, but it adds the config changed header when config is saved
- $retval = 0;
- config_lock();
- if (stristr($retval, "error") != true) {
- $savemsg = get_std_save_message($retval);
- $style = 'success';
+ if (!empty($_POST['smartmonemail']) && (filter_var($_POST['smartmonemail'], FILTER_VALIDATE_EMAIL) === false)) {
+ $savemsg = "The supplied e-mail address is invalid.";
+ $style = 'danger';
} else {
- $savemsg = $retval;
- $style='danger';
+ $config['system']['smartmonemail'] = $_POST['smartmonemail'];
+ write_config();
+ $retval = 0;
+ config_lock();
+ if (stristr($retval, "error") != true) {
+ $savemsg = get_std_save_message($retval);
+ $style = 'success';
+ } else {
+ $savemsg = $retval;
+ $style='danger';
+ }
+ config_unlock();
+ // 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");
}
-
- config_unlock();
-
- // 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
OpenPOWER on IntegriCloud