From e3ad6447b3072f996b9f07a110aee583955391e4 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 23 Feb 2021 17:34:43 +0100 Subject: [PATCH 01/11] net/haproxy: strip warning from final config, improve help text --- .../app/controllers/OPNsense/HAProxy/forms/generalTuning.xml | 2 +- .../opnsense/service/templates/OPNsense/HAProxy/haproxy.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 0fd011d4d..9fdeb1e63 100644 --- 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 @@ -7,7 +7,7 @@ haproxy.general.tuning.root checkbox -
NOTE: Enabling root could be a security issue but it's required by some feature.
]]>
+
NOTE: Running as user root could be a security issue but it may be required by some features.
]]>
true 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 091d1d4d0..536ce0814 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -836,8 +836,8 @@ userlist {{object.name | regex_replace ("[^A-Za-z0-9]","")}} {#- ############################### -#} global +{# # NOTE: Running as root could be a security issue, but is required for some features. #} {% if OPNsense.HAProxy.general.tuning.root != "1" %} - # NOTE: Could be a security issue, but required for some feature. uid 80 {% endif %} gid 80 From 0f7cec57e4c6adaeaf448c6c21ae166b4cc1b01e Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 23 Feb 2021 17:36:51 +0100 Subject: [PATCH 02/11] net/haproxy: update plugin changelog --- net/haproxy/pkg-descr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index a8d97d695..92a2c6d13 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -9,7 +9,8 @@ Plugin Changelog 3.0 Added: -* new feature to change server state and weight on-the-fly (#2213) +* add new maintenance page to change server state and weight on-the-fly (#2213) +* add new commands to update SSL certificates in runtime (#2244, #1882) * add new SSL bind option: prefer-client-ciphers * add global option to enable old buggy behaviour for PROXY v2 connections * add support for HTTP/2 in health checks @@ -24,7 +25,6 @@ Added: * add support for resolve-prefer option (#1975) Fixed: -* fix maintenance page (python error: 'list' object has no attribute 'strip') * prevent service outage by aborting "Apply" when configtest fails * fix direct links to individual statistics tabs From db054b6f486bbf37f9023ab3209241c51de66f1a Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 23 Feb 2021 23:34:38 +0100 Subject: [PATCH 03/11] net/haproxy: prevent the deletion of referenced items --- net/haproxy/pkg-descr | 1 + .../app/controllers/OPNsense/HAProxy/Api/ServiceController.php | 1 + .../app/controllers/OPNsense/HAProxy/Api/SettingsController.php | 1 + 3 files changed, 3 insertions(+) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 92a2c6d13..c27404a0d 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -27,6 +27,7 @@ Added: Fixed: * prevent service outage by aborting "Apply" when configtest fails * fix direct links to individual statistics tabs +* prevent the deletion of items that are still referenced elsewhere (core/#1897) Changed: * change default SSL version to TLSv1.2 (ssl-min-ver) diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php index 524597aef..6c97f4132 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php @@ -45,6 +45,7 @@ class ServiceController extends ApiMutableServiceControllerBase protected static $internalServiceTemplate = 'OPNsense/HAProxy'; protected static $internalServiceEnabled = 'general.enabled'; protected static $internalServiceName = 'haproxy'; + protected static $internalModelUseSafeDelete = true; /** * run syntax check for haproxy configuration diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php index e899a083d..1b1d79b9e 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php @@ -44,6 +44,7 @@ class SettingsController extends ApiMutableModelControllerBase { protected static $internalModelName = 'haproxy'; protected static $internalModelClass = '\OPNsense\HAProxy\HAProxy'; + protected static $internalModelUseSafeDelete = true; public function getFrontendAction($uuid = null) { From 7308240cad0f398e365a53f711e0ecc00dbac50e Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 23 Feb 2021 23:39:40 +0100 Subject: [PATCH 04/11] net/haproxy: deprecate nbproc --- net/haproxy/pkg-descr | 3 +++ .../app/controllers/OPNsense/HAProxy/forms/generalTuning.xml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index c27404a0d..4fc52805d 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -41,6 +41,9 @@ Changed: * make restart/reload commands usable in cron jobs * relax GUI input validation for servers, move validation to jinja template (#1975) +Deprecated: +* nbproc is deprecated and will be removed in os-haproxy 4.0 + 2.26 Fixed: 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 index 9fdeb1e63..ea55662de 100644 --- 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 @@ -12,9 +12,9 @@ haproxy.general.tuning.nbproc - + text -
NOTE: You may experience random issues in multi-process mode. For more information about the "nbproc" option please see the HAProxy Documentation.
]]>
+
WARNING: This option is deprecated and will be removed in a future version of HAProxy, threads should be used instead.
]]>
true
From 3bbf3303ce2a50b4d2b072aa1a18d77bc12c865d Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 23 Feb 2021 23:43:13 +0100 Subject: [PATCH 05/11] net/haproxy: prefer the static server type, refs #1975 This could be useful for cases where the migration did not run as expected and the "type" field is empty. In this case the old behaviour is enforced. While here, fix indentation of other options. --- .../templates/OPNsense/HAProxy/haproxy.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 536ce0814..2a41875e1 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -1106,11 +1106,11 @@ resolvers {{resolver.id}} # Mailer: {{mailer.name}} mailers {{mailer.id}} timeout mail {{mailer.timeout}}s -{% if mailer.mailservers|default("") != "" %} -{% for mailserver in mailer.mailservers.split(",") %} +{% if mailer.mailservers|default("") != "" %} +{% for mailserver in mailer.mailservers.split(",") %} mailer {{mailserver}} {{mailserver}} -{% endfor %} -{% endif %} +{% endfor %} +{% endif %} {% else %} # NOTE: Mailer {{mailer.name}} ignored: not configured in any backend @@ -1518,10 +1518,10 @@ backend {{backend.name}} {% else %} {# # server type #} {% set server_basics = [] %} -{% if server_data.type|default("") == 'static' %} -{% do server_basics.append('server ' ~ server_data.name ~ ' ' ~ server_data.address) %} -{% else %} +{% if server_data.type|default("") == 'template' %} {% do server_basics.append('server-template ' ~ server_data.name ~ ' ' ~ server_data.number ~ ' ' ~ server_data.serviceName) %} +{% else %} +{% do server_basics.append('server ' ~ server_data.name ~ ' ' ~ server_data.address) %} {% endif %} {# # collect optional server parameters #} {% set server_options = [] %} From 0a65d44c05ba9554e0cd1e033ee3443f50ff4d7f Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Wed, 24 Feb 2021 12:14:17 +0100 Subject: [PATCH 06/11] net/haproxy: cleanup: remove unused parameter --- .../OPNsense/HAProxy/Api/StatisticsController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/StatisticsController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/StatisticsController.php index 5864728ff..d90f272fc 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/StatisticsController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/StatisticsController.php @@ -45,7 +45,7 @@ class StatisticsController extends ApiControllerBase * get info * @return array|mixed */ - public function infoAction($zoneid = 0) + public function infoAction() { $backend = new Backend(); $responseRaw = $backend->configdRun("haproxy statistics info"); @@ -57,7 +57,7 @@ class StatisticsController extends ApiControllerBase * get counters * @return array|mixed */ - public function countersAction($zoneid = 0) + public function countersAction() { $backend = new Backend(); $responseRaw = $backend->configdRun("haproxy statistics stat"); @@ -69,7 +69,7 @@ class StatisticsController extends ApiControllerBase * get tables * @return array|mixed */ - public function tablesAction($zoneid = 0) + public function tablesAction() { $backend = new Backend(); $responseRaw = $backend->configdRun("haproxy statistics table"); From b9e25ac40b2e0264e378c116fd2fb94c0c01b1c7 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 2 Mar 2021 12:19:26 +0100 Subject: [PATCH 07/11] net/haproxy: assorted optimizations, update copyright information --- .../OPNsense/HAProxy/Api/ServiceController.php | 1 - .../OPNsense/HAProxy/Api/SettingsController.php | 2 +- .../opnsense/mvc/app/views/OPNsense/HAProxy/index.volt | 2 +- .../src/opnsense/scripts/OPNsense/HAProxy/exportCerts.php | 2 +- .../service/templates/OPNsense/HAProxy/haproxy.conf | 8 ++++++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php index 6c97f4132..524597aef 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/ServiceController.php @@ -45,7 +45,6 @@ class ServiceController extends ApiMutableServiceControllerBase protected static $internalServiceTemplate = 'OPNsense/HAProxy'; protected static $internalServiceEnabled = 'general.enabled'; protected static $internalServiceName = 'haproxy'; - protected static $internalModelUseSafeDelete = true; /** * run syntax check for haproxy configuration diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php index 1b1d79b9e..44ccd006c 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php @@ -1,7 +1,7 @@ Date: Tue, 2 Mar 2021 16:42:59 +0100 Subject: [PATCH 08/11] net/haproxy: fix direct links to individual maintenance tabs --- .../mvc/app/views/OPNsense/HAProxy/maintenance.volt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt index 9e4b0bbd7..9db0cab18 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt @@ -425,6 +425,17 @@ POSSIBILITY OF SUCH DAMAGE. }); }); + + // update history on tab state and implement navigation + if(window.location.hash != "") { + $('a[href="' + window.location.hash + '"]').click() + } + $('.nav-tabs a').on('shown.bs.tab', function (e) { + history.pushState(null, null, e.target.hash); + }); + $(window).on('hashchange', function(e) { + $('a[href="' + window.location.hash + '"]').click() + }); }); From 5cb97e8110cb11c34da9379ea4d5f2000edaefdf Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 2 Mar 2021 17:02:36 +0100 Subject: [PATCH 09/11] net/haproxy: use a consistent wording throughout (GUI only, backend unchanged) While here, improve visibility of important table data in maintenance page. --- .../views/OPNsense/HAProxy/maintenance.volt | 26 +++++++++---------- .../conf/actions.d/actions_haproxy.conf | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt index 9db0cab18..7934afc06 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt @@ -64,7 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. $.post('/api/haproxy/maintenance/certDiff', payload, function(data) { BootstrapDialog.show({ type: BootstrapDialog.TYPE_INFO, - title: "{{ lang._('Diff between configured and active ssl certificates') }}", + title: "{{ lang._('Diff between configured and active SSL certificates') }}", message: `
${data}
`, buttons: [{ label: '{{ lang._('Close') }}', @@ -80,7 +80,7 @@ POSSIBILITY OF SUCH DAMAGE. $.post('/api/haproxy/maintenance/certActions', payload, function(data_actions) { question = '' question += `
${data_actions}
`; - question += '{{ lang._('Apply ssl certificates to HaProxy?') }}

'; + question += '{{ lang._('Apply SSL certificates to HAProxy?') }}

'; stdDialogConfirm('{{ lang._('Confirmation Required') }}', question, @@ -92,7 +92,7 @@ POSSIBILITY OF SUCH DAMAGE. var error_msg = syncErrorMessage(data.result.modified, data.result.deleted); BootstrapDialog.show({ type: BootstrapDialog.TYPE_DANGER, - title: "{{ lang._('Error applying ssl certificates to HAProxy') }}", + title: "{{ lang._('Error applying SSL certificates to HAProxy') }}", message: error_msg, buttons: [{ label: '{{ lang._('Close') }}', @@ -124,8 +124,8 @@ POSSIBILITY OF SUCH DAMAGE. formatters: { "commands": function (column, row) { buttons = "" - buttons += "" - buttons += " " + buttons += "" + buttons += " " return buttons; }, }, @@ -202,7 +202,7 @@ POSSIBILITY OF SUCH DAMAGE. var error_msg = syncErrorMessage(data.result.modified, data.result.deleted); BootstrapDialog.show({ type: BootstrapDialog.TYPE_DANGER, - title: "{{ lang._('Error applying ssl certificates to HAProxy') }}", + title: "{{ lang._('Error applying SSL certificates to HAProxy') }}", message: error_msg, buttons: [{ label: '{{ lang._('Close') }}', @@ -344,7 +344,7 @@ POSSIBILITY OF SUCH DAMAGE. }); question += ''; question += '{{ lang._('State: ') }}' + state + '

'; - question += '{{ lang._('Set administrative state for all selected server?') }}

'; + question += '{{ lang._('Set administrative state for all selected servers?') }}

'; stdDialogConfirm('{{ lang._('Confirmation Required') }}', question, @@ -389,7 +389,7 @@ POSSIBILITY OF SUCH DAMAGE. question += '
'; question += ''; question += '
'; - question += '{{ lang._('Set weight for all selected server?') }}

'; + question += '{{ lang._('Set weight for all selected servers?') }}

'; stdDialogConfirm('{{ lang._('Confirmation Required') }}', question, @@ -451,11 +451,11 @@ POSSIBILITY OF SUCH DAMAGE. {{ lang._('id') }} - {{ lang._('Proxy') }} - {{ lang._('Server') }} + {{ lang._('Virtual Service') }} + {{ lang._('Real Server') }} {{ lang._('Address') }} {{ lang._('Status') }} - {{ lang._('Check Status') }} + {{ lang._('Check Status') }} {{ lang._('Weight') }} {{ lang._('Sessions') }} {{ lang._('Bytes in') }} @@ -501,8 +501,8 @@ POSSIBILITY OF SUCH DAMAGE. - - + + diff --git a/net/haproxy/src/opnsense/service/conf/actions.d/actions_haproxy.conf b/net/haproxy/src/opnsense/service/conf/actions.d/actions_haproxy.conf index ac6bd8336..a9f3c5b25 100644 --- a/net/haproxy/src/opnsense/service/conf/actions.d/actions_haproxy.conf +++ b/net/haproxy/src/opnsense/service/conf/actions.d/actions_haproxy.conf @@ -113,7 +113,7 @@ command:configctl template reload OPNsense/HAProxy 2 > /dev/null; /usr/local/opn parameters: type:script_output message:Sync ssl certificates into HAProxy memory for all frontends -description:Sync ssl certificates changes into HAProxy memory +description:Sync SSL certificate changes into running HAProxy service [showconf] command:test -f /usr/local/etc/haproxy.conf.staging && cat /usr/local/etc/haproxy.conf.staging From 89534c805a9fe52755bdbbbfa599b39ea7018876 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Wed, 3 Mar 2021 16:17:48 +0100 Subject: [PATCH 10/11] add pre-defined cron jobs to maintenance page --- net/haproxy/pkg-descr | 1 + .../HAProxy/Api/MaintenanceController.php | 104 +++++++++++++++++- .../HAProxy/MaintenanceController.php | 1 + .../HAProxy/forms/maintenanceCronjobs.xml | 46 ++++++++ .../app/models/OPNsense/HAProxy/HAProxy.xml | 76 +++++++++++++ .../views/OPNsense/HAProxy/maintenance.volt | 84 +++++++++++++- 6 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/maintenanceCronjobs.xml diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 4fc52805d..4e83fe306 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -23,6 +23,7 @@ Added: * add support for server templates (#1975) * add support for additional resolver options (#1975) * add support for resolve-prefer option (#1975) +* add pre-defined cron jobs to maintenance page Fixed: * prevent service outage by aborting "Apply" when configtest fails diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/MaintenanceController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/MaintenanceController.php index c727e6017..1aac6f4ec 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/MaintenanceController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/MaintenanceController.php @@ -31,16 +31,21 @@ namespace OPNsense\HAProxy\Api; -use OPNsense\Base\ApiControllerBase; +use OPNsense\Base\ApiMutableModelControllerBase; use OPNsense\Core\Backend; +use OPNsense\Core\Config; +use OPNsense\Cron\Cron; use OPNsense\HAProxy\HAProxy; /** * Class MaintenanceController * @package OPNsense\HAProxy */ -class MaintenanceController extends ApiControllerBase +class MaintenanceController extends ApiMutableModelControllerBase { + protected static $internalModelName = 'haproxy'; + protected static $internalModelClass = '\OPNsense\HAProxy\HAProxy'; + /** * jQuery bootstrap certificates diff list * @return array|mixed @@ -268,4 +273,99 @@ class MaintenanceController extends ApiControllerBase ]; } + /** + * create new cron job or return already available one + * @return array status action + */ + public function fetchCronIntegrationAction() + { + $result = array("result" => "no change"); + + if ($this->request->isPost()) { + $mdlHaproxy = $this->getModel(); + $backend = new Backend(); + + // Define possible cron jobs with their configd actions + $cronjobs = array( + 'syncCerts' => 'cert_sync_bulk', + 'updateOcsp' => 'update_ocsp', + 'reloadService' => 'reload', + 'restartService' => 'restart', + ); + + // Iterate over all possible cron jobs + foreach ($cronjobs as $cron => $cron_action) { + + // Name of the item that holds the cron UUID + $cron_ref = "${cron}Cron"; + + // Check if the cron job is enabled or disabled + if ((string)$mdlHaproxy->maintenance->cronjobs->$cron == "1") { + // Check if a cron job already exists + if ((string)$mdlHaproxy->maintenance->cronjobs->$cron_ref == "") { + + // Create new cron job + $mdlCron = new Cron(); + // NOTE: Only configd actions are valid commands for cronjobs + // and they *must* provide a description that is not empty. + $cron_uuid = $mdlCron->newDailyJob( + "HAProxy", + "haproxy ${cron_action}", + "Added by HAProxy plugin", + "*", + "1" + ); + $mdlHaproxy->maintenance->cronjobs->$cron_ref = $cron_uuid; + + // Save updated configuration. + if ($mdlCron->performValidation()->count() == 0) { + $mdlCron->serializeToConfig(); + // save data to config, do not validate because the current in memory model doesn't know about the + // cron item just created. + $mdlHaproxy->serializeToConfig($validateFullModel = false, $disable_validation = true); + Config::getInstance()->save(); + // Refresh the crontab + $backend->configdRun('template reload OPNsense/Cron'); + // (res)start daemon + $backend->configdRun("cron restart"); + $this->getLogger()->error("HAProxy: successfully created cron job $cron ($cron_uuid)"); + $result['result'] = "new"; + $result['uuid'] = $cron_uuid; + } else { + $this->getLogger()->error("HAProxy: unable to create cron job $cron"); + $result['result'] = "unable to add cron"; + } + } + } else { + // Check if a cron job exists + if ((string)$mdlHaproxy->maintenance->cronjobs->$cron_ref != "") { + + // Clean existin entry + $cron_uuid = (string)$mdlHaproxy->maintenance->cronjobs->$cron_ref; + $mdlHaproxy->maintenance->cronjobs->$cron_ref = ""; + + // Delete the cronjob item + $mdlCron = new Cron(); + if ($mdlCron->jobs->job->del($cron_uuid)) { + // If item is removed, serialize to config and save + $mdlCron->serializeToConfig(); + $mdlHaproxy->serializeToConfig($validateFullModel = false, $disable_validation = true); + Config::getInstance()->save(); + // Regenerate the crontab + $backend->configdRun('template reload OPNsense/Cron'); + // (res)start daemon + $backend->configdRun("cron restart"); + $this->getLogger()->error("HAProxy: successfully deleted cron job $cron ($cron_uuid)"); + $result['result'] = "deleted"; + } else { + $this->getLogger()->error("HAProxy: unable to delete cron job $cron ($cron_uuid)"); + $result['result'] = "unable to delete cron"; + } + } + } + } + } + + return $result; + } } diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/MaintenanceController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/MaintenanceController.php index d5a073cc7..92ef3a051 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/MaintenanceController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/MaintenanceController.php @@ -41,5 +41,6 @@ class MaintenanceController extends \OPNsense\Base\IndexController { // choose template $this->view->pick('OPNsense/HAProxy/maintenance'); + $this->view->maintenanceCronjobsForm = $this->getForm("maintenanceCronjobs"); } } diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/maintenanceCronjobs.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/maintenanceCronjobs.xml new file mode 100644 index 000000000..f9c4edf83 --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/maintenanceCronjobs.xml @@ -0,0 +1,46 @@ +
+ + + header + + + + haproxy.maintenance.cronjobs.syncCerts + + checkbox + Automation instead of this cron job.]]> + + + + header + + + + haproxy.maintenance.cronjobs.updateOcsp + + checkbox + HAProxy service settings.]]> + + + + header + + + + haproxy.maintenance.cronjobs.reloadService + + checkbox + + + + + header + + + + haproxy.maintenance.cronjobs.restartService + + checkbox + + +
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 e889fb8f9..8c172b6cf 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 @@ -2815,5 +2815,81 @@ + + + + 0 + N + + + + + OPNsense.Cron.Cron + jobs.job + description + + /HAProxy/ + + + + Related cron not found. + N + + + 0 + N + + + + + OPNsense.Cron.Cron + jobs.job + description + + /HAProxy/ + + + + Related cron not found. + N + + + 0 + N + + + + + OPNsense.Cron.Cron + jobs.job + description + + /HAProxy/ + + + + Related cron not found. + N + + + 0 + N + + + + + OPNsense.Cron.Cron + jobs.job + description + + /HAProxy/ + + + + Related cron not found. + N + + + diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt index 7934afc06..159a67159 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt @@ -28,6 +28,72 @@ POSSIBILITY OF SUCH DAMAGE. #}
@@ -514,6 +581,21 @@ POSSIBILITY OF SUCH DAMAGE.
+ +
+
+ {{ partial("layout_partials/base_form",['fields':maintenanceCronjobsForm,'id':'frm_cronjobs'])}} +
+
+ +
+
+
+ {{ lang._('%sNOTE:%s When enabling multiple cron jobs, please adjust them so that they do not run at the same time. Check the %scron settings page%s for more cron job details and additional customization options.') | format('', '', '', '') }} +
+
+
+
{{ partial("layout_partials/base_dialog_processing") }} From e2feb5e5b858c2366d69e26de0209c1e2a79af1a Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Fri, 5 Mar 2021 00:05:23 +0100 Subject: [PATCH 11/11] net/haproxy: add inline command help, shorten tooltips --- .../views/OPNsense/HAProxy/maintenance.volt | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt index 159a67159..3ab54d181 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/maintenance.volt @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. content_id = "[id=\"haproxy.maintenance.cronjobs." + key + "\"]"; $(content_id).each(function(){ // Finally add the link to the cron job edit page. - cron_link = "
{{ lang._('Configure cron job') }}"; + cron_link = "
{{ lang._('Configure cron job') }}"; $(this).closest("td").append(cron_link); }); }; @@ -190,8 +190,8 @@ POSSIBILITY OF SUCH DAMAGE. formatters: { "commands": function (column, row) { buttons = "" - buttons += "" - buttons += " " + buttons += "" + buttons += " " return buttons; }, }, @@ -300,10 +300,10 @@ POSSIBILITY OF SUCH DAMAGE. formatters: { "commands": function (column, row) { buttons = "" - buttons += "" - buttons += " " - buttons += " " - buttons += " " + buttons += "" + buttons += " " + buttons += " " + buttons += " " return buttons; }, }, @@ -539,14 +539,24 @@ POSSIBILITY OF SUCH DAMAGE. - - - - + + + + +
+

{{ lang._("%sChoose a command to change a server's state in runtime:%s") | format('', '') }}

+
    +
  • {{ lang._('%sSet state to ready:%s This puts the server in normal mode.') | format('', '') }}
  • +
  • {{ lang._('%sSet state to drain:%s This removes the server from load balancing. Health checks will continue to run and it still accepts new persistent connections.') | format('', '') }}
  • +
  • {{ lang._('%sSet state to maintenance:%s This disables any traffic to the server. Health checks will also be disabled.') | format('', '') }}
  • +
  • {{ lang._("%sChange server weight:%s Adjust the server's weight relative to other servers. Servers will receive a load proportional to their weight.") | format('', '') }}
  • +
+

{{ lang._('%sNOTE:%s These changes will not be persisted across restarts of HAProxy.') | format('', '') }}

+
@@ -568,8 +578,8 @@ POSSIBILITY OF SUCH DAMAGE. - - + + @@ -580,6 +590,14 @@ POSSIBILITY OF SUCH DAMAGE.

+
+

{{ lang._("%sApply SSL certificate changes in runtime:%s") | format('', '') }}

+
    +
  • {{ lang._('%sShow diff:%s Show difference between configured SSL certificates and SSL certificates from the running HAProxy service.') | format('', '') }}
  • +
  • {{ lang._('%sApply changes:%s Apply all changes by syncing all shown SSL certificates into running HAProxy service.') | format('', '') }}
  • +
+

{{ lang._('%sNOTE:%s Changes can only be applied for Public Services that already exist in the running HAProxy service. When adding or removing Public Services HAProxy must be reloaded or restarted.') | format('', '') }}

+