From e163c27b43e36ac6ba44ba5f4b3386009e1048a5 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 25 Mar 2019 17:59:12 +0100 Subject: [PATCH 01/31] Commit para revisar progreso Former-commit-id: 498b7c6a44a18c075c431853d8bf6875e92945f9 --- pandora_console/include/api.php | 53 ++++++++- pandora_console/include/functions_api.php | 136 +++++++++++++++++++++- 2 files changed, 182 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 3b04cedd24..8fbeccafe7 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -107,14 +107,13 @@ if ($correctLogin) { if ($op == 'set' && $id) { switch ($op2) { case 'update_agent': - case 'add_module_in_conf': case 'update_module_in_conf': case 'delete_module_in_conf': $id_os = db_get_value_sql('select id_os from tagente where id_agente = '.$id); - if ($id_os == 100) { + if ($id_os === 100) { returnError('not_allowed_operation_cluster', $returnType); return false; } @@ -130,7 +129,7 @@ if ($correctLogin) { $id_os = db_get_value_sql('select id_os from tagente where nombre = "'.$id.'"'); - if ($id_os == 100) { + if ($id_os === 100) { returnError('not_allowed_operation_cluster', $returnType); return false; } @@ -143,14 +142,58 @@ if ($correctLogin) { $id_os = db_get_value_sql('select id_os from tagente where id_agente = (select id_agente from tagente_modulo where id_agente_modulo ='.$id.')'); - if ($id_os == 100) { + if ($id_os === 100) { returnError('not_allowed_operation_cluster', $returnType); return false; } break; - default: + case 'get_info_user_name': + $id_os = get_info_user_name($user); + + if ($id_os === 100) { + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + break; + + case 'get_filter_user_group': + + $id_os = get_filter_user_group($user, $group, $disable); + + if ($id_os === false) { + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + break; + + case 'delete_user_profile': + $id_os = delete_user_profile($user); + + if ($id_os === false) { + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + break; + + case 'get_list_all_user': + $id_os = get_list_all_user(); + + if ($id_os === false) { + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + + case 'add_permission_user_to_group': + $id_os = add_permisson_user_to_group(); + + if ($id_os === false) { + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + + default: // break; } } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index e57dd31013..a792da92c5 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -542,7 +542,6 @@ $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 = [ @@ -13952,7 +13951,7 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash break; case 5: - $values['status'] = (array_key_exists($other['data'][5], events_get_all_status()) || $other['data'][5] == -1) ? $other['data'][5] : -1; + $values['status'] = (array_key_exists($other['data'][5], events_get_all_status()) || $db_process_sql_insertother['data'][5] == -1) ? $other['data'][5] : -1; break; case 6: @@ -14684,3 +14683,136 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3) } } + + +function api_get_list_all_user() +{ + $sql = sprintf('SELECT * FROM tusuario ORDER BY fullname'); + $users = db_get_all_rows_sql($sql); + + if ($users === false) { + returnError('Error_user', ' Users could not be found.'); + } else { + $data = [ + 'type' => 'string', + 'data' => $users, + ]; + + returnData('string', ['type' => 'string', 'data' => $data]); + } + +} + + +function api_get_info_user_name($user) +{ + if ($user === null) { + return false; + } + + $sql = sprintf("select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user')"); + $user_profile = db_get_all_rows_sql($sql); + if ($user_profile === false) { + returnError('Error_user', ' User could not be found.'); + } else { + $data = [ + 'type' => 'string', + 'data' => $user_profile, + ]; + + returnData('string', ['type' => 'string', 'data' => $data]); + } +} + + +function api_get_filter_user_group($user, $group, $disable) +{ + if ($user === null && ($group === null || $disable === null)) { + return false; + } + + if ($group !== null) { + $sql = "select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and id_grupo = $group) LIMIT 1"; + $filter_user = db_get_all_rows_sql($sql); + } + + if ($disable !== null) { + $sql = "select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and disable = $disable) LIMIT 1"; + $filter_user = db_get_all_rows_sql($sql); + } + + if ($filter_user === false) { + returnError('Error_user', ' User profile could not be found.'); + } else { + $data = [ + 'type' => 'string', + 'data' => $filter_user, + ]; + + returnData('string', ['type' => 'string', 'data' => $data]); + } +} + + +function api_get_delete_user_profile($id_user) +{ + if ($id_user === null) { + return false; + } + + $sql = "delete from tusuario_perfil where id_usuario = '$id_user'"; + $deleted_permission = db_process_sql_delete($sql); + + if ($deleted_permission === false) { + returnError('Error_delete', ' User profile could not be deleted.'); + } else { + $data = [ + 'type' => 'string', + 'data' => $deleted_permission, + ]; + + returnData('string', ['type' => 'string', 'data' => $data]); + } +} + + +function api_add_permisson_user_to_group($id_user, $group, $profile, $other=';') +{ + if ($user === null || $group === null || $profile === null) { + return false; + } + + $other[0] = $id_user; + $other[1] = $group; + $other[2] = $profile; + if ($id_user === null || $group === null || $profile === null) { + return false; + } + + // take it up last value(id_up) for tusuario_peril and increase 1 value + $sql = 'select MAX(id_up) from tusuario_perfil'; + + $last_id_up = db_get_value_sql($sql); + + $last_id_up ++; + + $values = [ + 'id_up' => $last_id_up, + 'id_usuario' => $other[0], + 'id_perfil' => $other[2], + 'id_grupo' => $other[1], + 'no_hierarchy' => 0, + 'assigned_by' => 0, + 'id_policy' => 0, + 'tags' => '', + + ]; + + $sucessfull_insert = db_process_sql_insert('tusuario_perfil', $values); + + if ($sucessfull_insert === false) { + returnError('Error_insert', ' User profile could not be aviable.'); + } else { + returnData('string', ['type' => 'string', 'data' => $data]); + } +} From ce49a45d2a3fe8f9337f375ab0507f7041045b94 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Tue, 26 Mar 2019 11:03:36 +0100 Subject: [PATCH 02/31] Commit para revisar progreso Former-commit-id: e1e07ad590624f958e0e8cc31b18d6f936df485e --- pandora_console/include/functions_api.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a792da92c5..9d9216e0b3 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14732,15 +14732,26 @@ function api_get_filter_user_group($user, $group, $disable) } if ($group !== null) { - $sql = "select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and id_grupo = $group) LIMIT 1"; - $filter_user = db_get_all_rows_sql($sql); + $condition = $grupo; + $campo = 'group'; } if ($disable !== null) { - $sql = "select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and disable = $disable) LIMIT 1"; - $filter_user = db_get_all_rows_sql($sql); + $condition = $disable; + $campo = 'disable'; } + // CASO CON USUARIO DE META CONSOLE + /* + if ($user_meta !== null) { + $campo = 'metaconsole_assigned_server'; + $condition = 1; + } + */ + + $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and %s = % d)'), $campo, $condition); + $filter_user = db_get_all_rows_sql($sql); + if ($filter_user === false) { returnError('Error_user', ' User profile could not be found.'); } else { From 1f02159a43888f3080a4950f4d52de7fb7480486 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Tue, 26 Mar 2019 12:06:54 +0100 Subject: [PATCH 03/31] Commit para revisar progreso Former-commit-id: f51d1e10ad320772c77d41aa2da3a1e4eded146a --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 9d9216e0b3..1df222957f 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14749,7 +14749,7 @@ function api_get_filter_user_group($user, $group, $disable) } */ - $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and %s = % d)'), $campo, $condition); + $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and %s = %d)'), $campo, $condition); $filter_user = db_get_all_rows_sql($sql); if ($filter_user === false) { From ad15ed613d763f30f7198ffd444184b0972fe3fb Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 1 Apr 2019 11:17:07 +0200 Subject: [PATCH 04/31] changed wrong traduction from out of agents limits Former-commit-id: a2b6cf49298f3c215ab73804943c61f2ab3d865d --- pandora_console/include/languages/en_GB.po | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/languages/en_GB.po b/pandora_console/include/languages/en_GB.po index 3eab48be5d..8cab372920 100644 --- a/pandora_console/include/languages/en_GB.po +++ b/pandora_console/include/languages/en_GB.po @@ -36481,8 +36481,8 @@ msgstr "" #: ../../enterprise/load_enterprise.php:584 #, php-format msgid "" -"License out of limits

" -"This node has a metaconsole license and it allows %d agents and you have %d " +"Out of license limits

" +"This node has a Metaconsole license that allows %d agents, and you have %d " "agents cached." msgstr "" "License expired

This " @@ -36492,20 +36492,21 @@ msgstr "" #: ../../enterprise/load_enterprise.php:592 #, php-format msgid "" -"License out of limits

" -"This license allows %d agents and you have %d agents configured." +"Out of license limits

" +"This node has a Metaconsole license that allows %d agents, and you have %d " +"agents configured." msgstr "" "License expired

This " -"license allows %d agents and you have %d agents configured." +"license allows %d agents, and you have %d agents configured." #: ../../enterprise/load_enterprise.php:597 #, php-format msgid "" -"License out of limits

" +"Out of license limits

" "This license allows %d modules and you have %d modules configured." msgstr "" -"License expired

This " -"license allows %d modules and you have %d modules configured." +"Out of license limits

This " +"license allows %d modules, and you have %d modules configured." #: ../../enterprise/load_enterprise.php:604 msgid "" From 0afc699b2b674887307751d1da76c6c0990fdf30 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Thu, 11 Apr 2019 10:15:00 +0200 Subject: [PATCH 05/31] Add concatenation to user variable in filter user group function Former-commit-id: 3e1cef1d560309cbfad9670e8e020ca352ac3619 --- pandora_console/include/functions_api.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 1df222957f..1247eea406 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14685,6 +14685,7 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3) } +// Functions por get all user to Carrefour new feature function api_get_list_all_user() { $sql = sprintf('SELECT * FROM tusuario ORDER BY fullname'); @@ -14704,6 +14705,7 @@ function api_get_list_all_user() } +// Funtion for get all info user for Carrefour new feature function api_get_info_user_name($user) { if ($user === null) { @@ -14725,6 +14727,7 @@ function api_get_info_user_name($user) } +// Function for get group user to Carrefour new feature function api_get_filter_user_group($user, $group, $disable) { if ($user === null && ($group === null || $disable === null)) { @@ -14749,7 +14752,7 @@ function api_get_filter_user_group($user, $group, $disable) } */ - $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user' and %s = %d)'), $campo, $condition); + $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '.$user.' and %s = %d)'), $campo, $condition); $filter_user = db_get_all_rows_sql($sql); if ($filter_user === false) { @@ -14765,6 +14768,7 @@ function api_get_filter_user_group($user, $group, $disable) } +// Function for delete an user profile for Carrefour new feature function api_get_delete_user_profile($id_user) { if ($id_user === null) { @@ -14787,6 +14791,7 @@ function api_get_delete_user_profile($id_user) } +// Function for add permission an user to a group for Carrefour new feature function api_add_permisson_user_to_group($id_user, $group, $profile, $other=';') { if ($user === null || $group === null || $profile === null) { From 2ec72c4d7835641addc574e1f6719b5c9a6cc812 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Fri, 12 Apr 2019 11:10:42 +0200 Subject: [PATCH 06/31] Changed query Former-commit-id: f5094c8747677108187e0ba377b80afce2bbd5e0 --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 1247eea406..5941a08615 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14712,7 +14712,7 @@ function api_get_info_user_name($user) return false; } - $sql = sprintf("select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '$user')"); + $sql = sprintf("select * from tperfil p,tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '$user')"); $user_profile = db_get_all_rows_sql($sql); if ($user_profile === false) { returnError('Error_user', ' User could not be found.'); From 1e7fb2f37595503d10a93de7acef1b517d599969 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Fri, 12 Apr 2019 11:37:12 +0200 Subject: [PATCH 07/31] concatenation Former-commit-id: 1a025ccb247ada9f36f51309baee13f4a2c03a78 --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 5941a08615..707c0ad14b 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14712,7 +14712,7 @@ function api_get_info_user_name($user) return false; } - $sql = sprintf("select * from tperfil p,tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '$user')"); + $sql = sprintf("select * from tperfil p,tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '.$user.')"); $user_profile = db_get_all_rows_sql($sql); if ($user_profile === false) { returnError('Error_user', ' User could not be found.'); From 3dafe2d66d2d301e0f4e7602b9d20c37b40a0b4e Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Fri, 12 Apr 2019 13:20:59 +0200 Subject: [PATCH 08/31] changed querys and refactor methods Former-commit-id: 8a9ca4a6e70809ff76b922d20980725eb2d879ca --- pandora_console/include/functions_api.php | 70 ++++++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 415588626a..820791f999 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14733,15 +14733,32 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3) // Functions por get all user to Carrefour new feature function api_get_list_all_user() { - $sql = sprintf('SELECT * FROM tusuario ORDER BY fullname'); + $sql = sprintf('select u.id_usuario, p.id_perfil, p.name, u.id_grupo from tperfil p, tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil)'); $users = db_get_all_rows_sql($sql); - if ($users === false) { + foreach ($users as $up) { + if ($up['id_grupo'] === 0) { + $group_name = 'All'; + } else { + $sql = 'select nombre from tgrupo where id_grupo = '.$up['id_grupo'].''; + $group_name = db_get_value_sql($sql); + } + + $values = [ + 'id_usuario' => $users['id_usuario'], + 'id_perfil' => $users['id_perfil'], + 'perfil_name' => $users['name'], + 'id_grupo' => $users['id_grupo'], + 'group_name' => $users, + ]; + } + + if ($values === false) { returnError('Error_user', ' Users could not be found.'); } else { $data = [ 'type' => 'string', - 'data' => $users, + 'data' => $values, ]; returnData('string', ['type' => 'string', 'data' => $data]); @@ -14757,14 +14774,32 @@ function api_get_info_user_name($user) return false; } - $sql = sprintf("select * from tperfil p,tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '.$user.')"); + $sql = sprintf("select u.id_usuario, p.id_perfil, p.name, u.id_grupo from tperfil p, tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '.$user.')"); $user_profile = db_get_all_rows_sql($sql); - if ($user_profile === false) { + + foreach ($user_profile as $up) { + if ($up['id_grupo'] === 0) { + $group_name = 'All'; + } else { + $sql = 'select nombre from tgrupo where id_grupo = '.$up['id_grupo'].''; + $group_name = db_get_value_sql($sql); + } + + $values = [ + 'id_usuario' => $user_profile['id_usuario'], + 'id_perfil' => $user_profile['id_perfil'], + 'perfil_name' => $user_profile['name'], + 'id_grupo' => $user_profile['id_grupo'], + 'group_name' => $group_name, + ]; + } + + if ($values === false) { returnError('Error_user', ' User could not be found.'); } else { $data = [ 'type' => 'string', - 'data' => $user_profile, + 'data' => $values, ]; returnData('string', ['type' => 'string', 'data' => $data]); @@ -14797,15 +14832,32 @@ function api_get_filter_user_group($user, $group, $disable) } */ - $sql = sprintf(('select * from tperfil,tusuario_perfil where tperfil.id_perfil in (select tusuario_perfil.id_perfil from tusuario_perfil where id_usuario = '.$user.' and %s = %d)'), $campo, $condition); + $sql = sprintf(('select u.id_usuario, p.id_perfil, p.name, u.id_grupo from tperfil p, tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where %s = %d)'), $campo, $condition); $filter_user = db_get_all_rows_sql($sql); - if ($filter_user === false) { + foreach ($filter_user as $up) { + if ($up['id_grupo'] === 0) { + $group_name = 'All'; + } else { + $sql = 'select nombre from tgrupo where id_grupo = '.$up['id_grupo'].''; + $group_name = db_get_value_sql($sql); + } + + $values = [ + 'id_usuario' => $up['id_usuario'], + 'id_perfil' => $up['id_perfil'], + 'perfil_name' => $up['name'], + 'id_grupo' => $up['id_grupo'], + 'group_name' => $group_name, + ]; + } + + if ($values === false) { returnError('Error_user', ' User profile could not be found.'); } else { $data = [ 'type' => 'string', - 'data' => $filter_user, + 'data' => $values, ]; returnData('string', ['type' => 'string', 'data' => $data]); From 994424fe52c69f6f3c5a82ccf11ed1bd83018645 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 15 Apr 2019 12:19:35 +0200 Subject: [PATCH 09/31] Functions changed Former-commit-id: 7eb0fb25ec863df6c60ed88bf84a6f5db5c90979 --- pandora_console/include/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 7adfdbe2fe..589ce3a046 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -149,7 +149,7 @@ if ($correctLogin) { break; case 'get_info_user_name': - $id_os = get_info_user_name($user); + $id_os = get_info_user_name($type, $user); if ($id_os === 100) { returnError('not_allowed_operation_cluster', $returnType); @@ -158,7 +158,7 @@ if ($correctLogin) { break; case 'get_filter_user_group': - $id_os = get_filter_user_group($user, $group, $disable); + $id_os = get_filter_user_group($type, $user, $group, $disable); if ($id_os === false) { returnError('not_allowed_operation_cluster', $returnType); @@ -176,7 +176,7 @@ if ($correctLogin) { break; case 'get_list_all_user': - $id_os = get_list_all_user(); + $id_os = get_list_all_user($type); if ($id_os === false) { returnError('not_allowed_operation_cluster', $returnType); @@ -184,7 +184,7 @@ if ($correctLogin) { } case 'add_permission_user_to_group': - $id_os = add_permisson_user_to_group(); + $id_os = add_permisson_user_to_group($type, $id_user, $group, $profile, $other = ';'); if ($id_os === false) { returnError('not_allowed_operation_cluster', $returnType); From c8af83b1128c89e90125acdeef8503f4a4a89c1d Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Mon, 15 Apr 2019 12:30:42 +0200 Subject: [PATCH 10/31] Update with validations and type return data functions_api.php Former-commit-id: 0757de69c24df3e547924d8dacd32ba9dd88524c --- pandora_console/include/functions_api.php | 133 ++++++++++++++++------ 1 file changed, 96 insertions(+), 37 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 820791f999..24e03f0e8e 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14730,9 +14730,15 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3) } -// Functions por get all user to Carrefour new feature -function api_get_list_all_user() +// Functions por get all user to new feature for Carrefour +// It depends of type the method will return csv or json data +function api_get_list_all_user($type) { +//validate return type data +//if return type data is not specifiqued you will return message error + if($type === null){ + returnError('no_data_to_show', 'type data return not specifiqued.'); + } $sql = sprintf('select u.id_usuario, p.id_perfil, p.name, u.id_grupo from tperfil p, tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil)'); $users = db_get_all_rows_sql($sql); @@ -14749,29 +14755,40 @@ function api_get_list_all_user() 'id_perfil' => $users['id_perfil'], 'perfil_name' => $users['name'], 'id_grupo' => $users['id_grupo'], - 'group_name' => $users, + 'group_name' => $group_name, ]; } if ($values === false) { returnError('Error_user', ' Users could not be found.'); - } else { - $data = [ - 'type' => 'string', - 'data' => $values, - ]; - - returnData('string', ['type' => 'string', 'data' => $data]); } + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + switch ($type) { + case 'csv': + returnData('csv', $data, ';'); + + case 'json': + returnData('json', $data, ';'); + } } -// Funtion for get all info user for Carrefour new feature -function api_get_info_user_name($user) +// Funtion for get all info user to new feature for Carrefour +// It depends of type the method will return csv or json data +function api_get_info_user_name($type,$user) { if ($user === null) { - return false; + returnError('no_data_to_show', 'User not specifiqued.'); + } +//validate return type data +//if return type data is not specifiqued you will return message error + if($type === null){ + returnError('no_data_to_show', 'type data return not specifiqued.'); + } $sql = sprintf("select u.id_usuario, p.id_perfil, p.name, u.id_grupo from tperfil p, tusuario_perfil u where p.id_perfil in (select u.id_perfil from tusuario_perfil where u.id_usuario = '.$user.')"); @@ -14796,24 +14813,36 @@ function api_get_info_user_name($user) if ($values === false) { returnError('Error_user', ' User could not be found.'); - } else { + } $data = [ - 'type' => 'string', + 'type' => 'array', 'data' => $values, ]; - - returnData('string', ['type' => 'string', 'data' => $data]); - } + switch ($type) { + case 'csv': + returnData('csv', $data, ';'); + + case 'json': + returnData('json', $data, ';'); + } } -// Function for get group user to Carrefour new feature -function api_get_filter_user_group($user, $group, $disable) +// Function for get user from a group to new feature for Carrefour. +// It depends of type the method will return csv or json data. + +function api_get_filter_user_group($type,$user, $group, $disable) { if ($user === null && ($group === null || $disable === null)) { - return false; + returnError('no_data_to_show', 'User, group or is disable not specifiqued.'); } +//validate return type data +//if return type data is not specifiqued you will return message error + if($type === null){ + returnError('no_data_to_show', 'type data return not specifiqued.'); + + } if ($group !== null) { $condition = $grupo; $campo = 'group'; @@ -14853,48 +14882,66 @@ function api_get_filter_user_group($user, $group, $disable) } if ($values === false) { - returnError('Error_user', ' User profile could not be found.'); - } else { + returnError('Error_user', ' User could not be found.'); + } $data = [ - 'type' => 'string', + 'type' => 'array', 'data' => $values, ]; - - returnData('string', ['type' => 'string', 'data' => $data]); - } + switch ($type) { + case 'csv': + returnData('csv', $data, ';'); + + case 'json': + returnData('json', $data, ';'); + } } // Function for delete an user profile for Carrefour new feature +// The return of this function its only a message function api_get_delete_user_profile($id_user) { if ($id_user === null) { return false; } +//validate return type data +//if return type data is not specifiqued you will return message error + if($type === null){ + returnError('no_data_to_show', 'type data return not specifiqued.'); + + } $sql = "delete from tusuario_perfil where id_usuario = '$id_user'"; $deleted_permission = db_process_sql_delete($sql); if ($deleted_permission === false) { returnError('Error_delete', ' User profile could not be deleted.'); - } else { - $data = [ + } + + $data = [ 'type' => 'string', 'data' => $deleted_permission, - ]; + ]; returnData('string', ['type' => 'string', 'data' => $data]); - } } - - -// Function for add permission an user to a group for Carrefour new feature -function api_add_permisson_user_to_group($id_user, $group, $profile, $other=';') + +// 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 +function api_add_permisson_user_to_group($type, $id_user, $group, $profile, $other=';') { if ($user === null || $group === null || $profile === null) { return false; } +//validate return type data +//if return type data is not specifiqued you will return message error + if($type === null){ + returnError('no_data_to_show', 'type data return not specifiqued.'); + + } + $other[0] = $id_user; $other[1] = $group; $other[2] = $profile; @@ -14925,7 +14972,19 @@ function api_add_permisson_user_to_group($id_user, $group, $profile, $other=';') if ($sucessfull_insert === false) { returnError('Error_insert', ' User profile could not be aviable.'); - } else { - returnData('string', ['type' => 'string', 'data' => $data]); } + + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + switch ($type) { + + case 'csv': + returnData('csv', $data, ';'); + + case 'json': + returnData('json', $data, ';'); + } + } From a3787c687c8ba8a7623747c8786ffe24d873353a Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 15 Apr 2019 15:10:43 +0200 Subject: [PATCH 11/31] prueba Former-commit-id: 61d4bc20b7811c44125b806f960561eb40412818 --- pandora_console/godmode/servers/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index b04643e1c3..5ff8022afa 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -281,7 +281,7 @@ if (($create != '') || ($view != '')) { } else { if ($create != '') { ui_print_page_header( - __('Plugin creation'), + __('Plugin registration'), 'images/gm_servers.png', false, 'plugin_definition', From 8c27411be633878cd5654a24e2dcc91664e585e5 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Mon, 15 Apr 2019 15:18:22 +0200 Subject: [PATCH 12/31] Delete plugin.php Former-commit-id: c37a85bcf4082a148e72cdc9b1a166a70ec94537 --- pandora_console/godmode/servers/plugin.php | 1205 -------------------- 1 file changed, 1205 deletions(-) delete mode 100644 pandora_console/godmode/servers/plugin.php diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php deleted file mode 100644 index 5ff8022afa..0000000000 --- a/pandora_console/godmode/servers/plugin.php +++ /dev/null @@ -1,1205 +0,0 @@ - $id_plugin]); - $preload = io_safe_output($description); - $preload = str_replace("\n", '
', $preload); - - echo $preload; - return; - } - - if ($get_list_modules_and_component_locked_plugin) { - $id_plugin = (int) get_parameter('id_plugin', 0); - - $network_components = db_get_all_rows_filter( - 'tnetwork_component', - ['id_plugin' => $id_plugin] - ); - if (empty($network_components)) { - $network_components = []; - } - - $modules = db_get_all_rows_filter( - 'tagente_modulo', - [ - 'delete_pending' => 0, - 'id_plugin' => $id_plugin, - ] - ); - if (empty($modules)) { - $modules = []; - } - - $table = null; - $table->width = '100%'; - $table->head[0] = __('Network Components'); - $table->data = []; - foreach ($network_components as $net_comp) { - $table->data[] = [$net_comp['name']]; - } - - if (!empty($table->data)) { - html_print_table($table); - - echo '
'; - } - - $table = null; - $table->width = '100%'; - $table->head[0] = __('Agent'); - $table->head[1] = __('Module'); - foreach ($modules as $mod) { - $agent_name = ''.modules_get_agentmodule_agent_name( - $mod['id_agente_modulo'] - ).''; - - - $table->data[] = [ - $agent_name, - $mod['nombre'], - ]; - } - - if (!empty($table->data)) { - html_print_table($table); - } - - return; - } -} - - -require_once $config['homedir'].'/include/functions_filemanager.php'; - -check_login(); - -if (! check_acl($config['id_user'], 0, 'PM')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access Plugin Management' - ); - include 'general/noaccess.php'; - return; -} - -enterprise_include_once('meta/include/functions_components_meta.php'); - -$view = get_parameter('view', ''); -$create = get_parameter('create', ''); -$filemanager = (bool) get_parameter('filemanager', false); -$edit_file = get_parameter('edit_file', false); -$update_file = get_parameter('update_file', false); -$plugin_command = get_parameter('plugin_command', ''); -$tab = get_parameter('tab', ''); -$deploy_plugin = get_parameter('deploy_plugin', 0); - -if ($view != '') { - $form_id = $view; - $plugin = db_get_row('tplugin', 'id', $form_id); - $form_name = $plugin['name']; - $form_description = $plugin['description']; - $form_max_timeout = $plugin['max_timeout']; - $form_max_retries = $plugin['max_retries']; - if (empty($plugin_command)) { - $form_execute = $plugin['execute']; - } else { - $form_execute = $plugin_command; - } - - $form_plugin_type = $plugin['plugin_type']; - $macros = $plugin['macros']; - $parameters = $plugin['parameters']; -} - -if ($create != '') { - $form_id = 0; - $form_name = ''; - $form_description = ''; - $form_max_timeout = 15; - $form_max_retries = 1; - $form_execute = $plugin_command; - $form_plugin_type = 0; - $form_parameters = ''; - $macros = ''; - $parameters = ''; -} - -// END LOAD VALUES -// ===================================================================== -// INIT FILEMANAGER -// ===================================================================== -if ($filemanager) { - if ($edit_file) { - $location_file = get_parameter('location_file', ''); - $filename = array_pop(explode('/', $location_file)); - $file = file_get_contents($location_file); - echo '

'.__('Edit file').' '.$filename.'

'; - // echo "" . __('Back to file explorer') . ""; - echo "
"; - // html_print_input_hidden('location_file', $locationFile); - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ""; - echo ''; - echo ''; - echo '
'.__('Edit').'
'; - echo "'; - echo '
'; - html_print_input_hidden('location_file', $location_file); - - echo __('Compatibility mode').':'; - $options = [ - 'unix' => 'Unix', - 'windows' => 'Windows', - ]; - html_print_select($options, 'compatibility', $compatibility); - echo " "; - echo '
'; - echo '
'; - } else { - if ($update_file) { - $location_file = get_parameter('location_file', ''); - $contentFile = io_safe_output(get_parameter('content_file', '')); - $compatibility = get_parameter('compatibility', 'unix'); - $is_win_compatible = strpos($contentFile, "\r\n"); - // If is win compatible and the compatibility must be unix - if ($is_win_compatible !== false && $compatibility == 'unix') { - $contentFile = str_replace("\r\n", "\n", $contentFile); - } else if ($is_win_compatible === false && $compatibility == 'windows') { - // If is unix compatible and the compatibility must be win - $contentFile = str_replace("\n", "\r\n", $contentFile); - } - - $result = file_put_contents($location_file, $contentFile); - } - - $id_plugin = (int) get_parameter('id_plugin', 0); - - // Add custom directories here - $fallback_directory = 'attachment/plugin'; - - $directory = (string) get_parameter('directory', $fallback_directory); - $directory = str_replace('\\', '/', $directory); - - // A miminal security check to avoid directory traversal - if (preg_match('/\.\./', $directory)) { - $directory = $fallback_directory; - } - - if (preg_match('/^\//', $directory)) { - $directory = $fallback_directory; - } - - if (preg_match('/^manager/', $directory)) { - $directory = $fallback_directory; - } - - $banned_directories['include'] = true; - $banned_directories['godmode'] = true; - $banned_directories['operation'] = true; - $banned_directories['reporting'] = true; - $banned_directories['general'] = true; - $banned_directories[ENTERPRISE_DIR] = true; - - if (isset($banned_directories[$directory])) { - $directory = $fallback_directory; - } - - $real_directory = realpath($config['homedir'].'/'.$directory); - - echo '

'.__('Index of %s', $directory).'

'; - - $chunck_url = '&view='.$id_plugin; - if ($id_plugin == 0) { - $chunck_url = '&create=1'; - } - - $homedir_filemanager = isset($config['homedir_filemanager']) ? $config['homedir_filemanager'] : false; - filemanager_file_explorer( - $real_directory, - $directory, - 'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&id_plugin='.$id_plugin, - $fallback_directory, - true, - false, - 'index.php?sec=gservers&sec2=godmode/servers/plugin'.$chunck_url.'&plugin_command=[FILE_FULLPATH]&id_plugin='.$id_plugin, - true, - 0775, - $homedir_filemanager - ); - } - - return; -} - -// ===================================================================== -// END FILEMANAGER -// ===================================================================== -// ===================================================================== -// SHOW THE FORM -// ===================================================================== -$sec = 'gservers'; - -if (($create != '') || ($view != '')) { - enterprise_hook('open_meta_frame'); - - if (defined('METACONSOLE')) { - components_meta_print_header(); - $sec = 'advanced'; - $management_allowed = is_management_allowed(); - if (!$management_allowed) { - ui_print_warning_message(__('To manage plugin you must activate centralized management')); - } - } else { - if ($create != '') { - ui_print_page_header( - __('Plugin registration'), - 'images/gm_servers.png', - false, - 'plugin_definition', - true - ); - } else { - ui_print_page_header( - __('Plugin update'), - 'images/gm_servers.png', - false, - 'plugin_definition', - true - ); - } - - $management_allowed = !is_central_policies_on_node(); - if (!$management_allowed) { - ui_print_warning_message( - __( - 'This console is not manager of this environment, - please manage this feature from centralized manager console (Metaconsole).' - ) - ); - } - } - - - if ($create == '') { - $plugin_id = get_parameter('view', ''); - echo "
"; - } else { - echo ""; - } - - $table = new stdClass(); - $table->width = '100%'; - $table->id = 'table-form'; - $table->class = 'databox filters'; - $table->style = []; - $table->style[0] = 'font-weight: bold'; - $table->style[2] = 'font-weight: bold'; - $table->data = []; - - $data = []; - $data[0] = __('Name'); - $data[1] = ''; - $table->colspan['plugin_name'][1] = 3; - $table->data['plugin_name'] = $data; - - $data = []; - $data[0] = __('Plugin type'); - $fields[0] = __('Standard'); - $fields[1] = __('Nagios'); - $data[1] = html_print_select($fields, 'form_plugin_type', $form_plugin_type, '', '', 0, true); - $table->data['plugin_type'] = $data; - $table->colspan['plugin_type'][1] = 3; - - $data[0] = __('Max. timeout').ui_print_help_tip(__('This value only will be applied if is minor than the server general configuration plugin timeout').'.

'.__('If you set a 0 seconds timeout, the server plugin timeout will be used'), true); - $data[1] = html_print_extended_select_for_time('form_max_timeout', $form_max_timeout, '', '', '0', false, true); - - $table->data['plugin_timeout'] = $data; - - $data = []; - $data[0] = __('Description'); - $data[1] = ''; - $table->colspan['plugin_desc'][1] = 3; - $table->data['plugin_desc'] = $data; - - // if (!defined("METACONSOLE")) { - // echo '
'; - // echo ''; - } - - enterprise_hook('close_meta_frame'); -} else { - enterprise_hook('open_meta_frame'); - - if (defined('METACONSOLE')) { - components_meta_print_header(); - $sec = 'advanced'; - $management_allowed = is_management_allowed(); - if (!$management_allowed) { - ui_print_warning_message(__('To manage plugin you must activate centralized management')); - } - - if (!$config['metaconsole_deploy_plugin_server'] && $management_allowed) { - $deploy_plugin_server = true; - - echo ''; - ?> - - '; - echo __('You need to create your own plugins with Windows compatibility'); - echo ''; - } - } - - - // Update plugin. - if (isset($_GET['update_plugin'])) { - $plugin_id = get_parameter('update_plugin', 0); - $plugin_name = get_parameter('form_name', ''); - $plugin_description = get_parameter('form_description', ''); - $plugin_max_timeout = get_parameter('form_max_timeout', ''); - $plugin_execute = get_parameter('form_execute', ''); - $plugin_plugin_type = get_parameter('form_plugin_type', '0'); - $parameters = get_parameter('form_parameters', ''); - - // Get macros - $i = 1; - $macros = []; - while (1) { - $macro = (string) get_parameter('field'.$i.'_macro'); - if ($macro == '') { - break; - } - - $desc = (string) get_parameter('field'.$i.'_desc'); - $help = (string) get_parameter('field'.$i.'_help'); - $value = (string) get_parameter('field'.$i.'_value'); - $hide = get_parameter('field'.$i.'_hide'); - - $macros[$i]['macro'] = $macro; - $macros[$i]['desc'] = $desc; - $macros[$i]['help'] = $help; - if ($hide == 1) { - $macros[$i]['value'] = io_input_password($value); - } else { - $macros[$i]['value'] = $value; - } - - $macros[$i]['hide'] = $hide; - - $i++; - } - - $macros = io_json_mb_encode($macros); - - $values = [ - 'name' => $plugin_name, - 'description' => $plugin_description, - 'max_timeout' => $plugin_max_timeout, - 'execute' => $plugin_execute, - 'plugin_type' => $plugin_plugin_type, - 'parameters' => $parameters, - 'macros' => $macros, - ]; - - $result = false; - if ($values['name'] != '' && $values['execute'] != '') { - $result = db_process_sql_update( - 'tplugin', - $values, - ['id' => $plugin_id] - ); - } - - if (! $result) { - ui_print_error_message(__('Problem updating plugin')); - } else { - ui_print_success_message(__('Plugin updated successfully')); - } - } - - // Create plugin - if (isset($_GET['create_plugin'])) { - $plugin_name = get_parameter('form_name', ''); - $plugin_description = get_parameter('form_description', ''); - $plugin_max_timeout = get_parameter('form_max_timeout', ''); - $plugin_execute = get_parameter('form_execute', ''); - $plugin_plugin_type = get_parameter('form_plugin_type', '0'); - $plugin_parameters = get_parameter('form_parameters', ''); - - // Get macros - $i = 1; - $macros = []; - while (1) { - $macro = (string) get_parameter('field'.$i.'_macro'); - if ($macro == '') { - break; - } - - $desc = (string) get_parameter('field'.$i.'_desc'); - $help = (string) get_parameter('field'.$i.'_help'); - $value = (string) get_parameter('field'.$i.'_value'); - $hide = get_parameter('field'.$i.'_hide'); - - $macros[$i]['macro'] = $macro; - $macros[$i]['desc'] = $desc; - $macros[$i]['help'] = $help; - if ($hide == 1) { - $macros[$i]['value'] = io_input_password($value); - } else { - $macros[$i]['value'] = $value; - } - - $macros[$i]['hide'] = $hide; - $i++; - } - - $macros = io_json_mb_encode($macros); - - $values = [ - 'name' => $plugin_name, - 'description' => $plugin_description, - 'max_timeout' => $plugin_max_timeout, - 'execute' => $plugin_execute, - 'plugin_type' => $plugin_plugin_type, - 'parameters' => $plugin_parameters, - 'macros' => $macros, - ]; - - $result = false; - if ($values['name'] != '' && $values['execute'] != '') { - $result = db_process_sql_insert('tplugin', $values); - } - - if (! $result) { - ui_print_error_message(__('Problem creating plugin')); - } else { - ui_print_success_message(__('Plugin created successfully')); - } - } - - if (isset($_GET['kill_plugin'])) { - // if delete alert - $plugin_id = get_parameter('kill_plugin', 0); - - $result = db_process_sql_delete('tplugin', ['id' => $plugin_id]); - - if (!is_metaconsole()) { - if (!$result) { - ui_print_error_message(__('Problem deleting plugin')); - } else { - ui_print_success_message(__('Plugin deleted successfully')); - } - } - - - if ($plugin_id != 0) { - // Delete all the modules with this plugin - $plugin_modules = db_get_all_rows_filter( - 'tagente_modulo', - ['id_plugin' => $plugin_id] - ); - - if (empty($plugin_modules)) { - $plugin_modules = []; - } - - foreach ($plugin_modules as $pm) { - modules_delete_agent_module($pm['id_agente_modulo']); - } - - if (enterprise_installed()) { - enterprise_include_once('include/functions_policies.php'); - $policies_ids = db_get_all_rows_filter('tpolicy_modules', ['id_plugin' => $plugin_id]); - foreach ($policies_ids as $policies_id) { - policies_change_delete_pending_module($policies_id['id']); - } - } - - if (is_metaconsole()) { - enterprise_include_once('include/functions_plugins.php'); - $result = plugins_delete_plugin($plugin_id); - if (!$result) { - ui_print_error_message(__('Problem deleting plugin')); - } else { - ui_print_success_message(__('Plugin deleted successfully')); - } - } - } - } - - if ($deploy_plugin) { - if (is_metaconsole()) { - enterprise_include_once('include/functions_plugins.php'); - $result = plugins_deploy_plugin($deploy_plugin); - if (!$result) { - ui_print_error_message(__('Problem deploying plugin')); - } else { - ui_print_success_message(__('Plugin deployed successfully')); - } - } - } - - if ($deploy_plugin_server) { - $setup = db_get_all_rows_in_table('tmetaconsole_setup'); - // recorremos todos los nodos. - foreach ($setup as $key => $value) { - // Obtenemos los plugins de la meta. - $all_plugin_meta = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); - // Conectamos con el nodo. - if (metaconsole_connect($value) == NOERR) { - $values = []; - // Obtenemos los plugin del nodo. - $node_plugin_server = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); - foreach ($node_plugin_server as $key2 => $plugin) { - // Comprobamos si el id esta meta y nodo al mismo tiempo. - $key_exists = array_search($plugin['id'], array_column($all_plugin_meta, 'id')); - if ($key_exists !== false) { - // Si el plugin tiene el mismo id pero diferentes datos. - if ($all_plugin_meta[$key_exists] != $plugin) { - $old_id = $plugin['id']; - $new_id = ($plugin['id'] + (1000 * $value['id'])); - - // El plugin del nodo pasa a tener otro id y otro nombre. - $plugin['id'] = $new_id; - $plugin['name'] = $plugin['name'].'_'.$value['server_name']; - $result_update = db_process_sql_update( - 'tplugin', - [ - 'id' => $new_id, - 'name' => $plugin['name'], - ], - ['id' => $old_id] - ); - - if ($result_update) { - db_process_sql_update( - 'tagente_modulo', - ['id_plugin' => $new_id], - ['id_plugin' => $old_id] - ); - - db_process_sql_update( - 'tnetwork_component', - ['id_plugin' => $new_id], - ['id_plugin' => $old_id] - ); - - db_process_sql_update( - 'tpolicy_modules', - ['id_plugin' => $new_id], - ['id_plugin' => $old_id] - ); - } - - // New plugins to insert in the metaconsole. - $values[$plugin['id']] = $plugin; - } - } else { - // Exists in the node, but does not exist in the metaconsole. - $values[$plugin['id']] = $plugin; - } - } - - // Restore to metaconsole. - metaconsole_restore_db(); - - // Insert in metaconsole. - if (!empty($values)) { - foreach ($values as $key2 => $val) { - // Insert into metaconsole. - $result_insert = db_process_sql_insert('tplugin', $val); - } - } - } - } - - $all_plugin_meta = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); - - foreach ($setup as $key => $value) { - if (metaconsole_connect($value) == NOERR) { - $all_plugin_node = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); - - $array_diff = array_diff(array_column($all_plugin_meta, 'id'), array_column($all_plugin_node, 'id')); - foreach ($array_diff as $key2 => $pluginid) { - $other = []; - $plugin_meta = $all_plugin_meta[$key2]; - - unset($plugin_meta['id']); - $other['name'] = urlencode($plugin_meta['name']); - $other['description'] = urlencode($plugin_meta['description']); - $other['max_timeout'] = $plugin_meta['max_timeout']; - $other['max_retries'] = $plugin_meta['max_retries']; - $other['execute'] = urlencode($plugin_meta['execute']); - $other['net_dst_opt'] = $plugin_meta['net_dst_opt']; - $other['net_port_opt'] = $plugin_meta['net_port_opt']; - $other['user_opt'] = $plugin_meta['user_opt']; - $other['pass_opt'] = $plugin_meta['pass_opt']; - $other['plugin_type'] = $plugin_meta['plugin_type']; - $other['macros'] = urlencode($plugin_meta['macros']); - $other['parameters'] = urlencode($plugin_meta['parameters']); - $other = implode('%7C', $other); - - $auth_token = json_decode($value['auth_token']); - $url = $value['server_url'].'include/api.php?op=set&op2=push_plugin'.'&id='.$pluginid.'&other_mode=url_encode_separator_%7C&other='.$other."&apipass=$auth_token->api_password"."&user=$auth_token->console_user&pass=$auth_token->console_password"; - $file_path = realpath($plugin_meta['execute']); - $post = ''; - if (file_exists($file_path)) { - $post = ['file' => curl_file_create($file_path)]; - } - - $curlObj = curl_init(); - curl_setopt($curlObj, CURLOPT_URL, $url); - curl_setopt($curlObj, CURLOPT_POST, 1); - curl_setopt($curlObj, CURLOPT_POSTFIELDS, $post); - curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); - - $api_result = curl_exec($curlObj); - curl_close($curlObj); - } - } - - // restore to metaconsole - metaconsole_restore_db(); - } - } - - // If not edition or insert, then list available plugins - $rows = db_get_all_rows_sql('SELECT * FROM tplugin ORDER BY name'); - - if ($rows !== false) { - if (defined('METACONSOLE')) { - echo '
'; - // } - $table->width = '100%'; - $table->class = 'databox filters'; - - if (defined('METACONSOLE')) { - $table->head[0] = __('General'); - $table->head_colspan[0] = 4; - $table->headstyle[0] = 'text-align: center'; - html_print_table($table); - } else { - echo '
'.__('General').''; - html_print_table($table); - echo '
'; - } - - $table->data = []; - - $plugin_id = get_parameter('view', 0); - - $locked = true; - - // If we have plugin id (update mode) and this plugin used by any module or component - // The command configuration will be locked - if ($plugin_id > 0) { - $modules_using_plugin = db_get_value_filter('count(*)', 'tagente_modulo', ['delete_pending' => 0, 'id_plugin' => $plugin_id]); - $components_using_plugin = db_get_value_filter('count(*)', 'tnetwork_component', ['id_plugin' => $plugin_id]); - if (($components_using_plugin + $modules_using_plugin) == 0) { - $locked = false; - } - } else { - $locked = false; - } - - $disabled = ''; - if ($locked) { - $disabled = 'readonly="readonly"'; - } - - $data = []; - $data[0] = __('Plugin command'); - $data[1] = ''; - if ($locked) { - $data[1] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf lock']); - } - - $data[1] .= ' '; - $data[1] .= html_print_image('images/file.png', true); - $data[1] .= ''; - $table->data['plugin_command'] = $data; - - $data = []; - $data[0] = __('Plug-in parameters').ui_print_help_icon('plugin_parameters', true); - $data[1] = ''; - if ($locked) { - $data[1] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf lock']); - } - - $table->data['plugin_parameters'] = $data; - - $data = []; - $data[0] = __('Command preview'); - $data[1] = '
'; - $table->data['plugin_preview'] = $data; - - $table->width = '100%'; - $table->class = 'databox filters'; - if (defined('METACONSOLE')) { - $table->head[0] = __('Command'); - $table->head_colspan[0] = 4; - $table->headstyle[0] = 'text-align: center'; - html_print_table($table); - } else { - echo '
'.__('Command').''; - html_print_table($table); - echo '
'; - } - - $data = []; - - $table->data = []; - - $macros = json_decode($macros, true); - - // The next row number is plugin_9 - $next_name_number = 9; - $i = 1; - while (1) { - // Always print at least one macro - if ((!isset($macros[$i]) || $macros[$i]['desc'] == '') && $i > 1) { - break; - } - - $macro_desc_name = 'field'.$i.'_desc'; - $macro_desc_value = ''; - $macro_help_name = 'field'.$i.'_help'; - $macro_help_value = ''; - $macro_value_name = 'field'.$i.'_value'; - $macro_value_value = ''; - $macro_name_name = 'field'.$i.'_macro'; - $macro_name = '_field'.$i.'_'; - $macro_hide_value_name = 'field'.$i.'_hide'; - $macro_hide_value_value = 0; - - if (isset($macros[$i]['desc'])) { - $macro_desc_value = $macros[$i]['desc']; - } - - if (isset($macros[$i]['help'])) { - $macro_help_value = $macros[$i]['help']; - } - - if (isset($macros[$i]['value'])) { - $macro_value_value = $macros[$i]['value']; - } - - if (isset($macros[$i]['hide'])) { - $macro_hide_value_value = $macros[$i]['hide']; - - // Decrypt hidden macros. - $macro_value_value = io_output_password($macro_value_value); - } - - $datam = []; - $datam[0] = __('Description')." ($macro_name)"; - $datam[0] .= html_print_input_hidden($macro_name_name, $macro_name, true); - $datam[1] = html_print_input_text_extended($macro_desc_name, $macro_desc_value, 'text-'.$macro_desc_name, '', 30, 255, $locked, '', "class='command_macro'", true); - if ($locked) { - $datam[1] .= html_print_image('images/lock.png', true, ['class' => 'command_macro lock']); - } - - $datam[2] = __('Default value')." ($macro_name)"; - $datam[3] = html_print_input_text_extended($macro_value_name, $macro_value_value, 'text-'.$macro_value_name, '', 30, 255, $locked, '', "class='command_component command_macro'", true); - if ($locked) { - $datam[3] .= html_print_image('images/lock.png', true, ['class' => 'command_macro lock']); - } - - $table->data['plugin_'.$next_name_number] = $datam; - - $next_name_number++; - - $table->colspan['plugin_'.$next_name_number][1] = 3; - - $datam = []; - $datam[0] = __('Hide value').ui_print_help_tip(__('This field will show up as dots like a password'), true); - $datam[1] = html_print_checkbox_extended($macro_hide_value_name, 1, $macro_hide_value_value, 0, '', ['class' => 'command_macro'], true, 'checkbox-'.$macro_hide_value_name); - - $table->data['plugin_'.$next_name_number] = $datam; - $next_name_number++; - - $table->colspan['plugin_'.$next_name_number][1] = 3; - - $datam = []; - $datam[0] = __('Help')." ($macro_name)


"; - $tadisabled = $locked === true ? ' disabled' : ''; - $datam[1] = html_print_textarea($macro_help_name, 6, 100, $macro_help_value, 'class="command_macro" style="width: 97%;"'.$tadisabled, true); - - if ($locked) { - $datam[1] .= html_print_image('images/lock.png', true, ['class' => 'command_macro lock']); - } - - $datam[1] .= '


'; - - $table->data['plugin_'.$next_name_number] = $datam; - $next_name_number++; - $i++; - } - - // Add/Delete buttons - $datam = []; - $datam[0] = ''.''.__('Add macro').''.' '.html_print_image('images/add.png', true).''; - $datam[0] .= ''; - $datam[0] .= ''; - - if (!$locked) { - $delete_macro_style = ''; - if ($i <= 2) { - $delete_macro_style = 'display:none;'; - } - - $datam[2] = ''; - - $table->colspan['plugin_action'][0] = 2; - $table->colspan['plugin_action'][2] = 2; - } else { - $table->colspan['plugin_action'][0] = 4; - } - - $table->rowstyle['plugin_action'] = 'text-align:center'; - $table->data['plugin_action'] = $datam; - - - if (defined('METACONSOLE')) { - $table->head[0] = __('Parameters macros'); - $table->head_colspan[0] = 4; - $table->headstyle[0] = 'text-align: center'; - html_print_table($table); - } else { - echo '
'.''.__('Parameters macros').ui_print_help_icon('macros', true).''; - html_print_table($table); - echo '
'; - } - - echo ''; - - echo '
'; - - if ($create != '') { - echo ""; - } else { - echo ""; - } - - echo '
'; - - if (defined('METACONSOLE')) { - echo '
'; - } else { - echo '
'; - } - - echo ''; - echo ''; - echo ''; - if ($management_allowed) { - echo "'; - } - - $color = 0; - - foreach ($rows as $row) { - if ($color == 1) { - $tdcolor = 'datos'; - $color = 0; - } else { - $tdcolor = 'datos2'; - $color = 1; - } - - echo ''; - echo "'; - echo "'; - if ($management_allowed) { - echo "'; - } - - echo ''; - } - - echo '
'.__('Name').''.__('Type').''.__('Command').'".''.__('Op.').''.'
"; - if ($management_allowed) { - echo ""; - } - - echo $row['name']; - echo '"; - if ($row['plugin_type'] == 0) { - echo __('Standard'); - } else { - echo __('Nagios'); - } - - echo ""; - echo $row['execute']; - echo '"; - - // Show it is locket - $modules_using_plugin = db_get_value_filter( - 'count(*)', - 'tagente_modulo', - [ - 'delete_pending' => 0, - 'id_plugin' => $row['id'], - ] - ); - $components_using_plugin = db_get_value_filter( - 'count(*)', - 'tnetwork_component', - ['id_plugin' => $row['id']] - ); - if (($components_using_plugin + $modules_using_plugin) > 0) { - echo ''; - html_print_image('images/lock.png'); - echo ''; - } - - echo "".html_print_image('images/config.png', true, ['title' => __('Edit')]).'  '; - echo "".html_print_image('images/cross.png', true, ['border' => '0']).''; - if (is_metaconsole()) { - echo "   ".html_print_image('images/deploy.png', true, ['title' => __('Deploy'), 'width' => '21 px']).'  '; - } - - echo '
'; - } else { - ui_print_info_message(['no_close' => true, 'message' => __('There are no plugins in the system') ]); - } - - if ($management_allowed) { - echo ""; - - echo '
'; - echo "
"; - echo ""; - echo '
'; - echo '