Merge branch 'ent-5544-9725-llamada-api-para-ver-el-numero-de-licencias-agentes-disponibles' into 'develop'

API get license, get license_remaining

See merge request artica/pandorafms!3814
This commit is contained in:
Daniel Rodriguez 2021-04-06 17:18:24 +00:00
commit 7a0139accd
2 changed files with 98 additions and 0 deletions

View File

@ -36,6 +36,7 @@ define('DEBUG', 0);
define('VERBOSE', 0); define('VERBOSE', 0);
// TESTING THE UPDATE MANAGER. // TESTING THE UPDATE MANAGER.
enterprise_include_once('load_enterprise.php');
enterprise_include_once('include/functions_enterprise_api.php'); enterprise_include_once('include/functions_enterprise_api.php');
$ipOrigin = $_SERVER['REMOTE_ADDR']; $ipOrigin = $_SERVER['REMOTE_ADDR'];

View File

@ -375,6 +375,103 @@ function api_get_test_event_replication_db()
// -------------------------DEFINED OPERATIONS FUNCTIONS----------------- // -------------------------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,
]
);
}
/**
* Example: http://localhost/pandora_console/include/api.php?op=get&op2=license_remaining&user=admin&apipass=1234&pass=pandora&return_type=json
* 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) function api_get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db)
{ {
$returnAllGroup = true; $returnAllGroup = true;