From 719b4b00be0a7135c5978bd666ffe5b0fd5cd505 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sun, 31 Oct 2021 23:27:11 +0100 Subject: [PATCH 01/10] net/haproxy: improve handling of Lua scripts, fixes #2265 --- net/haproxy/pkg-descr | 11 +++++ .../OPNsense/HAProxy/forms/dialogLua.xml | 12 +++++ .../app/models/OPNsense/HAProxy/HAProxy.xml | 14 +++++- .../OPNsense/HAProxy/Migrations/M3_3_0.php | 45 +++++++++++++++++++ .../OPNsense/HAProxy/exportLuaScripts.php | 19 +++++--- .../templates/OPNsense/HAProxy/haproxy.conf | 13 ++++-- 6 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M3_3_0.php diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 5cba9c35d..ed0443984 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -6,6 +6,17 @@ very high loads while needing persistence or Layer7 processing. Plugin Changelog ================ +3.7 + +Added: +* add options "preload" and "filename scheme" to Lua scripts (#2265) + +Fixed: +* unable to use the "require" function in Lua scripts (#2265) + +Changed: +* set "lua-prepend-path" so that Lua scripts can be found (#2265) + 3.6 Added: diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogLua.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogLua.xml index 72a791e42..23ef5b030 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogLua.xml +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogLua.xml @@ -17,6 +17,18 @@ text Description for this Lua script. + + lua.preload + + checkbox + Whether HAProxy should load and execute this Lua script on startup. This is the default behaviour. However, if this Lua script is included by other Lua scripts using the "require" function, then preloading should be disabled to avoid HAProxy errors. + + + lua.filename_scheme + + dropdown + + lua.content diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml index 7eaa7c3dd..89cfe9e0f 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml @@ -1,6 +1,6 @@ //OPNsense/HAProxy - 3.2.0 + 3.3.0 the HAProxy load balancer @@ -2364,6 +2364,18 @@ Should be a string between 1 and 255 characters. N + + 1 + Y + + + Y + id + + Use a random ID for the filename [default] + Use the specified name as filename + + Y diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M3_3_0.php b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M3_3_0.php new file mode 100644 index 000000000..5714a405b --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M3_3_0.php @@ -0,0 +1,45 @@ +getNodeByReference('luas.lua')->iterateItems() as $lua) { + $lua->filename_scheme = 'id'; + $lua->preload = '1'; + } + } +} diff --git a/net/haproxy/src/opnsense/scripts/OPNsense/HAProxy/exportLuaScripts.php b/net/haproxy/src/opnsense/scripts/OPNsense/HAProxy/exportLuaScripts.php index d0da858af..82243d95f 100755 --- a/net/haproxy/src/opnsense/scripts/OPNsense/HAProxy/exportLuaScripts.php +++ b/net/haproxy/src/opnsense/scripts/OPNsense/HAProxy/exportLuaScripts.php @@ -2,7 +2,7 @@ OPNsense->HAProxy->luas)) { } $lua_name = (string)$lua->name; $lua_id = (string)$lua->id; - if ($lua_id != "") { - $lua_content = htmlspecialchars_decode(str_replace("\r", "", (string)$lua->content)); - $lua_filename = $export_path . $lua_id . ".lua"; - file_put_contents($lua_filename, $lua_content); - chmod($lua_filename, 0600); - echo "lua script exported to " . $lua_filename . "\n"; + $lua_filename_scheme = (string)$lua->filename_scheme; + if ($lua_filename_scheme != '' and $lua_filename_scheme === 'name') { + $_name_alnum = preg_replace("/[^A-Za-z0-9]/", '', $lua_name); + $lua_filename = $export_path . $_name_alnum . '.lua'; + } else { + $lua_filename = $export_path . $lua_id . '.lua'; } + $lua_content = htmlspecialchars_decode(str_replace("\r", "", (string)$lua->content)); + file_put_contents($lua_filename, $lua_content); + chmod($lua_filename, 0600); + chown($lua_filename, 'www'); + echo "lua script exported to " . $lua_filename . "\n"; } } diff --git a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf index d6e0624ef..44f3e25dd 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -995,12 +995,19 @@ global {% do logging.append(OPNsense.HAProxy.general.logging.facility) %} {% do logging.append(OPNsense.HAProxy.general.logging.level) if OPNsense.HAProxy.general.logging.level|default("") != "" %} log {{logging|join(' ')}} +{# # lua scripts #} + lua-prepend-path /tmp/haproxy/lua/?.lua {% if helpers.exists('OPNsense.HAProxy.luas.lua') %} - # lua scripts {% for lua in helpers.toList('OPNsense.HAProxy.luas.lua') %} -{% if lua.enabled == '1' %} +{% if lua.enabled == '1' and lua.preload|default('') == '1' %} +{# # select the filename scheme for lua scripts #} +{% if lua.filename_scheme|default('id') == 'name' %} +{% set lua_filename = lua.name | regex_replace ("[^A-Za-z0-9]","") %} +{% else %} +{% set lua_filename = lua.id %} +{% endif %} # lua script: {{lua.name}} - lua-load /tmp/haproxy/lua/{{lua.id}}.lua + lua-load /tmp/haproxy/lua/{{lua_filename}}.lua {% endif %} {% endfor %} {% endif %} From 8be174d6684fe2754f81cb34d676f89f4ef12099 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sun, 31 Oct 2021 23:41:06 +0100 Subject: [PATCH 02/10] net/haproxy: bump version --- net/haproxy/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/haproxy/Makefile b/net/haproxy/Makefile index 5bbe66377..36875ce93 100644 --- a/net/haproxy/Makefile +++ b/net/haproxy/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= haproxy -PLUGIN_VERSION= 3.6 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 3.7 PLUGIN_COMMENT= Reliable, high performance TCP/HTTP load balancer PLUGIN_DEPENDS= haproxy22 PLUGIN_MAINTAINER= opnsense@moov.de From e65a152efb86de7839be44ca72d1367e8ee4457a Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sun, 31 Oct 2021 23:48:49 +0100 Subject: [PATCH 03/10] net/haproxy: align global options for improved readability --- .../service/templates/OPNsense/HAProxy/haproxy.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf index 44f3e25dd..4ce226be3 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -994,9 +994,9 @@ global {% do logging.append('len ' ~ OPNsense.HAProxy.general.logging.length) if OPNsense.HAProxy.general.logging.length|default("") != "" %} {% do logging.append(OPNsense.HAProxy.general.logging.facility) %} {% do logging.append(OPNsense.HAProxy.general.logging.level) if OPNsense.HAProxy.general.logging.level|default("") != "" %} - log {{logging|join(' ')}} + log {{logging|join(' ')}} {# # lua scripts #} - lua-prepend-path /tmp/haproxy/lua/?.lua + lua-prepend-path /tmp/haproxy/lua/?.lua {% if helpers.exists('OPNsense.HAProxy.luas.lua') %} {% for lua in helpers.toList('OPNsense.HAProxy.luas.lua') %} {% if lua.enabled == '1' and lua.preload|default('') == '1' %} @@ -1007,7 +1007,7 @@ global {% set lua_filename = lua.id %} {% endif %} # lua script: {{lua.name}} - lua-load /tmp/haproxy/lua/{{lua_filename}}.lua + lua-load /tmp/haproxy/lua/{{lua_filename}}.lua {% endif %} {% endfor %} {% endif %} From 50815c9c509c3d0c71feaf9f007818c29477cfbc Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Mon, 1 Nov 2021 21:21:40 +0100 Subject: [PATCH 04/10] net/haproxy: update changelog for #2620 --- net/haproxy/pkg-descr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index ed0443984..b611a0698 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -10,9 +10,11 @@ Plugin Changelog Added: * add options "preload" and "filename scheme" to Lua scripts (#2265) +* add syslog-ng socket for logging (#2620) Fixed: * unable to use the "require" function in Lua scripts (#2265) +* request logging not working (#2587) Changed: * set "lua-prepend-path" so that Lua scripts can be found (#2265) From a387c1ff86f48a081f8cda2367787c0c2ddecf85 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Mon, 1 Nov 2021 23:44:45 +0100 Subject: [PATCH 05/10] net/haproxy: show hints after every config change, refs #2590 --- net/haproxy/pkg-descr | 2 + .../mvc/app/views/OPNsense/HAProxy/index.volt | 162 +++++------------- 2 files changed, 49 insertions(+), 115 deletions(-) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index b611a0698..1b3e21cd3 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -11,6 +11,7 @@ Plugin Changelog Added: * add options "preload" and "filename scheme" to Lua scripts (#2265) * add syslog-ng socket for logging (#2620) +* show hint to apply changes after every config change (#2590) Fixed: * unable to use the "require" function in Lua scripts (#2265) @@ -18,6 +19,7 @@ Fixed: Changed: * set "lua-prepend-path" so that Lua scripts can be found (#2265) +* show "apply" and "test syntax" buttons on introduction pages 3.6 diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt index 51f40d96a..07a4ffe54 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt @@ -300,7 +300,6 @@ POSSIBILITY OF SUCH DAMAGE. $("#healthcheck\\.type").change(function(){ var service_id = 'table_' + $(this).val(); $(".type_table").hide(); - // $(".table_"+$(this).val()).show(); $("."+service_id).show(); }); $("#healthcheck\\.type").change(); @@ -517,15 +516,35 @@ POSSIBILITY OF SUCH DAMAGE. }); }); } - //}); }); }); }); }); + // show hint after every config change + function add_apply_reminder() { + hint_msg = "{{ lang._('After changing settings, please remember to apply them with the button below') }}" + $('[id*="haproxyChangeMessage"]').each(function(){ + $(this).append(hint_msg); + }); + + }; + add_apply_reminder(); + + // show or hide the correct buttons depending on which tab is shown + // NOTE: This does not work on already shown tabs, so this event must + // fire first. + $('.nav-tabs a').on('show.bs.tab', function (e) { + if (/^\#general/.test(e.target.hash)) { + $("#haproxyCommonButtons").hide(); + } else { + $("#haproxyCommonButtons").show(); + } + }); + // update history on tab state and implement navigation - if(window.location.hash != "") { + if (window.location.hash != "") { $('a[href="' + window.location.hash + '"]').click() } $('.nav-tabs a').on('shown.bs.tab', function (e) { @@ -745,7 +764,7 @@ POSSIBILITY OF SUCH DAMAGE.
- +
@@ -768,17 +787,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -801,17 +813,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -837,17 +842,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -869,17 +867,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Health Monitor ID') }}
-
-
- - -
-
-
- +
@@ -901,17 +892,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Rule ID') }}
-
-
- - -
-
-
- +
@@ -933,17 +917,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Condition ID') }}
-
-
- - -
-
-
- +
@@ -966,17 +943,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -999,17 +969,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -1032,17 +995,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Enabled') }}
-
-
- - -
-
-
- +
@@ -1064,17 +1020,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Error Message ID') }}
-
-
- - -
-
-
- +
@@ -1096,17 +1045,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Map File ID') }}
-
-
- - -
-
-
- +
@@ -1131,17 +1073,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('CPU Rule ID') }}
-
-
- - -
-
-
- +
@@ -1164,17 +1099,10 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Resolver ID') }}
-
-
- - -
-
-
- +
@@ -1198,13 +1126,6 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('Mailer ID') }}
-
-
- - -
-
-
@@ -1284,6 +1205,17 @@ POSSIBILITY OF SUCH DAMAGE. + + + + {# include dialogs #} From 440e76aa8fd397cd7b1c1fae76cf19654c9f273b Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 2 Nov 2021 00:49:56 +0100 Subject: [PATCH 06/10] net/haproxy: show warning for pending configuration changes, closes #2590 --- net/haproxy/pkg-descr | 1 + .../mvc/app/views/OPNsense/HAProxy/index.volt | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 1b3e21cd3..6ba357c23 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -12,6 +12,7 @@ Added: * add options "preload" and "filename scheme" to Lua scripts (#2265) * add syslog-ng socket for logging (#2620) * show hint to apply changes after every config change (#2590) +* show warning for pending configuration changes (#2590) Fixed: * unable to use the "require" function in Lua scripts (#2265) diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt index 07a4ffe54..6aaf9cef2 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt @@ -356,6 +356,11 @@ POSSIBILITY OF SUCH DAMAGE. message: data['status'], draggable: true }); + } else { + // reload page to hide pending changes reminder + setTimeout(function () { + window.location.reload(true) + }, 300); } // when done, disable progress animation $('[id*="reconfigureAct_progress"]').each(function(){ @@ -509,6 +514,11 @@ POSSIBILITY OF SUCH DAMAGE. message: data['status'], draggable: true }); + } else { + // reload page to hide pending changes reminder + setTimeout(function () { + window.location.reload(true) + }, 300); } // when done, disable progress animation $('[id*="saveAndReconfigureAct_progress"]').each(function(){ @@ -522,9 +532,25 @@ POSSIBILITY OF SUCH DAMAGE. }); }); + /*********************************************************************** + * UI tricks + **********************************************************************/ + + // show reminder when config has pending changes + function pending_changes_reminder() { + ajaxCall(url="/api/haproxy/export/diff/", sendData={}, callback=function(data,status) { + if (data['response'] && data['response'].trim()) { + $("#haproxyPendingReminder").show(); + } else { + $("#haproxyPendingReminder").hide(); + } + }); + } + pending_changes_reminder(); + // show hint after every config change function add_apply_reminder() { - hint_msg = "{{ lang._('After changing settings, please remember to apply them with the button below') }}" + hint_msg = "{{ lang._('After changing settings, please remember to test and apply them with the buttons below.') }}" $('[id*="haproxyChangeMessage"]').each(function(){ $(this).append(hint_msg); }); @@ -1208,6 +1234,9 @@ POSSIBILITY OF SUCH DAMAGE.