From 28445e3decc55f7a899dca18c99b8113673c7f98 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 2 Feb 2021 15:45:47 +0100 Subject: [PATCH] API get license, get license_remaining --- pandora_console/include/api.php | 1 + pandora_console/include/functions_api.php | 96 +++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 944c3a710c..5182a87d25 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -36,6 +36,7 @@ define('DEBUG', 0); define('VERBOSE', 0); // TESTING THE UPDATE MANAGER. +enterprise_include_once('load_enterprise.php'); enterprise_include_once('include/functions_enterprise_api.php'); $ipOrigin = $_SERVER['REMOTE_ADDR']; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d30da4cc4c..843ae291cb 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -375,6 +375,102 @@ function api_get_test_event_replication_db() // -------------------------DEFINED OPERATIONS FUNCTIONS----------------- + + +/** + * Example: http://localhost/pandora_console/include/api.php?op=get&op2=license&user=admin&apipass=1234&pass=pandora&return_type=json + * Retrieve license information. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license($trash1, $trash2, $trash3, $returnType='json') +{ + global $config; + check_login(); + + if (! check_acl($config['id_user'], 0, 'PM')) { + returnError('forbidden', $returnType); + return; + } + + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + // Not an enterprise environment? + if (license_free()) { + $license = 'PANDORA_FREE'; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => ['license_mode' => $license], + ] + ); + return; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => $license, + ] + ); + +} + + +/** + * Retrieve license status agents or modules left. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license_remaining( + $trash1, + $trash2, + $trash3, + $returnType='json' +) { + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + if (license_free()) { + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => PHP_INT_MAX, + ] + ); + } else { + returnError('get-license', 'Failed to verify license.'); + } + + return; + } + + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => ($license['limit'] - $license['count_enabled']), + ] + ); +} + + function api_get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) { $returnAllGroup = true;