Commit 730d291e authored by Ad Schellevis's avatar Ad Schellevis

(IDS) merge model changes from master

parent 93427baf
......@@ -29,10 +29,9 @@
namespace OPNsense\IDS\Api;
use \Phalcon\Filter;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Base\ApiMutableModelControllerBase;
use \OPNsense\Base\Filters\QueryFilter;
use \OPNsense\Core\Backend;
use \OPNsense\IDS\IDS;
use \OPNsense\Core\Config;
use \OPNsense\Base\UIModelGrid;
......@@ -40,24 +39,23 @@ use \OPNsense\Base\UIModelGrid;
* Class SettingsController Handles settings related API actions for the IDS module
* @package OPNsense\IDS
*/
class SettingsController extends ApiControllerBase
class SettingsController extends ApiMutableModelControllerBase
{
/**
* @var null|IDS IDS model to share across some methods (see getModel)
*/
private $idsModel = null;
static protected $internalModelName = 'ids';
static protected $internalModelClass = '\OPNsense\IDS\IDS';
/**
* get ids model
* @return null|IDS
* @return array plain model settings (non repeating items)
*/
public function getModel()
protected function getModelNodes()
{
if ($this->idsModel == null) {
$this->idsModel = new IDS();
$settingsNodes = array('general');
$result = array();
$mdlIDS = $this->getModel();
foreach ($settingsNodes as $key) {
$result[$key] = $mdlIDS->$key->getNodes();
}
return $this->idsModel;
return $result;
}
/**
......@@ -464,49 +462,6 @@ class SettingsController extends ApiControllerBase
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
* @return array list of found user rules
......
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* 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\IDS\Migrations;
use OPNsense\Base\BaseModelMigration;
class M1_0_0 extends BaseModelMigration
{
}
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