Skip to content

Commit 713771e

Browse files
committed
net/haproxy: add "enabled" field to rules
1 parent fcece25 commit 713771e

File tree

7 files changed

+52
-26
lines changed

7 files changed

+52
-26
lines changed

net/haproxy/pkg-descr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Added:
1919
* add support for more sample fetches: quic_enabled, stopping, wait_end (#3702)
2020
* add support for HTTP compression (#4867)
2121
* add all action keywords for http-request/-response and tcp-request/-response rules
22+
* add "enabled" field to rules
2223

2324
Changed:
2425
* upgrade to HAProxy 3.2 release series (#5147)

net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Copyright (C) 2016-2022 Frank Wall
4+
* Copyright (C) 2016-2026 Frank Wall
55
* Copyright (C) 2015 Deciso B.V.
66
*
77
* All rights reserved.
@@ -206,9 +206,14 @@ public function delActionAction($uuid)
206206
return $this->delBase('actions.action', $uuid);
207207
}
208208

209+
public function toggleActionAction($uuid, $enabled = null)
210+
{
211+
return $this->toggleBase('actions.action', $uuid);
212+
}
213+
209214
public function searchActionsAction()
210215
{
211-
return $this->searchBase('actions.action', array('name', 'description'), 'name');
216+
return $this->searchBase('actions.action', array('enabled', 'name', 'description'), 'name');
212217
}
213218

214219
public function getLuaAction($uuid = null)

net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogAction.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<form>
2+
<field>
3+
<id>action.enabled</id>
4+
<label>Enabled</label>
5+
<type>checkbox</type>
6+
<help>Enable this rule.</help>
7+
</field>
28
<field>
39
<id>action.name</id>
410
<label>Name</label>

net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,10 @@
22282228
</acls>
22292229
<actions>
22302230
<action type="ArrayField">
2231+
<enabled type="BooleanField">
2232+
<default>1</default>
2233+
<Required>Y</Required>
2234+
</enabled>
22312235
<name type="TextField">
22322236
<Mask>/^[^\t^,^;^\.^\[^\]^\{^\}]{1,255}$/u</Mask>
22332237
<ValidationMessage>Should be a string between 1 and 255 characters.</ValidationMessage>

net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M4_2_0.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class M4_2_0 extends BaseModelMigration
3737
public function run($model)
3838
{
3939
foreach ($model->getNodeByReference('actions.action')->iterateItems() as $action) {
40+
// Rules have an 'enabled' field now
41+
$action->enabled = '1';
42+
// Migrate TCP/HTTP rules to new format
4043
switch ((string)$action->type) {
4144
case 'http-request_add-header':
4245
$action->type = 'http-request';

net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ POSSIBILITY OF SUCH DAMAGE.
101101
set:'/api/haproxy/settings/set_action/',
102102
add:'/api/haproxy/settings/add_action/',
103103
del:'/api/haproxy/settings/del_action/',
104+
toggle:'/api/haproxy/settings/toggle_action/',
104105
options: {
105106
}
106107
}
@@ -910,6 +911,7 @@ POSSIBILITY OF SUCH DAMAGE.
910911
<table id="grid-actions" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogAction" data-editAlert="haproxyChangeMessage">
911912
<thead>
912913
<tr>
914+
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
913915
<th data-column-id="actionid" data-type="number" data-visible="false">{{ lang._('Rule ID') }}</th>
914916
<th data-column-id="name" data-type="string">{{ lang._('Rule Name') }}</th>
915917
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>

net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -635,34 +635,39 @@
635635
{% set action_enabled = '0' %}
636636
# ERROR: unsupported rule type
637637
{% endif %}
638-
{# # check if action is valid #}
639-
{% if action_enabled == '1' %}
640-
{% if action_data.operator == 'or' %}
641-
{% set join_operator = ' || ' %}
642-
{% else %}
643-
{% set join_operator = ' ' %}
644-
{% endif %}
645-
{# # check if action depends on ACLs #}
646-
{% set comment_lines = ['# RULE: ' + action_data.name] %}
647-
{% if action_acls|length > 0 %}
648-
{% set acl_line = [action_data.testType, action_acls|join(join_operator)]|join(' ') %}
649-
{% else %}
650-
{% set acl_line = '' %}
651-
{% endif %}
652-
{% if action_options|length > 0 %}
653-
{# # handle multiline options #}
654-
{% if action_multiline == '1' %}
655-
{% set join_char = '\n ' %}
656-
{# # ACLs are unsupported in multiline options, remove them #}
657-
{% set acl_line = '' %}
638+
{# # Is this rule enabled in the GUI? #}
639+
{% if action_data.enabled|default('') == '1' %}
640+
{# # check if action is valid #}
641+
{% if action_enabled == '1' %}
642+
{% if action_data.operator == 'or' %}
643+
{% set join_operator = ' || ' %}
644+
{% else %}
645+
{% set join_operator = ' ' %}
646+
{% endif %}
647+
{# # check if action depends on ACLs #}
648+
{% set comment_lines = ['# RULE: ' + action_data.name] %}
649+
{% if action_acls|length > 0 %}
650+
{% set acl_line = [action_data.testType, action_acls|join(join_operator)]|join(' ') %}
658651
{% else %}
659-
{% set join_char = ' ' %}
652+
{% set acl_line = '' %}
653+
{% endif %}
654+
{% if action_options|length > 0 %}
655+
{# # handle multiline options #}
656+
{% if action_multiline == '1' %}
657+
{% set join_char = '\n ' %}
658+
{# # ACLs are unsupported in multiline options, remove them #}
659+
{% set acl_line = '' %}
660+
{% else %}
661+
{% set join_char = ' ' %}
662+
{% endif %}
663+
{% do global_action_options.append(comment_lines|join('\n')) -%}
664+
{% do global_action_options.append(([action_options|join(join_char), acl_line]|join(' '))) %}
660665
{% endif %}
661-
{% do global_action_options.append(comment_lines|join('\n')) -%}
662-
{% do global_action_options.append(([action_options|join(join_char), acl_line]|join(' '))) %}
666+
{% else %}
667+
# RULE INVALID: {{action_data.name}}
663668
{% endif %}
664669
{% else %}
665-
# RULE INVALID: {{action_data.name}}
670+
# RULE DISABLED: {{action_data.name}}
666671
{% endif %}
667672
{% else %}
668673
# RULE INVALID: {{action_data.name}}

0 commit comments

Comments
 (0)