2006-03-27 05:37:27 +02:00
< ? php
2008-07-30 20:39:40 +02:00
2009-06-08 20:21:21 +02:00
// Pandora FMS - http://pandorafms.com
// ==================================================
2020-11-27 13:52:35 +01:00
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
2009-06-08 20:21:21 +02:00
// Please see http://pandorafms.org for full contribution list
2008-04-01 15:53:11 +02:00
// 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.
2007-03-12 18:58:52 +01:00
// Load global vars
2019-01-30 16:18:44 +01:00
check_login ();
2007-03-12 18:58:52 +01:00
2019-11-06 10:31:26 +01:00
// Take some parameters (GET).
2019-01-30 16:18:44 +01:00
$offset = ( int ) get_parameter ( 'offset' );
$group_id = ( int ) get_parameter ( 'group_id' );
$ag_group = get_parameter ( 'ag_group_refresh' , - 1 );
2010-07-19 14:01:55 +02:00
$sortField = get_parameter ( 'sort_field' );
$sort = get_parameter ( 'sort' , 'none' );
2019-01-30 16:18:44 +01:00
$recursion = ( bool ) get_parameter ( 'recursion' , false );
2015-08-04 16:40:55 +02:00
$disabled = get_parameter ( 'disabled' , 0 );
2017-10-25 16:04:05 +02:00
$os = get_parameter ( 'os' , 0 );
2009-02-04 12:20:31 +01:00
2019-01-30 16:18:44 +01:00
if ( $ag_group == - 1 ) {
$ag_group = ( int ) get_parameter ( 'ag_group' , - 1 );
}
2009-02-04 12:20:31 +01:00
2019-01-30 16:18:44 +01:00
if (( $ag_group == - 1 ) && ( $group_id != 0 )) {
$ag_group = $group_id ;
}
2009-02-04 12:20:31 +01:00
2021-03-11 15:40:23 +01:00
if ( ! check_acl (
$config [ 'id_user' ],
0 ,
'AW'
) && ! check_acl (
$config [ 'id_user' ],
0 ,
'AD'
)
) {
2019-01-30 16:18:44 +01:00
db_pandora_audit (
'ACL Violation' ,
'Trying to access agent manager'
);
include 'general/noaccess.php' ;
exit ;
2008-12-12 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_console/operation/agentes/datos_agente.php: Rewrite. Uses new
functions and better security and validation
* pandora_console/include/functions_db.php: Renamed some functions and
created agentmodule functions for consistency with documentation and to
avoid searching for and typing certain function names:
get_agentmodules is now get_agent_modules;
dame_grupo is now get_group_name;
dame_nombre_agente is now get_agent_name; get_agentmodule_agent is new;
dame_nombre_agente_agentemodulo is now get_agentmodule_agent_name;
dame_nombre_modulo_agentemodulo is now get_agentmodule_name;
dame_id_tipo_modulo_agentemodulo is now get_agentmodule_type;
dame_nombre_tipo_modulo is now get_moduletype_name; dame_nombre_grupo is
now get_group_name; get_agentmodule_count is get_agent_modules_count;
get_agentmodule_group is new; get_agent_group is new;
* pandora_console/include/functions_reporting.php,
pandora_console/include/functions.php,
pandora_console/operation/incidents/incident.php,
pandora_console/operation/users/user.php,
pandora_console/operation/users/user_edit.php,
pandora_console/operation/events/events.php,
pandora_console/operation/visual_console/index.php,
pandora_console/operation/agentes/estado_grupo.php,
pandora_console/operation/agentes/export_csv.php,
pandora_console/operation/agentes/estado_agente.php,
pandora_console/operation/agentes/estado_ultimopaquete.php,
pandora_console/operation/agentes/estado_generalagente.php,
pandora_console/operation/agentes/sla_view.php,
pandora_console/operation/agentes/exportdata.php,
pandora_console/operation/agentes/ver_agente.php,
pandora_console/operation/agentes/tactical.php,
pandora_console/operation/agentes/networkmap.php,
pandora_console/operation/messages/message.php,
pandora_console/operation/reporting/reporting_xml.php,
pandora_console/operation/reporting/reporting_viewer.php,
pandora_console/reporting/fgraph.php,
pandora_console/godmode/groups/group_list.php,
pandora_console/godmode/users/user_list.php,
pandora_console/godmode/users/configure_user.php,
pandora_console/godmode/db/db_refine.php,
pandora_console/godmode/db/db_info.php,
pandora_console/godmode/db/db_purge.php,
pandora_console/godmode/agentes/manage_config.php,
pandora_console/godmode/agentes/modificar_agente.php,
pandora_console/godmode/agentes/configurar_agente.php,
pandora_console/godmode/agentes/manage_config_remote.php,
pandora_console/godmode/modules/manage_network_components_form_network.php,
pandora_console/godmode/modules/manage_network_components_form_wmi.php,
pandora_console/godmode/reporting/reporting_builder.php,
pandora_console/godmode/reporting/map_builder.php,
pandora_console/godmode/reporting/graph_builder.php: Renamed functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1291 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-12-12 22:54:40 +01:00
}
2009-02-04 12:20:31 +01:00
2010-09-21 14:09:04 +02:00
enterprise_include_once ( 'include/functions_policies.php' );
2019-01-30 16:18:44 +01:00
require_once 'include/functions_agents.php' ;
require_once 'include/functions_users.php' ;
2010-09-21 14:09:04 +02:00
2019-01-30 16:18:44 +01:00
$search = get_parameter ( 'search' , '' );
2007-09-27 17:12:49 +02:00
2019-11-06 10:31:26 +01:00
// Prepare the tab system to the future.
2011-12-07 16:04:40 +01:00
$tab = 'view' ;
2019-11-06 10:31:26 +01:00
// Setup tab.
2021-03-11 15:40:23 +01:00
$viewtab [ 'text' ] = '<a href="index.php?sec=estado&sec2=operation/agentes/estado_agente">' . html_print_image (
'images/eye_show.png' ,
true ,
[
'title' => __ ( 'View' ),
'class' => 'invert_filter' ,
]
) . '</a>' ;
2013-06-20 11:21:28 +02:00
2013-04-10 09:57:54 +02:00
$viewtab [ 'operation' ] = true ;
2013-06-20 11:21:28 +02:00
2013-04-10 09:57:54 +02:00
$viewtab [ 'active' ] = false ;
2013-06-20 11:21:28 +02:00
2019-01-30 16:18:44 +01:00
$onheader = [ 'view' => $viewtab ];
2011-12-07 16:04:40 +01:00
2019-11-06 10:31:26 +01:00
// Header.
2021-03-11 15:40:23 +01:00
ui_print_page_header (
__ ( 'Agents defined in %s' , get_product_name ()),
'images/agent.png' ,
false ,
'' ,
true ,
$onheader
);
2007-03-12 18:58:52 +01:00
2020-03-20 12:34:58 +01:00
if ( is_central_policies_on_node ()) {
2021-03-11 15:40:23 +01:00
ui_print_warning_message (
__ ( 'This node is configured with centralized mode. To delete an agent go to metaconsole.' )
);
2020-03-20 12:34:58 +01:00
}
2019-11-06 10:31:26 +01:00
// Perform actions.
2019-01-30 16:18:44 +01:00
$agent_to_delete = ( int ) get_parameter ( 'borrar_agente' );
$enable_agent = ( int ) get_parameter ( 'enable_agent' );
$disable_agent = ( int ) get_parameter ( 'disable_agent' );
if ( $disable_agent != 0 ) {
2021-03-11 15:40:23 +01:00
$server_name = db_get_row_sql (
'select server_name from tagente where id_agente = ' . $disable_agent
);
2019-01-30 16:18:44 +01:00
} else if ( $enable_agent != 0 ) {
2021-03-11 15:40:23 +01:00
$server_name = db_get_row_sql (
'select server_name from tagente where id_agente = ' . $enable_agent
);
2017-12-04 13:50:13 +01:00
}
2013-01-14 16:11:07 +01:00
$result = null ;
if ( $agent_to_delete ) {
2019-01-30 16:18:44 +01:00
$id_agente = $agent_to_delete ;
if ( check_acl_one_of_groups (
$config [ 'id_user' ],
agents_get_all_groups_agent ( $id_agente ),
'AW'
)
) {
$id_agentes [ 0 ] = $id_agente ;
$result = agents_delete_agent ( $id_agentes );
} else {
// NO permissions.
db_pandora_audit (
'ACL Violation' ,
" Trying to delete agent \ ' " . agents_get_name ( $id_agente ) . " \ ' "
);
include 'general/noaccess.php' ;
exit ;
}
2021-03-11 15:40:23 +01:00
ui_print_result_message (
$result ,
__ ( 'Success deleted agent.' ),
__ ( 'Could not be deleted.' )
);
2019-01-30 16:18:44 +01:00
if ( enterprise_installed ()) {
2019-11-06 10:31:26 +01:00
// Check if the remote config file still exist.
2019-01-30 16:18:44 +01:00
if ( isset ( $config [ 'remote_config' ])) {
2021-03-11 15:40:23 +01:00
enterprise_include_once (
'include/functions_config_agents.php'
);
if ( enterprise_hook (
'config_agents_has_remote_configuration' ,
[ $id_agente ]
)
) {
ui_print_error_message (
__ ( 'Maybe the files conf or md5 could not be deleted' )
);
2019-01-30 16:18:44 +01:00
}
}
}
2011-08-17 16:20:45 +02:00
}
2013-02-27 10:51:48 +01:00
if ( $enable_agent ) {
2021-03-11 15:40:23 +01:00
$result = db_process_sql_update (
'tagente' ,
[ 'disabled' => 0 ],
[ 'id_agente' => $enable_agent ]
);
2020-08-28 13:56:15 +02:00
$alias = io_safe_output ( agents_get_alias ( $enable_agent ));
2019-01-30 16:18:44 +01:00
if ( $result ) {
2019-11-06 10:31:26 +01:00
// Update the agent from the metaconsole cache.
2019-01-30 16:18:44 +01:00
enterprise_include_once ( 'include/functions_agents.php' );
$values = [ 'disabled' => 0 ];
2021-03-11 15:40:23 +01:00
enterprise_hook (
'agent_update_from_cache' ,
[
$enable_agent ,
$values ,
$server_name ,
]
);
enterprise_hook (
'config_agents_update_config_token' ,
[
$enable_agent ,
'standby' ,
0 ,
]
);
db_pandora_audit (
'Agent management' ,
'Enable ' . $alias
);
2019-01-30 16:18:44 +01:00
} else {
2021-03-11 15:40:23 +01:00
db_pandora_audit (
'Agent management' ,
'Fail to enable ' . $alias
);
2019-01-30 16:18:44 +01:00
}
ui_print_result_message (
$result ,
__ ( 'Successfully enabled' ),
__ ( 'Could not be enabled' )
);
2013-01-14 16:11:07 +01:00
}
2013-02-27 10:51:48 +01:00
if ( $disable_agent ) {
2019-01-30 16:18:44 +01:00
$result = db_process_sql_update ( 'tagente' , [ 'disabled' => 1 ], [ 'id_agente' => $disable_agent ]);
2020-08-28 13:56:15 +02:00
$alias = io_safe_output ( agents_get_alias ( $disable_agent ));
2019-01-30 16:18:44 +01:00
if ( $result ) {
2019-11-06 10:31:26 +01:00
// Update the agent from the metaconsole cache.
2019-01-30 16:18:44 +01:00
enterprise_include_once ( 'include/functions_agents.php' );
$values = [ 'disabled' => 1 ];
2021-03-11 15:40:23 +01:00
enterprise_hook (
'agent_update_from_cache' ,
[
$disable_agent ,
$values ,
$server_name ,
]
);
enterprise_hook (
'config_agents_update_config_token' ,
[
$disable_agent ,
'standby' ,
1 ,
]
);
2019-01-30 16:18:44 +01:00
2021-03-11 15:40:23 +01:00
db_pandora_audit (
'Agent management' ,
'Disable ' . $alias
);
2019-01-30 16:18:44 +01:00
} else {
2021-03-11 15:40:23 +01:00
db_pandora_audit (
'Agent management' ,
'Fail to disable ' . $alias
);
2019-01-30 16:18:44 +01:00
}
ui_print_result_message (
$result ,
__ ( 'Successfully disabled' ),
__ ( 'Could not be disabled' )
);
2013-01-14 16:11:07 +01:00
}
2021-03-11 15:40:23 +01:00
echo " <table cellpadding='4' cellspacing='4' class='databox filters font_bold margin-bottom-10' width='100%'>
2013-06-20 11:21:28 +02:00
< tr > " ;
echo " <form method='post'
2012-04-24 Dario Rodriguez <dario.rodriguez@artica.es>
* operation/agentes/estado_agente.php,
operation/agentes/ver_agente.php,
operation/menu.php,
godmode/agentes/agent_template.php,
godmode/agentes/fields_manager.php,
godmode/agentes/agent_conf_gis.php,
godmode/agentes/module_manager.php,
godmode/agentes/modificar_agente.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/configure_field.php,
godmode/agentes/planned_downtime.php,
godmode/agentes/agent_manager.php,
godmode/menu.php: Fixed some problems with links and new menu structure.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6127 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-04-24 12:02:06 +02:00
action = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente' > " ;
2007-03-02 18:56:07 +01:00
2019-01-30 16:18:44 +01:00
echo '<td>' ;
2013-05-23 17:42:32 +02:00
2019-01-30 16:18:44 +01:00
echo __ ( 'Group' ) . ' ' ;
2011-07-13 18:39:35 +02:00
$own_info = get_user_info ( $config [ 'id_user' ]);
2021-03-11 15:40:23 +01:00
if ( ! $own_info [ 'is_admin' ] && ! check_acl (
$config [ 'id_user' ],
0 ,
'AR'
) && ! check_acl ( $config [ 'id_user' ], 0 , 'AW' )
) {
2019-01-30 16:18:44 +01:00
$return_all_group = false ;
} else {
$return_all_group = true ;
}
2020-10-02 14:31:41 +02:00
echo '<div class="w250px inline">' ;
2021-03-11 15:40:23 +01:00
html_print_select_groups (
false ,
'AR' ,
$return_all_group ,
'ag_group' ,
$ag_group ,
'this.form.submit();' ,
'' ,
0 ,
false ,
false ,
true ,
'' ,
false
);
2020-10-02 14:31:41 +02:00
echo '</div>' ;
2019-01-30 16:18:44 +01:00
echo '<td>' ;
echo __ ( 'Show Agents' ) . ' ' ;
$fields = [
2 => __ ( 'Everyone' ),
1 => __ ( 'Only disabled' ),
0 => __ ( 'Only enabled' ),
];
2021-03-11 15:40:23 +01:00
html_print_select (
$fields ,
'disabled' ,
$disabled ,
'this.form.submit()'
);
2019-01-30 16:18:44 +01:00
echo '</td>' ;
echo '<td>' ;
echo __ ( 'Operative System' ) . ' ' ;
2017-10-25 16:04:05 +02:00
2021-03-11 15:40:23 +01:00
$pre_fields = db_get_all_rows_sql (
'select distinct(tagente.id_os),tconfig_os.name from tagente,tconfig_os where tagente.id_os = tconfig_os.id_os'
);
2019-01-30 16:18:44 +01:00
$fields = [];
2017-10-25 16:04:05 +02:00
foreach ( $pre_fields as $key => $value ) {
2019-01-30 16:18:44 +01:00
$fields [ $value [ 'id_os' ]] = $value [ 'name' ];
2017-10-25 16:04:05 +02:00
}
2019-01-30 16:18:44 +01:00
html_print_select ( $fields , 'os' , $os , 'this.form.submit()' , 'All' , 0 );
2017-10-25 16:04:05 +02:00
2019-01-30 16:18:44 +01:00
echo '</td>' ;
2017-10-25 16:04:05 +02:00
2019-01-30 16:18:44 +01:00
echo '<td>' ;
echo __ ( 'Recursion' ) . ' ' ;
2021-03-11 15:40:23 +01:00
html_print_checkbox (
'recursion' ,
1 ,
$recursion ,
false ,
false ,
'this.form.submit()'
);
2008-01-10 17:40:00 +01:00
2019-01-30 16:18:44 +01:00
echo '</td><td>' ;
echo __ ( 'Search' ) . ' ' ;
html_print_input_text ( 'search' , $search , '' , 12 );
2008-01-10 17:40:00 +01:00
2021-03-11 15:40:23 +01:00
echo ui_print_help_tip (
__ ( 'Search filter by alias, name, description, IP address or custom fields content' ),
true
);
2017-10-25 16:04:05 +02:00
2019-01-30 16:18:44 +01:00
echo '</td><td>' ;
2010-05-25 23:38:57 +02:00
echo " <input name='srcbutton' type='submit' class='sub search' value=' " . __ ( 'Search' ) . " '> " ;
2019-01-30 16:18:44 +01:00
echo '</form>' ;
echo '<td>' ;
echo '</tr></table>' ;
$order_collation = '' ;
switch ( $config [ 'dbtype' ]) {
case 'mysql' :
$order_collation = '' ;
$order_collation = 'COLLATE utf8_general_ci' ;
break ;
case 'postgresql' :
case 'oracle' :
$order_collation = '' ;
break ;
2019-11-06 10:31:26 +01:00
default :
// Default.
break ;
2014-07-24 Miguel de Dios <miguel.dedios@artica.es>
* operation/snmpconsole/snmp_view.php,
operation/events/events_list.php, operation/incidents/incident.php,
extensions/files_repo.php,
extensions/files_repo/sql/files_repo.postgreSQL.sql,
extensions/files_repo/functions_files_repo.php,
extensions/files_repo/files_repo_list.php,
godmode/agentes/modificar_agente.php,
godmode/snmpconsole/snmp_alert.php, godmode/db/db_info.php,
include/functions_graph.php, include/functions_db.php,
include/db/postgresql.php, include/db/oracle.php,
include/db/mysql.php, include/functions_update_manager.php,
include/functions_events.php, include/graphs/functions_flot.php,
include/graphs/fgraph.php: tiny fixes for the improve the support of
postgreSQL databases.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10354 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2014-07-24 18:02:06 +02:00
}
2019-04-05 13:18:38 +02:00
$selected = true ;
$selectNameUp = false ;
$selectNameDown = false ;
$selectOsUp = false ;
$selectOsDown = false ;
$selectGroupUp = false ;
$selectGroupDown = false ;
2010-07-19 14:01:55 +02:00
switch ( $sortField ) {
2019-01-30 16:18:44 +01:00
case 'remote' :
switch ( $sort ) {
case 'up' :
$selectRemoteUp = $selected ;
$order = [
'field' => 'remote ' ,
'field2' => 'nombre ' . $order_collation ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectRemoteDown = $selected ;
$order = [
'field' => 'remote ' ,
'field2' => 'nombre ' . $order_collation ,
'order' => 'DESC' ,
];
break ;
2019-11-06 10:31:26 +01:00
default :
// Default.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
case 'name' :
switch ( $sort ) {
case 'up' :
$selectNameUp = $selected ;
$order = [
'field' => 'alias ' . $order_collation ,
'field2' => 'alias ' . $order_collation ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectNameDown = $selected ;
$order = [
'field' => 'alias ' . $order_collation ,
'field2' => 'alias ' . $order_collation ,
'order' => 'DESC' ,
];
break ;
2019-11-06 10:31:26 +01:00
default :
// Default.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
case 'os' :
switch ( $sort ) {
case 'up' :
$selectOsUp = $selected ;
$order = [
'field' => 'id_os' ,
'field2' => 'alias ' . $order_collation ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectOsDown = $selected ;
$order = [
'field' => 'id_os' ,
'field2' => 'alias ' . $order_collation ,
'order' => 'DESC' ,
];
break ;
2019-11-06 10:31:26 +01:00
default :
// Default.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
case 'group' :
switch ( $sort ) {
case 'up' :
$selectGroupUp = $selected ;
$order = [
'field' => 'id_grupo' ,
'field2' => 'alias ' . $order_collation ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectGroupDown = $selected ;
$order = [
'field' => 'id_grupo' ,
'field2' => 'alias ' . $order_collation ,
'order' => 'DESC' ,
];
break ;
2019-11-06 10:31:26 +01:00
default :
// Default.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
default :
$selectNameUp = $selected ;
$selectNameDown = '' ;
$selectOsUp = '' ;
$selectOsDown = '' ;
$selectGroupUp = '' ;
$selectGroupDown = '' ;
$order = [
'field' => 'alias ' . $order_collation ,
'field2' => 'alias ' . $order_collation ,
'order' => 'ASC' ,
];
break ;
2010-07-19 14:01:55 +02:00
}
2009-02-04 12:20:31 +01:00
$search_sql = '' ;
2019-01-30 16:18:44 +01:00
if ( $search != '' ) {
$sql = " SELECT DISTINCT taddress_agent.id_agent FROM taddress
2016-08-31 15:34:05 +02:00
INNER JOIN taddress_agent ON
taddress . id_a = taddress_agent . id_a
WHERE taddress . ip LIKE '%$search%' " ;
2019-01-30 16:18:44 +01:00
$id = db_get_all_rows_sql ( $sql );
if ( $id != '' ) {
$aux = $id [ 0 ][ 'id_agent' ];
$search_sql = ' AND ( LOWER(nombre) ' . $order_collation . "
2017-01-31 11:42:12 +01:00
LIKE LOWER ( '%$search%' ) OR tagente . id_agente = $aux " ;
2019-01-30 16:18:44 +01:00
if ( count ( $id ) >= 2 ) {
for ( $i = 1 ; $i < count ( $id ); $i ++ ) {
$aux = $id [ $i ][ 'id_agent' ];
$search_sql .= " OR tagente.id_agente = $aux " ;
}
}
$search_sql .= ')' ;
} else {
$search_sql = ' AND ( nombre ' . $order_collation . "
LIKE LOWER ( '%$search%' ) OR alias " . $order_collation . "
LIKE LOWER ( '%$search%' ) OR comentarios " . $order_collation . " LIKE LOWER ( '%$search%' )
2017-10-25 16:04:05 +02:00
OR EXISTS ( SELECT * FROM tagent_custom_data
WHERE id_agent = id_agente AND description LIKE '%$search%' )) " ;
2019-01-30 16:18:44 +01:00
}
2008-01-10 17:40:00 +01:00
}
2019-01-30 16:18:44 +01:00
if ( $disabled == 1 ) {
$search_sql .= ' AND disabled = ' . $disabled . $search_sql ;
} else {
if ( $disabled == 0 ) {
$search_sql .= ' AND disabled = 0' . $search_sql ;
}
2015-01-12 16:20:07 +01:00
}
2019-01-30 16:18:44 +01:00
if ( $os != 0 ) {
$search_sql .= ' AND id_os = ' . $os ;
2017-10-25 16:04:05 +02:00
}
2019-01-30 16:18:44 +01:00
$user_groups_to_sql = '' ;
2019-11-06 10:31:26 +01:00
// Show only selected groups.
2010-04-22 18:51:23 +02:00
if ( $ag_group > 0 ) {
2019-01-30 16:18:44 +01:00
$ag_groups = [];
$ag_groups = ( array ) $ag_group ;
if ( $recursion ) {
2020-10-21 11:38:57 +02:00
$ag_groups = groups_get_children_ids ( $ag_group , true );
2019-01-30 16:18:44 +01:00
}
$user_groups_to_sql = implode ( ',' , $ag_groups );
2018-08-20 11:38:01 +02:00
} else {
2019-11-06 10:31:26 +01:00
// Concatenate AW and AD permisions to get all the possible groups where the user can manage.
2019-01-30 16:18:44 +01:00
$user_groupsAW = users_get_groups ( $config [ 'id_user' ], 'AW' );
$user_groupsAD = users_get_groups ( $config [ 'id_user' ], 'AD' );
2018-08-20 11:38:01 +02:00
2019-01-30 16:18:44 +01:00
$user_groups = ( $user_groupsAW + $user_groupsAD );
$user_groups_to_sql = implode ( ',' , array_keys ( $user_groups ));
2008-01-10 17:40:00 +01:00
}
2019-01-30 16:18:44 +01:00
$sql = sprintf (
' SELECT COUNT ( DISTINCT ( tagente . id_agente ))
2018-08-20 11:38:01 +02:00
FROM tagente LEFT JOIN tagent_secondary_group tasg
ON tagente . id_agente = tasg . id_agent
WHERE ( tagente . id_grupo IN ( % s ) OR tasg . id_group IN ( % s ))
% s ' ,
2019-01-30 16:18:44 +01:00
$user_groups_to_sql ,
$user_groups_to_sql ,
$search_sql
);
2018-08-20 11:38:01 +02:00
2019-01-30 16:18:44 +01:00
$total_agents = db_get_sql ( $sql );
2018-08-20 11:38:01 +02:00
2019-01-30 16:18:44 +01:00
$sql = sprintf (
' SELECT *
2018-08-20 11:38:01 +02:00
FROM tagente LEFT JOIN tagent_secondary_group tasg
ON tagente . id_agente = tasg . id_agent
WHERE ( tagente . id_grupo IN ( % s ) OR tasg . id_group IN ( % s ))
% s
2018-08-20 12:02:34 +02:00
GROUP BY tagente . id_agente
2018-08-20 11:38:01 +02:00
ORDER BY % s % s , % s % s
LIMIT % d , % d ' ,
2019-01-30 16:18:44 +01:00
$user_groups_to_sql ,
$user_groups_to_sql ,
$search_sql ,
$order [ 'field' ],
$order [ 'order' ],
$order [ 'field2' ],
$order [ 'order' ],
$offset ,
$config [ 'block_size' ]
);
$agents = db_get_all_rows_sql ( $sql );
2007-03-02 18:56:07 +01:00
2019-11-06 10:31:26 +01:00
// Delete rnum row generated by oracle_recode_query() function.
2011-04-11 19:05:20 +02:00
if (( $config [ 'dbtype' ] == 'oracle' ) && ( $agents !== false )) {
2019-01-30 16:18:44 +01:00
for ( $i = 0 ; $i < count ( $agents ); $i ++ ) {
unset ( $agents [ $i ][ 'rnum' ]);
}
2011-04-11 19:05:20 +02:00
}
2019-11-06 10:31:26 +01:00
// Prepare pagination.
2019-01-30 16:18:44 +01:00
ui_pagination ( $total_agents , " index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id= $ag_group &recursion= $recursion &search= $search &sort_field= $sortField &sort= $sort &disabled= $disabled &os= $os " , $offset );
2007-03-12 18:58:52 +01:00
2009-02-04 12:20:31 +01:00
if ( $agents !== false ) {
2019-04-05 13:18:38 +02:00
// Urls to sort the table.
2019-11-06 10:31:26 +01:00
if ( $config [ 'language' ] == 'ja'
|| $config [ 'language' ] == 'zh_CN'
|| $own_info [ 'language' ] == 'ja'
|| $own_info [ 'language' ] == 'zh_CN'
) {
// Adds a custom font size for Japanese and Chinese language.
$custom_font_size = 'custom_font_size' ;
2019-08-06 14:35:15 +02:00
}
2019-04-05 13:18:38 +02:00
$url_up_agente = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=name&sort=up&disabled=$disabled' ;
$url_down_agente = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=name&sort=down&disabled=$disabled' ;
$url_up_remote = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=remote&sort=up&disabled=$disabled' ;
$url_down_remote = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=remote&sort=down&disabled=$disabled' ;
$url_up_os = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=os&sort=up&disabled=$disabled' ;
$url_down_os = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=os&sort=down&disabled=$disabled' ;
$url_up_group = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=group&sort=up&disabled=$disabled' ;
$url_down_group = 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=' . $ag_group . '&recursion=' . $recursion . '&search=' . $search . '&os=' . $os . '&offset=' . $offset . '&sort_field=group&sort=down&disabled=$disabled' ;
2019-03-27 17:03:55 +01:00
echo " <table cellpadding='0' id='agent_list' cellspacing='0' width='100%' class='info_table'> " ;
2019-04-02 13:42:30 +02:00
echo '<thead><tr>' ;
2019-04-05 13:18:38 +02:00
echo '<th>' . __ ( 'Agent name' ) . ui_get_sorting_arrows ( $url_up_agente , $url_down_agente , $selectNameUp , $selectNameDown ) . '</th>' ;
echo " <th title=' " . __ ( 'Remote agent configuration' ) . " '> " . __ ( 'R' ) . ui_get_sorting_arrows ( $url_up_remote , $url_down_remote , $selectRemoteUp , $selectRemoteDown ) . '</th>' ;
echo '<th>' . __ ( 'OS' ) . ui_get_sorting_arrows ( $url_up_os , $url_down_os , $selectOsUp , $selectOsDown ) . '</th>' ;
2019-01-30 16:18:44 +01:00
echo '<th>' . __ ( 'Type' ) . '</th>' ;
2019-04-05 13:18:38 +02:00
echo '<th>' . __ ( 'Group' ) . ui_get_sorting_arrows ( $url_up_group , $url_down_group , $selectGroupUp , $selectGroupDown ) . '</th>' ;
2019-01-30 16:18:44 +01:00
echo '<th>' . __ ( 'Description' ) . '</th>' ;
2021-03-11 15:40:23 +01:00
echo " <th class='context_help_body'> " . __ ( 'Actions' ) . '</th>' ;
2019-04-02 13:42:30 +02:00
echo '</tr></thead>' ;
2019-01-30 16:18:44 +01:00
$color = 1 ;
$rowPair = true ;
$iterator = 0 ;
foreach ( $agents as $agent ) {
2019-11-06 10:31:26 +01:00
// Begin Update tagente.remote 0/1 with remote agent function return.
2021-03-11 15:40:23 +01:00
if ( enterprise_hook (
'config_agents_has_remote_configuration' ,
[ $agent [ 'id_agente' ]]
)
) {
db_process_sql_update (
'tagente' ,
[ 'remote' => 1 ],
'id_agente = ' . $agent [ 'id_agente' ] . ''
);
2019-01-30 16:18:44 +01:00
} else {
db_process_sql_update ( 'tagente' , [ 'remote' => 0 ], 'id_agente = ' . $agent [ 'id_agente' ] . '' );
}
2019-11-06 10:31:26 +01:00
// End Update tagente.remote 0/1 with remote agent function return.
2021-03-11 15:40:23 +01:00
$all_groups = agents_get_all_groups_agent (
$agent [ 'id_agente' ],
$agent [ 'id_grupo' ]
);
$check_aw = check_acl_one_of_groups (
$config [ 'id_user' ],
$all_groups ,
'AW'
);
$check_ad = check_acl_one_of_groups (
$config [ 'id_user' ],
$all_groups ,
'AD'
);
2019-01-30 16:18:44 +01:00
$cluster = db_get_row_sql ( 'select id from tcluster where id_agent = ' . $agent [ 'id_agente' ]);
2019-11-06 10:31:26 +01:00
// Do not show the agent if there is not enough permissions.
2019-01-30 16:18:44 +01:00
if ( ! $check_aw && ! $check_ad ) {
continue ;
}
if ( $color == 1 ) {
$tdcolor = 'datos' ;
$color = 0 ;
} else {
$tdcolor = 'datos2' ;
$color = 1 ;
}
if ( $rowPair ) {
$rowclass = 'rowPair' ;
} else {
$rowclass = 'rowOdd' ;
}
$rowPair = ! $rowPair ;
$iterator ++ ;
2019-11-06 10:31:26 +01:00
// Agent name.
2019-01-30 16:18:44 +01:00
echo " <tr class=' $rowclass '><td class=' $tdcolor ' width='40%'> " ;
if ( $agent [ 'disabled' ]) {
echo '<em>' ;
}
echo '<span class="left">' ;
echo '<strong>' ;
if ( $check_aw ) {
$main_tab = 'main' ;
} else {
$main_tab = 'module' ;
}
if ( $agent [ 'alias' ] == '' ) {
$agent [ 'alias' ] = $agent [ 'nombre' ];
}
2020-05-22 12:14:01 +02:00
if ( $agent [ 'id_os' ] == CLUSTER_OS_ID ) {
if ( enterprise_installed ()) {
$cluster = PandoraFMS\Enterprise\Cluster :: loadFromAgentId (
$agent [ 'id_agente' ]
);
$url = 'index.php?sec=reporting&sec2=' . ENTERPRISE_DIR ;
$url .= '/operation/cluster/cluster' ;
$url = ui_get_full_url (
$url . '&op=update&id=' . $cluster -> id ()
);
2020-12-10 12:06:56 +01:00
echo '<a href="' . $url . '">' . ui_print_truncate_text ( $agent [ 'alias' ], 'agent_medium' ) . '</a>' ;
2020-05-22 12:14:01 +02:00
}
2019-01-30 16:18:44 +01:00
} else {
echo '<a alt =' . $agent [ 'nombre' ] . " href='index.php?sec=gagente&
2013-01-14 16:11:07 +01:00
sec2 = godmode / agentes / configurar_agente & tab = $main_tab &
2020-12-10 12:06:56 +01:00
id_agente = " . $agent['id_agente'] . " '>".' < span class = " '. $custom_font_size .' title = " '.$agent[' nombre '].' " >'.ui_print_truncate_text( $agent['alias'] , 'agent_medium').'</span>'.'</a>';
2019-01-30 16:18:44 +01:00
}
echo '</strong>' ;
2017-09-04 10:26:30 +02:00
2019-01-30 16:18:44 +01:00
$in_planned_downtime = db_get_sql (
' SELECT executed FROM tplanned_downtime
2017-10-18 11:15:51 +02:00
INNER JOIN tplanned_downtime_agents ON tplanned_downtime . id = tplanned_downtime_agents . id_downtime
2019-01-30 16:18:44 +01:00
WHERE tplanned_downtime_agents . id_agent = '.$agent[' id_agente '].' AND tplanned_downtime . executed = 1 '
);
if ( $agent [ 'disabled' ]) {
ui_print_help_tip ( __ ( 'Disabled' ));
if ( ! $in_planned_downtime ) {
echo '</em>' ;
}
}
if ( $agent [ 'quiet' ]) {
echo ' ' ;
2021-03-11 15:40:23 +01:00
html_print_image (
'images/dot_blue.png' ,
false ,
[
'border' => '0' ,
'title' => __ ( 'Quiet' ),
'alt' => '' ,
]
);
2019-01-30 16:18:44 +01:00
}
if ( $in_planned_downtime ) {
2021-03-11 15:40:23 +01:00
ui_print_help_tip (
__ ( 'Agent in planned downtime' ),
false ,
$config [ 'image' ][ 'minireloj_16' ]
);
2019-01-30 16:18:44 +01:00
echo '</em>' ;
}
2021-03-16 13:12:03 +01:00
echo '</span><div class="left actions clear_left" style=" visibility: hidden">' ;
2019-01-30 16:18:44 +01:00
if ( $check_aw ) {
2020-05-22 12:14:01 +02:00
if ( $agent [ 'id_os' ] == CLUSTER_OS_ID ) {
if ( enterprise_installed ()) {
$cluster = PandoraFMS\Enterprise\Cluster :: loadFromAgentId (
$agent [ 'id_agente' ]
);
$url = 'index.php?sec=reporting&sec2=' . ENTERPRISE_DIR ;
$url .= '/operation/cluster/cluster' ;
$url = ui_get_full_url (
$url . '&op=update&id=' . $cluster -> id ()
);
echo '<a href="' . $url . '">' . __ ( 'Edit' ) . '</a>' ;
2020-05-22 13:13:19 +02:00
echo ' | ' ;
2020-05-22 12:14:01 +02:00
}
2019-01-30 16:18:44 +01:00
} else {
echo ' < a href = " index.php?sec=gagente&
2018-03-19 10:05:29 +01:00
sec2 = godmode / agentes / configurar_agente & tab = main &
2019-01-30 16:18:44 +01:00
id_agente = '.$agent[' id_agente '].' " >'.__('Edit').'</a>';
echo ' | ' ;
}
}
if ( $agent [ 'id_os' ] != 100 ) {
echo ' < a href = " index.php?sec=gagente&
2009-02-04 12:20:31 +01:00
sec2 = godmode / agentes / configurar_agente & tab = module &
2019-01-30 16:18:44 +01:00
id_agente = '.$agent[' id_agente '].' " >'.__('Modules').'</a>';
echo ' | ' ;
}
echo ' < a href = " index.php?sec=gagente&
2009-02-04 12:20:31 +01:00
sec2 = godmode / agentes / configurar_agente & tab = alert &
2019-01-30 16:18:44 +01:00
id_agente = '.$agent[' id_agente '].' " >'.__('Alerts').'</a>';
echo ' | ' ;
2020-05-22 12:14:01 +02:00
if ( $agent [ 'id_os' ] == CLUSTER_OS_ID ) {
if ( enterprise_installed ()) {
$cluster = PandoraFMS\Enterprise\Cluster :: loadFromAgentId (
$agent [ 'id_agente' ]
);
$url = 'index.php?sec=reporting&sec2=' . ENTERPRISE_DIR ;
$url .= '/operation/cluster/cluster' ;
$url = ui_get_full_url (
$url . '&op=view&id=' . $cluster -> id ()
);
echo '<a href="' . $url . '">' . __ ( 'View' ) . '</a>' ;
}
2019-01-30 16:18:44 +01:00
} else {
echo ' < a href = " index.php?sec=estado
2009-02-04 12:20:31 +01:00
& sec2 = operation / agentes / ver_agente
2019-01-30 16:18:44 +01:00
& id_agente = '.$agent[' id_agente '].' " >'.__('View').'</a>';
}
echo '</div>' ;
echo '</td>' ;
echo " <td align='left' class=' $tdcolor '> " ;
// Has remote configuration ?
if ( enterprise_installed ()) {
enterprise_include_once ( 'include/functions_config_agents.php' );
if ( enterprise_hook ( 'config_agents_has_remote_configuration' , [ $agent [ 'id_agente' ]])) {
echo " <a href='index.php? " . 'sec=gagente&' . 'sec2=godmode/agentes/configurar_agente&' . 'tab=remote_configuration&' . 'id_agente=' . $agent [ 'id_agente' ] . " &disk_conf=1'> " ;
2021-03-11 15:40:23 +01:00
echo html_print_image (
'images/application_edit.png' ,
true ,
[
'align' => 'middle' ,
'title' => __ ( 'Edit remote config' ),
'class' => 'invert_filter' ,
]
);
2019-01-30 16:18:44 +01:00
echo '</a>' ;
}
}
echo '</td>' ;
2019-11-06 10:31:26 +01:00
// Operating System icon.
2019-01-30 16:18:44 +01:00
echo " <td class=' $tdcolor ' align='left' valign='middle'> " ;
ui_print_os_icon ( $agent [ 'id_os' ], false );
echo '</td>' ;
2019-11-06 10:31:26 +01:00
// Type agent (Networt, Software or Satellite).
2019-01-30 16:18:44 +01:00
echo " <td class=' $tdcolor ' align='left' valign='middle'> " ;
echo ui_print_type_agent_icon (
$agent [ 'id_os' ],
$agent [ 'ultimo_contacto_remoto' ],
$agent [ 'ultimo_contacto' ],
$agent [ 'remote' ],
$agent [ 'agent_version' ]
);
echo '</td>' ;
2019-11-06 10:31:26 +01:00
// Group icon and name.
2019-01-30 16:18:44 +01:00
echo " <td class=' $tdcolor ' align='left' valign='middle'> " . ui_print_group_icon ( $agent [ 'id_grupo' ], true ) . '</td>' ;
2019-11-06 10:31:26 +01:00
// Description.
echo " <td class=' " . $tdcolor . " f9'><span class=' " . $custom_font_size . " '> " . ui_print_truncate_text ( $agent [ 'comentarios' ], 'description' , true , true , true , '[…]' ) . '</span></td>' ;
2019-01-30 16:18:44 +01:00
// Action
// When there is only one element in page it's necesary go back page.
if (( count ( $agents ) == 1 ) && ( $offset >= $config [ 'block_size' ])) {
$offsetArg = ( $offset - $config [ 'block_size' ]);
} else {
$offsetArg = $offset ;
}
2021-03-11 15:40:23 +01:00
echo " <td class=' $tdcolor action_buttons' align='left' width=7% valign='middle'> " ;
2019-01-30 16:18:44 +01:00
if ( $agent [ 'disabled' ]) {
echo " <a href='index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&
enable_agent = " . $agent['id_agente'] . " & group_id = $ag_group & recursion = $recursion & search = $search & offset = $offsetArg & sort_field = $sortField & sort = $sort & disabled = $disabled ' " ;
if ( $agent [ 'id_os' ] != 100 ) {
echo '>' ;
} else {
echo ' onClick="if (!confirm(\' ' . __ ( 'You are going to enable a cluster agent. Are you sure?' ) . '\')) return false;">' ;
}
echo html_print_image ( 'images/lightbulb_off.png' , true , [ 'alt' => __ ( 'Enable agent' ), 'title' => __ ( 'Enable agent' )]) . '</a>' ;
} else {
echo " <a href='index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&
disable_agent = " . $agent['id_agente'] . " & group_id = $ag_group & recursion = $recursion & search = $search & offset = $offsetArg & sort_field = $sortField & sort = $sort & disabled = $disabled ' " ;
if ( $agent [ 'id_os' ] != 100 ) {
echo '>' ;
} else {
echo ' onClick="if (!confirm(\' ' . __ ( 'You are going to disable a cluster agent. Are you sure?' ) . '\')) return false;">' ;
}
2021-03-11 15:40:23 +01:00
echo html_print_image ( 'images/lightbulb.png' , true , [ 'alt' => __ ( 'Disable agent' ), 'title' => __ ( 'Disable agent' ), 'class' => 'invert_filter' ]) . '</a>' ;
2019-01-30 16:18:44 +01:00
}
2020-03-20 12:34:58 +01:00
if ( $check_aw && ! is_central_policies_on_node ()) {
2019-04-02 13:42:30 +02:00
echo " <a href='index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&
2019-01-30 16:18:44 +01:00
borrar_agente = " . $agent['id_agente'] . " & group_id = $ag_group & recursion = $recursion & search = $search & offset = $offsetArg & sort_field = $sortField & sort = $sort & disabled = $disabled ' " ;
if ( $agent [ 'id_os' ] != 100 ) {
echo ' onClick="if (!confirm(\' ' . __ ( 'Are you sure?' ) . '\')) return false;">' ;
} else {
echo ' onClick="if (!confirm(\' ' . __ ( 'WARNING! - You are going to delete a cluster agent. Are you sure?' ) . '\')) return false;">' ;
}
2021-03-11 15:40:23 +01:00
echo html_print_image ( 'images/cross.png' , true , [ 'border' => '0' , 'class' => 'invert_filter' ]) . '</a>' ;
2019-01-30 16:18:44 +01:00
}
echo '</td>' ;
}
echo '</table>' ;
2019-03-20 18:30:52 +01:00
ui_pagination ( $total_agents , " index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id= $ag_group &recursion= $recursion &search= $search &sort_field= $sortField &sort= $sort &disabled= $disabled &os= $os " , $offset );
2019-01-30 16:18:44 +01:00
echo " <table width='100%'><tr><td align='right'> " ;
} else {
ui_print_info_message ([ 'no_close' => true , 'message' => __ ( 'There are no defined agents' ) ]);
2007-04-21 18:14:11 +02:00
}
2007-04-11 05:12:48 +02:00
2019-01-30 16:18:44 +01:00
if ( check_acl ( $config [ 'id_user' ], 0 , 'AW' )) {
2019-11-06 10:31:26 +01:00
// Create agent button.
2021-03-11 15:40:23 +01:00
echo '<div class="action-buttons">' ;
2019-01-30 16:18:44 +01:00
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente">' ;
html_print_submit_button (
__ ( 'Create agent' ),
'crt-2' ,
false ,
'class="sub next"'
);
echo '</form>' ;
echo '</div>' ;
2013-01-14 16:11:07 +01:00
}
2019-01-30 16:18:44 +01:00
echo '</td></tr></table>' ;
2006-10-07 13:52:52 +02:00
?>
2009-02-04 12:20:31 +01:00
< script type = " text/javascript " >
2019-01-30 16:18:44 +01:00
$ ( document ) . ready ( function () {
$ ( " table#agent_list tr " ) . hover ( function () {
$ ( " .actions " , this ) . css ( " visibility " , " " );
},
function () {
$ ( " .actions " , this ) . css ( " visibility " , " hidden " );
});
$ ( " #ag_group " ) . click (
function () {
$ ( this ) . css ( " width " , " auto " );
$ ( this ) . css ( " min-width " , " 100px " );
});
$ ( " #ag_group " ) . blur ( function () {
$ ( this ) . css ( " width " , " 100px " );
});
});
2009-02-04 12:20:31 +01:00
</ script >