diff --git a/src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php index 66fccec01..971ed8ad9 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php @@ -650,4 +650,73 @@ class SettingsController extends ApiMutableModelControllerBase { return $this->toggleBase("userDefinedRules.rule", $uuid, $enabled); } + + /** + * Search policy + * @return array list of found user rules + * @throws \ReflectionException when not bound to model + */ + public function searchPolicyAction() + { + return $this->searchBase("policies.policy", array("enabled", "prio", "description"), "description"); + } + + /** + * Update policy + * @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 setPolicyAction($uuid) + { + return $this->setBase("policy", "policies.policy", $uuid); + } + + /** + * Add new policy + * @return array save result + validation output + * @throws \Phalcon\Validation\Exception when field validations fail + * @throws \ReflectionException when not bound to model + */ + public function addPolicyAction() + { + return $this->addBase("policy", "policies.policy"); + } + + /** + * Get properties of a policy + * @param null|string $uuid user rule internal id + * @return array user defined properties + * @throws \ReflectionException when not bound to model + */ + public function getPolicyAction($uuid = null) + { + return $this->getBase("policy", "policies.policy", $uuid); + } + + /** + * Delete policy item + * @param string $uuid user rule internal id + * @return array save status + * @throws \Phalcon\Validation\Exception when field validations fail + * @throws \ReflectionException when not bound to model + */ + public function delPolicyAction($uuid) + { + return $this->delBase("policies.policy", $uuid); + } + + /** + * Toggle policy by uuid (enable/disable) + * @param $uuid user defined rule internal id + * @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle + * @return array save result + * @throws \Phalcon\Validation\Exception when field validations fail + * @throws \ReflectionException when not bound to model + */ + public function togglePolicyAction($uuid, $enabled = null) + { + return $this->toggleBase("policies.policy", $uuid, $enabled); + } } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/IDS/PolicyController.php b/src/opnsense/mvc/app/controllers/OPNsense/IDS/PolicyController.php new file mode 100644 index 000000000..168a7c114 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/IDS/PolicyController.php @@ -0,0 +1,44 @@ +view->formDialogPolicy = $this->getForm("dialogPolicy"); + $this->view->pick('OPNsense/IDS/policy'); + } +} diff --git a/src/opnsense/mvc/app/controllers/OPNsense/IDS/forms/dialogPolicy.xml b/src/opnsense/mvc/app/controllers/OPNsense/IDS/forms/dialogPolicy.xml new file mode 100644 index 000000000..0cc53076b --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/IDS/forms/dialogPolicy.xml @@ -0,0 +1,38 @@ +
+ + policy.enabled + + checkbox + Enable this policy. + + + policy.prio + + text + Policies are processed on a first match basis a lower number means more important. + + + policy.rulesets + + select_multiple + rulesets this policy applies to (all when none selected) + + + policy.content + + + hidden + metadata rules per category + + + policy.new_action + + dropdown + Action to perform when filter policy applies + + + policy.description + + text + +
diff --git a/src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyContentField.php b/src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyContentField.php new file mode 100644 index 000000000..d603a3f8f --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyContentField.php @@ -0,0 +1,68 @@ +configdRun("ids list rulemetadata"); + $data = json_decode($response, true); + if (!empty($data)) { + foreach ($data as $prop => $values) { + foreach ($values as $value) { + $item_key = "{$prop}.{$value}"; + self::$internalStaticOptionList[$item_key] = $value; + } + } + } + } + $this->internalOptionList = self::$internalStaticOptionList; + } +} diff --git a/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml b/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml index ad3e9714a..d669792e9 100644 --- a/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml +++ b/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml @@ -25,6 +25,52 @@ + + + + 1 + Y + + + Priority should be a number. + Y + 0 + + + + + OPNsense.IDS.IDS + files.file + filename + + /1/ + + + + Y + Related ruleset not found. + N + + + Y + Y + Policy rule not found. + + + Y + alert + + Alert + Drop + + + + N + /^(.){1,255}$/u + Description should be a string between 1 and 255 characters + + + diff --git a/src/opnsense/mvc/app/models/OPNsense/IDS/Menu/Menu.xml b/src/opnsense/mvc/app/models/OPNsense/IDS/Menu/Menu.xml index d2edbb35f..526efaa03 100644 --- a/src/opnsense/mvc/app/models/OPNsense/IDS/Menu/Menu.xml +++ b/src/opnsense/mvc/app/models/OPNsense/IDS/Menu/Menu.xml @@ -1,8 +1,9 @@ - - + + + diff --git a/src/opnsense/mvc/app/views/OPNsense/IDS/policy.volt b/src/opnsense/mvc/app/views/OPNsense/IDS/policy.volt new file mode 100644 index 000000000..e711d7a51 --- /dev/null +++ b/src/opnsense/mvc/app/views/OPNsense/IDS/policy.volt @@ -0,0 +1,110 @@ +{# + +OPNsense® is Copyright © 2020 by 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. + +#} + + + +
+
+ + + + + + + + + + + + + + + + + + +
{{ lang._('Enabled') }}{{ lang._('Priority') }}{{ lang._('Description') }}{{ lang._('Commands') }}{{ lang._('ID') }}
+ + +
+
+
+ + +{{ partial("layout_partials/base_dialog",['fields':formDialogPolicy,'id':'DialogPolicy','label':lang._('Rule details'),'hasSaveBtn':'true'])}}