mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
restauro functions api
Former-commit-id: e22da32fb91e8f7b06d7fe627a9a3f2eca877390
This commit is contained in:
parent
58d2abbdae
commit
8987a60755
@ -1,36 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category API
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
global $config;
|
||||
|
||||
// Set character encoding to UTF-8
|
||||
// fixes a lot of multibyte character headaches.
|
||||
// Set character encoding to UTF-8 - fixes a lot of multibyte character headaches
|
||||
require_once 'functions_agents.php';
|
||||
require_once 'functions_modules.php';
|
||||
require_once $config['homedir'].'/include/functions_profile.php';
|
||||
@ -254,7 +237,7 @@ function returnData($returnType, $data, $separator=';')
|
||||
case 'json':
|
||||
$data = array_apply_io_safe_output($data);
|
||||
header('Content-type: application/json');
|
||||
// Allows extra parameters to json_encode, like JSON_FORCE_OBJECT.
|
||||
// Allows extra parameters to json_encode, like JSON_FORCE_OBJECT
|
||||
if ($separator == ';') {
|
||||
$separator = null;
|
||||
}
|
||||
@ -559,6 +542,7 @@ $module_field_column_mampping = [
|
||||
'module_critical_inverse' => 'critical_inverse as module_critical_inverse',
|
||||
'module_warning_inverse' => 'warning_inverse as module_warning_inverse',
|
||||
];
|
||||
|
||||
// module related field mappings 2/2 (output field => column for 'tagente_estado')
|
||||
// module_id_agent_modulo is not in this list
|
||||
$estado_fields_to_columns_mapping = [
|
||||
@ -3030,20 +3014,21 @@ function api_get_policy_modules($thrash1, $thrash2, $other, $thrash3)
|
||||
|
||||
|
||||
/**
|
||||
* Create a network module in agent.
|
||||
* And return the id_agent_module of new module.
|
||||
* Create a network module in agent. And return the id_agent_module of new module.
|
||||
*
|
||||
* @param string $id Name of agent to add the module.
|
||||
* @param string $thrash1 Don't use.
|
||||
* @param array $other It's array, $other as param is <name_module>;<disabled>;<id_module_type>;
|
||||
* <id_module_group>;<min_warning>;<max_warning>;<str_warning>;<min_critical>;<max_critical>;<str_critical>;<ff_threshold>;
|
||||
* <history_data>;<ip_target>;<module_port>;<snmp_community>;<snmp_oid>;<module_interval>;<post_process>;
|
||||
* <min>;<max>;<custom_id>;<description>;<disabled_types_event>;<module_macros>;
|
||||
* <each_ff>;<ff_threshold_normal>;<ff_threshold_warning>;<ff_threshold_critical>; in this order
|
||||
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>).
|
||||
* @param string $thrash3 Don't use.
|
||||
* @example: api.php?op=set&op2=create_network_module&id=pepito&other=prueba|0|7|1|10|15|0|16|18|0|15|0|www.google.es|0||0|180|0|0|0|0|latency%20ping&other_mode=url_encode_separator_|*
|
||||
* @return mixed Return.
|
||||
* @param string $id Name of agent to add the module.
|
||||
* @param $thrash1 Don't use.
|
||||
* @param array $other it's array, $other as param is <name_module>;<disabled>;<id_module_type>;
|
||||
* <id_module_group>;<min_warning>;<max_warning>;<str_warning>;<min_critical>;<max_critical>;<str_critical>;<ff_threshold>;
|
||||
* <history_data>;<ip_target>;<module_port>;<snmp_community>;<snmp_oid>;<module_interval>;<post_process>;
|
||||
* <min>;<max>;<custom_id>;<description>;<disabled_types_event>;<module_macros>;
|
||||
* <each_ff>;<ff_threshold_normal>;<ff_threshold_warning>;<ff_threshold_critical>; in this order
|
||||
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
|
||||
* example:
|
||||
*
|
||||
* api.php?op=set&op2=create_network_module&id=pepito&other=prueba|0|7|1|10|15|0|16|18|0|15|0|www.google.es|0||0|180|0|0|0|0|latency%20ping&other_mode=url_encode_separator_|
|
||||
*
|
||||
* @param $thrash3 Don't use
|
||||
*/
|
||||
function api_set_create_network_module($id, $thrash1, $other, $thrash3)
|
||||
{
|
||||
@ -3105,23 +3090,22 @@ function api_set_create_network_module($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_critical' => $other['data'][27],
|
||||
'critical_inverse' => $other['data'][28],
|
||||
'warning_inverse' => $other['data'][29],
|
||||
'ff_type' => $other['data'][30],
|
||||
];
|
||||
|
||||
if (! $values['descripcion']) {
|
||||
$values['descripcion'] = '';
|
||||
// Column 'descripcion' cannot be null.
|
||||
// Column 'descripcion' cannot be null
|
||||
}
|
||||
|
||||
if (! $values['module_macros']) {
|
||||
$values['module_macros'] = '';
|
||||
// Column 'module_macros' cannot be null.
|
||||
// Column 'module_macros' cannot be null
|
||||
}
|
||||
|
||||
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
|
||||
|
||||
if (is_error($idModule)) {
|
||||
// TODO: Improve the error returning more info.
|
||||
// TODO: Improve the error returning more info
|
||||
returnError('error_create_network_module', __('Error in creation network module.'));
|
||||
} else {
|
||||
returnData('string', ['type' => 'string', 'data' => $idModule]);
|
||||
@ -3238,7 +3222,6 @@ function api_set_update_network_module($id_module, $thrash1, $other, $thrash3)
|
||||
'critical_inverse',
|
||||
'warning_inverse',
|
||||
'policy_linked',
|
||||
'ff_type',
|
||||
];
|
||||
|
||||
$values = [];
|
||||
@ -3343,23 +3326,22 @@ function api_set_create_plugin_module($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_critical' => $other['data'][32],
|
||||
'critical_inverse' => $other['data'][33],
|
||||
'warning_inverse' => $other['data'][34],
|
||||
'ff_type' => $other['data'][35],
|
||||
];
|
||||
|
||||
if (! $values['descripcion']) {
|
||||
$values['descripcion'] = '';
|
||||
// Column 'descripcion' cannot be null.
|
||||
// Column 'descripcion' cannot be null
|
||||
}
|
||||
|
||||
if (! $values['module_macros']) {
|
||||
$values['module_macros'] = '';
|
||||
// Column 'module_macros' cannot be null.
|
||||
// Column 'module_macros' cannot be null
|
||||
}
|
||||
|
||||
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
|
||||
|
||||
if (is_error($idModule)) {
|
||||
// TODO: Improve the error returning more info.
|
||||
// TODO: Improve the error returning more info
|
||||
returnError('error_create_plugin_module', __('Error in creation plugin module.'));
|
||||
} else {
|
||||
returnData('string', ['type' => 'string', 'data' => $idModule]);
|
||||
@ -3405,7 +3387,7 @@ function api_set_update_plugin_module($id_module, $thrash1, $other, $thrash3)
|
||||
return;
|
||||
}
|
||||
|
||||
// If we want to change the module to a new agent.
|
||||
// If we want to change the module to a new agent
|
||||
if ($other['data'][0] != '') {
|
||||
if (!util_api_check_agent_and_print_error($other['data'][0], 'string', 'AW')) {
|
||||
return;
|
||||
@ -3422,7 +3404,7 @@ function api_set_update_plugin_module($id_module, $thrash1, $other, $thrash3)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if agent exists.
|
||||
// Check if agent exists
|
||||
$check_id_agent = db_get_value('id_agente', 'tagente', 'id_agente', $other['data'][0]);
|
||||
if (!$check_id_agent) {
|
||||
returnError('error_update_data_module', __('Error updating plugin module. Id_agent doesn\'t exist.'));
|
||||
@ -3466,7 +3448,6 @@ function api_set_update_plugin_module($id_module, $thrash1, $other, $thrash3)
|
||||
'critical_inverse',
|
||||
'warning_inverse',
|
||||
'policy_linked',
|
||||
'ff_type',
|
||||
];
|
||||
|
||||
$values = [];
|
||||
@ -3565,23 +3546,22 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3)
|
||||
'ff_timeout' => $other['data'][23],
|
||||
'critical_inverse' => $other['data'][24],
|
||||
'warning_inverse' => $other['data'][25],
|
||||
'ff_type' => $other['data'][26],
|
||||
];
|
||||
|
||||
if (! $values['descripcion']) {
|
||||
$values['descripcion'] = '';
|
||||
// Column 'descripcion' cannot be null.
|
||||
// Column 'descripcion' cannot be null
|
||||
}
|
||||
|
||||
if (! $values['module_macros']) {
|
||||
$values['module_macros'] = '';
|
||||
// Column 'module_macros' cannot be null.
|
||||
// Column 'module_macros' cannot be null
|
||||
}
|
||||
|
||||
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
|
||||
|
||||
if (is_error($idModule)) {
|
||||
// TODO: Improve the error returning more info.
|
||||
// TODO: Improve the error returning more info
|
||||
returnError('error_create_data_module', __('Error in creation data module.'));
|
||||
} else {
|
||||
returnData('string', ['type' => 'string', 'data' => $idModule]);
|
||||
@ -3838,7 +3818,7 @@ function api_set_update_data_module($id_module, $thrash1, $other, $thrash3)
|
||||
return;
|
||||
}
|
||||
|
||||
// If we want to change the module to a new agent.
|
||||
// If we want to change the module to a new agent
|
||||
if ($other['data'][0] != '') {
|
||||
if (!util_api_check_agent_and_print_error($other['data'][0], 'string', 'AW')) {
|
||||
return;
|
||||
@ -3855,7 +3835,7 @@ function api_set_update_data_module($id_module, $thrash1, $other, $thrash3)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if agent exists.
|
||||
// Check if agent exists
|
||||
$check_id_agent = db_get_value('id_agente', 'tagente', 'id_agente', $other['data'][0]);
|
||||
if (!$check_id_agent) {
|
||||
returnError('error_update_data_module', __('Error updating data module. Id_agent doesn\'t exist.'));
|
||||
@ -3890,7 +3870,6 @@ function api_set_update_data_module($id_module, $thrash1, $other, $thrash3)
|
||||
'critical_inverse',
|
||||
'warning_inverse',
|
||||
'policy_linked',
|
||||
'ff_type',
|
||||
];
|
||||
|
||||
$values = [];
|
||||
@ -3968,7 +3947,7 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3)
|
||||
$disabled_types_event[EVENTS_GOING_UNKNOWN] = (int) !$other['data'][27];
|
||||
$disabled_types_event = json_encode($disabled_types_event);
|
||||
|
||||
// SNMP version 3.
|
||||
// SNMP version 3
|
||||
if ($other['data'][14] == '3') {
|
||||
if ($other['data'][23] != 'AES' and $other['data'][23] != 'DES') {
|
||||
returnError('error_create_snmp_module', __('Error in creation SNMP module. snmp3_priv_method doesn\'t exist. Set it to \'AES\' or \'DES\'. '));
|
||||
@ -4021,7 +4000,6 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_normal' => $other['data'][31],
|
||||
'min_ff_event_warning' => $other['data'][32],
|
||||
'min_ff_event_critical' => $other['data'][33],
|
||||
'ff_type' => $other['data'][34],
|
||||
];
|
||||
} else {
|
||||
$values = [
|
||||
@ -4054,19 +4032,18 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_normal' => $other['data'][25],
|
||||
'min_ff_event_warning' => $other['data'][26],
|
||||
'min_ff_event_critical' => $other['data'][27],
|
||||
'ff_type' => $other['data'][28],
|
||||
];
|
||||
}
|
||||
|
||||
if (! $values['descripcion']) {
|
||||
$values['descripcion'] = '';
|
||||
// Column 'descripcion' cannot be null.
|
||||
// Column 'descripcion' cannot be null
|
||||
}
|
||||
|
||||
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
|
||||
|
||||
if (is_error($idModule)) {
|
||||
// TODO: Improve the error returning more info.
|
||||
// TODO: Improve the error returning more info
|
||||
returnError('error_create_snmp_module', __('Error in creation SNMP module.'));
|
||||
} else {
|
||||
returnData('string', ['type' => 'string', 'data' => $idModule]);
|
||||
@ -4114,7 +4091,7 @@ function api_set_update_snmp_module($id_module, $thrash1, $other, $thrash3)
|
||||
return;
|
||||
}
|
||||
|
||||
// If we want to change the module to a new agent.
|
||||
// If we want to change the module to a new agent
|
||||
if ($other['data'][0] != '') {
|
||||
if (!util_api_check_agent_and_print_error($other['data'][0], 'string', 'AW')) {
|
||||
return;
|
||||
@ -4131,7 +4108,7 @@ function api_set_update_snmp_module($id_module, $thrash1, $other, $thrash3)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if agent exists.
|
||||
// Check if agent exists
|
||||
$check_id_agent = db_get_value('id_agente', 'tagente', 'id_agente', $other['data'][0]);
|
||||
if (!$check_id_agent) {
|
||||
returnError('error_update_data_module', __('Error updating snmp module. Id_agent doesn\'t exist.'));
|
||||
@ -4139,7 +4116,7 @@ function api_set_update_snmp_module($id_module, $thrash1, $other, $thrash3)
|
||||
}
|
||||
}
|
||||
|
||||
// SNMP version 3.
|
||||
// SNMP version 3
|
||||
if ($other['data'][13] == '3') {
|
||||
if ($other['data'][22] != 'AES' and $other['data'][22] != 'DES') {
|
||||
returnError(
|
||||
@ -4203,7 +4180,6 @@ function api_set_update_snmp_module($id_module, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_warning',
|
||||
'min_ff_event_critical',
|
||||
'policy_linked',
|
||||
'ff_type',
|
||||
];
|
||||
} else {
|
||||
$snmp_module_fields = [
|
||||
@ -4235,7 +4211,6 @@ function api_set_update_snmp_module($id_module, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_warning',
|
||||
'min_ff_event_critical',
|
||||
'policy_linked',
|
||||
'ff_type',
|
||||
];
|
||||
}
|
||||
|
||||
@ -4333,7 +4308,6 @@ function api_set_new_network_component($id, $thrash1, $other, $thrash2)
|
||||
'min_ff_event_normal' => $other['data'][20],
|
||||
'min_ff_event_warning' => $other['data'][21],
|
||||
'min_ff_event_critical' => $other['data'][22],
|
||||
'ff_type' => $other['data'][23],
|
||||
];
|
||||
|
||||
$name_check = db_get_value('name', 'tnetwork_component', 'name', $id);
|
||||
@ -4434,7 +4408,6 @@ function api_set_new_plugin_component($id, $thrash1, $other, $thrash2)
|
||||
'min_ff_event_normal' => $other['data'][24],
|
||||
'min_ff_event_warning' => $other['data'][25],
|
||||
'min_ff_event_critical' => $other['data'][26],
|
||||
'ff_type' => $other['data'][27],
|
||||
];
|
||||
|
||||
$name_check = db_get_value('name', 'tnetwork_component', 'name', $id);
|
||||
@ -4570,7 +4543,6 @@ function api_set_new_snmp_component($id, $thrash1, $other, $thrash2)
|
||||
'min_ff_event_normal' => $other['data'][29],
|
||||
'min_ff_event_warning' => $other['data'][30],
|
||||
'min_ff_event_critical' => $other['data'][31],
|
||||
'ff_type' => $other['data'][32],
|
||||
];
|
||||
} else {
|
||||
$values = [
|
||||
@ -4602,7 +4574,6 @@ function api_set_new_snmp_component($id, $thrash1, $other, $thrash2)
|
||||
'min_ff_event_normal' => $other['data'][25],
|
||||
'min_ff_event_warning' => $other['data'][26],
|
||||
'min_ff_event_critical' => $other['data'][27],
|
||||
'ff_type' => $other['data'][28],
|
||||
];
|
||||
}
|
||||
|
||||
@ -4683,7 +4654,6 @@ function api_set_new_local_component($id, $thrash1, $other, $thrash2)
|
||||
'min_ff_event_warning' => $other['data'][8],
|
||||
'min_ff_event_critical' => $other['data'][9],
|
||||
'ff_timeout' => $other['data'][10],
|
||||
'ff_type' => $other['data'][11],
|
||||
];
|
||||
|
||||
$name_check = enterprise_hook(
|
||||
@ -6439,7 +6409,6 @@ function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3)
|
||||
$values['min_ff_event_warning'] = $other['data'][21];
|
||||
$values['min_ff_event_critical'] = $other['data'][22];
|
||||
$values['ff_timeout'] = $other['data'][23];
|
||||
$values['ff_type'] = $other['data'][24];
|
||||
|
||||
if ($name_module_policy !== false) {
|
||||
if ($name_module_policy[0]['name'] == $other['data'][0]) {
|
||||
@ -6681,7 +6650,6 @@ function api_set_add_network_module_policy($id, $thrash1, $other, $thrash3)
|
||||
$values['min_ff_event_normal'] = $other['data'][24];
|
||||
$values['min_ff_event_warning'] = $other['data'][25];
|
||||
$values['min_ff_event_critical'] = $other['data'][26];
|
||||
$values['ff_type'] = $other['data'][27];
|
||||
|
||||
if ($name_module_policy !== false) {
|
||||
if ($name_module_policy[0]['name'] == $other['data'][0]) {
|
||||
@ -6891,7 +6859,6 @@ function api_set_add_plugin_module_policy($id, $thrash1, $other, $thrash3)
|
||||
$values['min_ff_event_normal'] = $other['data'][29];
|
||||
$values['min_ff_event_warning'] = $other['data'][30];
|
||||
$values['min_ff_event_critical'] = $other['data'][31];
|
||||
$values['ff_type'] = $other['data'][32];
|
||||
|
||||
if ($name_module_policy !== false) {
|
||||
if ($name_module_policy[0]['name'] == $other['data'][0]) {
|
||||
@ -7309,7 +7276,6 @@ function api_set_add_snmp_module_policy($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_normal' => $other['data'][30],
|
||||
'min_ff_event_warning' => $other['data'][31],
|
||||
'min_ff_event_critical' => $other['data'][32],
|
||||
'ff_type' => $other['data'][33],
|
||||
];
|
||||
} else {
|
||||
$values = [
|
||||
@ -7339,7 +7305,6 @@ function api_set_add_snmp_module_policy($id, $thrash1, $other, $thrash3)
|
||||
'min_ff_event_normal' => $other['data'][24],
|
||||
'min_ff_event_warning' => $other['data'][25],
|
||||
'min_ff_event_critical' => $other['data'][26],
|
||||
'ff_type' => $other['data'][27],
|
||||
];
|
||||
}
|
||||
|
||||
@ -8829,14 +8794,7 @@ function api_set_alert_actions($id, $id2, $other, $trash1)
|
||||
}
|
||||
|
||||
$firesMin = $other['data'][2];
|
||||
if (!$firesMin) {
|
||||
$firesMin = 0;
|
||||
}
|
||||
|
||||
$firesMax = $other['data'][3];
|
||||
if (!$firesMax) {
|
||||
$firesMax = 0;
|
||||
}
|
||||
|
||||
$values = [
|
||||
'id_alert_template_module' => $idAlertTemplateModule,
|
||||
@ -13311,7 +13269,6 @@ function api_set_apply_module_template($id_template, $id_agent, $thrash3, $thras
|
||||
'min_ff_event_normal' => $row2['min_ff_event_normal'],
|
||||
'min_ff_event_warning' => $row2['min_ff_event_warning'],
|
||||
'min_ff_event_critical' => $row2['min_ff_event_critical'],
|
||||
'ff_type' => $row2['ff_type'],
|
||||
];
|
||||
|
||||
$name = $row2['name'];
|
||||
@ -14728,308 +14685,3 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions por get all user to new feature for Carrefour
|
||||
* It depends of type the method will return csv or json data
|
||||
*
|
||||
* @param string $returnType
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_set_list_all_user($returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'SELECT
|
||||
tup.id_usuario AS user_id,
|
||||
tp.id_perfil AS profile_id,
|
||||
tp.name AS profile_name,
|
||||
tup.id_grupo AS group_id,
|
||||
tgp.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tgp
|
||||
ON tup.id_grupo = tgp.id_grupo;';
|
||||
|
||||
$users = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($users as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
if ($values === false) {
|
||||
returnError('Error_user', __('Users could not be found.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Funtion for get all info user to new feature for Carrefour
|
||||
* It depends of type the method will return csv or json data
|
||||
*
|
||||
* @param string $returnType
|
||||
* @param string $user_db
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_set_info_user_name($returnType, $user_db)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT
|
||||
tup.id_usuario AS user_id, tp.id_perfil AS profile_id,
|
||||
tp.name AS profile_name, tup.id_grupo AS group_id,
|
||||
tg.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tg
|
||||
ON tup.id_grupo = tg.id_grupo
|
||||
WHERE tup.id_usuario = %s',
|
||||
io_safe_output($user_db)
|
||||
);
|
||||
|
||||
$user_profile = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($user_profile as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for get user from a group to new feature for Carrefour.
|
||||
* It depends of type the method will return csv or json data.
|
||||
*
|
||||
* @param string $returnType
|
||||
* @param string $user_db
|
||||
* @param string $group_db
|
||||
* @param integer $disable
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_set_filter_user_group($returnType, $user_db, $group_db, $disable)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$filter_group = '';
|
||||
if ($group_db !== null) {
|
||||
$filter_group = 'AND tup.id_grupo = '.io_safe_output($group_db).'';
|
||||
}
|
||||
|
||||
$sql_disable = '';
|
||||
if ($disable !== null) {
|
||||
$sql_disable = 'INNER JOIN tusuario tu
|
||||
ON tu.disabled = '.io_safe_output($disable).'';
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT DISTINCT
|
||||
tup.id_usuario AS user_id,
|
||||
tp.id_perfil AS profile_id,
|
||||
tp.name AS profile_name,
|
||||
tup.id_grupo AS group_id,
|
||||
tg.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tg
|
||||
ON tup.id_grupo = tg.id_grupo
|
||||
'.$sql_disable.'
|
||||
WHERE tup.id_usuario = %s '.$filter_group.'',
|
||||
io_safe_output($user_db)
|
||||
);
|
||||
|
||||
$filter_user = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($filter_user as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for delete an user profile for Carrefour new feature
|
||||
* The return of this function its only a message
|
||||
*
|
||||
* @param string $user_db
|
||||
* @param integer $id_up
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
function api_set_delete_user_profiles($user_db, $id_up)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AW')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$values = [
|
||||
'id_usuario' => io_safe_output($user_db),
|
||||
'id_up' => io_safe_output($id_up),
|
||||
];
|
||||
$deleted_permission = db_process_sql_delete('tusuario_perfil', $values);
|
||||
|
||||
if ($deleted_permission == false) {
|
||||
returnError('Error_delete', __('User profile could not be deleted.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'string',
|
||||
'data' => $deleted_permission,
|
||||
];
|
||||
|
||||
returnData('string', ['type' => 'string', 'data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for add permission a user to a group for Carrefour new feature
|
||||
* It depends of type the method will return csv or json data
|
||||
*
|
||||
* @param string $returnType
|
||||
* @param string $user_db
|
||||
* @param integer $group_db
|
||||
* @param integer $id_up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
function api_set_add_permission_user_to_group($returnType, $user_db, $group_db, $id_up, $id_profile)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AW')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'SELECT id_up
|
||||
FROM tusuario_perfil
|
||||
WHERE id_up = '.$id_profile.'';
|
||||
|
||||
$exist_profile = db_get_value_sql($sql);
|
||||
|
||||
$values = [
|
||||
'id_usuario' => $user_db,
|
||||
'id_perfil' => $id_up,
|
||||
'id_grupo' => $group_db,
|
||||
'no_hierarchy' => 0,
|
||||
'assigned_by' => 0,
|
||||
'id_policy' => 0,
|
||||
'tags' => '',
|
||||
|
||||
];
|
||||
|
||||
$where_id_up = ['id_up' => $id_profile];
|
||||
if ($exist_profile == $id_profile) {
|
||||
$sucessfull_insert = db_process_sql_update('tusuario_perfil', $values, $where_id_up);
|
||||
} else {
|
||||
$sucessfull_insert = db_process_sql_insert('tusuario_perfil', $values);
|
||||
}
|
||||
|
||||
if ($sucessfull_insert == false) {
|
||||
returnError('Error_insert', __('User profile could not be available.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user