From 02b3bc85740e18e207cc76385e70476387ae865f Mon Sep 17 00:00:00 2001
From: Daniel Barbero Martin <daniel.barbero@artica.es>
Date: Tue, 23 Nov 2021 10:18:20 +0100
Subject: [PATCH 1/2] fix setup centraliced active directory

---
 pandora_console/godmode/setup/setup_auth.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php
index d0177731e2..ea3397b30f 100644
--- a/pandora_console/godmode/setup/setup_auth.php
+++ b/pandora_console/godmode/setup/setup_auth.php
@@ -60,6 +60,7 @@ if (is_ajax()) {
             $table->data['fallback_local_auth'] = $row;
 
             if (enterprise_installed()) {
+                $is_management_allowed = is_management_allowed();
                 // Autocreate remote users.
                 $row = [];
                 $row['name'] = __('Autocreate remote users');
@@ -67,7 +68,7 @@ if (is_ajax()) {
                     'autocreate_remote_users',
                     1,
                     $config['autocreate_remote_users'],
-                    false,
+                    (is_metaconsole() === false) ? !$is_management_allowed : false,
                     '',
                     '',
                     true

From 347769299bd478e34819c16c938c0dfc16c48de1 Mon Sep 17 00:00:00 2001
From: Daniel Barbero Martin <daniel.barbero@artica.es>
Date: Tue, 30 Nov 2021 14:23:19 +0100
Subject: [PATCH 2/2] outocreate remote user centralized node

---
 pandora_console/extras/mr/51.sql                              | 2 ++
 pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql
index 0a6e837195..d358c8b349 100644
--- a/pandora_console/extras/mr/51.sql
+++ b/pandora_console/extras/mr/51.sql
@@ -29,4 +29,6 @@ ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `ta
 
 ALTER TABLE `tagent_repository` ADD COLUMN `deployment_timeout` INT UNSIGNED DEFAULT 600 AFTER `path`;
 
+UPDATE `tconfig` c1 JOIN (select count(*) as n FROM `tconfig` c2 WHERE (c2.`token` = "node_metaconsole" AND c2.`value` = 1) OR (c2.`token` = "centralized_management" AND c2.`value` = 1) ) v SET c1. `value` = 0 WHERE c1.token = "autocreate_remote_users" AND v.n = 2;
+
 COMMIT;
diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql
index b31b13875c..b82023a1a3 100644
--- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql
+++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql
@@ -4252,3 +4252,5 @@ UPDATE `talert_special_days` set `day_code` = 7 WHERE `same_day` = 'sunday';
 
 ALTER TABLE `talert_special_days` DROP COLUMN `same_day`;
 ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+UPDATE `tconfig` c1 JOIN (select count(*) as n FROM `tconfig` c2 WHERE (c2.`token` = "node_metaconsole" AND c2.`value` = 1) OR (c2.`token` = "centralized_management" AND c2.`value` = 1) ) v SET c1. `value` = 0 WHERE c1.token = "autocreate_remote_users" AND v.n = 2;