diff --git a/pandora_console/extras/mr/69.sql b/pandora_console/extras/mr/69.sql index 16d746f09a..91ece86c2b 100644 --- a/pandora_console/extras/mr/69.sql +++ b/pandora_console/extras/mr/69.sql @@ -7708,7 +7708,7 @@ UPDATE `twelcome_tip` SET url = 'https://pandorafms.com/manual/!current/start?id DELETE FROM tconfig WHERE `token` = 'legacy_database_ha'; -INSERT INTO `tconfig` (`token`, `value`) VALUES ('JWT_signature', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('JWT_signature', 1); DELETE FROM tconfig WHERE `token` = 'loginhash_pwd'; COMMIT; \ No newline at end of file diff --git a/pandora_console/include/class/JWTRepository.class.php b/pandora_console/include/class/JWTRepository.class.php index 367e596eea..13a0cc267c 100644 --- a/pandora_console/include/class/JWTRepository.class.php +++ b/pandora_console/include/class/JWTRepository.class.php @@ -185,4 +185,30 @@ final class JWTRepository } + /** + * Sync the signature with nodes for jwt. + * + * @param string|null $signature Signature to send nodes. + * + * @return void + */ + public static function syncSignatureWithNodes(?string $signature):void + { + global $config; + if (function_exists('metaconsole_get_servers') === true) { + $config['JWT_signature'] = -1; + $servers = metaconsole_get_servers(); + foreach ($servers as $server) { + if (metaconsole_connect($server) == NOERR) { + config_update_value('JWT_signature', $signature, true); + } + + metaconsole_restore_db(); + } + + $config['JWT_signature'] = $signature; + } + } + + } diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 3180e9dba1..9682ab4858 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -185,6 +185,7 @@ if (session_status() === PHP_SESSION_NONE) { config_process_config(); config_prepare_session(); +config_prepare_jwt_signature(); if ((bool) $config['console_log_enabled'] === true) { error_reporting(E_ALL ^ E_NOTICE); diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 6e9f6aa9a9..aea58b373c 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -30,6 +30,7 @@ // Config functions. require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/functions.php'; +require_once __DIR__.'/class/JWTRepository.class.php'; enterprise_include_once('include/functions_config.php'); use PandoraFMS\Core\DBMaintainer; @@ -4212,3 +4213,14 @@ function config_prepare_session() ini_set('post_max_size', $config['max_file_size']); ini_set('upload_max_filesize', $config['max_file_size']); } + + +function config_prepare_jwt_signature() +{ + global $config; + if (is_metaconsole() === true && is_centralized() === true && $config['JWT_signature'] == 1) { + $signature = JWTRepository::generateSignature(); + config_update_value('JWT_signature', $signature, true); + JWTRepository::syncSignatureWithNodes($signature); + } +} diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 5f42345380..b162996e05 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -71,7 +71,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('trap2agent', '0'), ('date_format', 'F j, Y, g:i a'), ('event_view_hr', 8), -('JWT_signature', ''), +('JWT_signature', 1), ('trap2agent', 0), ('prominent_time', 'comparation'), ('timesource', 'system'),