diff --git a/sysutils/smart/Makefile b/sysutils/smart/Makefile index b1a0dec69..216677250 100644 --- a/sysutils/smart/Makefile +++ b/sysutils/smart/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= smart -PLUGIN_VERSION= 1.5 +PLUGIN_VERSION= 2.0.d PLUGIN_COMMENT= SMART tools PLUGIN_DEPENDS= smartmontools PLUGIN_MAINTAINER= franco@opnsense.org diff --git a/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/Api/ServiceController.php b/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/Api/ServiceController.php new file mode 100644 index 000000000..451a1f5b3 --- /dev/null +++ b/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/Api/ServiceController.php @@ -0,0 +1,143 @@ +configdRun("smart list"))); + + return $devices; + } + + public function listAction () + { + if ($this->request->isPost()) + return array("devices" => $this->getDevices ()); + + return array("message" => "Unable to run list action"); + } + + public function infoAction () + { + if ($this->request->isPost()) { + $device = $this->request->getPost ('device'); + $type = $this->request->getPost ('type'); + + if (!in_array ($device, $this->getDevices ())) + return array("message" => "Invalid device name"); + + $valid_info_types = array("i", "H", "c", "A", "a"); + + if (!in_array ($type, $valid_info_types)) + return array("message" => "Invalid info type"); + + $backend = new Backend(); + + $output = $backend->configdpRun("smart", array("info", $type, "/dev/".$device)); + + return array("output" => $output); + } + + return array("message" => "Unable to run info action"); + } + + public function logsAction () + { + if ($this->request->isPost()) { + $device = $this->request->getPost ('device'); + $type = $this->request->getPost ('type'); + + if (!in_array ($device, $this->getDevices ())) + return array("message" => "Invalid device name"); + + $valid_log_types = array("error", "selftest"); + + if (!in_array ($type, $valid_log_types)) + return array("message" => "Invalid log type"); + + $backend = new Backend(); + + $output = $backend->configdpRun("smart", array("log", $type, "/dev/".$device)); + + return array("output" => $output); + } + + return array("message" => "Unable to run logs action"); + } + + public function testAction () + { + if ($this->request->isPost()) { + $device = $this->request->getPost ('device'); + $type = $this->request->getPost ('type'); + + if (!in_array ($device, $this->getDevices ())) + return array("message" => "Invalid device name"); + + $valid_test_types = array("offline", "short", "long", "conveyance"); + + if (!in_array ($type, $valid_test_types)) + return array("message" => "Invalid test type"); + + $backend = new Backend(); + + $output = $backend->configdpRun("smart", array("test", $type, "/dev/".$device)); + + return array("output" => $output); + } + + return array("message" => "Unable to run test action"); + } + + public function abortAction () + { + if ($this->request->isPost()) { + $device = $this->request->getPost ('device'); + + if (!in_array ($device, $this->getDevices ())) + return array("message" => "Invalid device name"); + + $backend = new Backend(); + + $output = $backend->configdpRun("smart", array("abort", "/dev/".$device)); + + return array("output" => $output); + } + + return array("message" => "Unable to run abort action"); + } +} diff --git a/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/IndexController.php b/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/IndexController.php new file mode 100644 index 000000000..b446f5475 --- /dev/null +++ b/sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/IndexController.php @@ -0,0 +1,38 @@ +view->pick('OPNsense/Smart/index'); + } +} diff --git a/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/ACL/ACL.xml b/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/ACL/ACL.xml index b6f6ad617..d728c5897 100644 --- a/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/ACL/ACL.xml +++ b/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/ACL/ACL.xml @@ -2,7 +2,8 @@ Services: SMART - diag_smart.php* + ui/smart/* + api/smart/* diff --git a/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/Menu/Menu.xml b/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/Menu/Menu.xml index 11e5ac7ec..a94063e55 100644 --- a/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/Menu/Menu.xml +++ b/sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/Menu/Menu.xml @@ -1,5 +1,5 @@ - + diff --git a/sysutils/smart/src/opnsense/mvc/app/views/OPNsense/Smart/index.volt b/sysutils/smart/src/opnsense/mvc/app/views/OPNsense/Smart/index.volt new file mode 100644 index 000000000..96d2d7441 --- /dev/null +++ b/sysutils/smart/src/opnsense/mvc/app/views/OPNsense/Smart/index.volt @@ -0,0 +1,260 @@ +{# + +Copyright (C) 2018 Smart-Soft +Copyright (C) 2014 Deciso B.V. +Copyright (C) 2010 Jim Pingle +Copyright (C) 2006 Eric Friesen +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +#} + + + + + diff --git a/sysutils/smart/src/opnsense/scripts/OPNsense/smart/detailed_list.sh b/sysutils/smart/src/opnsense/scripts/OPNsense/smart/detailed_list.sh new file mode 100755 index 000000000..cfcb64891 --- /dev/null +++ b/sysutils/smart/src/opnsense/scripts/OPNsense/smart/detailed_list.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# Copyright (C) 2018 Smart-Soft +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +result="" + +for dev in `ls /dev | grep '^\(ad\|da\|ada\)[0-9]\{1,2\}$'`; do + ident=`/usr/sbin/diskinfo -v $dev | grep ident | awk '{print $1}'`; + state=`/usr/local/sbin/smartctl -H $dev | awk -F: ' +/^SMART overall-health self-assessment test result/ {print $2;exit} +/^SMART Health Status/ {print $2;exit}'`; + + if [ -n "$result" ]; then + result="$result,"; + fi + + result="$result{\"device\":\"$dev\",\"ident\":\"$ident\",\"state\":\"$state\"}"; +done + +echo "[$result]" diff --git a/sysutils/smart/src/opnsense/service/conf/actions.d/actions_smart.conf b/sysutils/smart/src/opnsense/service/conf/actions.d/actions_smart.conf new file mode 100644 index 000000000..004b8f163 --- /dev/null +++ b/sysutils/smart/src/opnsense/service/conf/actions.d/actions_smart.conf @@ -0,0 +1,97 @@ +[list] +command:/bin/ls /dev | grep '^\(ad\|da\|ada\)[0-9]\{1,2\}$' +parameters: +type:script_output +message:list installed devices +description:Get all IDE and SCSI devices currently installed + +[detailed.list] +command:/usr/local/opnsense/scripts/OPNsense/smart/detailed_list.sh +parameters: +type:script_output +message:list installed devices +description:Get all IDE and SCSI devices currently installed + +[info.i] +command:/usr/local/sbin/smartctl -i +parameters:%s; exit 0 +type:script_output +message:Get identity info for device %s +description:Get identity info for devices + +[info.H] +command:/usr/local/sbin/smartctl -H +parameters:%s; exit 0 +type:script_output +message:Get SMART health status info for device %s +description:Get SMART health status info for devices + +[info.c] +command:/usr/local/sbin/smartctl -c +parameters:%s; exit 0 +type:script_output +message:Get capabilities for device %s +description:Get capabilities for devices + +[info.A] +command:/usr/local/sbin/smartctl -A +parameters:%s; exit 0 +type:script_output +message:Get vendor-specific attributes for device %s +description:Get vendor-specific attributes for devices + +[info.a] +command:/usr/local/sbin/smartctl -a +parameters:%s; exit 0 +type:script_output +message:Get all SMART info for device %s +description:Get info for devices + +[log.error] +command:/usr/local/sbin/smartctl -l error +parameters:%s; exit 0 +type:script_output +message:Get error log for device %s +description:Get error logs for devices + +[log.selftest] +command:/usr/local/sbin/smartctl -l selftest +parameters:%s; exit 0 +type:script_output +message:Get selftest log for device %s +description:Get selftest logs for devices + +[test.offline] +command:/usr/local/sbin/smartctl -t offline +parameters:%s; exit 0 +type:script_output +message:Testing device %s (offline) +description:Testing devices + +[test.short] +command:/usr/local/sbin/smartctl -t short +parameters:%s; exit 0 +type:script_output +message:Testing device %s (short) +description:Testing devices + +[test.long] +command:/usr/local/sbin/smartctl -t long +parameters:%s; exit 0 +type:script_output +message:Testing device %s (long) +description:Testing devices + +[test.conveyance] +command:/usr/local/sbin/smartctl -t conveyance +parameters:%s; exit 0 +type:script_output +message:Testing device %s (conveyance) +description:Testing devices + +[abort] +command:/usr/local/sbin/smartctl -X +parameters:%s; exit 0 +type:script_output +message:Abort test on device %s +description:Abort tests on devices diff --git a/sysutils/smart/src/www/diag_smart.php b/sysutils/smart/src/www/diag_smart.php deleted file mode 100644 index 90b6cbe91..000000000 --- a/sysutils/smart/src/www/diag_smart.php +++ /dev/null @@ -1,299 +0,0 @@ - - Copyright (C) 2006 Eric Friesen - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ - -require_once("guiconfig.inc"); - -$smartctl = "/usr/local/sbin/smartctl"; - -$valid_test_types = array("offline", "short", "long", "conveyance"); -$valid_info_types = array("i", "H", "c", "A", "a"); -$valid_log_types = array("error", "selftest"); - -include("head.inc"); -?> - - - - - -
-
-
- -
- -' . gettext("PASSED") . ''; - $replacements[1] = '' . gettext("FAILED") . ''; - $replacements[2] = ''; - ksort($patterns); - ksort($replacements); - return preg_replace($patterns, $replacements, $string); -} - -// 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']); -$targetdev = basename($_POST['device']); -if (!file_exists('/dev/' . $targetdev)) { - echo gettext("Device does not exist, bailing."); - return; -} - -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))); - echo '
' . $output . '
-    
- - - -
-
'; - break; - - // Info on devices - case 'info': - $type = $_POST['type']; - if (!in_array($type, $valid_info_types)) { - echo gettext("Invalid info type, bailing."); - return; - } - $output = add_colors(shell_exec($smartctl . " -" . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev))); - echo "
$output
"; - break; - - // View logs - case 'logs': - $type = $_POST['type']; - if (!in_array($type, $valid_log_types)) { - echo gettext("Invalid log type, bailing."); - return; - } - $output = add_colors(shell_exec($smartctl . " -l " . escapeshellarg($type) . " /dev/" . escapeshellarg($targetdev))); - echo "
$output
"; - break; - - // Abort tests - case 'abort': - $output = shell_exec($smartctl . " -X /dev/" . escapeshellarg($targetdev)); - echo "
$output
"; - break; - - // Default page, prints the forms to view info, test, etc... - default: - // Get all AD* and DA* (IDE and SCSI) devices currently installed and stores them in the $devs array - exec("ls /dev | grep '^\(ad\|da\|ada\)[0-9]\{1,2\}$'", $devs); - - if (count($devs) > 0): - ?> - -
-
- - - - - - - - - - - - - - - - -
-   -   -   -   - -
-
- -
  - - " /> -
-
-
-
- -
-
-
- - - - - - - - - - - - - - - - -
-
-   -   -   - -
-
- -
  - - " /> -
-
-
-
- - -
-
-
- - - - - - - - - - - - - - - - -
-
-   - -
-
- -
  - - " /> -
-
-
-
- - -
-
-
- - - - - - - - - - - - -
- -
  - - " class="btn btn-primary" - onclick="return confirm('')" /> -
-
-
-
- - ' . gettext("Back") . ''; -} -?> - -
- - diff --git a/sysutils/smart/src/www/widgets/include/smart_status.inc b/sysutils/smart/src/www/widgets/include/smart_status.inc index 3b51107f4..a01b863d6 100644 --- a/sysutils/smart/src/www/widgets/include/smart_status.inc +++ b/sysutils/smart/src/www/widgets/include/smart_status.inc @@ -1,4 +1,4 @@ 0) { - foreach ($devs as $dev) { -## for each found drive do - $dev_ident = exec("diskinfo -v /dev/$dev | grep ident | awk '{print $1}'"); ## get identifier from drive - $dev_state = trim(exec("smartctl -H /dev/$dev | awk -F: '/^SMART overall-health self-assessment test result/ {print $2;exit} -/^SMART Health Status/ {print $2;exit}'")); ## get SMART state from drive - $dev_state_translated = ""; - switch ($dev_state) { - case "PASSED": - case "OK": - $dev_state_translated = gettext('OK'); - $color = "success"; - break; - case "": - $dev_state = "Unknown"; - $dev_state_translated = gettext('Unknown'); - $color = "warning"; - break; - default: - $color = "danger"; - break; - } +foreach ($devs as $dev) { + $dev_state_translated = ""; + + switch ($dev->state) { + case "PASSED": + case "OK": + $dev_state_translated = gettext('OK'); + $color = "success"; + break; + case "": + $dev_state_translated = gettext('Unknown'); + $color = "warning"; + break; + default: + $color = "danger"; + break; + } ?> - - + device ?> + ident ?>