mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
Firewall/Alias, API work in progress https://github.com/opnsense/core/issues/1858 add grid and empty model
This commit is contained in:
parent
bcf679570d
commit
301565b449
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 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\Firewall;
|
||||
use \OPNsense\Base\IndexController;
|
||||
|
||||
/**
|
||||
* @package OPNsense\Firewall
|
||||
*/
|
||||
class AliasController extends IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
// include dialog form definitions
|
||||
$this->view->formDialogAlias = $this->getForm("dialogEditAlias");
|
||||
$this->view->pick('OPNsense/Firewall/alias');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 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\Firewall\Api;
|
||||
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
|
||||
/**
|
||||
* @package OPNsense\Firewall
|
||||
*/
|
||||
class AliasController extends ApiMutableModelControllerBase
|
||||
{
|
||||
|
||||
static protected $internalModelName = 'alias';
|
||||
static protected $internalModelClass = 'OPNsense\Firewall\Alias';
|
||||
|
||||
/**
|
||||
* search aliases
|
||||
* @return array search results
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function searchItemAction()
|
||||
{
|
||||
return $this->searchBase(
|
||||
"aliases.alias",
|
||||
array('enabled', 'name', 'description'),
|
||||
"description"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update alias with given properties
|
||||
* @param string $uuid internal id
|
||||
* @return array save result + validation output
|
||||
* @throws \Phalcon\Validation\Exception when field validations fail
|
||||
* @throws \ReflectionException when not bound to model
|
||||
*/
|
||||
public function setItemAction($uuid)
|
||||
{
|
||||
return $this->setBase("alias", "aliases.alias", $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new alias and set with attributes from post
|
||||
* @return array save result + validation output
|
||||
* @throws \OPNsense\Base\ModelException when not bound to model
|
||||
* @throws \Phalcon\Validation\Exception when field validations fail
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function addItemAction()
|
||||
{
|
||||
return $this->addBase("alias", "aliases.alias");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve alias settings or return defaults for new one
|
||||
* @param $uuid item unique id
|
||||
* @return array alias content
|
||||
* @throws \ReflectionException when not bound to model
|
||||
*/
|
||||
public function getItemAction($uuid = null)
|
||||
{
|
||||
return $this->getBase("alias", "aliases.alias", $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete alias by uuid, save contents to tmp for removal on apply
|
||||
* @param string $uuid internal id
|
||||
* @return array save status
|
||||
* @throws \Phalcon\Validation\Exception when field validations fail
|
||||
* @throws \ReflectionException when not bound to model
|
||||
*/
|
||||
public function delItemAction($uuid)
|
||||
{
|
||||
return $this->delBase("aliases.alias", $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle status
|
||||
* @param string $uuid id to toggled
|
||||
* @param string|null $disabled set disabled by default
|
||||
* @return array status
|
||||
* @throws \Phalcon\Validation\Exception when field validations fail
|
||||
* @throws \ReflectionException when not bound to model
|
||||
*/
|
||||
public function toggleItemAction($uuid, $disabled = null)
|
||||
{
|
||||
return $this->toggleBase("aliases.aliases", $uuid);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>alias.enabled</id>
|
||||
<label>enabled</label>
|
||||
<type>checkbox</type>
|
||||
<help>enable this alias</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>alias.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>The name of the alias may only consist of the characters "a-z, A-Z, 0-9 and _". Aliases can be nested using this name.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>alias.description</id>
|
||||
<label>Description</label>
|
||||
<help>You may enter a description here for your reference (not parsed).</help>
|
||||
<type>text</type>
|
||||
</field>
|
||||
</form>
|
||||
40
src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php
Normal file
40
src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 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\Firewall;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
/**
|
||||
* Class Alias
|
||||
* @package OPNsense\Firewall
|
||||
*/
|
||||
class Alias extends BaseModel
|
||||
{
|
||||
}
|
||||
31
src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.xml
Normal file
31
src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<model>
|
||||
<mount>//OPNSense/Firewall/Alias</mount>
|
||||
<version>0.0.1</version>
|
||||
<description>
|
||||
OPNsense central management
|
||||
</description>
|
||||
<items>
|
||||
<aliases>
|
||||
<alias type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<name type=".\AliasNameField">
|
||||
<Required>Y</Required>
|
||||
<Constraints>
|
||||
<check001>
|
||||
<ValidationMessage>An alias with this name already exists.</ValidationMessage>
|
||||
<type>UniqueConstraint</type>
|
||||
</check001>
|
||||
</Constraints>
|
||||
</name>
|
||||
<description type="TextField">
|
||||
<Required>Y</Required>
|
||||
<mask>/^([\t\n\v\f\r 0-9a-zA-Z.\-,_\x{00A0}-\x{FFFF}]){1,255}$/u</mask>
|
||||
<ValidationMessage>Description should be a string between 1 and 255 characters</ValidationMessage>
|
||||
</description>
|
||||
</alias>
|
||||
</aliases>
|
||||
</items>
|
||||
</model>
|
||||
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 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\Firewall\FieldTypes;
|
||||
|
||||
use OPNsense\Base\FieldTypes\BaseField;
|
||||
use Phalcon\Validation\Validator\Regex;
|
||||
use Phalcon\Validation\Validator\ExclusionIn;
|
||||
|
||||
/**
|
||||
* Class AliasField
|
||||
* @package OPNsense\Base\FieldTypes
|
||||
*/
|
||||
class AliasNameField extends BaseField
|
||||
{
|
||||
/**
|
||||
* @var bool marks if this is a data node or a container
|
||||
*/
|
||||
protected $internalIsContainer = false;
|
||||
|
||||
/**
|
||||
* @var string default validation message string
|
||||
*/
|
||||
protected $internalValidationMessage = "alias name required";
|
||||
|
||||
/**
|
||||
* retrieve field validators for this field type
|
||||
* @return array returns Text/regex validator
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
$validators = parent::getValidators();
|
||||
$reservedwords = array(
|
||||
'all', 'pass', 'block', 'out', 'queue', 'max', 'min', 'pptp', 'pppoe', 'L2TP', 'OpenVPN', 'IPsec'
|
||||
);
|
||||
if ($this->internalValue != null) {
|
||||
$validators[] = new ExclusionIn(array(
|
||||
'message' => sprintf(gettext('The name cannot be the internally reserved keyword "%s".'),
|
||||
(string)$this),
|
||||
'domain' => $reservedwords)
|
||||
);
|
||||
|
||||
// $validators[] = new Regex(array(
|
||||
// 'message' => sprintf(gettext(
|
||||
// 'The name must be less than 32 characters long and may only consist of the following characters: %s'
|
||||
// ), 'a-z, A-Z, 0-9, _'),
|
||||
// 'pattern'=>'/(^_*$|^\d*$|[^a-z0-9_]){1,32}/')
|
||||
// );
|
||||
|
||||
}
|
||||
return $validators;
|
||||
}
|
||||
}
|
||||
49
src/opnsense/mvc/app/views/OPNsense/Firewall/alias.volt
Normal file
49
src/opnsense/mvc/app/views/OPNsense/Firewall/alias.volt
Normal file
@ -0,0 +1,49 @@
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$("#grid-aliases").UIBootgrid(
|
||||
{ search:'/api/firewall/alias/searchItem',
|
||||
get:'/api/firewall/alias/getItem/',
|
||||
set:'/api/firewall/alias/setItem/',
|
||||
add:'/api/firewall/alias/addItem/',
|
||||
del:'/api/firewall/alias/delItem/',
|
||||
toggle:'/api/firewall/alias/toggleItem/'
|
||||
}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<section class="col-xs-12">
|
||||
<div class="content-box">
|
||||
<table id="grid-aliases" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogAlias">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
|
||||
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
|
||||
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>
|
||||
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{# include dialogs #}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogAlias,'id':'DialogAlias','label':lang._('Edit Alias')])}}
|
||||
Loading…
x
Reference in New Issue
Block a user