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 ce3977eca..c727e6017 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 @@ -47,6 +47,9 @@ class MaintenanceController extends ApiControllerBase */ public function searchCertificateDiffAction() { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + return $this->getData( ["cert_diff_list"], ["rowCount", "current", "searchPhrase", "sort"] @@ -59,6 +62,9 @@ class MaintenanceController extends ApiControllerBase */ public function searchServerAction() { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + return $this->getData( ["server_status_list"], ["rowCount", "current", "searchPhrase", "sort"] @@ -71,18 +77,38 @@ class MaintenanceController extends ApiControllerBase */ public function certSyncAction() { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + return $this->syncCerts( ["cert_sync"], ["frontend_ids"] ); } + /** + * sync certificate for frontends + * @return array|mixed + */ + public function certSyncBulkAction() + { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + + return $this->syncCerts( + ["cert_sync_bulk"] + ); + } + /** * show certificate diff for frontends * @return array|mixed */ public function certDiffAction() { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + return $this->getData( ["cert_diff"], ["frontend_ids"] @@ -95,6 +121,9 @@ class MaintenanceController extends ApiControllerBase */ public function certActionsAction() { + $backend = new Backend(); + $backend->configdRun('template reload OPNsense/HAProxy'); + return $this->getData( ["cert_actions"], ["frontend_ids"] 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 7422f22a6..a70204a4d 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 @@ -48,8 +48,10 @@ POSSIBILITY OF SUCH DAMAGE. message += `{{ lang._('REMOVE:') }} ${remove.cert}:`; message += `
${remove.messages.join("")}`;
});
+ message += ``;
});
+ message += `{{ lang._('CERTIFICATES:') }}`;
deleted.forEach(function(del) {
message += `{{ lang._('DELETE:') }} ${del.cert}:`;
message += `${del.messages.join("")}`;
@@ -58,6 +60,53 @@ POSSIBILITY OF SUCH DAMAGE.
return message;
}
+ function showDiffDialog(payload) {
+ $.post('/api/haproxy/maintenance/certDiff', payload, function(data) {
+ BootstrapDialog.show({
+ type: BootstrapDialog.TYPE_INFO,
+ title: "{{ lang._('Diff between configured and remote ssl certificates') }}",
+ message: `${data}`,
+ buttons: [{
+ label: '{{ lang._('Close') }}',
+ action: function(dialog){
+ dialog.close();
+ }
+ }]
+ });
+ });
+ }
+
+ function applyDiffDialog(payload, requested_count) {
+ $.post('/api/haproxy/maintenance/certActions', payload, function(data_actions) {
+ question = ''
+ question += `${data_actions}`;
+ question += '{{ lang._('Apply ssl certificates to HaProxy?') }}';
+
+ stdDialogConfirm('{{ lang._('Confirmation Required') }}',
+ question,
+ '{{ lang._('Yes') }}', '{{ lang._('Cancel') }}', function() {
+ $.post('/api/haproxy/maintenance/certSync', payload, function(data) {
+ modified_count = data.result.add_count + data.result.remove_count + data.result.update_count;
+
+ if (requested_count != modified_count) {
+ var error_msg = syncErrorMessage(data.result.modified, data.result.deleted);
+ BootstrapDialog.show({
+ type: BootstrapDialog.TYPE_DANGER,
+ title: "{{ lang._('Error applying ssl certificates to HAProxy') }}",
+ message: error_msg,
+ buttons: [{
+ label: '{{ lang._('Close') }}',
+ action: function(dialog){
+ dialog.close();
+ }
+ }]
+ });
+ }
+ $("#grid-certificates").bootgrid("reload");
+ });
+ });
+ });
+ }
$("#grid-certificates").bootgrid('destroy');
var grid_certificates = $("#grid-certificates").UIBootgrid({
@@ -88,21 +137,7 @@ POSSIBILITY OF SUCH DAMAGE.
var payload = {
'frontend_ids': frontend_ids,
};
-
- $.post('/api/haproxy/maintenance/certDiff', payload, function(data) {
- BootstrapDialog.show({
- type: BootstrapDialog.TYPE_INFO,
- title: "{{ lang._('Diff between configured and remote ssl certificates') }}",
- message: `${data}`,
- buttons: [{
- label: '{{ lang._('Close') }}',
- action: function(dialog){
- dialog.close();
- }
- }]
- });
- });
-
+ showDiffDialog(payload);
});
grid_certificates.find("*[data-action=applyDiff]").off().on("click", function(e) {
@@ -111,57 +146,76 @@ POSSIBILITY OF SUCH DAMAGE.
var row = rows.filter(function(row) {
return row.id == row_id;
})[0];
-
var requested_count = row.total_count;
var frontend_ids = row.id
var payload = {
'frontend_ids': frontend_ids,
};
- $.post('/api/haproxy/maintenance/certActions', payload, function(data_actions) {
- question = ''
- question += `${data_actions}`;
- question += '{{ lang._('Apply ssl certificates to HaProxy?') }}';
-
- stdDialogConfirm('{{ lang._('Confirmation Required') }}',
- question,
- '{{ lang._('Yes') }}', '{{ lang._('Cancel') }}', function() {
- $.post('/api/haproxy/maintenance/certSync', payload, function(data) {
- modified_count = data.result.add_count + data.result.remove_count + data.result.update_count;
- if (requested_count != modified_count) {
- var error_msg = syncErrorMessage(data.result.modified, data.result.deleted);
- BootstrapDialog.show({
- type: BootstrapDialog.TYPE_DANGER,
- title: "{{ lang._('Error applying ssl certificates to HAProxy') }}",
- message: error_msg,
- buttons: [{
- label: '{{ lang._('Close') }}',
- action: function(dialog){
- dialog.close();
- }
- }]
- });
- }
- $("#grid-certificates").bootgrid("reload");
- });
- });
- });
-
+ applyDiffDialog(payload, requested_count);
});
grid_certificates.find("*[data-action=showDiffBulk]").off().on("click", function(e) {
var rows = $("#grid-certificates").bootgrid("getSelectedRows");
- console.log('Show diff for multi')
+ var payload = {
+ 'frontend_ids': rows.join()
+ };
+ if (rows != undefined && rows.length > 0) {
+ showDiffDialog(payload);
+ }
});
grid_certificates.find("*[data-action=applyDiffBulk]").off().on("click", function(e) {
var rows = $("#grid-certificates").bootgrid("getSelectedRows");
- console.log('Apply diff for multi')
+ var frontend_ids = rows.join();
+ var all_rows = $("#grid-certificates").bootgrid("getCurrentRows");
+ var requested_count = 0;
+ all_rows.forEach(function(row) {
+ if (rows.indexOf(row.id) != -1) {
+ requested_count = requested_count + row.total_count;
+ }
+ });
+ var payload = {
+ 'frontend_ids': frontend_ids,
+ };
+ if (rows != undefined && rows.length > 0) {
+ applyDiffDialog(payload, requested_count);
+ }
});
-
-
});
+ // Apply all changes
+ $("*[data-action=applyDiffAll]").off().on("click", function(e) {
+ $('[id*="applyDiffAll_progress"]').each(function(){
+ $(this).addClass("fa fa-spinner fa-pulse");
+ });
+ var all_rows = $("#grid-certificates").bootgrid("getCurrentRows");
+ var requested_count = 0;
+ all_rows.forEach(function(row) {
+ requested_count = requested_count + row.total_count;
+ });
+
+ var payload = {};
+ $.post('/api/haproxy/maintenance/certSyncBulk', payload, function(data) {
+ modified_count = data.result.add_count + data.result.remove_count + data.result.update_count;
+ if (requested_count != modified_count) {
+ var error_msg = syncErrorMessage(data.result.modified, data.result.deleted);
+ BootstrapDialog.show({
+ type: BootstrapDialog.TYPE_DANGER,
+ title: "{{ lang._('Error applying ssl certificates to HAProxy') }}",
+ message: error_msg,
+ buttons: [{
+ label: '{{ lang._('Close') }}',
+ action: function(dialog){
+ dialog.close();
+ }
+ }]
+ });
+ }
+ $("#grid-certificates").bootgrid("reload");
+ $("#applyDiffAll_progress").removeClass("fa fa-spinner fa-pulse");
+ });
+ });
// grid-status
$("#grid-status").bootgrid('destroy');
@@ -436,12 +490,18 @@ POSSIBILITY OF SUCH DAMAGE.