forked from opnsense/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smart plugin uses MVC. Changes agreed with Smart-Soft.
- Loading branch information
1 parent
e0a5227
commit 50d6842
Showing
11 changed files
with
607 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= [email protected] | ||
|
143 changes: 143 additions & 0 deletions
143
sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/Api/ServiceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
/* | ||
Copyright (C) 2018 Smart-Soft | ||
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. | ||
*/ | ||
|
||
namespace OPNsense\Smart\Api; | ||
|
||
use \OPNsense\Base\ApiControllerBase; | ||
use \OPNsense\Core\Backend; | ||
|
||
class ServiceController extends ApiControllerBase | ||
{ | ||
private function getDevices () | ||
{ | ||
$backend = new Backend(); | ||
|
||
$devices = preg_split ("/[\s]+/", trim($backend->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"); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
sysutils/smart/src/opnsense/mvc/app/controllers/OPNsense/Smart/IndexController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
Copyright (C) 2018 Smart-Soft | ||
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. | ||
*/ | ||
|
||
namespace OPNsense\Smart; | ||
class IndexController extends \OPNsense\Base\IndexController | ||
{ | ||
public function indexAction() | ||
{ | ||
// pick the template to serve to our users. | ||
$this->view->pick('OPNsense/Smart/index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sysutils/smart/src/opnsense/mvc/app/models/OPNsense/Smart/Menu/Menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<menu> | ||
<Services> | ||
<SMART url="/diag_smart.php" cssClass="fa fa-stethoscope fa-fw"/> | ||
<SMART url="/ui/smart" cssClass="fa fa-stethoscope fa-fw"/> | ||
</Services> | ||
</menu> |
Oops, something went wrong.