diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index aa44ceea56..d15e49cf38 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,7 +1,7 @@ START TRANSACTION; ALTER TABLE `tncm_queue` -ADD COLUMN `id_agent_data` INT NOT NULL DEFAULT 0 AFTER `id_script`; +ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`, +ADD CONSTRAINT `fk_tncm_queue_tncm_agent_data` FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL; - -COMMIT; \ No newline at end of file +COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 8a4fca2917..de34968f68 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4240,10 +4240,12 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` ( `id` SERIAL, `id_agent` INT UNSIGNED NOT NULL, `id_script` BIGINT UNSIGNED NOT NULL, + `id_agent_data` bigint unsigned, `utimestamp` INT UNSIGNED NOT NULL, `scheduled` INT UNSIGNED DEFAULT NULL, FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE + FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ---------------------------------------------------------------------- diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 70d697dab4..a0cc1c15ac 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -30,6 +30,9 @@ use Scalar::Util qw(looks_like_number); use LWP::UserAgent; use threads; use threads::shared; +use MIME::Base64; +use Crypt::CBC; +use Digest::SHA qw(hmac_sha256_base64); use JSON; use Encode qw/decode_utf8 encode_utf8/; @@ -181,6 +184,7 @@ our @EXPORT = qw( check_cron_value check_cron_element cron_check + decrypt_AES ); # ID of the different servers @@ -2983,6 +2987,63 @@ sub get_server_name { return "UNKNOWN"; } +############################################################################### +# Encrypt with AES cypher +############################################################################### +sub encrypt_AES { + my ($str_to_encrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher($password); + + my $cipher_text = $cipher->encrypt($str_to_encrypt); + my $b64str = encode_base64($cipher_text, ''); + + return $b64str; +} + +############################################################################### +# Decrypt with AES cypher +############################################################################### +sub decrypt_AES { + my ($str_to_decrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher($password); + + my $cipher_text = decode_base64($str_to_decrypt); + my $decrypted_str = $cipher->decrypt($cipher_text); + + return $decrypted_str; +} + +############################################################################### +# Get cipher for AES encrypt and decrypt +############################################################################### +sub _get_cipher { + my ($password) = @_; + + my $hash_base64 = substr(Digest::SHA::hmac_sha256_base64($password,''), 0, 16); + + my $iv = '0000000000000000'; + + my $cipher = Crypt::CBC->new( + -key => $hash_base64, + -cipher => 'Cipher::AES', + -iv => $iv, + -header => 'none', + -padding => 'standard', # PKCS7 padding + -keysize => 16, + -literal_key => 1 + ); + + return $cipher; +} + 1; __END__