Commit bd5be5aa authored by Ad Schellevis's avatar Ad Schellevis

(Proxy) merge model changes, add constraints.

parent 730d291e
......@@ -28,8 +28,7 @@
*/
namespace OPNsense\Proxy\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Proxy\Proxy;
use \OPNsense\Base\ApiMutableModelControllerBase;
use \OPNsense\Cron\Cron;
use \OPNsense\Core\Config;
use \OPNsense\Base\UIModelGrid;
......@@ -38,57 +37,10 @@ use \OPNsense\Base\UIModelGrid;
* Class SettingsController
* @package OPNsense\Proxy
*/
class SettingsController extends ApiControllerBase
class SettingsController extends ApiMutableModelControllerBase
{
/**
* retrieve proxy settings
* @return array
*/
public function getAction()
{
$result = array();
if ($this->request->isGet()) {
$mdlProxy = new Proxy();
$result['proxy'] = $mdlProxy->getNodes();
}
return $result;
}
/**
* update proxy configuration fields
* @return array
* @throws \Phalcon\Validation\Exception
*/
public function setAction()
{
$result = array("result"=>"failed");
if ($this->request->hasPost("proxy")) {
// load model and update with provided data
$mdlProxy = new Proxy();
$mdlProxy->setNodes($this->request->getPost("proxy"));
// perform validation
$valMsgs = $mdlProxy->performValidation();
foreach ($valMsgs as $field => $msg) {
if (!array_key_exists("validations", $result)) {
$result["validations"] = array();
}
$result["validations"]["proxy.".$msg->getField()] = $msg->getMessage();
}
// serialize model to config and save
if ($valMsgs->count() == 0) {
$mdlProxy->serializeToConfig();
$cnf = Config::getInstance();
$cnf->save();
$result["result"] = "saved";
}
}
return $result;
}
static protected $internalModelName = 'proxy';
static protected $internalModelClass = '\OPNsense\Proxy\Proxy';
/**
*
......@@ -98,7 +50,7 @@ class SettingsController extends ApiControllerBase
public function searchRemoteBlacklistsAction()
{
$this->sessionClose();
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
$grid = new UIModelGrid($mdlProxy->forward->acl->remoteACLs->blacklists->blacklist);
return $grid->fetchBindRequest(
$this->request,
......@@ -114,7 +66,7 @@ class SettingsController extends ApiControllerBase
*/
public function getRemoteBlacklistAction($uuid = null)
{
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
if ($uuid != null) {
$node = $mdlProxy->getNodeByReference('forward.acl.remoteACLs.blacklists.blacklist.' . $uuid);
if ($node != null) {
......@@ -139,7 +91,7 @@ class SettingsController extends ApiControllerBase
public function setRemoteBlacklistAction($uuid)
{
if ($this->request->isPost() && $this->request->hasPost("blacklist")) {
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
if ($uuid != null) {
$node = $mdlProxy->getNodeByReference('forward.acl.remoteACLs.blacklists.blacklist.' . $uuid);
if ($node != null) {
......@@ -175,7 +127,7 @@ class SettingsController extends ApiControllerBase
$result = array("result" => "failed");
if ($this->request->isPost() && $this->request->hasPost("blacklist")) {
$result = array("result" => "failed", "validations" => array());
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
$node = $mdlProxy->forward->acl->remoteACLs->blacklists->blacklist->Add();
$node->setNodes($this->request->getPost("blacklist"));
$valMsgs = $mdlProxy->performValidation();
......@@ -207,7 +159,7 @@ class SettingsController extends ApiControllerBase
$result = array("result" => "failed");
if ($this->request->isPost()) {
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
if ($uuid != null) {
if ($mdlProxy->forward->acl->remoteACLs->blacklists->blacklist->del($uuid)) {
// if item is removed, serialize to config and save
......@@ -233,7 +185,7 @@ class SettingsController extends ApiControllerBase
$result = array("result" => "failed");
if ($this->request->isPost()) {
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
if ($uuid != null) {
$node = $mdlProxy->getNodeByReference('forward.acl.remoteACLs.blacklists.blacklist.' . $uuid);
if ($node != null) {
......@@ -262,7 +214,7 @@ class SettingsController extends ApiControllerBase
$result = array("result" => "failed");
if ($this->request->isPost()) {
$mdlProxy = new Proxy();
$mdlProxy = $this->getModel();
if ((string)$mdlProxy->forward->acl->remoteACLs->UpdateCron == "") {
$mdlCron = new Cron();
// update cron relation (if this doesn't break consistency)
......
<?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\Proxy\Migrations;
use OPNsense\Base\BaseModelMigration;
class M1_0_0 extends BaseModelMigration
{
}
<model>
<mount>//OPNsense/proxy</mount>
<version>1.0.0</version>
<description>
(squid) proxy settings
</description>
......@@ -151,12 +152,26 @@
<MinimumValue>1</MinimumValue>
<ValidationMessage>Specify the overall bandwidth for downloads in kilobits per second.</ValidationMessage>
<Required>N</Required>
<Constraints>
<check001>
<ValidationMessage>Both throttling parameters should either be filled or empty</ValidationMessage>
<type>AllOrNoneConstraint</type>
<addFields>
<field1>perHostTrotteling</field1>
</addFields>
</check001>
</Constraints>
</OverallBandwidthTrotteling>
<perHostTrotteling type="IntegerField">
<default>256</default>
<MinimumValue>1</MinimumValue>
<ValidationMessage>Specify the per host bandwidth for downloads in kilobits per second.</ValidationMessage>
<Required>N</Required>
<Constraints>
<check001>
<reference>OverallBandwidthTrotteling.check001</reference>
</check001>
</Constraints>
</perHostTrotteling>
</traffic>
</general>
......@@ -289,6 +304,12 @@
<Required>Y</Required>
<Mask>/^[a-zA-Z0-9]{1,245}\.?[a-zA-z0-9]{1,10}$/</Mask>
<ValidationMessage>The filename may only contain letters, digits and one dot (not required).</ValidationMessage>
<Constraints>
<check001>
<ValidationMessage>Filename should be unique</ValidationMessage>
<type>UniqueConstraint</type>
</check001>
</Constraints>
</filename>
<url type="UrlField">
<Required>Y</Required>
......
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