diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php index 1209f8ad0..141fac3e5 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php @@ -44,20 +44,26 @@ class IndexController extends \OPNsense\Base\IndexController public function indexAction() { // include form definitions - $this->view->mainForm = $this->getForm("main"); - $this->view->formDialogFrontend = $this->getForm("dialogFrontend"); - $this->view->formDialogBackend = $this->getForm("dialogBackend"); - $this->view->formDialogServer = $this->getForm("dialogServer"); - $this->view->formDialogHealthcheck = $this->getForm("dialogHealthcheck"); - $this->view->formDialogAction = $this->getForm("dialogAction"); $this->view->formDialogAcl = $this->getForm("dialogAcl"); - $this->view->formDialogUser = $this->getForm("dialogUser"); - $this->view->formDialogGroup = $this->getForm("dialogGroup"); - $this->view->formDialogLua = $this->getForm("dialogLua"); - $this->view->formDialogErrorfile = $this->getForm("dialogErrorfile"); - $this->view->formDialogMapfile = $this->getForm("dialogMapfile"); + $this->view->formDialogAction = $this->getForm("dialogAction"); + $this->view->formDialogBackend = $this->getForm("dialogBackend"); $this->view->formDialogCpu = $this->getForm("dialogCpu"); + $this->view->formDialogErrorfile = $this->getForm("dialogErrorfile"); + $this->view->formDialogFrontend = $this->getForm("dialogFrontend"); + $this->view->formDialogGroup = $this->getForm("dialogGroup"); + $this->view->formDialogHealthcheck = $this->getForm("dialogHealthcheck"); + $this->view->formDialogLua = $this->getForm("dialogLua"); + $this->view->formDialogMapfile = $this->getForm("dialogMapfile"); $this->view->formDialogResolver = $this->getForm("dialogResolver"); + $this->view->formDialogServer = $this->getForm("dialogServer"); + $this->view->formDialogUser = $this->getForm("dialogUser"); + $this->view->generalCacheForm = $this->getForm("generalCache"); + $this->view->generalDefaultsForm = $this->getForm("generalDefaults"); + $this->view->generalLoggingForm = $this->getForm("generalLogging"); + $this->view->generalPeersForm = $this->getForm("generalPeers"); + $this->view->generalSettingsForm = $this->getForm("generalSettings"); + $this->view->generalStatsForm = $this->getForm("generalStats"); + $this->view->generalTuningForm = $this->getForm("generalTuning"); // set additional view parameters $mdlHAProxy = new \OPNsense\HAProxy\HAProxy(); $this->view->showIntro = (string)$mdlHAProxy->general->showIntro; diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalCache.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalCache.xml new file mode 100644 index 000000000..d9fd948b3 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalCache.xml @@ -0,0 +1,30 @@ +
diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalDefaults.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalDefaults.xml new file mode 100644 index 000000000..4a44e0aee --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalDefaults.xml @@ -0,0 +1,63 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalLogging.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalLogging.xml new file mode 100644 index 000000000..cdc79ac14 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalLogging.xml @@ -0,0 +1,31 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalPeers.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalPeers.xml new file mode 100644 index 000000000..f1091f4f3 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalPeers.xml @@ -0,0 +1,56 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalSettings.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalSettings.xml new file mode 100644 index 000000000..78d7ce4b2 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalSettings.xml @@ -0,0 +1,30 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml new file mode 100644 index 000000000..6832e1e17 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml @@ -0,0 +1,60 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalTuning.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalTuning.xml new file mode 100644 index 000000000..a5abb322c --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalTuning.xml @@ -0,0 +1,102 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/main.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/main.xml deleted file mode 100644 index c7145c790..000000000 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/main.xml +++ /dev/null @@ -1,356 +0,0 @@ - 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 3e4086172..59adaa892 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 @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. $( document ).ready(function() { + // get general HAProxy settings var data_get_map = {'frm_haproxy':"/api/haproxy/settings/get"}; // load initial data @@ -298,7 +299,7 @@ POSSIBILITY OF SUCH DAMAGE. * Commands **********************************************************************/ - // Reconfigure haproxy - activate changes + // reconfigure haproxy to activate changes $('[id*="reconfigureAct"]').each(function(){ $(this).click(function(){ @@ -366,7 +367,7 @@ POSSIBILITY OF SUCH DAMAGE. }); }); - // Test configuration file + // test configuration file $('[id*="configtestAct"]').each(function(){ $(this).click(function(){ @@ -407,34 +408,115 @@ POSSIBILITY OF SUCH DAMAGE. }); }); - // form save event handlers for all defined forms - $('[id*="save_"]').each(function(){ + // save general settings and perform a config test + $('[id*="saveAndTestAct"]').each(function(){ $(this).click(function(){ - var frm_id = $(this).closest("form").attr("id"); - var frm_title = $(this).closest("form").attr("data-title"); + // extract the form id from the button id + var frm_id = "frm_" + $(this).attr("id").split('_')[1] - // set progress animation - $("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse"); - - // save data for tab + // save data for this tab saveFormToEndpoint(url="/api/haproxy/settings/set",formid=frm_id,callback_ok=function(){ + // set progress animation + $('[id*="saveAndTestAct_progress"]').each(function(){ + $(this).addClass("fa fa-spinner fa-pulse"); + }); - // on correct save, perform reconfigure - ajaxCall(url="/api/haproxy/service/reconfigure", sendData={}, callback=function(data,status) { - if (status != "success" || data['status'] != 'ok') { + // on correct save, perform config test + ajaxCall(url="/api/haproxy/service/configtest", sendData={}, callback=function(data,status) { + if (data['result'].indexOf('ALERT') > -1) { BootstrapDialog.show({ - type: BootstrapDialog.TYPE_WARNING, - title: "{{ lang._('Error reconfiguring HAProxy') }}", - message: data['status'], + type: BootstrapDialog.TYPE_DANGER, + title: "{{ lang._('HAProxy config contains critical errors') }}", + message: data['result'], draggable: true }); - } else { - ajaxCall(url="/api/haproxy/service/status", sendData={}, callback=function(data,status) { - updateServiceStatusUI(data['status']); + } else if (data['result'].indexOf('WARNING') > -1) { + BootstrapDialog.show({ + type: BootstrapDialog.TYPE_WARNING, + title: "{{ lang._('HAProxy config contains minor errors') }}", + message: data['result'], + draggable: true }); } - // when done, disable progress animation. - $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse"); + // when done, disable progress animation + $('[id*="saveAndTestAct_progress"]').each(function(){ + $(this).removeClass("fa fa-spinner fa-pulse"); + }); + }); + }); + }); + }); + + // save general settings and reconfigure HAProxy + $('[id*="saveAndReconfigureAct"]').each(function(){ + $(this).click(function(){ + // extract the form id from the button id + var frm_id = "frm_" + $(this).attr("id").split('_')[1] + + // save data for this tab + saveFormToEndpoint(url="/api/haproxy/settings/set",formid=frm_id,callback_ok=function(){ + // set progress animation + $('[id*="saveAndReconfigureAct_progress"]').each(function(){ + $(this).addClass("fa fa-spinner fa-pulse"); + }); + + // on correct save, perform config test + ajaxCall(url="/api/haproxy/service/configtest", sendData={}, callback=function(data,status) { + // show warning in case of critical errors + if (data['result'].indexOf('ALERT') > -1) { + BootstrapDialog.show({ + type: BootstrapDialog.TYPE_DANGER, + title: "{{ lang._('HAProxy config contains critical errors') }}", + message: "{{ lang._('The HAProxy service may not be able to start due to critical errors. Try anyway?') }}", + buttons: [{ + label: '{{ lang._('Continue') }}', + cssClass: 'btn-primary', + action: function(dlg){ + ajaxCall(url="/api/haproxy/service/reconfigure", sendData={}, callback=function(data,status) { + if (status != "success" || data['status'] != 'ok') { + BootstrapDialog.show({ + type: BootstrapDialog.TYPE_WARNING, + title: "{{ lang._('Error reconfiguring HAProxy') }}", + message: data['status'], + draggable: true + }); + } + }); + // when done, disable progress animation + $('[id*="saveAndReconfigureAct_progress"]').each(function(){ + $(this).removeClass("fa fa-spinner fa-pulse"); + }); + dlg.close(); + } + }, { + icon: 'fa fa-trash-o', + label: '{{ lang._('Abort') }}', + action: function(dlg){ + // when done, disable progress animation + $('[id*="saveAndReconfigureAct_progress"]').each(function(){ + $(this).removeClass("fa fa-spinner fa-pulse"); + }); + dlg.close(); + } + }] + }); + } else { + ajaxCall(url="/api/haproxy/service/reconfigure", sendData={}, callback=function(data,status) { + if (status != "success" || data['status'] != 'ok') { + BootstrapDialog.show({ + type: BootstrapDialog.TYPE_WARNING, + title: "{{ lang._('Error reconfiguring HAProxy') }}", + message: data['status'], + draggable: true + }); + } + // when done, disable progress animation + $('[id*="saveAndReconfigureAct_progress"]').each(function(){ + $(this).removeClass("fa fa-spinner fa-pulse"); + }); + }); + } + //}); }); }); @@ -513,30 +595,24 @@ POSSIBILITY OF SUCH DAMAGE. - {# add automatically generated tabs #} - {% for tab in mainForm['tabs']|default([]) %} - {% if tab['subtabs']|default(false) %} - {# Tab with dropdown #} -{{ lang._('Please be aware that you need to %smanually%s add the required firewall rules for all configured services.') | format('', '') }}
{{ lang._('Further information is available in our %sHAProxy plugin documentation%s and of course in the %sofficial HAProxy documentation%s. Be sure to report bugs and request features on our %sGitHub issue page%s. Code contributions are also very welcome!') | format('', '', '', '', '', '') }}
@@ -631,6 +707,24 @@ POSSIBILITY OF SUCH DAMAGE. +{{ lang._("Manage HAProxy core configuration:") }}
+{{ lang._("For more details visit HAProxy's official documentation regarding the %sStatistics%s, %sCache%s and %sPeers%s features.") | format('', '', '', '', '', '') }}
+