Commit 1e6406e0 authored by Ad Schellevis's avatar Ad Schellevis
parent 93872326
...@@ -29,10 +29,9 @@ ...@@ -29,10 +29,9 @@
namespace OPNsense\IDS\Api; namespace OPNsense\IDS\Api;
use \Phalcon\Filter; use \Phalcon\Filter;
use \OPNsense\Base\ApiControllerBase; use \OPNsense\Base\ApiMutableModelControllerBase;
use \OPNsense\Base\Filters\QueryFilter; use \OPNsense\Base\Filters\QueryFilter;
use \OPNsense\Core\Backend; use \OPNsense\Core\Backend;
use \OPNsense\IDS\IDS;
use \OPNsense\Core\Config; use \OPNsense\Core\Config;
use \OPNsense\Base\UIModelGrid; use \OPNsense\Base\UIModelGrid;
...@@ -40,24 +39,23 @@ use \OPNsense\Base\UIModelGrid; ...@@ -40,24 +39,23 @@ use \OPNsense\Base\UIModelGrid;
* Class SettingsController Handles settings related API actions for the IDS module * Class SettingsController Handles settings related API actions for the IDS module
* @package OPNsense\IDS * @package OPNsense\IDS
*/ */
class SettingsController extends ApiControllerBase class SettingsController extends ApiMutableModelControllerBase
{ {
/** static protected $internalModelName = 'ids';
* @var null|IDS IDS model to share across some methods (see getModel) static protected $internalModelClass = '\OPNsense\IDS\IDS';
*/
private $idsModel = null;
/** /**
* get ids model * @return array plain model settings (non repeating items)
* @return null|IDS
*/ */
public function getModel() protected function getModelNodes()
{ {
if ($this->idsModel == null) { $settingsNodes = array('general');
$this->idsModel = new IDS(); $result = array();
$mdlIDS = $this->getModel();
foreach ($settingsNodes as $key) {
$result[$key] = $mdlIDS->$key->getNodes();
} }
return $result;
return $this->idsModel;
} }
/** /**
...@@ -464,49 +462,6 @@ class SettingsController extends ApiControllerBase ...@@ -464,49 +462,6 @@ class SettingsController extends ApiControllerBase
return $result; return $result;
} }
/**
* retrieve IDS settings
* @return array IDS settings
*/
public function getAction()
{
// define list of configurable settings
$settingsNodes = array('general');
$result = array();
if ($this->request->isGet()) {
$mdlIDS = $this->getModel();
$result['ids'] = array();
foreach ($settingsNodes as $key) {
$result['ids'][$key] = $mdlIDS->$key->getNodes();
}
}
return $result;
}
/**
* update IDS settings
* @return array status
*/
public function setAction()
{
$result = array("result"=>"failed");
if ($this->request->isPost()) {
// load model and update with provided data
$mdlIDS = $this->getModel();
$mdlIDS->setNodes($this->request->getPost("ids"));
$validations = $mdlIDS->validate(null, "ids.");
if (count($validations)) {
$result['validations'] = $validations;
} else {
$mdlIDS->serializeToConfig();
Config::getInstance()->save();
$result["result"] = "saved";
}
}
return $result;
}
/** /**
* search user defined rules * search user defined rules
* @return array list of found user rules * @return array list of found user rules
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment